| 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); |
|---|
| 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); |
|---|
| | 163 | OSyncObjFormatSink *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 | */ |
|---|
| | 176 | OSyncObjFormatSink *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; |
|---|
| 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 | */ |
|---|
| | 197 | OSyncList *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 | */ |
|---|
| | 210 | void 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); |
|---|
| 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 | | } |
|---|
| | 227 | void 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); |
|---|