From: <dg...@su...> - 2009-01-16 13:04:38
|
Author: bricks Date: Fri Jan 16 14:03:49 2009 New Revision: 5164 URL: http://www.opensync.org/changeset/5164 Log: adapted example plugins to latest api changes Modified: trunk/docs/examples/plugins/src/plugin.c trunk/docs/examples/plugins/src/simple_plugin.c Modified: trunk/docs/examples/plugins/src/plugin.c ============================================================================== --- trunk/docs/examples/plugins/src/plugin.c Fri Jan 16 13:41:49 2009 (r5163) +++ trunk/docs/examples/plugins/src/plugin.c Fri Jan 16 14:03:49 2009 (r5164) @@ -62,14 +62,18 @@ //you can also use the anchor system to detect a device reset //or some parameter change here. Check the docs to see how it works - char *lanchor = NULL; //Now you get the last stored anchor from the device - char *anchorpath = osync_strdup_printf("%s/anchor.db", osync_plugin_info_get_configdir(info)); - - if (!osync_anchor_compare(anchorpath, "lanchor", lanchor)) + OSyncAnchor *anchor = osync_objtype_sink_get_anchor(sink); + osync_bool anchormatch; + + if (!osync_anchor_compare(anchor, "lanchor", &anchormatch, &error)) { + /* anchor couldn't be compared */ + goto error; + } + if (!anchormatch) { + /* request slow sync */ osync_objtype_sink_set_slowsync(sink, TRUE); - - osync_free(anchorpath); + } osync_context_report_success(ctx); osync_trace(TRACE_EXIT, "%s", __func__); @@ -81,7 +85,7 @@ osync_error_unref(&error); } -static void get_changes(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *userdata) +static void get_changes(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, osync_bool slow_sync, void *userdata) { osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, sink, info, ctx, userdata); @@ -94,9 +98,8 @@ //If you use opensync hashtables you can detect if you need //to do a slow-sync and set this on the hastable directly //otherwise you have to make 2 function like "get_changes" and - //"get_all" and decide which to use using - //osync_objtype_sink_get_slow_sync - if (osync_objtype_sink_get_slowsync(sinkenv->sink)) { + //"get_all" and decide which to use + if (slow_sync) { osync_trace(TRACE_INTERNAL, "Slow sync requested"); if (osync_hashtable_slowsync(sinkenv->hashtable, &error)) { @@ -261,10 +264,11 @@ //If we use anchors we have to update it now. //Now you get/calculate the current anchor of the device - char *lanchor = NULL; - char *anchorpath = osync_strdup_printf("%s/anchor.db", osync_plugin_info_get_configdir(info)); - osync_anchor_update(anchorpath, "lanchor", lanchor); - osync_free(anchorpath); + OSyncAnchor *anchor = osync_objtype_sink_get_anchor(sink); + if (!osync_anchor_update(anchor, "lanchor", &error)) { + goto error; + } + //Save hashtable to database if (!osync_hashtable_save(sinkenv->hashtable, &error)) goto error; Modified: trunk/docs/examples/plugins/src/simple_plugin.c ============================================================================== --- trunk/docs/examples/plugins/src/simple_plugin.c Fri Jan 16 13:41:49 2009 (r5163) +++ trunk/docs/examples/plugins/src/simple_plugin.c Fri Jan 16 14:03:49 2009 (r5164) @@ -33,7 +33,7 @@ static void connect(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *userdata) { - osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, userdata, info, ctx); + osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, sink, info, ctx, userdata); //Each time you get passed a context (which is used to track //calls to your plugin) you can get the data your returned in //initialize via this call: @@ -60,14 +60,19 @@ //you can also use the anchor system to detect a device reset //or some parameter change here. Check the docs to see how it works - char *lanchor = NULL; //Now you get the last stored anchor from the device - char *anchorpath = osync_strdup_printf("%s/anchor.db", osync_plugin_info_get_configdir(info)); + OSyncAnchor *anchor = osync_objtype_sink_get_anchor(sink); + osync_bool anchormatch; - if (!osync_anchor_compare(anchorpath, "lanchor", lanchor)) + if (!osync_anchor_compare(anchor, "lanchor", &anchormatch, &error)) { + /* anchor couldn't be compared */ + goto error; + } + + if (!anchormatch) { + /* request slow sync */ osync_objtype_sink_set_slowsync(sink, TRUE); - - osync_free(anchorpath); + } osync_context_report_success(ctx); osync_trace(TRACE_EXIT, "%s", __func__); @@ -195,11 +200,10 @@ //If we use anchors we have to update it now. //Now you get/calculate the current anchor of the device - char *lanchor = NULL; - char *anchorpath = osync_strdup_printf("%s/anchor.db", osync_plugin_info_get_configdir(info)); - osync_anchor_update(anchorpath, "lanchor", lanchor); - osync_free(anchorpath); - + OSyncAnchor *anchor = osync_objtype_sink_get_anchor(sink); + if (!osync_anchor_update(anchor, "lanchor", &error)) + goto error; + //Answer the call osync_context_report_success(ctx); return; @@ -209,7 +213,7 @@ return; } -static void disconnect(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, OSyncObjTypeSink *sink) +static void disconnect(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *data) { sink_environment *sinkenv = osync_objtype_sink_get_userdata(sink); |