[gnome-pilot] Rework dbus method org.gnome.GnomePilot.Daemon.GetCradles



commit e74277e91c117ccf6aedb43f3798ec2abcaedfae
Author: Halton Huo <halton huo sun com>
Date:   Tue Mar 16 18:58:29 2010 +0800

    Rework dbus method org.gnome.GnomePilot.Daemon.GetCradles
    
    Add argument --listcradles to gpilotd-client for better testing.

 gpilotd/gnome-pilot-client.gob |   19 ++++++-------------
 gpilotd/gpilot-daemon.c        |    7 ++++---
 gpilotd/gpilot-daemon.h        |    2 +-
 utils/gpilotd-client.c         |   16 ++++++++++++++++
 4 files changed, 27 insertions(+), 17 deletions(-)
---
diff --git a/gpilotd/gnome-pilot-client.gob b/gpilotd/gnome-pilot-client.gob
index 5725ffb..2681ec0 100644
--- a/gpilotd/gnome-pilot-client.gob
+++ b/gpilotd/gnome-pilot-client.gob
@@ -904,8 +904,8 @@ error:		if (file_copied == FALSE) {
 				 GList **output (check null)) onerror GPILOTD_ERR_INVAL {
 		GError     *error;
 		gboolean    res;
-		GPtrArray  *arr;
-		int         i;
+		char      **arr;
+                char      **p;
 
 #ifndef G_DISABLE_CHECKS		
 		if (*output != NULL) {
@@ -916,12 +916,11 @@ error:		if (file_copied == FALSE) {
 		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
 		error = NULL;
 		arr = NULL;
-
 		res = dbus_g_proxy_call (self->proxy,
 					"GetCradles",
 					&error,
 					G_TYPE_INVALID,
-					dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING),
+					G_TYPE_STRV,
 					&arr,
 					G_TYPE_INVALID);
 
@@ -932,19 +931,13 @@ error:		if (file_copied == FALSE) {
 		}
 
 		(*output) = NULL;
-		for (i = 0; i < arr->len; i++) {
-			char *str_tmp;
-
-			str_tmp = g_ptr_array_index (arr, i);
-			if (IS_STR_SET (str_tmp) ) {
+		for (p = arr; p != NULL && *p != NULL; p++) {
+			if (IS_STR_SET (*p) ) {
 				(*output) = g_list_append ((*output),
-							    g_strdup (str_tmp));
+							    g_strdup (*p));
 			}
-			g_free (str_tmp);
-			str_tmp = NULL;
 		}
 
-		g_ptr_array_free (arr, TRUE);
 		return GPILOTD_OK;
 	}
 
diff --git a/gpilotd/gpilot-daemon.c b/gpilotd/gpilot-daemon.c
index 63e8bbe..9bee331 100644
--- a/gpilotd/gpilot-daemon.c
+++ b/gpilotd/gpilot-daemon.c
@@ -1986,7 +1986,7 @@ org.gnome.GnomePilot.Daemon.GetCradles
 */
 gboolean
 gpilot_daemon_get_cradles (GpilotDaemon   *daemon,
-                           GPtrArray     **cradles,
+                           GPtrArray    ***cradles,
                            GError        **error)
 {
         int    i;
@@ -2002,11 +2002,12 @@ gpilot_daemon_get_cradles (GpilotDaemon   *daemon,
         *cradles = g_ptr_array_new ();
         l = daemon->priv->gpilotd_context->devices;
 
+        *cradles = g_new (char *, g_list_length (l)+1);
         for(i=0; i < g_list_length (l); i++) {
                 GPilotDevice *device = GPILOT_DEVICE (g_list_nth (l, i)->data);
-                g_ptr_array_add (*cradles,
-                                 g_strdup (device->name));
+                (*cradles)[i] = g_strdup (device->name);
         }
+        (*cradles)[g_list_length (l)] = NULL;
 
         return TRUE;
 }
diff --git a/gpilotd/gpilot-daemon.h b/gpilotd/gpilot-daemon.h
index 88d0d4c..3445ce0 100644
--- a/gpilotd/gpilot-daemon.h
+++ b/gpilotd/gpilot-daemon.h
@@ -202,7 +202,7 @@ gboolean        gpilot_daemon_get_users         (GpilotDaemon   *daemon,
                                                  char         ***users,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_cradles       (GpilotDaemon   *daemon,
-                                                 GPtrArray     **cradles,
+                                                 GPtrArray    ***cradles,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_pilots        (GpilotDaemon   *daemon,
                                                  GPtrArray     **pilots,
diff --git a/utils/gpilotd-client.c b/utils/gpilotd-client.c
index cbcf2a7..3af7e75 100644
--- a/utils/gpilotd-client.c
+++ b/utils/gpilotd-client.c
@@ -21,6 +21,7 @@ int     arg_pause=0,
 	arg_setuser = 0,
 	arg_listbases = 0,
 	arg_listusers = 0,
+	arg_listcradles = 0,
 	arg_monitorall=0,
 	arg_monitor,
 	arg_getinfo = 0;
@@ -54,6 +55,7 @@ static GOptionEntry options[] = {
 	{"pilot", '\0', 0, G_OPTION_ARG_STRING, &arg_pilot, N_("Specify PDA to operate on (defaults to MyPDA)"), N_("PILOTNAME")},
 	{"cradle", '\0', 0, G_OPTION_ARG_STRING, &arg_cradle, N_("Specify a cradle to operate on (defaults to Cradle0)"), N_("CRADLENAME")},
 	{"listusers", NULL, 0, G_OPTION_ARG_NONE, &arg_listusers, N_("List users"), NULL},
+	{"listcradles", NULL, 0, G_OPTION_ARG_NONE, &arg_listcradles, N_("List cradles"), NULL},
 	{"listbases", 'l', 0, G_OPTION_ARG_NONE, &arg_listbases, N_("List the specified PDA's bases"), NULL},
 	{NULL},
 };
@@ -145,6 +147,18 @@ static void list_users (void) {
 		g_message ("No users");
 }
 
+static void list_cradles (void) {
+	GList *list = NULL,*ptr;
+
+	gnome_pilot_client_get_cradles (gpc, &list);
+	if (list)
+		for (ptr = list; ptr; ptr = ptr->next) {
+			g_message ("cradle %s", (char*)ptr->data);
+		}
+	else 
+		g_message ("No cradle");
+}
+
 static void list_bases (void) {
 	GList *list = NULL,*ptr;
 
@@ -414,6 +428,8 @@ main (int argc, char *argv[]) {
 		set_user ();
 	} else if (arg_listusers) {
 		list_users ();
+	} else if (arg_listcradles) {
+		list_cradles ();
 	} else if (arg_listbases) {
 		list_bases ();
 	} else if (arg_list_by_login) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]