Changeset 3316

Show
Ignore:
Timestamp:
05/04/08 22:39:46 (3 months ago)
Author:
dgollub
Message:

Added marshal/demarshal functions for OSyncObjFormatSink

Files:

Legend:

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

    r3201 r3316  
    3131osync_bool osync_marshal_data(OSyncMessage *message, OSyncData *data, OSyncError **error) 
    3232{ 
     33        osync_assert(message); 
     34        osync_assert(data); 
     35 
    3336        /* Order: 
    3437         *  
     
    4649        /* Write the format and objtype first */ 
    4750        osync_message_write_string(message, osync_objformat_get_name(objformat)); 
    48         osync_message_write_string(message, osync_objformat_get_config(objformat)); 
    4951        osync_message_write_string(message, osync_data_get_objtype(data)); 
    5052 
     
    8284osync_bool osync_demarshal_data(OSyncMessage *message, OSyncData **data, OSyncFormatEnv *env, OSyncError **error) 
    8385{ 
     86        osync_assert(message); 
     87        osync_assert(env); 
     88 
    8489        /* Order: 
    8590         *  
     
    9196        /* Get the objtype and format */ 
    9297        char *objformat = NULL; 
    93         char *objformat_config = NULL; 
    9498        char *objtype = NULL; 
    9599        osync_message_read_string(message, &objformat); 
    96         osync_message_read_string(message, &objformat_config); 
    97100        osync_message_read_string(message, &objtype); 
    98101         
     
    103106                goto error; 
    104107        } 
    105         osync_objformat_set_config(format, objformat_config); 
    106         g_free(objformat_config); 
    107108 
    108109        unsigned int input_size = 0; 
     
    147148osync_bool osync_marshal_change(OSyncMessage *message, OSyncChange *change, OSyncError **error) 
    148149{ 
     150        osync_assert(message); 
     151        osync_assert(change); 
     152 
    149153        /* Order: 
    150154         *  
     
    170174osync_bool osync_demarshal_change(OSyncMessage *message, OSyncChange **change, OSyncFormatEnv *env, OSyncError **error) 
    171175{ 
     176        osync_assert(message); 
     177        osync_assert(env); 
     178 
    172179        /* Order: 
    173180         *  
     
    213220} 
    214221 
     222osync_bool osync_marshal_objformat_sink(OSyncMessage *message, OSyncObjFormatSink *sink, OSyncError **error) 
     223{ 
     224        /* Order: 
     225         *  
     226         * objformat name 
     227         * objformat sink config 
     228         */ 
     229 
     230        const char *objformat_name = osync_objformat_sink_get_objformat(sink); 
     231        const char *objformat_sink_config = osync_objformat_sink_get_config(sink); 
     232 
     233        osync_message_write_string(message, objformat_name);  
     234        osync_message_write_string(message, objformat_sink_config);  
     235         
     236        return TRUE; 
     237} 
     238 
     239osync_bool osync_demarshal_objformat_sink(OSyncMessage *message, OSyncObjFormatSink **sink, OSyncError **error) 
     240{ 
     241        osync_assert(message); 
     242 
     243        /* Order: 
     244         *  
     245         * objformat name 
     246         * objformat sink config 
     247         */ 
     248         
     249        /* Get the objtype and format */ 
     250        char *objformat_name = NULL; 
     251        char *objformat_sink_config = NULL; 
     252        osync_message_read_string(message, &objformat_name); 
     253         
     254        *sink = osync_objformat_sink_new(objformat_name, error); 
     255        if (!*sink) 
     256                goto error; 
     257 
     258        osync_message_read_string(message, &objformat_sink_config); 
     259        osync_objformat_sink_set_config(*sink, objformat_sink_config); 
     260        g_free(objformat_sink_config); 
     261 
     262        return TRUE; 
     263 
     264error: 
     265        osync_trace(TRACE_ERROR, "%s: %s", __func__, osync_error_print(error)); 
     266        return FALSE; 
     267} 
     268 
    215269osync_bool osync_marshal_objtype_sink(OSyncMessage *message, OSyncObjTypeSink *sink, OSyncError **error) 
    216270{ 
     271        osync_assert(message); 
     272        osync_assert(sink); 
     273 
    217274        /* Order: 
    218275         *  
     
    221278         * get_changes function (bool) 
    222279         * write function (bool) 
    223          * number of formats 
    224          * format list (string
     280         * number of format sinks  
     281         * format sink list (format sinks
    225282         * enabled (int) 
    226283         * timeout connect (int) 
     
    237294         
    238295        int i = 0; 
    239         int num = osync_objtype_sink_num_objformats(sink); 
     296        unsigned int num = osync_objtype_sink_num_objformat_sinks(sink); 
    240297        osync_message_write_string(message, osync_objtype_sink_get_name(sink)); 
    241298 
     
    246303        osync_message_write_int(message, num); 
    247304        for (i = 0; i < num; i++) { 
    248                 const char *format = osync_objtype_sink_nth_objformat(sink, i); 
    249                 const char *format_config = osync_objtype_sink_nth_objformat_config(sink, i); 
    250                 osync_message_write_string(message, format); 
    251                 osync_message_write_string(message, format_config); 
     305                OSyncObjFormatSink *formatsink = osync_objtype_sink_nth_objformat_sink(sink, i); 
     306                if (!osync_marshal_objformat_sink(message, formatsink, error))  
     307                        goto error; 
    252308        } 
    253309         
     
    270326         
    271327        return TRUE; 
     328 
     329error: 
     330        return FALSE; 
    272331} 
    273332 
    274333osync_bool osync_demarshal_objtype_sink(OSyncMessage *message, OSyncObjTypeSink **sink, OSyncError **error) 
    275334{ 
     335        osync_assert(message); 
     336 
    276337        /* Order: 
    277338         *  
     
    280341         * get_changes function (bool) 
    281342         * write function (bool) 
    282          * number of formats 
    283          * format list (string
     343         * number of format sinks  
     344         * format sink list (format sinks
    284345         * enabled (int) 
    285346         * timeout connect (int) 
     
    303364        int enabled = 0, timeout = 0; 
    304365        int read = 0, get_changes = 0, write = 0; 
    305         char *format = NULL; 
    306         char *format_config = NULL; 
    307366         
    308367        osync_message_read_string(message, &name); 
     
    322381        int i = 0; 
    323382        for (i = 0; i < num_formats; i++) { 
    324                 osync_message_read_string(message, &format); 
    325                 osync_message_read_string(message, &format_config); 
    326                 osync_objtype_sink_add_objformat_with_config(*sink, format, format_config); 
    327                 g_free(format); 
    328                 g_free(format_config); 
     383                OSyncObjFormatSink *formatsink; 
     384                if (!osync_demarshal_objformat_sink(message, &formatsink, error))  
     385                        goto error; 
     386 
     387                osync_objtype_sink_add_objformat_sink(*sink, formatsink); 
     388                osync_objformat_sink_unref(formatsink); 
    329389        } 
    330390 
     
    369429void osync_marshal_error(OSyncMessage *message, OSyncError *error) 
    370430{ 
     431        osync_assert(message); 
     432 
    371433        if (error) { 
    372434                osync_message_write_int(message, 1); 
     
    381443void osync_demarshal_error(OSyncMessage *message, OSyncError **error) 
    382444{ 
     445        osync_assert(message); 
     446 
    383447        int hasError = 0; 
    384448 
  • trunk/opensync/ipc/opensync_serializer.h

    r1084 r3316  
    3131void osync_demarshal_error(OSyncMessage *message, OSyncError **error); 
    3232 
     33osync_bool osync_marshal_objformat_sink(OSyncMessage *message, OSyncObjFormatSink *sink, OSyncError **error); 
     34osync_bool osync_demarshal_objformat_sink(OSyncMessage *message, OSyncObjFormatSink **sink, OSyncError **error); 
     35 
    3336osync_bool osync_marshal_objtype_sink(OSyncMessage *message, OSyncObjTypeSink *sink, OSyncError **error); 
    3437osync_bool osync_demarshal_objtype_sink(OSyncMessage *message, OSyncObjTypeSink **sink, OSyncError **error);