summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lord <chris@openedhand.com>2006-12-04 20:44:56 +0000
committerChris Lord <chris@openedhand.com>2006-12-04 20:44:56 +0000
commitf19f4013fce5f9b5daaac9e0f3114f2df56dbbdc (patch)
treec67cef75a76a97c820fe074082ef02c5dd773a60
parent3a05af3873c0e178f3e58e9b2e4853d686277567 (diff)
downloadsync-f19f4013fce5f9b5daaac9e0f3114f2df56dbbdc.tar.gz
sync-f19f4013fce5f9b5daaac9e0f3114f2df56dbbdc.tar.bz2
sync-f19f4013fce5f9b5daaac9e0f3114f2df56dbbdc.zip
Check in some unfinished work from summer (SyncML server item, various
bits)
-rw-r--r--sync/src/Makefile.am1
-rw-r--r--sync/src/sync_group.c65
-rw-r--r--sync/src/sync_group.h1
-rw-r--r--sync/src/sync_main.c80
-rw-r--r--sync/src/sync_main.h1
-rw-r--r--sync/src/sync_syncml_server_item.c111
-rw-r--r--sync/src/sync_syncml_server_item.h16
7 files changed, 249 insertions, 26 deletions
diff --git a/sync/src/Makefile.am b/sync/src/Makefile.am
index 87a4753..765d2b0 100644
--- a/sync/src/Makefile.am
+++ b/sync/src/Makefile.am
@@ -6,6 +6,7 @@ bin_PROGRAMS = sync
sync_SOURCES = sync_main.c sync.h sync_group.c sync_group.h sync_item.c \
sync_item.h sync_evo2_item.c sync_evo2_item.h sync_file_item.c \
sync_file_item.h sync_syncml_item.c sync_syncml_item.h \
+ sync_syncml_server_item.c sync_syncml_server_item.h \
sync_collection.c sync_collection.h
sync_LDADD = $(SYNC_LIBS)
diff --git a/sync/src/sync_group.c b/sync/src/sync_group.c
index 7aa592f..db34e13 100644
--- a/sync/src/sync_group.c
+++ b/sync/src/sync_group.c
@@ -284,6 +284,10 @@ sync_group_get_default_env ()
{
if (!default_env) {
OSyncError *error = NULL;
+
+ /* Threads must be initialised for autostart, do it here */
+ if (!g_thread_supported ()) g_thread_init (NULL);
+
default_env = osync_env_new ();
g_debug ("Creating new environment");
if (!osync_env_initialize (default_env, &error)) {
@@ -697,8 +701,8 @@ sync_memberstatus_cb (OSyncMemberUpdate *status, void *user_data)
}
}
-gboolean
-sync_group_start (SyncGroup *group)
+static gboolean
+sync_group_sync (SyncGroup *group, gboolean wait)
{
OSyncError *error = NULL;
OSyncGroup *os_group;
@@ -746,11 +750,58 @@ sync_group_start (SyncGroup *group)
priv->changes = 0;
priv->max_changes = 0;
- if (!osengine_synchronize (priv->engine, &error)) {
- g_warning ("Error while starting synchronization: %s",
- osync_error_print (&error));
- osync_error_free (&error);
- sync_group_free_engine (group);
+ if (!wait) {
+ if (!osengine_synchronize (priv->engine, &error)) {
+ g_warning ("Error while starting synchronization: %s",
+ osync_error_print (&error));
+ osync_error_free (&error);
+ sync_group_free_engine (group);
+ return FALSE;
+ }
+
+ g_debug ("Sync started");
+ } else {
+ if (!osengine_wait_sync_end (priv->engine, &error)) {
+ g_warning ("osengine_wait_sync_end unsuccessful: %s",
+ osync_error_print (&error));
+ osync_error_free (&error);
+ sync_group_free_engine (group);
+ return FALSE;
+ }
+
+ g_debug ("Auto-sync finished");
+ }
+
+ return TRUE;
+}
+
+gboolean
+sync_group_start (SyncGroup *group)
+{
+ return sync_group_sync (group, FALSE);
+}
+
+static gpointer
+sync_group_autostart_cb (gpointer data)
+{
+ SyncGroup *group = (SyncGroup *)data;
+ if (!sync_group_sync (group, TRUE)) {
+ g_idle_add ((GSourceFunc)
+ sync_group_failed_idle, group);
+ }
+
+ return NULL;
+}
+
+gboolean
+sync_group_autostart (SyncGroup *group)
+{
+ GError *error = NULL;
+
+ /* TODO: Have a proper think about threading issues here */
+ if (!g_thread_create (sync_group_autostart_cb, group, TRUE, &error)) {
+ g_warning ("Failed to create thread: %s", error->message);
+ g_error_free (error);
return FALSE;
}
diff --git a/sync/src/sync_group.h b/sync/src/sync_group.h
index 783f9de..08318fb 100644
--- a/sync/src/sync_group.h
+++ b/sync/src/sync_group.h
@@ -72,6 +72,7 @@ const gchar * sync_group_get_namespace (SyncGroup *group);
gchar * sync_group_get_name (SyncGroup *group);
gboolean sync_group_start (SyncGroup *group);
+gboolean sync_group_autostart (SyncGroup *group);
void sync_group_resolve_conflict (SyncGroup *group,
SyncGroupConflictRes res);
void sync_group_abort (SyncGroup *group);
diff --git a/sync/src/sync_main.c b/sync/src/sync_main.c
index dcfbaa7..7881145 100644
--- a/sync/src/sync_main.c
+++ b/sync/src/sync_main.c
@@ -16,6 +16,7 @@
#include "sync_evo2_item.h"
#include "sync_file_item.h"
#include "sync_syncml_item.h"
+#include "sync_syncml_server_item.h"
#if 0
static gboolean
sync_clean_backup (SyncData *data)
@@ -104,6 +105,26 @@ sync_animate (SyncData *data)
}
static void
+sync_server_started_cb (SyncGroup *group)
+{
+ g_message ("Server started sync");
+}
+
+static void
+sync_server_finished_cb (SyncGroup *group)
+{
+ g_message ("Server finished sync");
+ sync_group_autostart (group);
+}
+
+static void
+sync_server_failed_cb (SyncGroup *group, const gchar *error)
+{
+ g_warning ("Server sync failed");
+ sync_group_autostart (group);
+}
+
+static void
sync_started_cb (SyncCollection *collection, SyncData *data)
{
GtkWidget *widget = glade_xml_get_widget (
@@ -179,46 +200,51 @@ sync_item_activated_cb (GtkIconView *iconview, GtkTreePath *arg1,
&iter, COL_NAME, &name, COL_TYPE, &type, -1);
switch (type) {
- SyncItem *item;
+ SyncItem *item, *item2;
SyncGroup *group;
gchar *path;
case TYPE_SYNCML:
+ path = g_strdup_printf (TEMP_PATH,
+ g_getenv ("HOME"));
+ item2 = sync_file_item_new ("Test", path);
+ g_free (path);
+
/* Contacts SyncML item */
- item = sync_syncml_item_new ("Mobical",
- "http://www.mobical.net/sync/server",
- CONTACTS, "Cwiiis", "2e9tp2", "con");
+ item = sync_syncml_item_new ("Server",
+ "http://localhost:8080",
+ CONTACTS, "", "", "card");
group = sync_group_new_with_items (
- data->local_item, item);
+ item2, item);
sync_collection_add_group (data->collection,
group);
g_object_unref (group);
g_object_unref (item);
/* Events SyncML item */
- item = sync_syncml_item_new ("Mobical",
- "http://www.mobical.net/sync/server",
- EVENTS, "Cwiiis", "2e9tp2", "cal");
+/* item = sync_syncml_item_new ("Server",
+ "http://localhost:8080",
+ EVENTS, "", "", "cal");
group = sync_group_new_with_items (
- data->local_item, item);
+ item2, item);
sync_collection_add_group (data->collection,
group);
g_object_unref (group);
- g_object_unref (item);
+ g_object_unref (item);*.
/* Todo SyncML item */
- item = sync_syncml_item_new ("Mobical",
- "http://www.mobical.net/sync/server",
- TODO, "Cwiiis", "2e9tp2", "task");
+/* item = sync_syncml_item_new ("Server",
+ "http://localhost:8080",
+ TODO, "", "", "cal");
group = sync_group_new_with_items (
- data->local_item, item);
+ item2, item);
sync_collection_add_group (data->collection,
group);
g_object_unref (group);
- g_object_unref (item);
+ g_object_unref (item);*/
/* TODO: Check if notes sync works? */
-
+ g_object_unref (item2);
break;
case TYPE_FILE:
path = g_strdup_printf (TEMP_PATH,
@@ -367,6 +393,7 @@ main (int argc, char **argv)
GtkIconTheme *icon_theme;
gint width = 0, height = 0;
SyncData data;
+ SyncItem *server_item;
gtk_init (&argc, &argv);
glade_init ();
@@ -407,7 +434,22 @@ main (int argc, char **argv)
/* Create local sync-item and sync collection */
data.collection = sync_collection_new ();
data.local_item = sync_evo2_item_new ("Local", NULL, NULL, NULL);
-
+
+ /* Create and start server */
+ server_item = sync_syncml_server_item_new ("Server", "", "",
+ 8080, "card", "cal", "note");
+ data.server_group = sync_group_new_with_items (
+ server_item, data.local_item);
+ g_object_unref (server_item);
+ /* TODO: Conflicts? */
+ g_signal_connect (G_OBJECT (data.server_group), "started",
+ G_CALLBACK (sync_server_started_cb), NULL);
+ g_signal_connect (G_OBJECT (data.server_group), "finished",
+ G_CALLBACK (sync_server_finished_cb), NULL);
+ g_signal_connect (G_OBJECT (data.server_group), "failed",
+ G_CALLBACK (sync_server_failed_cb), NULL);
+ sync_group_autostart (data.server_group);
+
/* Insert some items for testing (TODO: look at loading groups later) */
gtk_list_store_insert_with_values (GTK_LIST_STORE (data.model), &iter,
G_MAXINT, COL_NAME, "SyncML Test", COL_TYPE, TYPE_SYNCML,
@@ -417,7 +459,7 @@ main (int argc, char **argv)
COL_PIXBUF, data.backup_icon, -1);
/* Insert preset items */
- gtk_list_store_insert_with_values (GTK_LIST_STORE (data.model), &iter,
+/* gtk_list_store_insert_with_values (GTK_LIST_STORE (data.model), &iter,
G_MAXINT, COL_NAME, "Backup", COL_TYPE, TYPE_BACKUP,
COL_PIXBUF, data.backup_icon, -1);
gtk_list_store_insert_with_values (GTK_LIST_STORE (data.model), &iter,
@@ -425,7 +467,7 @@ main (int argc, char **argv)
COL_PIXBUF, data.restore_icon, -1);
gtk_list_store_insert_with_values (GTK_LIST_STORE (data.model), &iter,
G_MAXINT, COL_NAME, "Add target...", COL_TYPE, TYPE_ADD_NEW,
- COL_PIXBUF, data.add_icon, -1);
+ COL_PIXBUF, data.add_icon, -1);*/
/* TODO: Avahi detection of local sync servers? */
/* TODO: Bluetooth scanning? */
diff --git a/sync/src/sync_main.h b/sync/src/sync_main.h
index 1f8e7c7..7542029 100644
--- a/sync/src/sync_main.h
+++ b/sync/src/sync_main.h
@@ -54,6 +54,7 @@ typedef struct {
SyncCollection *collection;
SyncGroup *group;
SyncItem *local_item;
+ SyncGroup *server_group;
gboolean started;
guint animate_id;
diff --git a/sync/src/sync_syncml_server_item.c b/sync/src/sync_syncml_server_item.c
new file mode 100644
index 0000000..c0f5643
--- /dev/null
+++ b/sync/src/sync_syncml_server_item.c
@@ -0,0 +1,111 @@
+
+#include <opensync/opensync.h>
+#include <glib.h>
+#include <string.h>
+#include "sync_item.h"
+#include "sync_group.h"
+#include "sync_syncml_server_item.h"
+
+#define SYNCML_SERVER_PLUGIN "syncml-http-server"
+#define SYNCML_SERVER_CONFIG \
+ "<config>" \
+ "<username>%s</username>" \
+ "<password>%s</password>" \
+ "<url>%s</url>" \
+ "<port>%d</port>" \
+ "<usestringtable>1</usestringtable>" \
+ "<onlyreplace>0</onlyreplace>" \
+ "<recvLimit>0</recvLimit>" \
+ "<contact_db>%s</contact_db>" \
+ "<calendar_db>%s</calendar_db>" \
+ "<note_db>%s</note_db>" \
+ "</config>"
+
+typedef struct {
+ gchar *user;
+ gchar *pass;
+ guint port;
+ gchar *card_db;
+ gchar *cal_db;
+ gchar *note_db;
+} SyncSyncMLServerItemData;
+
+static void
+sync_syncml_server_free_data (SyncSyncMLServerItemData *data)
+{
+ g_free (data->user);
+ g_free (data->pass);
+ g_free (data->card_db);
+ g_free (data->cal_db);
+ g_free (data->note_db);
+}
+
+static OSyncMember *
+sync_syncml_server_item_get_member (SyncItem *item, SyncGroup *group)
+{
+ OSyncMember *member;
+ OSyncError *error = NULL;
+ OSyncConfigurationTypes type = NO_CONFIGURATION;
+
+ member = osync_member_new (sync_group_get_osync_group (group));
+ if (!osync_member_instance_plugin (member, SYNCML_SERVER_PLUGIN,
+ &error)) {
+ g_warning ("Error instancing syncml server plug-in: %s",
+ osync_error_print (&error));
+ osync_error_free (&error);
+ return NULL;
+ }
+ if (!osync_member_need_config (member, &type, &error)) {
+ g_warning ("Error reading plug-in config requirements: %s",
+ osync_error_print (&error));
+ osync_error_free (&error);
+ return NULL;
+ }
+ if (type == NO_CONFIGURATION) {
+ g_warning (
+ "syncml server plug-in reports no need for "
+ "configuration");
+ } else {
+ SyncSyncMLServerItemData *data;
+ const gchar *url;
+ gchar *config;
+
+ data = (SyncSyncMLServerItemData *)sync_item_get_data (item);
+ url = sync_item_get_name (item);
+
+ config = g_strdup_printf (SYNCML_SERVER_CONFIG, data->user,
+ data->pass, url, data->port, data->card_db,
+ data->cal_db, data->note_db);
+ osync_member_set_config (
+ member, config, strlen (config));
+ g_free (config);
+ }
+
+ return member;
+}
+
+SyncItem *
+sync_syncml_server_item_new (const gchar *name, const gchar *user,
+ const gchar *pass, guint port,
+ const gchar *card_db, const gchar *cal_db,
+ const gchar *note_db)
+{
+ SyncItem *item;
+ SyncSyncMLServerItemData *data;
+
+ item = sync_item_new (name, "", sync_syncml_server_item_get_member);
+
+ data = g_new0 (SyncSyncMLServerItemData, 1);
+ data->user = g_strdup (user);
+ data->pass = g_strdup (pass);
+ data->port = port;
+ data->card_db = g_strdup (card_db);
+ data->cal_db = g_strdup (cal_db);
+ data->note_db = g_strdup (note_db);
+
+ sync_item_set_data (item, data);
+ sync_item_set_data_free_func (item,
+ (SyncItemDataFreeFunc)sync_syncml_server_free_data);
+
+ return item;
+}
diff --git a/sync/src/sync_syncml_server_item.h b/sync/src/sync_syncml_server_item.h
new file mode 100644
index 0000000..625bc08
--- /dev/null
+++ b/sync/src/sync_syncml_server_item.h
@@ -0,0 +1,16 @@
+
+#ifndef SYNC_SYNCML_SERVER_ITEM_H
+#define SYNC_SYNCML_SERVER_ITEM_H
+
+#include <glib.h>
+#include "sync_item.h"
+
+SyncItem *sync_syncml_server_item_new (const gchar *name,
+ const gchar *user,
+ const gchar *pass,
+ guint port,
+ const gchar *card_db,
+ const gchar *cal_db,
+ const gchar *note_db);
+
+#endif