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



commit cdc93b3bb222ba1864d7084e5b4cac3bfecf8f29
Author: Halton Huo <halton huo sun com>
Date:   Wed Mar 17 11:49:24 2010 +0800

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

 gpilotd/gnome-pilot-client.gob |   22 +++++++-------------
 gpilotd/gpilot-daemon.c        |   18 ++++++++++++----
 gpilotd/gpilot-daemon.h        |    2 +-
 utils/gpilotd-client.c         |   42 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 64 insertions(+), 20 deletions(-)
---
diff --git a/gpilotd/gnome-pilot-client.gob b/gpilotd/gnome-pilot-client.gob
index 10af028..3dc2051 100644
--- a/gpilotd/gnome-pilot-client.gob
+++ b/gpilotd/gnome-pilot-client.gob
@@ -1030,8 +1030,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) {
@@ -1042,14 +1042,12 @@ 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,
 					"GetPilotsByUserName",
 					&error,
 					G_TYPE_STRING, name,
 					G_TYPE_INVALID,
-					dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING),
-					&arr,
+					G_TYPE_STRV, &arr,
 					G_TYPE_INVALID);
 
 		if (!res) {
@@ -1059,19 +1057,15 @@ 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 9e087c9..0bf34e6 100644
--- a/gpilotd/gpilot-daemon.c
+++ b/gpilotd/gpilot-daemon.c
@@ -2071,16 +2071,19 @@ gpilot_daemon_get_pilot_ids (GpilotDaemon   *daemon,
 dbus-send --session --dest=org.gnome.GnomePilot \
 --type=method_call --print-reply \
 /org/gnome/GnomePilot/Daemon \
-org.gnome.GnomePilot.Daemon.GetPilotsByUserName
+org.gnome.GnomePilot.Daemon.GetPilotsByUserName \
+string:'foo'
 */
 gboolean
 gpilot_daemon_get_pilots_by_user_name (GpilotDaemon   *daemon,
                                        const char     *username,
-                                       GPtrArray     **pilots,
+                                       char         ***pilots,
                                        GError        **error)
 {
         int    i;
         GList *l;
+        int    count;
+        GList *matches;
 
         g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
         
@@ -2089,18 +2092,23 @@ gpilot_daemon_get_pilots_by_user_name (GpilotDaemon   *daemon,
         if (pilots == NULL)
                 return FALSE;
 
-        *pilots = g_ptr_array_new ();
         l = daemon->priv->gpilotd_context->pilots;
 
+        matches = NULL;
         for(i=0; i < g_list_length (l); i++) {
                 GPilotPilot *pilot = GPILOT_PILOT (g_list_nth (l, i)->data);
                 if (g_str_equal (pilot->pilot_username, username)) {
                         LOG (("match on %s", pilot->pilot_username));
-                        g_ptr_array_add (*pilots,
-                                         g_strdup (pilot->name));
+                        matches = g_list_append (matches, pilot->name);
                 }
         }
 
+        *pilots = g_new (char *, g_list_length (matches)+1);
+        for(i=0; i < g_list_length (matches); i++) {
+                (*pilots)[i] = g_strdup (g_list_nth (matches, i)->data);
+        }
+        (*pilots)[g_list_length (matches)] = NULL;
+
         return TRUE;
 }
 
diff --git a/gpilotd/gpilot-daemon.h b/gpilotd/gpilot-daemon.h
index cbd96b9..2d5db0d 100644
--- a/gpilotd/gpilot-daemon.h
+++ b/gpilotd/gpilot-daemon.h
@@ -213,7 +213,7 @@ gboolean        gpilot_daemon_get_pilot_ids     (GpilotDaemon   *daemon,
 gboolean        gpilot_daemon_get_pilots_by_user_name
                                                 (GpilotDaemon   *daemon,
                                                  const char     *username,
-                                                 GPtrArray     **pilots,
+                                                 char         ***pilots,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_pilots_by_user_login
                                                 (GpilotDaemon   *daemon,
diff --git a/utils/gpilotd-client.c b/utils/gpilotd-client.c
index bf4b22c..f50a433 100644
--- a/utils/gpilotd-client.c
+++ b/utils/gpilotd-client.c
@@ -32,6 +32,7 @@ char
 	*arg_conduit = NULL,
 	*arg_cradle = NULL,
 	*arg_list_by_login = NULL,
+	*arg_list_by_username = NULL,
 	*arg_pilot = NULL;
 
 GList *outstanding_requests;
@@ -52,6 +53,7 @@ static GOptionEntry options[] = {
 	{"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")},
+	{"listpilots1", '\0', 0, G_OPTION_ARG_STRING, &arg_list_by_username, N_("list PDAs by username (all for all pilots)"), N_("USERNAME")},
 	{"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", '\0', 0, G_OPTION_ARG_NONE, &arg_listusers, N_("List users"), NULL},
@@ -208,6 +210,43 @@ static void list_by_login (void) {
 	}
 }
 
+static void list_by_username (void) {
+	GList *list = NULL, *ptr;
+	gint *ids = NULL;
+	gint idx;
+
+	if (strcmp (arg_list_by_username, "all")==0) {
+		gnome_pilot_client_get_pilots (gpc, &list);
+		gnome_pilot_client_get_pilot_ids (gpc, &ids);
+	} else {
+		gnome_pilot_client_get_pilots_by_user_name (gpc, arg_list_by_username, &list);
+	}
+	if (list) {
+		idx = 0;
+		for (ptr = list; ptr; ptr = ptr->next ) {			
+			if (ids) {
+				char *user = NULL;
+				char *uid = NULL;
+				gnome_pilot_client_get_user_name_by_pilot_name (gpc, 
+										(char*)ptr->data,
+										&user);
+				gnome_pilot_client_get_user_login_by_pilot_name (gpc, 
+										 (char*)ptr->data,
+										 &uid);
+				g_message ("%s is %d, owned by %s aka %s", 
+					   (char*)ptr->data,
+					   ids[idx], 
+					   user, uid);
+			} else {
+				g_message ("Pilot : %s", (char*)ptr->data);
+			}
+			idx++;
+		}
+	} else {
+		g_message ("No pilots");
+	}
+}
+
 static void
 print_err (gint err, gint outstanding_request) {
 	stay_alive = FALSE;
@@ -434,6 +473,9 @@ main (int argc, char *argv[]) {
 		list_bases ();
 	} else if (arg_list_by_login) {
 		list_by_login ();
+	} else if (arg_list_by_username) {
+                g_debug ("%s", arg_list_by_username);
+		list_by_username ();
 	} else if (arg_monitor) {
 		g_message ("Monitor on %s",arg_pilot);
                 /*TODO turn on notify with dbus



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