OSyncFormatConverterPath *osync_format_env_find_path_formats_with_detectors(OSyncFormatEnv *env, OSyncData *sourcedata, OSyncList *targets, const char *preferred_format, OSyncError **error) { OSyncFormatConverterPath *path = NULL; GString *string = g_string_new(""); OSyncList *t; guint size = osync_list_length(targets); guint count = 0; for (t = targets; t; t = t->next) { OSyncObjFormatSink *format_sink = t->data; count ++; g_string_append(string, osync_objformat_sink_get_objformat(format_sink)); if (size > 1 && count < size) g_string_append(string, " - "); } osync_trace(TRACE_ENTRY, "%s(%p, %p, %p:%s, %s, %p)", __func__, env, sourcedata, targets, string->str, preferred_format ? preferred_format:"NONE", error); g_string_free(string, TRUE); path = osync_format_env_find_path_fn(env, sourcedata, osync_format_converter_path_vertice_target_fn_format_sinks, osync_format_converter_tree_target_fn_format_sinks_reached_lastconverter, targets, preferred_format, error); if (!path) { osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return NULL; } osync_trace(TRACE_EXIT, "%s: %p", __func__, path); return path; }
static osync_bool osync_format_converter_tree_target_fn_format_sinks_reached_lastconverter(const void *data, OSyncFormatConverterTree *tree) { OSyncList *f, *formats = (OSyncList *) data; GList *c; OSyncFormatConverter *converter = NULL; for (c = tree->unused; c; c = c->next) { converter = c->data; for (f = formats; f; f = f->next) { OSyncObjFormatSink *format_sink = f->data; const char *format = osync_objformat_sink_get_objformat(format_sink); if (!strcmp(format, osync_objformat_get_name(osync_converter_get_targetformat(converter)))) return FALSE; } } return TRUE; }
/** Function used on a path search OSyncFormatConverterPathVertice objformat to check if it matches an OSyncList of OSyncObjFormatSinks * @param data List of OSyncObjFormatSinks * @param fmt format to compare with * @see osync_conv_find_path_fn(), osync_change_convert_fmtnames() */ static osync_bool osync_format_converter_path_vertice_target_fn_format_sinks(const void *data, OSyncObjFormat *fmt) { OSyncList *f, *formats = (OSyncList *) data; for (f = formats; f; f = f->next) { OSyncObjFormatSink *format_sink = f->data; const char *format = osync_objformat_sink_get_objformat(format_sink); /*if (osync_objformat_is_equal(fmt, format))*/ if (!strcmp(format, osync_objformat_get_name(fmt))) /* Found */ return TRUE; } /* Not found */ return FALSE; }
static void *initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) { /* * get the config */ OSyncPluginConfig *config = osync_plugin_info_get_config(info); if (!config) { osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get config."); goto error; } /* * You need to specify the <some name>_environment somewhere with * all the members you need */ plugin_environment *env = osync_try_malloc0(sizeof(plugin_environment), error); if (!env) goto error; env->sink_envs = NULL; osync_trace(TRACE_INTERNAL, "The config: %s", osync_plugin_info_get_config(info)); /* * Process the config here and set the options on your environment */ /* * Process plugin specific advanced options */ OSyncList *optslist = osync_plugin_config_get_advancedoptions(config); for (; optslist; optslist = optslist->next) { OSyncPluginAdvancedOption *option = optslist->data; const char *val = osync_plugin_advancedoption_get_value(option); const char *name = osync_plugin_advancedoption_get_name(option); if (!strcmp(name,"<your-option>")) { if (!strcmp(val, "<your-value>")) { /* * set a varaible to a specific value */; } } } /* * Process Ressource options */ int i, numobjs = osync_plugin_info_num_objtypes(info); for (i = 0; i < numobjs; i++) { sink_environment *sinkenv = osync_try_malloc0(sizeof(sink_environment), error); if (!sinkenv) goto error_free_env; sinkenv->sink = osync_plugin_info_nth_objtype(info, i); osync_assert(sinkenv->sink); const char *objtype = osync_objtype_sink_get_name(sinkenv->sink); OSyncPluginResource *res = osync_plugin_config_find_active_resource(config, objtype); /* get objformat sinks */ OSyncList *s = osync_plugin_resource_get_objformat_sinks(res); for (; s; s = s->next) { OSyncObjFormatSink *fsink = s->data; // there could be only one sink const char *objformat = osync_objformat_sink_get_objformat(fsink); osync_assert(objformat); osync_trace(TRACE_INTERNAL, "objtype %s has objformat %s", objtype, objformat); } /* Every sink can have different functions ... */ OSyncObjTypeSinkFunctions functions; memset(&functions, 0, sizeof(functions)); functions.connect = connect; functions.disconnect = disconnect; functions.get_changes = get_changes; functions.commit = commit_change; functions.sync_done = sync_done; /* We pass the OSyncFileDir object to the sink, so we dont have to look it up * again once the functions are called */ osync_objtype_sink_set_functions(sinkenv->sink, functions, sinkenv); osync_trace(TRACE_INTERNAL, "The configdir: %s", osync_plugin_info_get_configdir(info)); char *tablepath = osync_strdup_printf("%s/hashtable.db", osync_plugin_info_get_configdir(info)); sinkenv->hashtable = osync_hashtable_new(tablepath, objtype, error); osync_free(tablepath); env->sink_envs = osync_list_append(env->sink_envs, sinkenv); } //Now your return your struct. return (void *) env; error_free_env: free_env(env); error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return NULL; }
static void *initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) { /* * get the config */ OSyncPluginConfig *config = osync_plugin_info_get_config(info); if (!config) { osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get config."); goto error; } /* * You need to specify the <some name>_environment somewhere with * all the members you need */ plugin_environment *env = osync_try_malloc0(sizeof(plugin_environment), error); if (!env) goto error; /* * Process the config here and set the options on your environment * if required. */ /* * Process plugin specific advanced options */ OSyncList *optslist = osync_plugin_config_get_advancedoptions(config); OSyncList *o; for (o = optslist; o; o = o->next) { OSyncPluginAdvancedOption *option = o->data; const char *val = osync_plugin_advancedoption_get_value(option); const char *name = osync_plugin_advancedoption_get_name(option); if (!strcmp(name,"<your-option>")) { if (!strcmp(val, "<your-value>")) { /* * set a varaible to a specific value */; } } } osync_list_free(optslist); /* * Process Ressource options */ OSyncList *l, *list = NULL; list = osync_plugin_info_get_objtype_sinks(info); for (l=list; l; l = l->next) { OSyncObjTypeSink *sink = (OSyncObjTypeSink *) l->data; const char *objtype = osync_objtype_sink_get_name(sink); OSyncPluginResource *res = osync_plugin_config_find_active_resource(config, objtype); /* get objformat sinks */ OSyncList *s = NULL; OSyncList *objformats = osync_plugin_resource_get_objformat_sinks(res); for (s = objformats; s; s = s->next) { OSyncObjFormatSink *fsink = s->data; // there could be only one sink const char *objformat = osync_objformat_sink_get_objformat(fsink); osync_assert(objformat); osync_trace(TRACE_INTERNAL, "objtype %s has objformat %s", objtype, objformat); } osync_list_free(objformats); /* Every sink can have different functions ... */ osync_objtype_sink_set_connect_func(sink, connect); osync_objtype_sink_set_disconnect_func(sink, disconnect); osync_objtype_sink_set_get_changes_func(sink, get_changes); osync_objtype_sink_set_commit_func(sink, commit_change); osync_objtype_sink_set_sync_done_func(sink, sync_done); /* * If you need plugin specific userdata passed to this * plugin sink functions. You can set it with: * * osync_objtype_sink_set_userdata(sink, userdata_pointer); */ /* Request a Hahstable here - if you need it. * It will be later available via osync_objtype_sink_get_hashtable(OSyncObjTypeSink *) * in the plugin sink functions (e.g. connect, get_changes, commit, ...) */ osync_objtype_sink_enable_hashtable(sink, TRUE); } osync_list_free(list); //Now your return your environemtn struct. return (void *) env; error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return NULL; }
/* In initialize, we get the config for the plugin. Here we also must register * all _possible_ objtype sinks. */ static void *mock_initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, plugin, info, error); if (mock_get_error(info->memberid, "INIT_NULL_NOERROR")) { osync_trace(TRACE_EXIT, "%s: %s", __func__, "Everything is fine. I don't need plugin userdata."); return NULL; } if (mock_get_error(info->memberid, "INIT_NULL")) { osync_error_set(error, OSYNC_ERROR_EXPECTED, "Triggering INIT_NULL error"); osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return NULL; } mock_env *env = osync_try_malloc0(sizeof(mock_env), error); osync_assert(env); OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info); osync_assert(formatenv); OSyncPluginConfig *config = osync_plugin_info_get_config(info); osync_assert(config); if (mock_get_error(info->memberid, "MAINSINK_CONNECT")) { env->mainsink = osync_objtype_main_sink_new(error); osync_objtype_sink_set_connect_func(env->mainsink, mock_connect); osync_objtype_sink_set_disconnect_func(env->mainsink, mock_mainsink_disconnect); osync_objtype_sink_set_userdata(env->mainsink, env); osync_plugin_info_set_main_sink(info, env->mainsink); } /* Now we register the objtypes that we can sync. This plugin is special. It can * synchronize any objtype we configure it to sync and where a conversion * path to the file format can be found */ OSyncList *objtypesinks = osync_plugin_info_get_objtype_sinks(info); OSyncList *list = NULL; for (list = objtypesinks;list; list = list->next) { MockDir *dir = osync_try_malloc0(sizeof(MockDir), error); osync_assert(dir); dir->committed_all = TRUE; OSyncObjTypeSink *sink = (OSyncObjTypeSink*)list->data; osync_assert(sink); const char *objtype = osync_objtype_sink_get_name(sink); dir->res = osync_plugin_config_find_active_resource(config, objtype); osync_plugin_resource_ref(dir->res); dir->path = osync_plugin_resource_get_path(dir->res); osync_assert(dir->path); OSyncList *format_sinks = osync_plugin_resource_get_objformat_sinks(dir->res); osync_assert(osync_list_length(format_sinks) == 1); OSyncObjFormatSink *format_sink = osync_list_nth_data(format_sinks, 0); const char *objformat_str = osync_objformat_sink_get_objformat(format_sink); osync_assert(objformat_str); dir->objformat = osync_format_env_find_objformat(formatenv, objformat_str); osync_assert(dir->objformat); osync_objformat_ref(dir->objformat); osync_list_free(format_sinks); /* const char *objformat = osync_objformat_get_name(dir->objformat); OSyncObjFormatSink *format_sink = osync_objformat_sink_new(objformat, error); if (!format_sink) return NULL; osync_objtype_sink_add_objformat_sink(sink, format_sink); */ /* Sanity check for connect_done */ dir->connect_done = TRUE; if (!mock_get_error(info->memberid, "MAINSINK_CONNECT")) { osync_objtype_sink_set_connect_func(sink, mock_connect); osync_objtype_sink_set_connect_done_func(sink, mock_connect_done); osync_objtype_sink_set_disconnect_func(sink, mock_disconnect); } osync_objtype_sink_set_get_changes_func(sink, mock_get_changes); osync_objtype_sink_set_committed_all_func(sink, mock_committed_all); osync_objtype_sink_set_commit_func(sink, mock_commit_change); osync_objtype_sink_set_read_func(sink, mock_read); osync_objtype_sink_set_sync_done_func(sink, mock_sync_done); /* We pass the MockDir object to the sink, so we dont have to look it up * again once the functions are called */ osync_objtype_sink_set_userdata(sink, dir); /* Request an Anchor */ osync_objtype_sink_enable_state_db(sink, TRUE); /* Request an Hashtable */ osync_objtype_sink_enable_hashtable(sink, TRUE); //Lets reduce the timeouts a bit so the checks work faster osync_objtype_sink_set_connect_timeout(sink, 2); osync_objtype_sink_set_getchanges_timeout(sink, 2); osync_objtype_sink_set_commit_timeout(sink, 4); osync_objtype_sink_set_committedall_timeout(sink, 4); osync_objtype_sink_set_syncdone_timeout(sink, 2); osync_objtype_sink_set_disconnect_timeout(sink, 2); osync_objtype_sink_set_read_timeout(sink, 2); /* XXX No testcase is currently using this at all! */ #if 0 if (g_getenv("NO_TIMEOUTS")) { /* XXX Timeout value of wouldn't work out, since the Sink object would fallback to the default timeout value: sink->timeout.connect ? sink->timeout.connect : OSYNC_SINK_TIMEOUT_CONNECT; Really needed?! */ osync_objtype_sink_set_connect_timeout(sink, 0); osync_objtype_sink_set_getchanges_timeout(sink, 0); osync_objtype_sink_set_commit_timeout(sink, 0); osync_objtype_sink_set_committedall_timeout(sink, 0); osync_objtype_sink_set_syncdone_timeout(sink, 0); osync_objtype_sink_set_disconnect_timeout(sink, 0); osync_objtype_sink_set_read_timeout(sink, 0); } /* What is meant by this?! Maybe OSyncPlugin.useable?! Not used at all... if (g_getenv("IS_AVAILABLE")) info->functions.is_available = mock_is_available; */ #endif env->directories = g_list_append(env->directories, dir); } osync_list_free(objtypesinks); osync_trace(TRACE_EXIT, "%s: %p", __func__, env); return (void *)env; }