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



commit 8b4c9032d2aa771077f6db851306ca20cfda496f
Author: Halton Huo <halton huo sun com>
Date:   Wed Mar 17 10:35:30 2010 +0800

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

 gpilotd/gnome-pilot-client.gob |   21 ++++++++-------------
 gpilotd/gpilot-daemon.c        |   20 +++++---------------
 gpilotd/gpilot-daemon.h        |    4 ++--
 utils/gpilotd-client.c         |   22 +++++++++++++++++++---
 4 files changed, 34 insertions(+), 33 deletions(-)
---
diff --git a/gpilotd/gnome-pilot-client.gob b/gpilotd/gnome-pilot-client.gob
index 2681ec0..4f44204 100644
--- a/gpilotd/gnome-pilot-client.gob
+++ b/gpilotd/gnome-pilot-client.gob
@@ -938,6 +938,7 @@ error:		if (file_copied == FALSE) {
 			}
 		}
 
+                g_strfreev (arr);
 		return GPILOTD_OK;
 	}
 
@@ -945,8 +946,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) {
@@ -957,12 +958,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,
 					"GetPilots",
 					&error,
 					G_TYPE_INVALID,
-					dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING),
+					G_TYPE_STRV,
 					&arr,
 					G_TYPE_INVALID);
 
@@ -973,19 +973,14 @@ 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);
+                g_strfreev (arr);
 		return GPILOTD_OK;
 	}
 	
diff --git a/gpilotd/gpilot-daemon.c b/gpilotd/gpilot-daemon.c
index 9bee331..09c0fe8 100644
--- a/gpilotd/gpilot-daemon.c
+++ b/gpilotd/gpilot-daemon.c
@@ -1966,9 +1966,6 @@ gpilot_daemon_get_users (GpilotDaemon   *daemon,
         
         LOG (("get_users()"));
 
-        if (users == NULL)
-                return FALSE;
-
         username = daemon->priv->gpilotd_context->user->username;
         if (IS_STR_SET (username)) {
                 *users = g_new (char *, 2);
@@ -1986,7 +1983,7 @@ org.gnome.GnomePilot.Daemon.GetCradles
 */
 gboolean
 gpilot_daemon_get_cradles (GpilotDaemon   *daemon,
-                           GPtrArray    ***cradles,
+                           char         ***cradles,
                            GError        **error)
 {
         int    i;
@@ -1996,10 +1993,6 @@ gpilot_daemon_get_cradles (GpilotDaemon   *daemon,
         
         LOG (("get_cradles()"));
 
-        if (cradles == NULL)
-                return FALSE;
-
-        *cradles = g_ptr_array_new ();
         l = daemon->priv->gpilotd_context->devices;
 
         *cradles = g_new (char *, g_list_length (l)+1);
@@ -2020,7 +2013,7 @@ org.gnome.GnomePilot.Daemon.GetPilots
 */
 gboolean
 gpilot_daemon_get_pilots (GpilotDaemon   *daemon,
-                          GPtrArray     **pilots,
+                          char         ***pilots,
                           GError        **error)
 {
         int    i;
@@ -2030,17 +2023,14 @@ gpilot_daemon_get_pilots (GpilotDaemon   *daemon,
         
         LOG (("get_pilots()"));
 
-        if (pilots == NULL)
-                return FALSE;
-
-        *pilots = g_ptr_array_new ();
         l = daemon->priv->gpilotd_context->pilots;
 
+        *pilots = g_new (char *, g_list_length (l)+1);
         for(i=0; i < g_list_length (l); i++) {
                 GPilotPilot *pilot = GPILOT_PILOT (g_list_nth (l, i)->data);
-                g_ptr_array_add (*pilots,
-                                 g_strdup (pilot->name));
+                (*pilots)[i] = g_strdup (pilot->name);
         }
+        (*pilots)[g_list_length (l)] = NULL;
 
         return TRUE;
 }
diff --git a/gpilotd/gpilot-daemon.h b/gpilotd/gpilot-daemon.h
index 3445ce0..cbd96b9 100644
--- a/gpilotd/gpilot-daemon.h
+++ b/gpilotd/gpilot-daemon.h
@@ -202,10 +202,10 @@ gboolean        gpilot_daemon_get_users         (GpilotDaemon   *daemon,
                                                  char         ***users,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_cradles       (GpilotDaemon   *daemon,
-                                                 GPtrArray    ***cradles,
+                                                 char         ***cradles,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_pilots        (GpilotDaemon   *daemon,
-                                                 GPtrArray     **pilots,
+                                                 char         ***pilots,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_pilot_ids     (GpilotDaemon   *daemon,
                                                  GPtrArray     **pilots,
diff --git a/utils/gpilotd-client.c b/utils/gpilotd-client.c
index 3af7e75..e008829 100644
--- a/utils/gpilotd-client.c
+++ b/utils/gpilotd-client.c
@@ -22,6 +22,7 @@ int     arg_pause=0,
 	arg_listbases = 0,
 	arg_listusers = 0,
 	arg_listcradles = 0,
+	arg_listpilots = 0,
 	arg_monitorall=0,
 	arg_monitor,
 	arg_getinfo = 0;
@@ -51,11 +52,12 @@ static GOptionEntry options[] = {
 	{"userid", '\0', 0, G_OPTION_ARG_STRING, &arg_username, N_("Username to set"), N_("USERNAME")},
 	{"monitor", 'm', 0, G_OPTION_ARG_NONE, &arg_monitor, N_("Monitor the specified PDA's actions"), NULL},
 	{"monitorall", 'A', 0, G_OPTION_ARG_NONE, &arg_monitorall, N_("Monitor all PDAs"), NULL},
-	{"listpilots", '\0', 0, G_OPTION_ARG_STRING, &arg_list_by_login, N_("list PDAs by login (all for all pilots)"), N_("LOGIN")},
+	{"listpilotsbylogin", '\0', 0, G_OPTION_ARG_STRING, &arg_list_by_login, N_("list PDAs by login (all for all pilots)"), N_("LOGIN")},
 	{"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},
+	{"listusers", '\0', 0, G_OPTION_ARG_NONE, &arg_listusers, N_("List users"), NULL},
+	{"listcradles", '\0', 0, G_OPTION_ARG_NONE, &arg_listcradles, N_("List cradles"), NULL},
+	{"listpilots", '\0', 0, G_OPTION_ARG_NONE, &arg_listpilots, N_("List pilots"), NULL},
 	{"listbases", 'l', 0, G_OPTION_ARG_NONE, &arg_listbases, N_("List the specified PDA's bases"), NULL},
 	{NULL},
 };
@@ -159,6 +161,18 @@ static void list_cradles (void) {
 		g_message ("No cradle");
 }
 
+static void list_pilots (void) {
+	GList *list = NULL,*ptr;
+
+	gnome_pilot_client_get_pilots (gpc, &list);
+	if (list)
+		for (ptr = list; ptr; ptr = ptr->next) {
+			g_message ("pilot %s", (char*)ptr->data);
+		}
+	else 
+		g_message ("No pilot");
+ }
+
 static void list_bases (void) {
 	GList *list = NULL,*ptr;
 
@@ -430,6 +444,8 @@ main (int argc, char *argv[]) {
 		list_users ();
 	} else if (arg_listcradles) {
 		list_cradles ();
+	} else if (arg_listpilots) {
+		list_pilots ();
 	} 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]