From: <svn...@op...> - 2009-06-25 14:09:02
|
Author: bellmich Date: Thu Jun 25 16:02:43 2009 New Revision: 1118 URL: http://libsyncml.opensync.org/changeset/1118 Log: migrated SmlDevInf to GObject style The tests are not complete but the old tests pass now. Added: trunk/libsyncml/dev_inf_api/glib_mkenums.sh trunk/libsyncml/dev_inf_api/sml_dev_inf.c trunk/libsyncml/dev_inf_api/sml_dev_inf.h trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.c trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.c.tmpl trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.h trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.h.tmpl trunk/tests/check_dev_inf.c Modified: trunk/libsyncml/CMakeLists.txt trunk/libsyncml/data_sync_api/data_sync.c trunk/libsyncml/data_sync_api/data_sync_devinf.c trunk/libsyncml/dev_inf_api/sml_dev_inf_data_store.c trunk/libsyncml/objects/sml_devinf_obj.c trunk/libsyncml/parser/sml_xml_assm.c trunk/libsyncml/parser/sml_xml_parse.c trunk/libsyncml/sml_defines.h trunk/libsyncml/sml_devinf.c trunk/libsyncml/sml_devinf.h trunk/libsyncml/sml_devinf_internals.h trunk/libsyncml/syncml.h trunk/tests/CMakeLists.txt trunk/tests/check_devinf.c trunk/tests/check_sync.c trunk/tests/check_xml_assembler.c trunk/tests/check_xml_parser.c trunk/tools/syncml-ds-tool.c Modified: trunk/libsyncml/CMakeLists.txt ============================================================================== --- trunk/libsyncml/CMakeLists.txt Wed Jun 24 11:54:05 2009 (r1117) +++ trunk/libsyncml/CMakeLists.txt Thu Jun 25 16:02:43 2009 (r1118) @@ -33,11 +33,13 @@ parser/sml_wbxml.c parser/sml_xml_assm.c parser/sml_xml_parse.c + dev_inf_api/sml_dev_inf_enum_types.c dev_inf_api/sml_dev_inf_content_type.c dev_inf_api/sml_dev_inf_prop_param.c dev_inf_api/sml_dev_inf_property.c dev_inf_api/sml_dev_inf_ctcap.c dev_inf_api/sml_dev_inf_data_store.c + dev_inf_api/sml_dev_inf.c ) IF ( ENABLE_OBEX ) @@ -98,11 +100,13 @@ ## install header files of DevInf API INSTALL( FILES + dev_inf_api/sml_dev_inf_enum_types.h dev_inf_api/sml_dev_inf_content_type.h dev_inf_api/sml_dev_inf_prop_param.h dev_inf_api/sml_dev_inf_property.h dev_inf_api/sml_dev_inf_ctcap.h dev_inf_api/sml_dev_inf_data_store.h + dev_inf_api/sml_dev_inf.h DESTINATION ${LIBSYNCML_INCLUDE_DIR}/libsyncml/dev_inf_api ) Modified: trunk/libsyncml/data_sync_api/data_sync.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync.c Wed Jun 24 11:54:05 2009 (r1117) +++ trunk/libsyncml/data_sync_api/data_sync.c Thu Jun 25 16:02:43 2009 (r1118) @@ -945,9 +945,9 @@ /* cleanup device information */ if ((*dsObject)->localDevInf) - smlDevInfUnref((*dsObject)->localDevInf); + g_object_unref((*dsObject)->localDevInf); if ((*dsObject)->remoteDevInf) - smlDevInfUnref((*dsObject)->remoteDevInf); + g_object_unref((*dsObject)->remoteDevInf); if ((*dsObject)->agent) smlDevInfAgentFree((*dsObject)->agent); Modified: trunk/libsyncml/data_sync_api/data_sync_devinf.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_devinf.c Wed Jun 24 11:54:05 2009 (r1117) +++ trunk/libsyncml/data_sync_api/data_sync_devinf.c Thu Jun 25 16:02:43 2009 (r1118) @@ -154,7 +154,7 @@ goto error; } - if (smlDevInfGetCTCap(devinf, ct) != NULL) + if (sml_dev_inf_get_ctcap(devinf, ct) != NULL) { g_object_unref(ct); smlTrace(TRACE_EXIT, "%s - content type already present in devinf", __func__); @@ -282,7 +282,8 @@ _ADD_PROPERTY_PARAM("WORK"); _ADD_PROPERTY_PARAM("HOME"); _ADD_CTCAP_PROPERTY_BY_NAME_VALUE("VERSION", "2.1") - smlDevInfAppendCTCap(devinf, ctcap); + if (!sml_dev_inf_add_ctcap(devinf, ctcap, &gerror)) + goto error; } else if (!strcmp(cttype, SML_ELEMENT_TEXT_VCARD_30) && !strcmp(verct, "3.0")) @@ -326,7 +327,8 @@ _ADD_CTCAP_PROPERTY_BY_NAME("NOTE") _ADD_CTCAP_PROPERTY_BY_NAME("PHOTO") _ADD_PROPERTY_PARAM("TYPE") - smlDevInfAppendCTCap(devinf, ctcap); + if (!sml_dev_inf_add_ctcap(devinf, ctcap, &gerror)) + goto error; } /* Oracle collaboration Suite uses the content type to distinguish */ /* the versions of vCalendar (and iCalendar) */ @@ -383,7 +385,8 @@ _ADD_CTCAP_PROPERTY_BY_NAME("SUMMARY") _ADD_CTCAP_PROPERTY_BY_NAME("UID") _ADD_CTCAP_PROPERTY_BY_NAME_VALUE("VERSION", "1.0") - smlDevInfAppendCTCap(devinf, ctcap); + if (!sml_dev_inf_add_ctcap(devinf, ctcap, &gerror)) + goto error; } else if (!strcmp(cttype, SML_ELEMENT_TEXT_ICAL) && !strcmp(verct, "2.0")) @@ -437,7 +440,8 @@ _ADD_CTCAP_PROPERTY_BY_NAME("SUMMARY") _ADD_CTCAP_PROPERTY_BY_NAME("UID") _ADD_CTCAP_PROPERTY_BY_NAME_VALUE("VERSION", "2.0") - smlDevInfAppendCTCap(devinf, ctcap); + if (!sml_dev_inf_add_ctcap(devinf, ctcap, &gerror)) + goto error; } else { @@ -452,7 +456,8 @@ if (!ctcap) goto error; - smlDevInfAppendCTCap(devinf, ctcap); + if (!sml_dev_inf_add_ctcap(devinf, ctcap, &gerror)) + goto error; } smlTrace(TRACE_EXIT, "%s - content type newly added to devinf", __func__); @@ -474,12 +479,12 @@ // direct session config - smlSessionUseNumberOfChanges(session, smlDevInfSupportsNumberOfChanges(devinf)); - smlSessionUseLargeObjects(session, smlDevInfSupportsLargeObjs(devinf)); + smlSessionUseNumberOfChanges(session, sml_dev_inf_get_support_number_of_changes(devinf)); + smlSessionUseLargeObjects(session, sml_dev_inf_get_support_large_objs(devinf)); // local device information - if (smlDevInfSupportsUTC(devinf)) + if (sml_dev_inf_get_support_utc(devinf)) dsObject->onlyLocaltime = FALSE; else dsObject->onlyLocaltime = TRUE; @@ -620,13 +625,14 @@ // server alerted sync means that the client has to interpret alerts !!! // FIXME: we receive alerts but we do nothing with it if (smlDsServerGetServerType(datastore->server) == SML_DS_CLIENT) { - // smlDevInfDataStoreSetSyncCap(ds, SML_DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT, TRUE); + // sml_dev_inf_data_store_add_sync_cap(ds, SML_DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT, TRUE); smlTrace(TRACE_INTERNAL, "%s: SyncML clients only support SLOW and TWO WAY SYNC", __func__); } else { sml_dev_inf_data_store_set_sync_cap(ds, SML_DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC, TRUE); } - smlDevInfAddDataStore(devinf, ds); + if (!sml_dev_inf_add_data_store(devinf, ds, &gerror)) + goto error; smlTrace(TRACE_EXIT, "%s - content type newly added to devinf", __func__); return TRUE; error: @@ -652,13 +658,13 @@ * then cleanup the reference. */ if (dsObject->remoteDevInf) - smlDevInfUnref(dsObject->remoteDevInf); + g_object_unref(dsObject->remoteDevInf); dsObject->remoteDevInf = smlDevInfAgentGetSessionDevInf(dsObject->agent, dsObject->session); if (dsObject->remoteDevInf) { smlTrace(TRACE_INTERNAL, "%s: The remote DevInf was received.", __func__); - smlDevInfRef(dsObject->remoteDevInf); + g_object_ref(dsObject->remoteDevInf); _update_session_config_from_devinf(dsObject); /* DevInf caching is optional */ if (dsObject->writeDevInfCallback) { @@ -699,7 +705,7 @@ * So the reference counter must be incremented for * remoteDevInf. */ - smlDevInfRef(dsObject->remoteDevInf); + g_object_ref(dsObject->remoteDevInf); _update_session_config_from_devinf(dsObject); smlTrace(TRACE_EXIT, "%s - cached DevInf", __func__); return TRUE; @@ -746,6 +752,7 @@ SmlError **error) { CHECK_ERROR_REF + GError *gerror = NULL; SmlDevInf *devinf = NULL; /* fix missing identifier */ @@ -755,26 +762,40 @@ if (dsObject->fakeDevice) { smlTrace(TRACE_INTERNAL, "%s: faking devinf", __func__); - devinf = smlDevInfNew(dsObject->identifier, SML_DEVINF_DEVTYPE_SMARTPHONE, error); - if (!devinf) + devinf = sml_dev_inf_new(); + if (!devinf) { + smlErrorSet(error, SML_ERROR_GENERIC, "Cannot create new SmlDevInf object - out of memory."); goto error; + } + if (!sml_dev_inf_set_dev_id(devinf, dsObject->identifier, &gerror)) + goto error; + sml_dev_inf_set_dev_typ(devinf, SML_DEVINF_DEVTYPE_SMARTPHONE); - smlDevInfSetManufacturer(devinf, dsObject->fakeManufacturer); - smlDevInfSetModel(devinf, dsObject->fakeModel); - smlDevInfSetSoftwareVersion(devinf, dsObject->fakeSoftwareVersion); + if (!sml_dev_inf_set_man(devinf, dsObject->fakeManufacturer, &gerror)) + goto error; + if (!sml_dev_inf_set_mod(devinf, dsObject->fakeModel, &gerror)) + goto error; + if (!sml_dev_inf_set_swv(devinf, dsObject->fakeSoftwareVersion, &gerror)) + goto error; } else { smlTrace(TRACE_INTERNAL, "%s: not faking devinf", __func__); - devinf = smlDevInfNew(dsObject->identifier, type, error); - if (!devinf) + devinf = sml_dev_inf_new(); + if (!devinf) { + smlErrorSet(error, SML_ERROR_GENERIC, "Cannot create new SmlDevInf object - out of memory."); goto error; + } + if (!sml_dev_inf_set_dev_id(devinf, dsObject->identifier, &gerror)) + goto error; + sml_dev_inf_set_dev_typ(devinf, type); - smlDevInfSetSoftwareVersion(devinf, dsObject->fakeSoftwareVersion); + if (!sml_dev_inf_set_swv(devinf, dsObject->fakeSoftwareVersion, &gerror)) + goto error; } - smlDevInfSetSupportsNumberOfChanges(devinf, TRUE); - smlDevInfSetSupportsLargeObjs(devinf, TRUE); + sml_dev_inf_set_support_number_of_changes(devinf, TRUE); + sml_dev_inf_set_support_large_objs(devinf, TRUE); if (!dsObject->onlyLocaltime) - smlDevInfSetSupportsUTC(devinf, TRUE); + sml_dev_inf_set_support_utc(devinf, TRUE); smlAssert(dsObject->maxMsgSize); smlAssert(dsObject->maxObjSize); @@ -783,15 +804,19 @@ dsObject->agent = smlDevInfAgentNew(dsObject->localDevInf, error); if (!dsObject->agent) goto error; - smlDevInfRef(dsObject->localDevInf); /* the agent consumes the object */ + g_object_ref(dsObject->localDevInf); /* the agent consumes the object */ if (!smlDevInfAgentRegister(dsObject->agent, dsObject->manager, error)) goto error; return TRUE; error: + if (gerror) { + smlErrorSet(error, gerror->code, "%s", gerror->message); + g_error_free(gerror); + } if (devinf) - smlDevInfUnref(devinf); + g_object_unref(devinf); if (dsObject->agent) smlDevInfAgentFree(dsObject->agent); dsObject->localDevInf = NULL; @@ -846,7 +871,7 @@ * then dsObject must be configured properly */ if (dsObject->remoteDevInf && - !smlDevInfSupportsUTC(dsObject->remoteDevInf)) + !sml_dev_inf_get_support_utc(dsObject->remoteDevInf)) { smlTrace(TRACE_INTERNAL, "%s: enforcing localtime because of remote DevInf", Added: trunk/libsyncml/dev_inf_api/glib_mkenums.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/dev_inf_api/glib_mkenums.sh Thu Jun 25 16:02:43 2009 (r1118) @@ -0,0 +1,6 @@ +glib-mkenums \ + --fhead "#ifndef __SML_DEV_INF_ENUM_TYPES_H\n#define __SML_DEV_INF_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \ + --fprod "/* enumeration types from \"@filename@\" */\n" \ + --vhead "GType @EnumName@ (void);\n#define @EnumName@ (@EnumName@())\n" \ + --ftail "G_END_DECLS\n\n#endif /* __SML_DEV_INF_ENUM_TYPES_H__ */" \ + sml_dev_inf.h Added: trunk/libsyncml/dev_inf_api/sml_dev_inf.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/dev_inf_api/sml_dev_inf.c Thu Jun 25 16:02:43 2009 (r1118) @@ -0,0 +1,1043 @@ +/* sml_dev_inf.c + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include "sml_dev_inf.h" +#include "sml_dev_inf_enum_types.h" +#include <libsyncml/syncml.h> +#include "../sml_error_internals.h" + +G_DEFINE_TYPE (SmlDevInf, sml_dev_inf, G_TYPE_OBJECT) + +enum +{ + PROP_0, + PROP_VER_DTD, + PROP_MAN, + PROP_MOD, + PROP_OEM, + PROP_FWV, + PROP_SWV, + PROP_HWV, + PROP_DEV_ID, + PROP_DEV_TYP, + PROP_SUPPORT_UTC, + PROP_SUPPORT_LARGE_OBJS, + PROP_SUPPORT_NUMBER_OF_CHANGES, + PROP_DATA_STORES, + PROP_CTCAPS +}; + +struct _SmlDevInfPrivate +{ + SmlDevInfVersion ver_dtd; + gchar* man; + gchar* mod; + gchar* oem; + gchar* fwv; + gchar* swv; + gchar* hwv; + gchar* dev_id; + SmlDevInfDevTyp dev_typ; + gboolean support_utc; + gboolean support_large_objs; + gboolean support_number_of_changes; + GList* data_stores; + GList* ctcaps; +}; + +static void +sml_dev_inf_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_VER_DTD: + g_value_set_enum (value, SML_DEV_INF (object)->priv->ver_dtd); + break; + case PROP_MAN: + g_value_set_string (value, SML_DEV_INF (object)->priv->man); + break; + case PROP_MOD: + g_value_set_string (value, SML_DEV_INF (object)->priv->mod); + break; + case PROP_OEM: + g_value_set_string (value, SML_DEV_INF (object)->priv->oem); + break; + case PROP_FWV: + g_value_set_string (value, SML_DEV_INF (object)->priv->fwv); + break; + case PROP_SWV: + g_value_set_string (value, SML_DEV_INF (object)->priv->swv); + break; + case PROP_HWV: + g_value_set_string (value, SML_DEV_INF (object)->priv->hwv); + break; + case PROP_DEV_ID: + g_value_set_string (value, SML_DEV_INF (object)->priv->dev_id); + break; + case PROP_DEV_TYP: + g_value_set_enum (value, SML_DEV_INF (object)->priv->dev_typ); + break; + case PROP_SUPPORT_UTC: + g_value_set_boolean (value, SML_DEV_INF (object)->priv->support_utc); + break; + case PROP_SUPPORT_LARGE_OBJS: + g_value_set_boolean (value, SML_DEV_INF (object)->priv->support_large_objs); + break; + case PROP_SUPPORT_NUMBER_OF_CHANGES: + g_value_set_boolean (value, SML_DEV_INF (object)->priv->support_number_of_changes); + break; + case PROP_DATA_STORES: + g_value_set_pointer (value, SML_DEV_INF (object)->priv->data_stores); + break; + case PROP_CTCAPS: + g_value_set_pointer (value, SML_DEV_INF (object)->priv->ctcaps); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_dev_inf_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_VER_DTD: + SML_DEV_INF (object)->priv->ver_dtd = g_value_get_enum (value); + break; + case PROP_MAN: + g_free (SML_DEV_INF (object)->priv->man); + SML_DEV_INF (object)->priv->man = g_strdup (g_value_get_string (value)); + break; + case PROP_MOD: + g_free (SML_DEV_INF (object)->priv->mod); + SML_DEV_INF (object)->priv->mod = g_strdup (g_value_get_string (value)); + break; + case PROP_OEM: + g_free (SML_DEV_INF (object)->priv->oem); + SML_DEV_INF (object)->priv->oem = g_strdup (g_value_get_string (value)); + break; + case PROP_FWV: + g_free (SML_DEV_INF (object)->priv->fwv); + SML_DEV_INF (object)->priv->fwv = g_strdup (g_value_get_string (value)); + break; + case PROP_SWV: + g_free (SML_DEV_INF (object)->priv->swv); + SML_DEV_INF (object)->priv->swv = g_strdup (g_value_get_string (value)); + break; + case PROP_HWV: + g_free (SML_DEV_INF (object)->priv->hwv); + SML_DEV_INF (object)->priv->hwv = g_strdup (g_value_get_string (value)); + break; + case PROP_DEV_ID: + g_free (SML_DEV_INF (object)->priv->dev_id); + SML_DEV_INF (object)->priv->dev_id = g_strdup (g_value_get_string (value)); + break; + case PROP_DEV_TYP: + SML_DEV_INF (object)->priv->dev_typ = g_value_get_enum (value); + break; + case PROP_SUPPORT_UTC: + SML_DEV_INF (object)->priv->support_utc = g_value_get_boolean (value); + break; + case PROP_SUPPORT_LARGE_OBJS: + SML_DEV_INF (object)->priv->support_large_objs = g_value_get_boolean (value); + break; + case PROP_SUPPORT_NUMBER_OF_CHANGES: + SML_DEV_INF (object)->priv->support_number_of_changes = g_value_get_boolean (value); + break; + case PROP_DATA_STORES: + SML_DEV_INF (object)->priv->data_stores = (GList *) g_value_get_pointer(value); + break; + case PROP_CTCAPS: + SML_DEV_INF (object)->priv->ctcaps = (GList *) g_value_get_pointer(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_dev_inf_finalize (GObject *object) +{ + SmlDevInf *self = (SmlDevInf *) object; + g_free(self->priv->man); + g_free(self->priv->mod); + g_free(self->priv->oem); + g_free(self->priv->fwv); + g_free(self->priv->swv); + g_free(self->priv->hwv); + g_free(self->priv->dev_id); + while(self->priv->data_stores) { + SmlDevInfDataStore *data_store = self->priv->data_stores->data; + self->priv->data_stores = g_list_remove(self->priv->data_stores, data_store); + g_object_unref(data_store); + } + while(self->priv->ctcaps) { + SmlDevInfCTCap *ctcap = self->priv->ctcaps->data; + self->priv->ctcaps = g_list_remove(self->priv->ctcaps, ctcap); + g_object_unref(ctcap); + } + /* all pointers must be NULL */ + self->priv->man = NULL; + self->priv->mod = NULL; + self->priv->oem = NULL; + self->priv->fwv = NULL; + self->priv->swv = NULL; + self->priv->hwv = NULL; + self->priv->dev_id = NULL; + G_OBJECT_CLASS (sml_dev_inf_parent_class)->finalize (object); +} + +static void +sml_dev_inf_class_init (SmlDevInfClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (SmlDevInfPrivate)); + + object_class->get_property = sml_dev_inf_get_property; + object_class->set_property = sml_dev_inf_set_property; + object_class->finalize = sml_dev_inf_finalize; + + /** + * SmlDevInf:VerDTD: + * + * The This is the protocol version of the device information. property. + */ + g_object_class_install_property (object_class, + PROP_VER_DTD, + g_param_spec_enum ("VerDTD", + "VersionDTD", + "This is the protocol version of the device information.", + SML_DEV_INF_TYPE_DEV_INF_VERSION, + SML_DEVINF_VERSION_UNKNOWN, + G_PARAM_READWRITE)); + /** + * SmlDevInf:Man: + * + * The This is the name of the manufacturer property. + */ + g_object_class_install_property (object_class, + PROP_MAN, + g_param_spec_string ("Man", + "Manufacturer", + "This is the name of the manufacturer", + NULL, + G_PARAM_READWRITE)); + /** + * SmlDevInf:Mod: + * + * The This is the name of the model. property. + */ + g_object_class_install_property (object_class, + PROP_MOD, + g_param_spec_string ("Mod", + "Modell", + "This is the name of the model.", + NULL, + G_PARAM_READWRITE)); + /** + * SmlDevInf:OEM: + * + * The This is the name of the OEM. property. + */ + g_object_class_install_property (object_class, + PROP_OEM, + g_param_spec_string ("OEM", + "OEM", + "This is the name of the OEM.", + NULL, + G_PARAM_READWRITE)); + /** + * SmlDevInf:FwV: + * + * The This is the version if the firmware. property. + */ + g_object_class_install_property (object_class, + PROP_FWV, + g_param_spec_string ("FwV", + "FirmwareVersion", + "This is the version if the firmware.", + NULL, + G_PARAM_READWRITE)); + /** + * SmlDevInf:SwV: + * + * The This is the version of the firmware. property. + */ + g_object_class_install_property (object_class, + PROP_SWV, + g_param_spec_string ("SwV", + "SoftwareVersion", + "This is the version of the firmware.", + NULL, + G_PARAM_READWRITE)); + /** + * SmlDevInf:HwV: + * + * The This is the version of the hardware. property. + */ + g_object_class_install_property (object_class, + PROP_HWV, + g_param_spec_string ("HwV", + "HardwareVersion", + "This is the version of the hardware.", + NULL, + G_PARAM_READWRITE)); + /** + * SmlDevInf:DevID: + * + * The This is the identifier of the device. property. + */ + g_object_class_install_property (object_class, + PROP_DEV_ID, + g_param_spec_string ("DevID", + "DeviceID", + "This is the identifier of the device.", + NULL, + G_PARAM_READWRITE)); + /** + * SmlDevInf:DevTyp: + * + * The This is the type of the device property. + */ + g_object_class_install_property (object_class, + PROP_DEV_TYP, + g_param_spec_enum ("DevTyp", + "DeviceType", + "This is the type of the device", + SML_DEV_INF_TYPE_DEV_INF_DEV_TYP, + SML_DEVINF_DEVTYPE_UNKNOWN, + G_PARAM_READWRITE)); + /** + * SmlDevInf:SupportUTC: + * + * The Does this device support UTC? property. + */ + g_object_class_install_property (object_class, + PROP_SUPPORT_UTC, + g_param_spec_boolean ("SupportUTC", + "SupportUTC", + "Does this device support UTC?", + FALSE, + G_PARAM_READWRITE)); + /** + * SmlDevInf:SupportLargeObjs: + * + * The Does this device support large objects? property. + */ + g_object_class_install_property (object_class, + PROP_SUPPORT_LARGE_OBJS, + g_param_spec_boolean ("SupportLargeObjs", + "SupportLargeObjs", + "Does this device support large objects?", + FALSE, + G_PARAM_READWRITE)); + /** + * SmlDevInf:SupportNumberOfChanges: + * + * The Does this device supports number of changes? property. + */ + g_object_class_install_property (object_class, + PROP_SUPPORT_NUMBER_OF_CHANGES, + g_param_spec_boolean ("SupportNumberOfChanges", + "SupportNumberOfChanges", + "Does this device supports number of changes?", + FALSE, + G_PARAM_READWRITE)); + /** + * SmlDevInf:DataStores: + * + * The Supported data stores. property. + */ + g_object_class_install_property (object_class, + PROP_DATA_STORES, + g_param_spec_pointer ("DataStores", + "DataStores", + "Supported data stores.", + G_PARAM_PRIVATE)); + /** + * SmlDevInf:CTCaps: + * + * The Supported CTCaps. property. + */ + g_object_class_install_property (object_class, + PROP_CTCAPS, + g_param_spec_pointer ("CTCaps", + "CTCaps", + "Supported CTCaps.", + G_PARAM_PRIVATE)); + +} + +static void +sml_dev_inf_init (SmlDevInf *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + SML_TYPE_DEV_INF, + SmlDevInfPrivate); +} + +/** + * sml_dev_inf_new: + * + * Creates a new instance of #SmlDevInf. + * + * Return value: the newly created #SmlDevInf instance + */ +SmlDevInf* +sml_dev_inf_new (void) +{ + return g_object_new (SML_TYPE_DEV_INF, NULL); +} + +/** + * sml_dev_inf_get_ver_dtd: + * @self: A #SmlDevInf + * + * Gets the VerDTD property. + * + * Return value: + */ +SmlDevInfVersion +sml_dev_inf_get_ver_dtd (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), SML_DEVINF_VERSION_UNKNOWN); + return self->priv->ver_dtd; +} + +/** + * sml_dev_inf_set_ver_dtd: + * @self: A #SmlDevInf + * @ver_dtd: + * + * Sets the VerDTD property. + */ +void +sml_dev_inf_set_ver_dtd (SmlDevInf *self, + SmlDevInfVersion ver_dtd) +{ + g_return_if_fail (SML_IS_DEV_INF (self)); + + /* The version of the DTD is a minimum requirement. + * It is not optional. + */ + g_return_if_fail (ver_dtd != SML_DEVINF_VERSION_UNKNOWN); + + self->priv->ver_dtd = ver_dtd; +} + +/** + * sml_dev_inf_get_man: + * @self: A #SmlDevInf + * + * Gets the Manufacturer property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_dev_inf_get_man (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), NULL); + return self->priv->man; +} + +/** + * sml_dev_inf_set_man: + * @self: A #SmlDevInf + * @man: + * + * Sets the Manufacturer property. + */ +gboolean +sml_dev_inf_set_man (SmlDevInf *self, + const gchar* man, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DEV_INF (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDevInf object."); + + /* normalize the man */ + if (man && strlen(man) == 0) + man = NULL; + + g_free (self->priv->man); + self->priv->man = g_strdup (man); + sml_return_val_error_if_fail (!man || self->priv->man, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the manufacturer - out of memory."); + + return TRUE; +} + +/** + * sml_dev_inf_get_mod: + * @self: A #SmlDevInf + * + * Gets the Modell property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_dev_inf_get_mod (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), NULL); + return self->priv->mod; +} + +/** + * sml_dev_inf_set_mod: + * @self: A #SmlDevInf + * @mod: + * + * Sets the Modell property. + */ +gboolean +sml_dev_inf_set_mod (SmlDevInf *self, + const gchar* mod, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DEV_INF (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDevInf object."); + + /* normalize the mod */ + if (mod && strlen(mod) == 0) + mod = NULL; + + g_free (self->priv->mod); + self->priv->mod = g_strdup (mod); + sml_return_val_error_if_fail (!mod || self->priv->mod, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the model - out of memory."); + + return TRUE; +} + +/** + * sml_dev_inf_get_oem: + * @self: A #SmlDevInf + * + * Gets the OEM property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_dev_inf_get_oem (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), NULL); + return self->priv->oem; +} + +/** + * sml_dev_inf_set_oem: + * @self: A #SmlDevInf + * @oem: + * + * Sets the OEM property. + */ +gboolean +sml_dev_inf_set_oem (SmlDevInf *self, + const gchar* oem, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DEV_INF (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDevInf object."); + + /* normalize the oem */ + if (oem && strlen(oem) == 0) + oem = NULL; + + g_free (self->priv->oem); + self->priv->oem = g_strdup (oem); + sml_return_val_error_if_fail (!oem || self->priv->oem, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the OEM - out of memory."); + + return TRUE; +} + +/** + * sml_dev_inf_get_fwv: + * @self: A #SmlDevInf + * + * Gets the FirmwareVersion property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_dev_inf_get_fwv (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), NULL); + return self->priv->fwv; +} + +/** + * sml_dev_inf_set_fwv: + * @self: A #SmlDevInf + * @fwv: + * + * Sets the FirmwareVersion property. + */ +gboolean +sml_dev_inf_set_fwv (SmlDevInf *self, + const gchar* fwv, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DEV_INF (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDevInf object."); + + /* normalize the fwv */ + if (fwv && strlen(fwv) == 0) + fwv = NULL; + + g_free (self->priv->fwv); + self->priv->fwv = g_strdup (fwv); + sml_return_val_error_if_fail (!fwv || self->priv->fwv, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the firmware version - out of memory."); + + return TRUE; +} + +/** + * sml_dev_inf_get_swv: + * @self: A #SmlDevInf + * + * Gets the SoftwareVersion property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_dev_inf_get_swv (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), NULL); + return self->priv->swv; +} + +/** + * sml_dev_inf_set_swv: + * @self: A #SmlDevInf + * @swv: + * + * Sets the SoftwareVersion property. + */ +gboolean +sml_dev_inf_set_swv (SmlDevInf *self, + const gchar* swv, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DEV_INF (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDevInf object."); + + /* normalize the swv */ + if (swv && strlen(swv) == 0) + swv = NULL; + + g_free (self->priv->swv); + self->priv->swv = g_strdup (swv); + sml_return_val_error_if_fail (!swv || self->priv->swv, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the software version - out of memory."); + + return TRUE; +} + +/** + * sml_dev_inf_get_hwv: + * @self: A #SmlDevInf + * + * Gets the HardwareVersion property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_dev_inf_get_hwv (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), NULL); + return self->priv->hwv; +} + +/** + * sml_dev_inf_set_hwv: + * @self: A #SmlDevInf + * @hwv: + * + * Sets the HardwareVersion property. + */ +gboolean +sml_dev_inf_set_hwv (SmlDevInf *self, + const gchar* hwv, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DEV_INF (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDevInf object."); + + /* normalize the hwv */ + if (hwv && strlen(hwv) == 0) + hwv = NULL; + + g_free (self->priv->hwv); + self->priv->hwv = g_strdup (hwv); + sml_return_val_error_if_fail (!hwv || self->priv->hwv, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the hardware version - out of memory."); + + return TRUE; +} + +/** + * sml_dev_inf_get_dev_id: + * @self: A #SmlDevInf + * + * Gets the DeviceID property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_dev_inf_get_dev_id (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), NULL); + return self->priv->dev_id; +} + +/** + * sml_dev_inf_set_dev_id: + * @self: A #SmlDevInf + * @dev_id: + * + * Sets the DeviceID property. + */ +gboolean +sml_dev_inf_set_dev_id (SmlDevInf *self, + const gchar* dev_id, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DEV_INF (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDevInf object."); + sml_return_val_error_if_fail (dev_id, FALSE, error, SML_ERROR_GENERIC, "The device ID is a required element."); + sml_return_val_error_if_fail (strlen(dev_id) > 0, FALSE, error, SML_ERROR_GENERIC, "The device ID cannot be the empty word."); + + g_free (self->priv->dev_id); + self->priv->dev_id = g_strdup (dev_id); + sml_return_val_error_if_fail (self->priv->dev_id, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the device ID - out of memory."); + + return TRUE; +} + +/** + * sml_dev_inf_get_dev_typ: + * @self: A #SmlDevInf + * + * Gets the DeviceType property. + * + * Return value: + */ +SmlDevInfDevTyp +sml_dev_inf_get_dev_typ (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), SML_DEVINF_DEVTYPE_UNKNOWN); + return self->priv->dev_typ; +} + +/** + * sml_dev_inf_set_dev_typ: + * @self: A #SmlDevInf + * @dev_typ: + * + * Sets the DeviceType property. + */ +void +sml_dev_inf_set_dev_typ (SmlDevInf *self, + SmlDevInfDevTyp dev_typ) +{ + g_return_if_fail (SML_IS_DEV_INF (self)); + + /* The device ID is a minimum requirement. + * It is not optional. + */ + g_return_if_fail (dev_typ != SML_DEVINF_DEVTYPE_UNKNOWN); + + self->priv->dev_typ = dev_typ; +} + +/** + * sml_dev_inf_get_support_utc: + * @self: A #SmlDevInf + * + * Gets the SupportUTC property. + * + * Return value: + */ +gboolean +sml_dev_inf_get_support_utc (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), FALSE); + return self->priv->support_utc; +} + +/** + * sml_dev_inf_set_support_utc: + * @self: A #SmlDevInf + * @support_utc: + * + * Sets the SupportUTC property. + */ +void +sml_dev_inf_set_support_utc (SmlDevInf *self, + gboolean support_utc) +{ + g_return_if_fail (SML_IS_DEV_INF (self)); + self->priv->support_utc = support_utc; +} + +/** + * sml_dev_inf_get_support_large_objs: + * @self: A #SmlDevInf + * + * Gets the SupportLargeObjs property. + * + * Return value: + */ +gboolean +sml_dev_inf_get_support_large_objs (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), FALSE); + return self->priv->support_large_objs; +} + +/** + * sml_dev_inf_set_support_large_objs: + * @self: A #SmlDevInf + * @support_large_objs: + * + * Sets the SupportLargeObjs property. + */ +void +sml_dev_inf_set_support_large_objs (SmlDevInf *self, + gboolean support_large_objs) +{ + g_return_if_fail (SML_IS_DEV_INF (self)); + self->priv->support_large_objs = support_large_objs; +} + +/** + * sml_dev_inf_get_support_number_of_changes: + * @self: A #SmlDevInf + * + * Gets the SupportNumberOfChanges property. + * + * Return value: + */ +gboolean +sml_dev_inf_get_support_number_of_changes (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), FALSE); + return self->priv->support_number_of_changes; +} + +/** + * sml_dev_inf_set_support_number_of_changes: + * @self: A #SmlDevInf + * @support_number_of_changes: + * + * Sets the SupportNumberOfChanges property. + */ +void +sml_dev_inf_set_support_number_of_changes (SmlDevInf *self, + gboolean support_number_of_changes) +{ + g_return_if_fail (SML_IS_DEV_INF (self)); + self->priv->support_number_of_changes = support_number_of_changes; +} + +/** + * sml_dev_inf_num_data_stores: + * @self: A #SmlDevInf + * + * + */ +gsize +sml_dev_inf_num_data_stores (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), 0); + return g_list_length(self->priv->data_stores); +} + +/** + * sml_dev_inf_get_nth_data_store: + * @self: A #SmlDevInf + * + * + */ +SmlDevInfDataStore* +sml_dev_inf_get_nth_data_store (SmlDevInf *self, + gsize n) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), NULL); + return (SmlDevInfDataStore *)g_list_nth_data(self->priv->data_stores, n); +} + +/** + * sml_dev_inf_add_data_store: + * @self: A #SmlDevInf + * + * + */ +gboolean +sml_dev_inf_add_data_store (SmlDevInf *self, + SmlDevInfDataStore *data_store, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DEV_INF (self), FALSE, error, SML_ERROR_GENERIC, "There is no SmlDevInf object."); + sml_return_val_error_if_fail (data_store, FALSE, error, SML_ERROR_GENERIC, "The SmlDevInfDataStore object is missing."); + sml_return_val_error_if_fail (SML_IS_DEV_INF_DATA_STORE (data_store), FALSE, error, SML_ERROR_GENERIC, "The data store parameter must be a SmlDevInfDataStore object."); + + g_object_ref(data_store); + self->priv->data_stores = g_list_append(self->priv->data_stores, data_store); + sml_return_val_error_if_fail (self->priv->data_stores, FALSE, error, SML_ERROR_GENERIC, "Cannot add data store to data store list of device information."); + + return TRUE; +} + +/** + * sml_dev_inf_get_ctcap: + * @self: A #SmlDevInf + * + * + */ +SmlDevInfCTCap* +sml_dev_inf_get_ctcap (SmlDevInf *self, + SmlDevInfContentType* ct) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), 0); + g_return_val_if_fail (SML_IS_DEV_INF_CONTENT_TYPE (ct), 0); + + GList *h; + for (h = self->priv->ctcaps; h; h = h->next) + { + SmlDevInfCTCap *ctcap = h->data; + /* check that the content type matches */ + if (!strcmp(sml_dev_inf_content_type_get_cttype(ct), + sml_dev_inf_content_type_get_cttype(sml_dev_inf_ctcap_get_content_type(ctcap))) && + !strcmp(sml_dev_inf_content_type_get_verct(ct), + sml_dev_inf_content_type_get_verct(sml_dev_inf_ctcap_get_content_type(ctcap)))) + { + return ctcap; + } + } + return NULL; +} + +/** + * sml_dev_inf_num_ctcaps: + * @self: A #SmlDevInf + * + * + */ +gsize +sml_dev_inf_num_ctcaps (SmlDevInf *self) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), 0); + return g_list_length(self->priv->ctcaps); +} + +/** + * sml_dev_inf_get_nth_ctcap: + * @self: A #SmlDevInf + * + * + */ +SmlDevInfCTCap* +sml_dev_inf_get_nth_ctcap (SmlDevInf *self, + gsize n) +{ + g_return_val_if_fail (SML_IS_DEV_INF (self), NULL); + return (SmlDevInfCTCap *)g_list_nth_data(self->priv->ctcaps, n); +} + +/** + * sml_dev_inf_add_ctcap: + * @self: A #SmlDevInf + * + * + */ +gboolean +sml_dev_inf_add_ctcap (SmlDevInf *self, + SmlDevInfCTCap *ctcap, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DEV_INF (self), FALSE, error, SML_ERROR_GENERIC, "There is no SmlDevInf object."); + sml_return_val_error_if_fail (ctcap, FALSE, error, SML_ERROR_GENERIC, "The SmlDevInfCTCap object is missing."); + sml_return_val_error_if_fail (SML_IS_DEV_INF_CTCAP (ctcap), FALSE, error, SML_ERROR_GENERIC, "The ctcap parameter must be a SmlDevInfCTCap object."); + + g_object_ref(ctcap); + self->priv->ctcaps = g_list_append(self->priv->ctcaps, ctcap); + sml_return_val_error_if_fail (self->priv->ctcaps, FALSE, error, SML_ERROR_GENERIC, "Cannot add CTCap to CTCap list of device information."); + + return TRUE; +} + +/** + * sml_dev_inf_is_compliant: + * @self: A #SmlDevInfDataStore + * @error: A #GError + * + * This is the only function of this class where you have not to provide a pointer to the error parameter. + * If you only want to know if the data store is already compliant + * then you can ignore the error. + * + * Return value: + */ +gboolean +sml_dev_inf_is_compliant (SmlDevInf *self, + GError **error) +{ + sml_return_val_error_if_fail (SML_IS_DEV_INF (self), FALSE, error, SML_ERROR_GENERIC, "There is no SmlDevInf object."); + + /* Common SyncML requirements */ + + sml_return_val_error_if_fail (self->priv->ver_dtd == SML_DEVINF_VERSION_UNKNOWN, FALSE, error, SML_ERROR_GENERIC, "The VerDTD must be set."); + sml_return_val_error_if_fail (self->priv->dev_id != NULL, FALSE, error, SML_ERROR_GENERIC, "The device ID must be set."); + sml_return_val_error_if_fail (self->priv->dev_typ != SML_DEVINF_DEVTYPE_UNKNOWN, FALSE, error, SML_ERROR_GENERIC, "The device type must be set."); + sml_return_val_error_if_fail (self->priv->data_stores != NULL, FALSE, error, SML_ERROR_GENERIC, "There must be at minimum one data store."); + + /* SyncML 1.0 requirements */ + + if (self->priv->ver_dtd == SML_DEVINF_VERSION_10) { + sml_return_val_error_if_fail (self->priv->support_utc, FALSE, error, SML_ERROR_GENERIC, "SyncML 1.0 does not specify UTC support."); + sml_return_val_error_if_fail (self->priv->support_large_objs, FALSE, error, SML_ERROR_GENERIC, "SyncML 1.0 does not specify large object support."); + sml_return_val_error_if_fail (self->priv->support_number_of_changes, FALSE, error, SML_ERROR_GENERIC, "SyncML 1.0 does not specify number of changes support."); + } + + /* SyncML 1.2 requirements */ + + if (self->priv->ver_dtd >= SML_DEVINF_VERSION_12) { + sml_return_val_error_if_fail (self->priv->man != NULL, FALSE, error, SML_ERROR_GENERIC, "The manufacturer must be set."); + sml_return_val_error_if_fail (self->priv->mod != NULL, FALSE, error, SML_ERROR_GENERIC, "The model must be set."); + sml_return_val_error_if_fail (self->priv->fwv != NULL, FALSE, error, SML_ERROR_GENERIC, "The firmware version must be set."); + sml_return_val_error_if_fail (self->priv->swv != NULL, FALSE, error, SML_ERROR_GENERIC, "The software version must be set."); + sml_return_val_error_if_fail (self->priv->hwv != NULL, FALSE, error, SML_ERROR_GENERIC, "The hardware version must be set."); + } + + /* SyncML server requirements */ + + if (self->priv->dev_typ == SML_DEVINF_DEVTYPE_SERVER) { + sml_return_val_error_if_fail (!self->priv->support_utc, FALSE, error, SML_ERROR_GENERIC, "A server must support UTC."); + sml_return_val_error_if_fail (!self->priv->support_large_objs, FALSE, error, SML_ERROR_GENERIC, "A server must support large objects."); + sml_return_val_error_if_fail (!self->priv->support_number_of_changes, FALSE, error, SML_ERROR_GENERIC, "A server must support number of changes."); + } + + return TRUE; +} + Added: trunk/libsyncml/dev_inf_api/sml_dev_inf.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/dev_inf_api/sml_dev_inf.h Thu Jun 25 16:02:43 2009 (r1118) @@ -0,0 +1,114 @@ +/* sml_dev_inf.h + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __SML_DEV_INF_H__ +#define __SML_DEV_INF_H__ + +#include <glib-object.h> +#include <libsyncml/dev_inf_api/sml_dev_inf_ctcap.h> +#include <libsyncml/dev_inf_api/sml_dev_inf_data_store.h> + +/* this interface enforce the logical structure behind the devinf spec */ +/* so we can generate SyncML 1.0, 1.1 and 1.2 devinf from this structure */ +/* the CTCap will be assigned to a datastore if CTType and VerCT match */ + +G_BEGIN_DECLS + +#define SML_TYPE_DEV_INF (sml_dev_inf_get_type()) +#define SML_DEV_INF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SML_TYPE_DEV_INF, SmlDevInf)) +#define SML_DEV_INF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SML_TYPE_DEV_INF, SmlDevInfClass)) +#define SML_IS_DEV_INF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SML_TYPE_DEV_INF)) +#define SML_IS_DEV_INF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SML_TYPE_DEV_INF)) +#define SML_DEV_INF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SML_TYPE_DEV_INF, SmlDevInfClass)) + +typedef enum { + SML_DEVINF_VERSION_UNKNOWN = 0, + SML_DEVINF_VERSION_10 = 1, + SML_DEVINF_VERSION_11 = 2, + SML_DEVINF_VERSION_12 = 3 +} SmlDevInfVersion; + +typedef enum { + SML_DEVINF_DEVTYPE_UNKNOWN = 0, + SML_DEVINF_DEVTYPE_PAGER = 1, + SML_DEVINF_DEVTYPE_HANDHELD = 2, + SML_DEVINF_DEVTYPE_PDA = 3, + SML_DEVINF_DEVTYPE_PHONE = 4, + SML_DEVINF_DEVTYPE_SMARTPHONE = 5, + SML_DEVINF_DEVTYPE_SERVER = 6, + SML_DEVINF_DEVTYPE_WORKSTATION = 7 +} SmlDevInfDevTyp; + +typedef struct _SmlDevInf SmlDevInf; +typedef struct _SmlDevInfClass SmlDevInfClass; +typedef struct _SmlDevInfPrivate SmlDevInfPrivate; + +struct _SmlDevInf +{ + GObject parent; + + /*< private >*/ + SmlDevInfPrivate *priv; +}; + +struct _SmlDevInfClass +{ + GObjectClass parent_class; + +}; + +GType sml_dev_inf_get_type (void); +SmlDevInf* sml_dev_inf_new (void); +SmlDevInfVersion sml_dev_inf_get_ver_dtd (SmlDevInf *self); +void sml_dev_inf_set_ver_dtd (SmlDevInf *self, SmlDevInfVersion ver_dtd); +G_CONST_RETURN gchar* sml_dev_inf_get_man (SmlDevInf *self); +gboolean sml_dev_inf_set_man (SmlDevInf *self, const gchar* man, GError **error); +G_CONST_RETURN gchar* sml_dev_inf_get_mod (SmlDevInf *self); +gboolean sml_dev_inf_set_mod (SmlDevInf *self, const gchar* mod, GError **error); +G_CONST_RETURN gchar* sml_dev_inf_get_oem (SmlDevInf *self); +gboolean sml_dev_inf_set_oem (SmlDevInf *self, const gchar* oem, GError **error); +G_CONST_RETURN gchar* sml_dev_inf_get_fwv (SmlDevInf *self); +gboolean sml_dev_inf_set_fwv (SmlDevInf *self, const gchar* fwv, GError **error); +G_CONST_RETURN gchar* sml_dev_inf_get_swv (SmlDevInf *self); +gboolean sml_dev_inf_set_swv (SmlDevInf *self, const gchar* swv, GError **error); +G_CONST_RETURN gchar* sml_dev_inf_get_hwv (SmlDevInf *self); +gboolean sml_dev_inf_set_hwv (SmlDevInf *self, const gchar* hwv, GError **error); +G_CONST_RETURN gchar* sml_dev_inf_get_dev_id (SmlDevInf *self); +gboolean sml_dev_inf_set_dev_id (SmlDevInf *self, const gchar* devid, GError **error); +SmlDevInfDevTyp sml_dev_inf_get_dev_typ (SmlDevInf *self); +void sml_dev_inf_set_dev_typ (SmlDevInf *self, SmlDevInfDevTyp devtyp); +gboolean sml_dev_inf_get_support_utc (SmlDevInf *self); +void sml_dev_inf_set_support_utc (SmlDevInf *self, gboolean support_utc); +gboolean sml_dev_inf_get_support_large_objs (SmlDevInf *self); +void sml_dev_inf_set_support_large_objs (SmlDevInf *self, gboolean support_large_objs); +gboolean sml_dev_inf_get_support_number_of_changes (SmlDevInf *self); +void sml_dev_inf_set_support_number_of_changes (SmlDevInf *self, gboolean support_number_of_changes); +gsize sml_dev_inf_num_data_stores (SmlDevInf *self); +SmlDevInfDataStore* sml_dev_inf_get_nth_data_store (SmlDevInf *self, gsize n); +gboolean sml_dev_inf_add_data_store (SmlDevInf *self, SmlDevInfDataStore *data_store, GError **error); +SmlDevInfCTCap* sml_dev_inf_get_ctcap (SmlDevInf *self, SmlDevInfContentType*); +gsize sml_dev_inf_num_ctcaps (SmlDevInf *self); +SmlDevInfCTCap* sml_dev_inf_get_nth_ctcap (SmlDevInf *self, gsize n); +gboolean sml_dev_inf_add_ctcap (SmlDevInf *self, SmlDevInfCTCap *ctcap, GError **error); +gboolean sml_dev_inf_is_compliant (SmlDevInf *self, GError **error); + +G_END_DECLS + +#endif /* __SML_DEV_INF_H__ */ Modified: trunk/libsyncml/dev_inf_api/sml_dev_inf_data_store.c ============================================================================== --- trunk/libsyncml/dev_inf_api/sml_dev_inf_data_store.c Wed Jun 24 11:54:05 2009 (r1117) +++ trunk/libsyncml/dev_inf_api/sml_dev_inf_data_store.c Thu Jun 25 16:02:43 2009 (r1118) @@ -858,7 +858,8 @@ * Return value: */ gboolean -sml_dev_inf_data_store_is_compliant (SmlDevInfDataStore *self, GError **error) +sml_dev_inf_data_store_is_compliant (SmlDevInfDataStore *self, + GError **error) { sml_return_val_error_if_fail (SML_IS_DEV_INF_DATA_STORE (self), FALSE, error, SML_ERROR_GENERIC, "There is no SmlDevInfDataStore object."); Added: trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.c Thu Jun 25 16:02:43 2009 (r1118) @@ -0,0 +1,83 @@ + +/* Generated data (by glib-mkenums) */ + + +/* WARNING: This file was generated by glib-mkenums. + * WARNING: + * WARNING: glib-mkenums --template sml_dev_inf_enum_types.h.tmpl *.h > sml_dev_inf_enum_types.h + * WARNING: + * WARNING: If you need to update this file then please run the command again. + */ + + +/* enumerations from "sml_dev_inf.h" */ + +#include <libsyncml/dev_inf_api/sml_dev_inf.h> + +GType +sml_dev_inf_version_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY (etype == 0)) { + static const GEnumValue values[] = { + { SML_DEVINF_VERSION_UNKNOWN, "SML_DEVINF_VERSION_UNKNOWN", "unknown" }, + { SML_DEVINF_VERSION_10, "SML_DEVINF_VERSION_10", "10" }, + { SML_DEVINF_VERSION_11, "SML_DEVINF_VERSION_11", "11" }, + { SML_DEVINF_VERSION_12, "SML_DEVINF_VERSION_12", "12" }, + { 0, NULL, NULL } + }; + etype = g_enum_register_static (g_intern_static_string ("SmlDevInfVersion"), values); + } + return etype; +} + +GType +sml_dev_inf_dev_typ_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY (etype == 0)) { + static const GEnumValue values[] = { + { SML_DEVINF_DEVTYPE_UNKNOWN, "SML_DEVINF_DEVTYPE_UNKNOWN", "unknown" }, + { SML_DEVINF_DEVTYPE_PAGER, "SML_DEVINF_DEVTYPE_PAGER", "pager" }, + { SML_DEVINF_DEVTYPE_HANDHELD, "SML_DEVINF_DEVTYPE_HANDHELD", "handheld" }, + { SML_DEVINF_DEVTYPE_PDA, "SML_DEVINF_DEVTYPE_PDA", "pda" }, + { SML_DEVINF_DEVTYPE_PHONE, "SML_DEVINF_DEVTYPE_PHONE", "phone" }, + { SML_DEVINF_DEVTYPE_SMARTPHONE, "SML_DEVINF_DEVTYPE_SMARTPHONE", "smartphone" }, + { SML_DEVINF_DEVTYPE_SERVER, "SML_DEVINF_DEVTYPE_SERVER", "server" }, + { SML_DEVINF_DEVTYPE_WORKSTATION, "SML_DEVINF_DEVTYPE_WORKSTATION", "workstation" }, + { 0, NULL, NULL } + }; + etype = g_enum_register_static (g_intern_static_string ("SmlDevInfDevTyp"), values); + } + return etype; +} + + +/* enumerations from "sml_dev_inf_data_store.h" */ + +#include <libsyncml/dev_inf_api/sml_dev_inf_data_store.h> + +GType +sml_dev_inf_sync_cap_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY (etype == 0)) { + static const GFlagsValue values[] = { + { SML_DEVINF_SYNCTYPE_UNKNOWN, "SML_DEVINF_SYNCTYPE_UNKNOWN", "unknown" }, + { SML_DEVINF_SYNCTYPE_TWO_WAY, "SML_DEVINF_SYNCTYPE_TWO_WAY", "two-way" }, + { SML_DEVINF_SYNCTYPE_SLOW_SYNC, "SML_DEVINF_SYNCTYPE_SLOW_SYNC", "slow-sync" }, + { SML_DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT, "SML_DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT", "one-way-from-client" }, + { SML_DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT, "SML_DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT", "refresh-from-client" }, + { SML_DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER, "SML_DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER", "one-way-from-server" }, + { SML_DEVINF_SYNCTYPE_REFRESH_FROM_SERVER, "SML_DEVINF_SYNCTYPE_REFRESH_FROM_SERVER", "refresh-from-server" }, + { SML_DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC, "SML_DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC", "server-alerted-sync" }, + { 0, NULL, NULL } + }; + etype = g_flags_register_static (g_intern_static_string ("SmlDevInfSyncCap"), values); + } + return etype; +} + + +/* Generated data ends here */ + Added: trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.c.tmpl ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.c.tmpl Thu Jun 25 16:02:43 2009 (r1118) @@ -0,0 +1,44 @@ +/*** BEGIN file-header ***/ + +/* WARNING: This file was generated by glib-mkenums. + * WARNING: + * WARNING: glib-mkenums --template sml_dev_inf_enum_types.h.tmpl *.h > sml_dev_inf_enum_types.h + * WARNING: + * WARNING: If you need to update this file then please run the command again. + */ + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@filename@" */ + +#include <libsyncml/dev_inf_api/@filename@> + +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType +@enum_name@_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY (etype == 0)) { + static const G@Type@Value values[] = { +/*** END value-header ***/ + +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ + +/*** BEGIN value-tail ***/ + { 0, NULL, NULL } + }; + etype = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values); + } + return etype; +} + +/*** END value-tail ***/ + +/*** BEGIN file-tail ***/ +/*** END file-tail ***/ Added: trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.h Thu Jun 25 16:02:43 2009 (r1118) @@ -0,0 +1,32 @@ + +/* Generated data (by glib-mkenums) */ + +#ifndef __SML_DEV_INF_ENUM_TYPES_H__ +#define __SML_DEV_INF_ENUM_TYPES_H__ + +/* WARNING: This file was generated by glib-mkenums. + * WARNING: + * WARNING: glib-mkenums --template sml_dev_inf_enum_types.h.tmpl *.h > sml_dev_inf_enum_types.h + * WARNING: + * WARNING: If you need to update this file then please run the command again. + */ + +#include <glib-object.h> + +G_BEGIN_DECLS + +/* enumerations from "sml_dev_inf.h" */ +GType sml_dev_inf_version_get_type (void) G_GNUC_CONST; +#define SML_DEV_INF_TYPE_DEV_INF_VERSION (sml_dev_inf_version_get_type ()) +GType sml_dev_inf_dev_typ_get_type (void) G_GNUC_CONST; +#define SML_DEV_INF_TYPE_DEV_INF_DEV_TYP (sml_dev_inf_dev_typ_get_type ()) + +/* enumerations from "sml_dev_inf_data_store.h" */ +GType sml_dev_inf_sync_cap_get_type (void) G_GNUC_CONST; +#define SML_DEV_INF_TYPE_DEV_INF_SYNC_CAP (sml_dev_inf_sync_cap_get_type ()) +G_END_DECLS + +#endif /* __SML_DEV_INF_ENUM_TYPES_H__ */ + +/* Generated data ends here */ + Added: trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.h.tmpl ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.h.tmpl Thu Jun 25 16:02:43 2009 (r1118) @@ -0,0 +1,31 @@ +/*** BEGIN file-header ***/ +#ifndef __SML_DEV_INF_ENUM_TYPES_H__ +#define __SML_DEV_INF_ENUM_TYPES_H__ + +/* WARNING: This file was generated by glib-mkenums. + * WARNING: + * WARNING: glib-mkenums --template sml_dev_inf_enum_types.h.tmpl *.h > sml_dev_inf_enum_types.h + * WARNING: + * WARNING: If you need to update this file then please run the command again. + */ + +#include <glib-object.h> + +G_BEGIN_DECLS +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@filename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType @enum_name@_get_type (void) G_GNUC_CONST; +#define SML_DEV_INF_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ +G_END_DECLS + +#endif /* __SML_DEV_INF_ENUM_TYPES_H__ */ +/*** END file-tail ***/ Modified: trunk/libsyncml/objects/sml_devinf_obj.c ============================================================================== --- trunk/libsyncml/objects/sml_devinf_obj.c Wed Jun 24 11:54:05 2009 (r1117) +++ trunk/libsyncml/objects/sml_devinf_obj.c Thu Jun 25 16:02:43 2009 (r1118) @@ -92,8 +92,10 @@ smlTrace(TRACE_ENTRY, "%s(%p)", __func__, data); SmlDevInfAgentSession *as = data; - if (as->recvDevInf) - smlDevInfUnref(as->recvDevInf); + if (as->recvDevInf) { + g_object_unref(as->recvDevInf); + as->recvDevInf = NULL; + } smlSafeFree((gpointer *) &as); smlTrace(TRACE_EXIT, "%s", __func__); @@ -171,7 +173,7 @@ */ if (smlSessionGetVersion(session) >= SML_VERSION_11 && session->sessionType == SML_SESSION_TYPE_SERVER && - !smlDevInfSupportsLargeObjs(agent->devinf)) + !sml_dev_inf_get_support_large_objs(agent->devinf)) { smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, "OMA DS Server must support large object handling if SyncML 1.1 or higher is used."); @@ -181,7 +183,7 @@ /* If large object support is enabled then MaxMsgSize and * MaxObjSize must be set. */ - if (smlDevInfSupportsLargeObjs(agent->devinf)) + if (sml_dev_inf_get_support_large_objs(agent->devinf)) { if (smlSessionGetLocalMaxMsgSize(session) < 1) { @@ -358,6 +360,7 @@ smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, devinf, error); CHECK_ERROR_REF smlAssert(devinf); + GError *gerror = NULL; SmlDevInfAgent *agent = smlTryMalloc0(sizeof(SmlDevInfAgent), error); if (!agent) @@ -370,14 +373,17 @@ goto error; } - if (!smlDevInfGetManufacturer(devinf)) - smlDevInfSetManufacturer(devinf, "OpenSync"); - if (!smlDevInfGetModel(devinf)) - smlDevInfSetModel(devinf, "libsyncml"); - if (!smlDevInfGetOEM(devinf)) + if (!sml_dev_inf_get_man(devinf) && + !sml_dev_inf_set_man(devinf, "OpenSync", &gerror)) + goto error; + if (!sml_dev_inf_get_mod(devinf) && + !sml_dev_inf_set_mod(devinf, "libsyncml", &gerror)) + goto error; + if (!sml_dev_inf_get_oem(devinf)) { #ifdef WIN32 - smlDevInfSetOEM(devinf, "Windows"); + if (!sml_dev_inf_set_oem(devinf, "Microsoft (R)", &gerror)) + goto error; DW... [truncated message content] |