22 #include "opensync_internals.h" 33 #ifndef DOXYGEN_SHOULD_SKIP_THIS 34 OSyncObjTypeSink *osync_objtype_sink_from_template(
OSyncGroup *group, OSyncObjTypeTemplate *
template)
38 OSyncObjTypeSink *sink = g_malloc0(
sizeof(OSyncObjTypeSink));
41 osync_debug(
"OSYNC", 0,
"Unable to find objtype named %s to create objtype sink", template->name);
51 OSyncObjFormatSink *osync_objformat_sink_from_template(
OSyncGroup *group, OSyncObjFormatTemplate *
template)
53 OSyncObjFormatSink *sink = g_malloc0(
sizeof(OSyncObjFormatSink));
57 sink->format = format;
58 sink->functions.commit_change =
template->commit_change;
59 sink->functions.access =
template->access;
60 sink->functions.read =
template->read;
61 sink->functions.committed_all =
template->committed_all;
62 sink->functions.batch_commit =
template->batch_commit;
63 sink->extension_name = g_strdup(template->extension_name);
67 OSyncObjTypeTemplate *osync_plugin_find_objtype_template(
OSyncPlugin *plugin,
const char *objtypestr)
70 for (o = plugin->accepted_objtypes; o; o = o->next) {
71 OSyncObjTypeTemplate *
template = o->data;
72 if (!strcmp(template->name, objtypestr))
78 OSyncObjFormatTemplate *osync_plugin_find_objformat_template(OSyncObjTypeTemplate *type_template,
const char *objformatstr)
81 for (f = type_template->formats; f; f = f->next) {
82 OSyncObjFormatTemplate *
template = f->data;
83 if (!strcmp(template->name, objformatstr))
89 OSyncObjFormatSink *osync_objtype_find_format_sink(OSyncObjTypeSink *sink,
const char *formatstr)
92 for (f = sink->formatsinks; f; f = f->next) {
93 OSyncObjFormatSink *sink = f->data;
94 if (!strcmp(sink->format->name, formatstr))
100 void _osync_format_set_commit(OSyncObjTypeTemplate *
template,
const char *formatstr, OSyncFormatCommitFn commit_change)
102 OSyncObjFormatTemplate *format_template = NULL;
104 OSyncObjFormatTemplate *format_template = osync_plugin_find_objformat_template(
template, formatstr);
105 osync_assert_msg(format_template,
"Unable to set commit function. Did you forget to add the objformat?");
106 format_template->commit_change = commit_change;
109 for (f = template->formats; f; f = f->next) {
110 format_template = f->data;
111 format_template->commit_change = commit_change;
116 void _osync_format_set_access(OSyncObjTypeTemplate *
template,
const char *formatstr, OSyncFormatAccessFn access)
118 OSyncObjFormatTemplate *format_template = NULL;
120 format_template = osync_plugin_find_objformat_template(
template, formatstr);
121 osync_assert_msg(format_template,
"Unable to set commit function. Did you forget to add the objformat?");
122 format_template->access = access;
125 for (f = template->formats; f; f = f->next) {
126 format_template = f->data;
127 format_template->access = access;
132 void _osync_format_set_batch(OSyncObjTypeTemplate *
template,
const char *formatstr, OSyncFormatBatchCommitFn batch)
134 OSyncObjFormatTemplate *format_template = NULL;
136 format_template = osync_plugin_find_objformat_template(
template, formatstr);
137 osync_assert_msg(format_template,
"Unable to set batch commit function. Did you forget to add the objformat?");
138 format_template->batch_commit = batch;
141 for (f = template->formats; f; f = f->next) {
142 format_template = f->data;
143 format_template->batch_commit = batch;
171 memset(&(plugin->info), 0,
sizeof(plugin->info));
172 memset(&(plugin->info.functions), 0,
sizeof(plugin->info.functions));
173 memset(&(plugin->info.timeouts), 0,
sizeof(plugin->info.timeouts));
176 plugin->info.timeouts.connect_timeout = 60;
177 plugin->info.timeouts.sync_done_timeout = 60;
178 plugin->info.timeouts.disconnect_timeout = 60;
179 plugin->info.timeouts.get_changeinfo_timeout = 60;
180 plugin->info.timeouts.get_data_timeout = 60;
181 plugin->info.timeouts.commit_timeout = 60;
182 plugin->info.timeouts.read_change_timeout = 60;
184 plugin->info.plugin = plugin;
188 env->plugins = g_list_append(env->plugins, plugin);
190 plugin->real_plugin = env->current_module;
227 plugin->env->plugins = g_list_remove(plugin->env->plugins, plugin);
246 if (!plugin->real_plugin) {
247 osync_debug(
"OSPLG", 1,
"You need to load a plugin before getting a function");
248 osync_error_set(error, OSYNC_ERROR_MISCONFIGURATION,
"You need to load a plugin before getting a function");
252 if (!g_module_symbol (plugin->real_plugin, name, &
function)) {
253 osync_debug(
"OSPLG", 0,
"Unable to locate symbol %s on plugin", name);
254 osync_error_set(error, OSYNC_ERROR_PARAMETER,
"Unable to locate symbol %s: %s", name, g_module_error());
276 if (!g_module_supported()) {
277 osync_error_set(error, OSYNC_ERROR_GENERIC,
"This platform does not support loading of modules");
283 GModule *module = g_module_open(path, 0);
285 osync_error_set(error, OSYNC_ERROR_GENERIC,
"Unable to open module %s: %s", path, g_module_error());
291 void (* fct_info)(OSyncEnv *env) = NULL;
292 void (** fct_infop)(OSyncEnv *env) = &fct_info;
293 if (!g_module_symbol(module,
"get_info", (
void **)fct_infop)) {
300 env->modules = g_list_append(env->modules, module);
303 env->current_module = module;
305 env->current_module = NULL;
322 env->modules = g_list_remove(env->modules, module);
340 GError *gerror = NULL;
341 char *filename = NULL;
344 osync_error_set(error, OSYNC_ERROR_GENERIC,
"Not path given to load the modules from");
350 if (!g_file_test(path, G_FILE_TEST_IS_DIR)) {
361 dir = g_dir_open(path, 0, &gerror);
363 osync_error_set(error, OSYNC_ERROR_IO_ERROR,
"Unable to open directory %s: %s", path, gerror->message);
364 g_error_free(gerror);
369 const gchar *de = NULL;
370 while ((de = g_dir_read_name(dir))) {
371 filename = g_strdup_printf (
"%s/%s", path, de);
373 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR) || g_file_test(filename, G_FILE_TEST_IS_SYMLINK) || !g_pattern_match_simple(
"*.so", filename)) {
400 return plugin->info.name;
412 return plugin->info.longname;
424 return plugin->info.description;
436 return plugin->info.timeouts;
447 return plugin->info.plugin_data;
458 return g_module_name(plugin->real_plugin);
471 OSyncObjTypeTemplate *
template = NULL;
474 OSyncObjTypeTemplate *
template = osync_plugin_find_objtype_template(info->
plugin, objtypestr);
475 osync_assert_msg(
template,
"Unable to accept objformat. Did you forget to add the objtype?");
476 _osync_format_set_commit(
template, formatstr, commit_change);
479 for (o = info->
plugin->accepted_objtypes; o; o = o->next) {
481 _osync_format_set_commit(
template, formatstr, commit_change);
496 OSyncObjTypeTemplate *
template = NULL;
504 for (o = info->
plugin->accepted_objtypes; o; o = o->next) {
506 _osync_format_set_access(
template, formatstr, access);
521 OSyncObjTypeTemplate *
template = osync_plugin_find_objtype_template(info->
plugin, objtypestr);
522 osync_assert_msg(
template,
"Unable to accept objformat. Did you forget to add the objtype?");
523 OSyncObjFormatTemplate *format_template = osync_plugin_find_objformat_template(
template, formatstr);
524 osync_assert_msg(format_template,
"Unable to set commit function. Did you forget to add the objformat?");
525 format_template->read = read;
538 OSyncObjTypeTemplate *
template = NULL;
541 template = osync_plugin_find_objtype_template(info->
plugin, objtypestr);
542 osync_assert_msg(
template,
"Unable to accept objformat. Did you forget to add the objtype?");
543 _osync_format_set_batch(
template, formatstr, batch);
546 for (o = info->
plugin->accepted_objtypes; o; o = o->next) {
548 _osync_format_set_batch(
template, formatstr, batch);
563 OSyncObjTypeTemplate *
template = osync_plugin_find_objtype_template(info->
plugin, objtypestr);
564 osync_assert_msg(
template,
"Unable to accept objformat. Did you forget to add the objtype?");
565 OSyncObjFormatTemplate *format_template = osync_plugin_find_objformat_template(
template, formatstr);
566 osync_assert_msg(format_template,
"Unable to set committed_all function. Did you forget to add the objformat?");
567 format_template->committed_all = committed_all;
581 OSyncObjTypeTemplate *
template = g_malloc0(
sizeof(OSyncObjTypeTemplate));
582 template->name = g_strdup(objtypestr);
583 info->
plugin->accepted_objtypes = g_list_append(info->
plugin->accepted_objtypes,
template);
599 OSyncObjTypeTemplate *
template = osync_plugin_find_objtype_template(info->
plugin, objtypestr);
600 osync_assert_msg(
template,
"Unable to accept objformat. Did you forget to add the objtype?");
601 OSyncObjFormatTemplate *format_template = g_malloc0(
sizeof(OSyncObjFormatTemplate));
602 format_template->name = g_strdup(formatstr);
604 format_template->extension_name = g_strdup(extension);
605 template->formats = g_list_append(template->formats, format_template);
void osync_plugin_free(OSyncPlugin *plugin)
Used to free a plugin.
void osync_plugin_set_access_objformat(OSyncPluginInfo *info, const char *objtypestr, const char *formatstr, OSyncFormatAccessFn access)
Sets the access function of a format.
OSyncPluginTimeouts osync_plugin_get_timeouts(OSyncPlugin *plugin)
Returns the timeouts of the plugin.
void osync_module_unload(OSyncEnv *env, GModule *module)
Closes a module.
OSyncPluginInfo * osync_plugin_new_info(OSyncEnv *env)
Registers a new plugin.
OSyncObjFormat * osync_conv_find_objformat(OSyncFormatEnv *env, const char *name)
Finds the object format with the given name.
osync_bool osync_module_load(OSyncEnv *env, const char *path, OSyncError **error)
dlopen()s a format plugin
void osync_plugin_set_commit_objformat(OSyncPluginInfo *info, const char *objtypestr, const char *formatstr, OSyncFormatCommitFn commit_change)
Sets the commit function of a format.
OSyncPlugin * osync_plugin_new(OSyncEnv *env)
This will create a new plugin struct.
Represent a synchronzation plugin.
Represent a group of members that should be synchronized.
void * osync_plugin_get_function(OSyncPlugin *plugin, const char *name, OSyncError **error)
Used to look up a symbol on the plugin.
void osync_plugin_accept_objtype(OSyncPluginInfo *info, const char *objtypestr)
Tells opensync that the plugin can accepts this object.
void * osync_plugin_get_plugin_data(OSyncPlugin *plugin)
Returns the plugin_info data, set by the plugin.
void osync_error_free(OSyncError **error)
Frees the error so it can be reused.
void osync_plugin_set_committed_all_objformat(OSyncPluginInfo *info, const char *objtypestr, const char *formatstr, OSyncFormatCommittedAllFn committed_all)
Sets the committed_all function of a format.
const char * osync_plugin_get_name(OSyncPlugin *plugin)
Returns the name of the loaded plugin.
osync_bool osync_module_load_dir(OSyncEnv *env, const char *path, osync_bool must_exist, OSyncError **error)
Loads the modules from a given directory.
OSyncObjType * osync_conv_find_objtype(OSyncFormatEnv *env, const char *name)
Finds the object type with the given name.
void osync_plugin_set_read_objformat(OSyncPluginInfo *info, const char *objtypestr, const char *formatstr, OSyncFormatReadFn read)
Sets the read function of a format.
void osync_debug(const char *subpart, int level, const char *message,...)
Used for debugging.
Gives information about a plugin.
const char * osync_plugin_get_description(OSyncPlugin *plugin)
Returns the description of the plugin.
const char * osync_plugin_get_path(OSyncPlugin *plugin)
Get full path for plugin module.
void osync_plugin_accept_objformat(OSyncPluginInfo *info, const char *objtypestr, const char *formatstr, const char *extension)
Tells opensync that the plugin can accepts this format for the given object.
void osync_error_set(OSyncError **error, OSyncErrorType type, const char *format,...)
Sets the error.
const char * osync_error_print(OSyncError **error)
Returns the message of the error.
void osync_trace(OSyncTraceType type, const char *message,...)
Used for tracing the application.
void osync_plugin_set_batch_commit_objformat(OSyncPluginInfo *info, const char *objtypestr, const char *formatstr, OSyncFormatBatchCommitFn batch)
Sets the batch_commit function of a format.
Represent a abstract object type (like "contact")
The timeouts for the asynchronous functions of a plugin.
const char * osync_plugin_get_longname(OSyncPlugin *plugin)
Returns the long name of the loaded plugin.