From 9c017b017cd621f72d43d862daf9570692744f38 Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Date: Mon, 25 Aug 2008 10:32:59 -0400 Subject: [PATCH] Adding calls to libgcal to get all events/contacts (slow sync) and properly running each operation when each sink is called. I'm assuming that 'getchanges' is called only once for each sink object. --- src/gcalendar.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/gcalendar.c b/src/gcalendar.c index 95059bb..2eceef6 100644 --- a/src/gcalendar.c +++ b/src/gcalendar.c @@ -144,12 +144,12 @@ static void gc_connect(void *data, OSyncPluginInfo *info, OSyncContext *ctx) static void gc_get_changes(void *data, OSyncPluginInfo *info, OSyncContext *ctx) { osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, data, info, ctx); - + static int counter = 0; struct gc_plgdata *plgdata = data; OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); OSyncError *error = NULL; - int result; - char *timestamp = NULL; + int result = 0; + char *timestamp = NULL, *msg; timestamp = osync_anchor_retrieve(plgdata->anchor_path, "gdata"); if (timestamp) @@ -157,26 +157,46 @@ static void gc_get_changes(void *data, OSyncPluginInfo *info, OSyncContext *ctx) else fprintf(stderr, "first sync!\n"); - if (plgdata->gcal_sink) + if ((plgdata->gcal_sink) && (counter == 0)) { if (osync_objtype_sink_get_slowsync(plgdata->gcal_sink)) { - /* TODO: write getall */ fprintf(stderr, "\n\t\tgcal: Client asked for slow syncing...\n"); + result = gcal_get_events(plgdata->calendar, &(plgdata->all_events)); + if (result) { + msg = "Failed getting events!"; + goto error; + } + /* TODO: report back events to opensync */ + } else { /* TODO: write getchanges */ fprintf(stderr, "\n\t\tgcal: Its a fast sync!\n"); } - if (plgdata->gcont_sink) + } + + if ((plgdata->gcont_sink) && (counter == 1)) if (osync_objtype_sink_get_slowsync(plgdata->gcont_sink)) { - /* TODO: write getall */ fprintf(stderr, "\n\t\tgcont: Client asked for slow syncing...\n"); + result = gcal_get_contacts(plgdata->contacts, &(plgdata->all_contacts)); + if (result) { + msg = "Failed getting contacts!"; + goto error; + } + + /* TODO: report back contacts to opensync */ + } else { /* TODO: write getchanges */ fprintf(stderr, "\n\t\tgcont: Its a fast sync!\n"); } +exit: + ++counter; osync_context_report_success(ctx); - + return; +error: + ++counter; + osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, msg); } static void gc_commit_change(void *data, OSyncPluginInfo *info, -- 2.11.4.GIT