| 28 | | static void gpe_connect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) |
|---|
| 29 | | { |
|---|
| 30 | | osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p)", __func__, userdata, info, ctx); |
|---|
| 31 | | |
|---|
| 32 | | // We need to get the context to load all our stuff. |
|---|
| 33 | | gpe_environment *env = ((sink_environment *)userdata)->gpe_env; |
|---|
| 34 | | |
|---|
| | 28 | static void gpe_connect_internal(gpe_environment *env, char **client_err) |
|---|
| | 29 | { |
|---|
| | 30 | osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p)", __func__, env, client_err); |
|---|
| | 31 | |
|---|
| 49 | | env->client = gpesync_client_open (env->device_addr, env->device_port, &client_err); |
|---|
| 50 | | |
|---|
| 51 | | if (env->client == NULL) { |
|---|
| 52 | | osync_context_report_error(ctx, OSYNC_ERROR_NO_CONNECTION, client_err); |
|---|
| 53 | | osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: connect failed: %s", __func__, client_err); |
|---|
| 54 | | return; |
|---|
| 55 | | } |
|---|
| | 45 | env->client = gpesync_client_open (env->device_addr, env->device_port, client_err); |
|---|
| | 46 | } |
|---|
| | 47 | |
|---|
| | 48 | osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); |
|---|
| | 49 | } |
|---|
| | 50 | static void gpe_connect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) |
|---|
| | 51 | { |
|---|
| | 52 | char *client_err = NULL; |
|---|
| | 53 | |
|---|
| | 54 | osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p)", __func__, userdata, info, ctx); |
|---|
| | 55 | |
|---|
| | 56 | // We need to get the context to load all our stuff. |
|---|
| | 57 | gpe_environment *env = ((sink_environment *)userdata)->gpe_env; |
|---|
| | 58 | |
|---|
| | 59 | gpe_connect_internal(env, &client_err); |
|---|
| | 60 | |
|---|
| | 61 | if (env->client == NULL) { |
|---|
| | 62 | osync_context_report_error(ctx, OSYNC_ERROR_NO_CONNECTION, client_err); |
|---|
| | 63 | osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: connect failed: %s", __func__, client_err); |
|---|
| | 64 | if (client_err) g_free(client_err); |
|---|
| | 65 | return; |
|---|
| 83 | | static void gpe_disconnect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) |
|---|
| 84 | | { |
|---|
| 85 | | osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p)", __func__, userdata, info, ctx); |
|---|
| 86 | | gpe_environment *env = ((sink_environment *)userdata)->gpe_env; |
|---|
| | 93 | static void gpe_disconnect_internal(gpe_environment *env) |
|---|
| | 94 | { |
|---|
| | 95 | osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p)", __func__, env); |
|---|
| | 101 | |
|---|
| | 102 | osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); |
|---|
| | 103 | } |
|---|
| | 104 | static void gpe_disconnect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) |
|---|
| | 105 | { |
|---|
| | 106 | osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p)", __func__, userdata, info, ctx); |
|---|
| | 107 | gpe_environment *env = ((sink_environment *)userdata)->gpe_env; |
|---|
| | 108 | |
|---|
| | 109 | gpe_disconnect_internal(env); |
|---|
| 198 | | // Report avaliable sinks... |
|---|
| 199 | | // FIXME: one day this should connect to the device first and check its capabilities |
|---|
| 200 | | if (env->contact_sink.sink) osync_objtype_sink_set_available(env->contact_sink.sink, TRUE); |
|---|
| 201 | | if (env->todo_sink.sink) osync_objtype_sink_set_available(env->todo_sink.sink, TRUE); |
|---|
| 202 | | if (env->calendar_sink.sink) osync_objtype_sink_set_available(env->calendar_sink.sink, TRUE); |
|---|
| 203 | | |
|---|
| 204 | | // FIXME: should get version info from the device |
|---|
| | 220 | // Try to connect |
|---|
| | 221 | gpe_connect_internal(env, &err_string); |
|---|
| | 222 | |
|---|
| | 223 | if (env->client == NULL) { |
|---|
| | 224 | osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, err_string); |
|---|
| | 225 | osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: connect failed: %s", __func__, err_string); |
|---|
| | 226 | if (err_string) g_free(err_string); |
|---|
| | 227 | return FALSE; |
|---|
| | 228 | } |
|---|
| | 229 | |
|---|
| | 230 | // Get version info from the device |
|---|
| | 231 | gpesync_client_exec(env->client, "version", client_callback_string, &response, NULL); |
|---|
| | 232 | |
|---|
| | 233 | if (sscanf(response, "OK:%u:%u:%u", &v_major, &v_minor, &v_edit) != 3) { |
|---|
| | 234 | osync_trace(TRACE_INTERNAL, "version command error: %s", response); |
|---|
| | 235 | } |
|---|
| | 236 | osync_trace(TRACE_INTERNAL, "gpesyncd version = %d.%d.%d", v_major, v_minor, v_edit); |
|---|
| | 237 | |
|---|
| | 238 | if (v_major != MIN_PROTOCOL_MAJOR || v_minor < MIN_PROTOCOL_MINOR) { |
|---|
| | 239 | osync_error_set(error, OSYNC_ERROR_NOT_SUPPORTED, "gpesyncd version %d.%d not supported -- require %d.%d", |
|---|
| | 240 | v_major, v_minor, MIN_PROTOCOL_MAJOR, MIN_PROTOCOL_MINOR); |
|---|
| | 241 | osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: gpesyncd version %d.%d not supported -- require %d.%d", |
|---|
| | 242 | __func__, v_major, v_minor, MIN_PROTOCOL_MAJOR, MIN_PROTOCOL_MINOR); |
|---|
| | 243 | return FALSE; |
|---|
| | 244 | } |
|---|
| | 245 | |
|---|
| | 246 | gchar *version_string = g_strdup_printf("%d.%d.%d", v_major, v_minor, v_edit); |
|---|
| | 255 | g_free(version_string); |
|---|
| | 256 | |
|---|
| | 257 | // Report avaliable sinks... |
|---|
| | 258 | // GPE always supports contacts, todos and events |
|---|
| | 259 | if (env->contact_sink.sink) osync_objtype_sink_set_available(env->contact_sink.sink, TRUE); |
|---|
| | 260 | if (env->todo_sink.sink) osync_objtype_sink_set_available(env->todo_sink.sink, TRUE); |
|---|
| | 261 | if (env->calendar_sink.sink) osync_objtype_sink_set_available(env->calendar_sink.sink, TRUE); |
|---|
| | 262 | // One day we may add notes... |
|---|
| | 263 | |
|---|
| | 264 | gpe_disconnect_internal(env); |
|---|