Changeset 3319

Show
Ignore:
Timestamp:
05/04/08 22:44:01 (5 months ago)
Author:
dgollub
Message:

Introduced relation betwen OSyncObjTypeSink and OSyncObjFormatSink,

the format_vertice replacement.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/opensync/plugin/opensync_sink.c

    r3174 r3319  
    2323 
    2424#include "opensync-context.h" 
     25#include "opensync-format.h" 
     26 
    2527#include "opensync_sink.h" 
    2628#include "opensync_sink_internals.h" 
    2729 
    2830/** 
    29  * @defgroup OSyncSinkAPI OpenSync Sink 
     31 * @defgroup OSyncObjTypeSinkAPI OpenSync Object Type Sink 
    3032 * @ingroup OSyncPublic 
    31  * @brief Functions to register and manage sinks 
     33 * @brief Functions to register and manage object type sinks 
    3234 *  
    3335 */ 
     
    102104         
    103105        if (g_atomic_int_dec_and_test(&(sink->ref_count))) { 
    104                 while (sink->objformats) { 
    105                         char **format_vertice = sink->objformats->data; 
    106                         char *format = format_vertice[0]; 
    107                         char *format_config = format_vertice[1]; 
    108                         g_free(format); 
    109                         if(format_config) 
    110                               g_free(format_config); 
    111                         g_free(format_vertice); 
    112                         sink->objformats = osync_list_remove(sink->objformats, sink->objformats->data); 
     106                while (sink->objformatsinks) { 
     107                        osync_objformat_sink_unref(sink->objformatsinks->data); 
     108                        sink->objformatsinks = osync_list_remove(sink->objformatsinks, sink->objformatsinks->data); 
    113109                } 
    114110                 
     
    146142} 
    147143 
    148 static osync_bool _osync_objtype_sink_find_objformat(OSyncObjTypeSink *sink, const char *format) 
    149 { 
    150         osync_assert(sink); 
    151         OSyncList *f = sink->objformats; 
    152         for (; f; f = f->next) { 
    153                 const char **format_vertice = f->data; 
    154                 if (!strcmp(format_vertice[0], format)) 
    155                         return TRUE; 
    156         } 
    157         return FALSE; 
    158 } 
    159  
    160144/*! @brief Returns the number of object formats in the sink 
    161145 *  
     
    164148 *  
    165149 */ 
    166 int osync_objtype_sink_num_objformats(OSyncObjTypeSink *sink) 
    167 { 
    168         osync_assert(sink); 
    169         return osync_list_length(sink->objformats); 
     150unsigned int osync_objtype_sink_num_objformat_sinks(OSyncObjTypeSink *sink) 
     151{ 
     152        osync_assert(sink); 
     153        return osync_list_length(sink->objformatsinks); 
    170154} 
    171155 
     
    177161 *  
    178162 */ 
    179 const char *osync_objtype_sink_nth_objformat(OSyncObjTypeSink *sink, int nth) 
    180 
    181         osync_assert(sink); 
    182         char **format_vertice = osync_list_nth_data(sink->objformats, nth); 
    183         if (format_vertice) 
    184                 return format_vertice[0]; 
    185         else 
    186                 return NULL; 
    187 
    188  
    189 /*! @brief Returns the nth object format conversion config in the sink 
    190  *  
    191  * @param sink Pointer to the sink 
    192  * @param nth the index of the object format conversion config to return 
    193  * @returns the conversion config of the object format at the specified index 
    194  *  
    195  */ 
    196 const char *osync_objtype_sink_nth_objformat_config(OSyncObjTypeSink *sink, int nth) 
    197 
    198         osync_assert(sink); 
    199         char **format_vertice = osync_list_nth_data(sink->objformats, nth); 
    200         if (format_vertice)  
    201                 return format_vertice[1]; 
    202         else 
    203                 return NULL; 
    204 
    205  
    206 /** @brief Returns the list of object formats in the sink 
    207  *  
    208  * @param sink Pointer to the sink 
    209  * @returns the list of formats in the sink 
    210  *  
    211  */ 
    212 const OSyncList *osync_objtype_sink_get_objformats(OSyncObjTypeSink *sink) 
    213 
    214         osync_assert(sink); 
    215         return sink->objformats; 
    216 
    217  
    218 /** @brief Adds an object format to the sink 
    219  *  
    220  * @param sink Pointer to the sink 
    221  * @param format name of the object format 
    222  *  
    223  */ 
    224 void osync_objtype_sink_add_objformat(OSyncObjTypeSink *sink, const char *format) 
    225 
    226         osync_assert(sink); 
    227         osync_assert(format); 
    228          
    229         if (!_osync_objtype_sink_find_objformat(sink, format)) { 
    230                 char **format_vertice = g_malloc0(2*sizeof(char **)); 
    231                 format_vertice[0] = g_strdup(format); 
    232                 format_vertice[1] = NULL; 
    233                 sink->objformats = osync_list_append(sink->objformats, format_vertice); 
     163OSyncObjFormatSink *osync_objtype_sink_nth_objformat_sink(OSyncObjTypeSink *sink, unsigned int nth) 
     164
     165        osync_assert(sink); 
     166        return osync_list_nth_data(sink->objformatsinks, nth); 
     167
     168 
     169/*! @brief Finds the objformat sink for the corresponding objformat  
     170 *  
     171 * @param sink Pointer to the sink 
     172 * @param objformat the objformat to look for the corresponding objformat sink 
     173 * @returns Pointer to the corresponding objformat sink if found, NULL otherwise  
     174 *  
     175 */ 
     176OSyncObjFormatSink *osync_objtype_sink_find_objformat_sink(OSyncObjTypeSink *sink, OSyncObjFormat *objformat) 
     177
     178        osync_assert(sink); 
     179        osync_assert(objformat); 
     180 
     181        OSyncList *f = sink->objformatsinks; 
     182        for (; f; f = f->next) { 
     183                OSyncObjFormatSink *formatsink = f->data; 
     184                const char *objformat_name = osync_objformat_get_name(objformat); 
     185                if (!strcmp(osync_objformat_sink_get_objformat(formatsink), objformat_name)) 
     186                        return formatsink; 
    234187        } 
    235 
    236  
    237 /** @brief Adds an object format with its conversion config to the sink 
    238  *  
    239  * @param sink Pointer to the sink 
    240  * @param format name of the object format 
    241  * @param format_config config of the object format for the conversion path 
    242  *  
    243  */ 
    244 void osync_objtype_sink_add_objformat_with_config(OSyncObjTypeSink *sink, const char *format, const char *format_config) 
    245 
    246         osync_assert(sink); 
    247         osync_assert(format); 
    248          
    249         if (!_osync_objtype_sink_find_objformat(sink, format)) { 
    250                 char **format_vertice = g_malloc0(2*sizeof(char **)); 
    251                 format_vertice[0] = g_strdup(format); 
    252                 format_vertice[1] = g_strdup(format_config); 
    253                 osync_trace(TRACE_INTERNAL, "CONFIG %s", format_vertice[1]); 
    254                 sink->objformats = osync_list_append(sink->objformats, format_vertice); 
     188        return NULL; 
     189
     190 
     191/*! @brief Get list of object format sinks  
     192 *  
     193 * @param sink Pointer to the sink 
     194 * @returns List of object format sinks  
     195 *  
     196 */ 
     197OSyncList *osync_objtype_sink_get_objformat_sinks(OSyncObjTypeSink *sink) 
     198
     199        osync_assert(sink); 
     200        return sink->objformatsinks; 
     201
     202 
     203 
     204/** @brief Adds an object format sink to the sink 
     205 *  
     206 * @param sink Pointer to the sink 
     207 * @param objformat The object format sink to add  
     208 *  
     209 */ 
     210void osync_objtype_sink_add_objformat_sink(OSyncObjTypeSink *sink, OSyncObjFormatSink *objformatsink) 
     211
     212        osync_assert(sink); 
     213        osync_assert(objformatsink); 
     214 
     215        if (!osync_list_find(sink->objformatsinks, objformatsink)) { 
     216                sink->objformatsinks = osync_list_append(sink->objformatsinks, objformatsink); 
     217                osync_objformat_sink_ref(objformatsink); 
    255218        } 
    256219} 
     
    262225 *  
    263226 */ 
    264 void osync_objtype_sink_remove_objformat(OSyncObjTypeSink *sink, const char *format) 
    265 
    266         OSyncList *f = NULL; 
    267         osync_assert(sink); 
    268         osync_assert(format); 
    269         for (f = sink->objformats; f; f = f->next) { 
    270                 const char **format_vertice = f->data; 
    271                 if (!strcmp(format_vertice[0], format)) { 
    272                         sink->objformats = osync_list_remove(sink->objformats, f->data); 
    273                         break; 
    274                 } 
    275         } 
     227void osync_objtype_sink_remove_objformat_sink(OSyncObjTypeSink *sink, OSyncObjFormatSink *objformatsink) 
     228
     229        osync_assert(sink); 
     230        osync_assert(objformatsink); 
     231 
     232        sink->objformatsinks = osync_list_remove(sink->objformatsinks, objformatsink); 
     233        osync_objformat_sink_unref(objformatsink); 
    276234} 
    277235 
  • trunk/opensync/plugin/opensync_sink.h

    r3063 r3319  
    5252OSYNC_EXPORT void osync_objtype_sink_set_name(OSyncObjTypeSink *sink, const char *name); 
    5353 
    54 OSYNC_EXPORT int osync_objtype_sink_num_objformats(OSyncObjTypeSink *sink); 
    55 OSYNC_EXPORT const char *osync_objtype_sink_nth_objformat(OSyncObjTypeSink *sink, int nth); 
    56 OSYNC_EXPORT const char *osync_objtype_sink_nth_objformat_config(OSyncObjTypeSink *sink, int nth); 
    57 OSYNC_EXPORT void osync_objtype_sink_add_objformat(OSyncObjTypeSink *sink, const char *format); 
    58 OSYNC_EXPORT void osync_objtype_sink_add_objformat_with_config(OSyncObjTypeSink *sink, const char *format, const char *format_config); 
    59 OSYNC_EXPORT void osync_objtype_sink_remove_objformat(OSyncObjTypeSink *sink, const char *format); 
     54OSYNC_EXPORT unsigned int osync_objtype_sink_num_objformat_sinks(OSyncObjTypeSink *sink); 
     55OSYNC_EXPORT OSyncObjFormatSink *osync_objtype_sink_nth_objformat_sink(OSyncObjTypeSink *sink, unsigned int nth); 
     56OSYNC_EXPORT OSyncObjFormatSink *osync_objtype_sink_find_objformat_sink(OSyncObjTypeSink *sink, OSyncObjFormat *objformat); 
     57OSYNC_EXPORT OSyncList *osync_objtype_sink_get_objformat_sinks(OSyncObjTypeSink *sink); 
     58OSYNC_EXPORT void osync_objtype_sink_add_objformat_sink(OSyncObjTypeSink *sink, OSyncObjFormatSink *objformatsink); 
     59OSYNC_EXPORT void osync_objtype_sink_remove_objformat_sink(OSyncObjTypeSink *sink, OSyncObjFormatSink *objformatsink); 
    6060 
    6161OSYNC_EXPORT void osync_objtype_sink_set_functions(OSyncObjTypeSink *sink, OSyncObjTypeSinkFunctions functions, void *userdata); 
     
    134134OSYNC_EXPORT unsigned int osync_objtype_sink_get_read_timeout(OSyncObjTypeSink *sink); 
    135135 
    136 OSYNC_EXPORT const OSyncList *osync_objtype_sink_get_objformats(OSyncObjTypeSink *sink); 
    137  
    138136#endif //_OPENSYNC_SINK_H_ 
  • trunk/opensync/plugin/opensync_sink_internals.h

    r3095 r3319  
    6868struct OSyncObjTypeSink { 
    6969        /** The format which can be synchronized by this sink */ 
    70         OSyncList *objformats
     70        OSyncList *objformatsinks
    7171        /** The functions to be called */ 
    7272        OSyncObjTypeSinkFunctions functions;