Changeset 3397

Show
Ignore:
Timestamp:
07/07/08 09:52:14 (2 months ago)
Author:
dgollub
Message:

Added marshaling/demarshaling for OSyncPluginRessource and
OSyncObjFormatSink.

TODO: Complete marshaling of OSyncPluginConfig.
OSyncPluginAuthentication, OSyncPluginLocalization is missing.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/opensync/ipc/opensync_serializer.c

    r3333 r3397  
    635635} 
    636636 
     637#define MARSHAL_OBJFORMATSINK_CONFIG (0x1 << 1) 
     638 
     639osync_bool osync_marshal_objformatsink(OSyncMessage *message, OSyncObjFormatSink *sink, OSyncError **error) 
     640{ 
     641        osync_assert(message); 
     642        osync_assert(sink); 
     643 
     644        /* Order: 
     645         * 
     646         * name (string) 
     647         * 
     648         * available_settings (uint) 
     649         *  
     650         * (optional) 
     651         * config (string) 
     652         */ 
     653 
     654        unsigned int available_settings = 0; 
     655        const char *config = osync_objformat_sink_get_config(sink); 
     656        const char *name = osync_objformat_sink_get_objformat(sink); 
     657 
     658        osync_assert(name); 
     659        osync_message_write_string(message, name); 
     660         
     661        if (config) 
     662                available_settings |= MARSHAL_OBJFORMATSINK_CONFIG; 
     663 
     664        osync_message_write_uint(message, available_settings); 
     665 
     666        if (config) 
     667                osync_message_write_string(message, config);  
     668 
     669        return TRUE; 
     670} 
     671 
     672osync_bool osync_demarshal_objformatsink(OSyncMessage *message, OSyncObjFormatSink **sink, OSyncError **error) 
     673{ 
     674        osync_assert(message); 
     675 
     676        /* Order: 
     677         * 
     678         * name (string) 
     679         * 
     680         * available_settings (uint) 
     681         *  
     682         * (optional) 
     683         * config (string) 
     684         */ 
     685 
     686        char *name = NULL; 
     687        char *config = NULL; 
     688 
     689        unsigned int available_settings = 0; 
     690 
     691        osync_message_read_string(message, &name); 
     692        osync_assert(name); 
     693 
     694        *sink = osync_objformat_sink_new(name, error); 
     695        if (!*sink) 
     696                goto error; 
     697 
     698        g_free(name); 
     699 
     700        osync_message_read_uint(message, &available_settings); 
     701 
     702        if (available_settings & MARSHAL_OBJFORMATSINK_CONFIG) { 
     703                osync_message_read_string(message, &config); 
     704                osync_objformat_sink_set_config(*sink, config); 
     705                g_free(config); 
     706        } 
     707 
     708        return TRUE; 
     709 
     710error: 
     711        if (name) 
     712                g_free(name); 
     713        return FALSE; 
     714} 
     715 
     716#define MARSHAL_PLUGINRESSOURCE_NAME (0x1 << 1) 
     717#define MARSHAL_PLUGINRESSOURCE_MIME (0x1 << 2) 
     718#define MARSHAL_PLUGINRESSOURCE_PATH (0x1 << 3) 
     719#define MARSHAL_PLUGINRESSOURCE_URL  (0x1 << 4) 
     720 
     721osync_bool osync_marshal_pluginressource(OSyncMessage *message, OSyncPluginRessource *res, OSyncError **error) 
     722{ 
     723        osync_assert(message); 
     724        osync_assert(res); 
     725 
     726        /* Order: 
     727         * 
     728         * enabled (int) 
     729         * objtype (string) 
     730         * num_sinks (uint) 
     731         * sinks (OSyncObjFormatSink) 
     732         * 
     733         * available_settings (uint) 
     734         *  
     735         * (optional) 
     736         * name (string) 
     737         * mime (string) 
     738         * path (string) 
     739         * url (string) 
     740         */ 
     741 
     742        unsigned int available_settings = 0; 
     743 
     744        const char *name = osync_plugin_ressource_get_name(res); 
     745        const char *mime = osync_plugin_ressource_get_mime(res); 
     746        const char *objtype = osync_plugin_ressource_get_objtype(res); 
     747        const char *path = osync_plugin_ressource_get_path(res); 
     748        const char *url = osync_plugin_ressource_get_url(res); 
     749 
     750        /* enabled */ 
     751        osync_message_write_int(message, osync_plugin_ressource_is_enabled(res)); 
     752 
     753        /* objtype */ 
     754        osync_assert(objtype); 
     755        osync_message_write_string(message, objtype); 
     756 
     757        /* num_sinks */ 
     758        OSyncList *sinks = osync_plugin_ressource_get_objformat_sinks(res); 
     759        unsigned int num_sinks = osync_list_length(sinks); 
     760        osync_message_write_uint(message, num_sinks); 
     761 
     762        /* format sinks */ 
     763        OSyncList *s; 
     764        for (s = osync_plugin_ressource_get_objformat_sinks(res); s; s = s->next) { 
     765                OSyncObjFormatSink *sink = s->data; 
     766                if (!osync_marshal_objformatsink(message, sink, error)) 
     767                        goto error; 
     768        } 
     769 
     770        /** optional fields */ 
     771 
     772        if (name) 
     773                available_settings |= MARSHAL_PLUGINRESSOURCE_NAME; 
     774 
     775        if (mime) 
     776                available_settings |= MARSHAL_PLUGINRESSOURCE_MIME; 
     777 
     778        if (path) 
     779                available_settings |= MARSHAL_PLUGINRESSOURCE_PATH; 
     780 
     781        if (url) 
     782                available_settings |= MARSHAL_PLUGINRESSOURCE_URL; 
     783 
     784        osync_message_write_uint(message, available_settings); 
     785 
     786        if (name) 
     787                osync_message_write_string(message, name); 
     788 
     789        if (mime) 
     790                osync_message_write_string(message, mime); 
     791 
     792        if (path) 
     793                osync_message_write_string(message, path); 
     794 
     795        if (url) 
     796                osync_message_write_string(message, url); 
     797         
     798        return TRUE; 
     799 
     800error: 
     801        return FALSE; 
     802} 
     803 
     804osync_bool osync_demarshal_pluginressource(OSyncMessage *message, OSyncPluginRessource **res, OSyncError **error) 
     805{ 
     806        /* Order: 
     807         * 
     808         * enabled (int) 
     809         * objtype (string) 
     810         * num_sinks (uint) 
     811         * sinks (OSyncObjFormatSink) 
     812         * 
     813         * available_settings (uint) 
     814         *  
     815         * (optional) 
     816         * name (string) 
     817         * mime (string) 
     818         * path (string) 
     819         * url (string) 
     820         */ 
     821 
     822        int enabled; 
     823        char *objtype = NULL; 
     824        unsigned int i, num_sinks; 
     825        unsigned int available_settings; 
     826        char *name = NULL; 
     827        char *mime = NULL; 
     828        char *path = NULL; 
     829        char *url = NULL; 
     830 
     831        *res = osync_plugin_ressource_new(error); 
     832        if (!*res) 
     833                goto error; 
     834 
     835 
     836        osync_message_read_int(message, &enabled); 
     837        osync_plugin_ressource_enable(*res, enabled); 
     838 
     839        osync_message_read_string(message, &objtype); 
     840        osync_plugin_ressource_set_objtype(*res, objtype); 
     841        g_free(objtype); 
     842 
     843        osync_message_read_uint(message, &num_sinks); 
     844        for (i=0; i < num_sinks; i++) { 
     845                OSyncObjFormatSink *sink = NULL; 
     846                if (!osync_demarshal_objformatsink(message, &sink, error)) 
     847                        goto error; 
     848 
     849                osync_plugin_ressource_add_objformat_sink(*res, sink); 
     850        } 
     851 
     852        osync_message_read_uint(message, &available_settings); 
     853 
     854        if (available_settings & MARSHAL_PLUGINRESSOURCE_NAME) { 
     855                osync_message_read_string(message, &name); 
     856                osync_plugin_ressource_set_name(*res, name); 
     857                g_free(name); 
     858        } 
     859 
     860        if (available_settings & MARSHAL_PLUGINRESSOURCE_MIME) { 
     861                osync_message_read_string(message, &mime); 
     862                osync_plugin_ressource_set_mime(*res, mime); 
     863                g_free(mime); 
     864        } 
     865 
     866        if (available_settings & MARSHAL_PLUGINRESSOURCE_PATH) { 
     867                osync_message_read_string(message, &path); 
     868                osync_plugin_ressource_set_path(*res, path); 
     869                g_free(path); 
     870        } 
     871 
     872        if (available_settings & MARSHAL_PLUGINRESSOURCE_URL) { 
     873                osync_message_read_string(message, &url); 
     874                osync_plugin_ressource_set_url(*res, url); 
     875                g_free(url); 
     876        } 
     877 
     878        return TRUE; 
     879 
     880error: 
     881        return FALSE; 
     882} 
     883 
    637884#define MARSHAL_PLUGINCONFIG_CONNECTION (0x1 << 1) 
    638885#define MARSHAL_PLUGINCONFIG_AUTHENTICATON (0x1 << 2) 
     
    651898         * $authenticatoin 
    652899         * $localization 
     900         * $num_ressources 
     901         * $ressources 
    653902         */ 
    654903 
     
    665914        if (conn && !osync_marshal_pluginconnection(message, conn, error)) 
    666915                goto error; 
     916 
     917 
     918        OSyncList *r = osync_plugin_config_get_ressources(config); 
     919        osync_message_write_uint(message, osync_list_length(r)); 
     920 
     921        for (; r; r = r->next) { 
     922                OSyncPluginRessource *res = r->data; 
     923                if (!osync_marshal_pluginressource(message, res, error)) 
     924                        goto error; 
     925        } 
     926 
    667927         
    668928        return TRUE; 
     
    681941         * $authenticatoin 
    682942         * $localization 
     943         * $num_ressources 
     944         * $ressources 
    683945 
    684946         */ 
     
    686948        OSyncPluginConnection *conn = NULL; 
    687949        unsigned int available_subconfigs = 0; 
     950        unsigned int i, num_ressources = 0; 
    688951         
    689952        *config = osync_plugin_config_new(error); 
     
    702965        } 
    703966 
     967        osync_message_read_uint(message, &num_ressources); 
     968 
     969        /* number of ressources */ 
     970        for (i = 0; i < num_ressources; i++) { 
     971                OSyncPluginRessource *res; 
     972                if (!osync_demarshal_pluginressource(message, &res, error)) 
     973                        goto error_free_config; 
     974 
     975                osync_plugin_config_add_ressource(*config, res); 
     976 
     977        } 
    704978 
    705979        return TRUE;