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



commit c44f67b15c2e6152ba5734b26348454b05f3d3ea
Author: Halton Huo <halton huo sun com>
Date:   Tue Mar 16 18:46:52 2010 +0800

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

 gpilotd/gnome-pilot-client.gob |   24 +++++---------
 gpilotd/gpilot-daemon.c        |   69 +++++++++++++++++++++++++++++++++-------
 gpilotd/gpilot-daemon.h        |    2 +-
 gpilotd/gpilot-daemon.xml      |    2 +-
 utils/gpilotd-client.c         |   16 +++++++++
 5 files changed, 84 insertions(+), 29 deletions(-)
---
diff --git a/gpilotd/gnome-pilot-client.gob b/gpilotd/gnome-pilot-client.gob
index c32c037..5725ffb 100644
--- a/gpilotd/gnome-pilot-client.gob
+++ b/gpilotd/gnome-pilot-client.gob
@@ -811,10 +811,10 @@ 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		
+#ifndef G_DISABLE_CHECKS
 		if (*output != NULL) {
 			g_warning ("%s:%d: get_users called with non-null pointer for output, leak-alert!",
 				  __FILE__,__LINE__);
@@ -823,35 +823,29 @@ 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,
 					"GetUsers",
 					&error,
 					G_TYPE_INVALID,
-					dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING),
+                                        G_TYPE_STRV,
 					&arr,
 					G_TYPE_INVALID);
 
 		if (!res) {
-			g_warning ("Unable to GetUsers%s", error->message);
+			g_warning ("Unable to GetUsers %s", error->message);
 			g_error_free (error);
 			return GPILOTD_ERR_FAILED;
 		}
 
 		(*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 701b39a..63e8bbe 100644
--- a/gpilotd/gpilot-daemon.c
+++ b/gpilotd/gpilot-daemon.c
@@ -63,6 +63,8 @@
 #define GP_DBUS_PATH         "/org/gnome/GnomePilot/Daemon"
 #define GP_DBUS_INTERFACE    "org.gnome.GnomePilot.Daemon"
 
+#define IS_STR_SET(x) (x != NULL && x[0] != '\0')
+
 #define GPILOT_DAEMON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPILOT_TYPE_DAEMON, GpilotDaemonPrivate))
 
 #define DEBUG_CODE
@@ -1635,7 +1637,7 @@ gpilot_daemon_error_get_type (void)
 /*
 Example:
 dbus-send --session --dest=org.gnome.GnomePilot \
---type=method_call --print-reply --reply-timeout=2000 \
+--type=method_call --print-reply \
 /org/gnome/GnomePilot/Daemon \
 org.gnome.GnomePilot.Daemon.Pause boolean:true
 */
@@ -1667,7 +1669,7 @@ gpilot_daemon_pause (GpilotDaemon   *daemon,
 /*
 Example:
 dbus-send --session --dest=org.gnome.GnomePilot \
---type=method_call --print-reply --reply-timeout=2000 \
+--type=method_call --print-reply \
 /org/gnome/GnomePilot/Daemon \
 org.gnome.GnomePilot.Daemon.RereadConfig
 */
@@ -1692,7 +1694,7 @@ gpilot_daemon_reread_config (GpilotDaemon   *daemon,
    check to see if the daemon has blown up
 Example:
 dbus-send --session --dest=org.gnome.GnomePilot \
---type=method_call --print-reply --reply-timeout=2000 \
+--type=method_call --print-reply \
 /org/gnome/GnomePilot/Daemon \
 org.gnome.GnomePilot.Daemon.Noop
 */
@@ -1912,7 +1914,7 @@ gpilot_daemon_remove_request (GpilotDaemon   *daemon,
 /* information operations */
 /* Example:
 dbus-send --session --dest=org.gnome.GnomePilot \
---type=method_call --print-reply --reply-timeout=2000 \
+--type=method_call --print-reply \
 /org/gnome/GnomePilot/Daemon \
 org.gnome.GnomePilot.Daemon.GetSystemInfo \
 string:'Cradle' uint32:0 uint32:0
@@ -1949,15 +1951,17 @@ gpilot_daemon_get_system_info (GpilotDaemon   *daemon,
 
 /* Example:
 dbus-send --session --dest=org.gnome.GnomePilot \
---type=method_call --print-reply --reply-timeout=2000 \
+--type=method_call --print-reply \
 /org/gnome/GnomePilot/Daemon \
 org.gnome.GnomePilot.Daemon.GetUsers
 */
 gboolean
 gpilot_daemon_get_users (GpilotDaemon   *daemon,
-                         GPtrArray     **users,
+                         char         ***users,
                          GError        **error)
 {
+        char *username;
+
         g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
         
         LOG (("get_users()"));
@@ -1965,11 +1969,21 @@ gpilot_daemon_get_users (GpilotDaemon   *daemon,
         if (users == NULL)
                 return FALSE;
 
-        *users = g_ptr_array_new ();
-        g_ptr_array_add (*users, g_strdup (daemon->priv->gpilotd_context->user->username));
+        username = daemon->priv->gpilotd_context->user->username;
+        if (IS_STR_SET (username)) {
+                *users = g_new (char *, 2);
+                (*users)[0] = g_strdup (username);
+                (*users)[1] = NULL;
+        }
         return TRUE;
 }
 
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetCradles
+*/
 gboolean
 gpilot_daemon_get_cradles (GpilotDaemon   *daemon,
                            GPtrArray     **cradles,
@@ -1997,6 +2011,12 @@ gpilot_daemon_get_cradles (GpilotDaemon   *daemon,
         return TRUE;
 }
 
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetPilots
+*/
 gboolean
 gpilot_daemon_get_pilots (GpilotDaemon   *daemon,
                           GPtrArray     **pilots,
@@ -2007,7 +2027,7 @@ gpilot_daemon_get_pilots (GpilotDaemon   *daemon,
 
         g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
         
-        LOG (("get_pilot_ids()"));
+        LOG (("get_pilots()"));
 
         if (pilots == NULL)
                 return FALSE;
@@ -2024,6 +2044,12 @@ gpilot_daemon_get_pilots (GpilotDaemon   *daemon,
         return TRUE;
 }
 
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetPilotIDs
+*/
 gboolean
 gpilot_daemon_get_pilot_ids (GpilotDaemon   *daemon,
                              GPtrArray     **pilots,
@@ -2051,6 +2077,12 @@ gpilot_daemon_get_pilot_ids (GpilotDaemon   *daemon,
         return TRUE;
 }
 
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetPilotsByUserName
+*/
 gboolean
 gpilot_daemon_get_pilots_by_user_name (GpilotDaemon   *daemon,
                                        const char     *username,
@@ -2082,6 +2114,12 @@ gpilot_daemon_get_pilots_by_user_name (GpilotDaemon   *daemon,
         return TRUE;
 }
 
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.GetPilotsByUserLogin
+*/
 gboolean
 gpilot_daemon_get_pilots_by_user_login (GpilotDaemon   *daemon,
                                         const char     *uid,
@@ -2259,7 +2297,7 @@ gpilot_daemon_get_databases_from_cache (GpilotDaemon   *daemon,
 /* admin operations */
 /* Example:
 dbus-send --session --dest=org.gnome.GnomePilot \
---type=method_call --print-reply --reply-timeout=2000 \
+--type=method_call --print-reply \
 /org/gnome/GnomePilot/Daemon \
 org.gnome.GnomePilot.Daemon.GetUserInfo \
 string:'Cradle' uint32:0 uint32:0
@@ -2294,6 +2332,14 @@ gpilot_daemon_get_user_info (GpilotDaemon   *daemon,
         return ret;
 }
 
+/* Example:
+dbus-send --session --dest=org.gnome.GnomePilot \
+--type=method_call --print-reply \
+/org/gnome/GnomePilot/Daemon \
+org.gnome.GnomePilot.Daemon.SetUserInfo \
+string:'Cradle' boolean:true uint32:0 \
+uint32:0 uint32:1111 username:'foo' 
+*/
 gboolean
 gpilot_daemon_set_user_info (GpilotDaemon   *daemon,
                              const char     *cradle,
@@ -2509,8 +2555,7 @@ bus_name_owner_changed (DBusGProxy   *bus_proxy,
                         const char   *new_service_name,
                         GpilotDaemon *daemon)
 {
-        g_debug ("NameOwnerChanged: service_name='%s', old_service_name='%s' new_service_name='%s'",
-                   service_name, old_service_name, new_service_name);
+        return;
 }
 
 static gboolean
diff --git a/gpilotd/gpilot-daemon.h b/gpilotd/gpilot-daemon.h
index 340064d..88d0d4c 100644
--- a/gpilotd/gpilot-daemon.h
+++ b/gpilotd/gpilot-daemon.h
@@ -199,7 +199,7 @@ gboolean        gpilot_daemon_get_system_info   (GpilotDaemon   *daemon,
                                                  unsigned long  *handle,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_users         (GpilotDaemon   *daemon,
-                                                 GPtrArray     **users,
+                                                 char         ***users,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_cradles       (GpilotDaemon   *daemon,
                                                  GPtrArray     **cradles,
diff --git a/gpilotd/gpilot-daemon.xml b/gpilotd/gpilot-daemon.xml
index b871fe7..14bbc4b 100644
--- a/gpilotd/gpilot-daemon.xml
+++ b/gpilotd/gpilot-daemon.xml
@@ -184,7 +184,7 @@
     </method>
 
     <method name="GetUsers">
-      <arg name="users" direction="out" type="ao">
+      <arg name="users" direction="out" type="as">
         <doc:doc>
           <doc:summary>An array of user names.</doc:summary>
         </doc:doc>
diff --git a/utils/gpilotd-client.c b/utils/gpilotd-client.c
index 2a45054..cbcf2a7 100644
--- a/utils/gpilotd-client.c
+++ b/utils/gpilotd-client.c
@@ -20,6 +20,7 @@ int     arg_pause=0,
 	arg_restart=0,
 	arg_setuser = 0,
 	arg_listbases = 0,
+	arg_listusers = 0,
 	arg_monitorall=0,
 	arg_monitor,
 	arg_getinfo = 0;
@@ -52,6 +53,7 @@ static GOptionEntry options[] = {
 	{"listpilots", '\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},
 	{"listbases", 'l', 0, G_OPTION_ARG_NONE, &arg_listbases, N_("List the specified PDA's bases"), NULL},
 	{NULL},
 };
@@ -131,6 +133,18 @@ the_loop (void) {
 	}
 }
 
+static void list_users (void) {
+	GList *list = NULL,*ptr;
+
+	gnome_pilot_client_get_users (gpc, &list);
+	if (list)
+		for (ptr = list; ptr; ptr = ptr->next) {
+			g_message ("user %s", (char*)ptr->data);
+		}
+	else 
+		g_message ("No users");
+}
+
 static void list_bases (void) {
 	GList *list = NULL,*ptr;
 
@@ -398,6 +412,8 @@ main (int argc, char *argv[]) {
 		conduit (arg_conduit);
 	} else if (arg_setuser) {
 		set_user ();
+	} else if (arg_listusers) {
+		list_users ();
 	} 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]