[gnome-pilot] Add signal Connected Disconnected implements.



commit c294db8104e11ca0d2394bc383bf95e7c00de03f
Author: Halton Huo <halton huo sun com>
Date:   Wed Mar 17 16:18:28 2010 +0800

    Add signal Connected Disconnected implements.
    
    Test with gpilotd-client -A

 gpilotd/gnome-pilot-client.gob |   90 +++++++++++++++++++++++++++++-----------
 gpilotd/gpilot-daemon.c        |   63 +++++++++++++++++++++++----
 2 files changed, 119 insertions(+), 34 deletions(-)
---
diff --git a/gpilotd/gnome-pilot-client.gob b/gpilotd/gnome-pilot-client.gob
index 2fa6eac..2c29a12 100644
--- a/gpilotd/gnome-pilot-client.gob
+++ b/gpilotd/gnome-pilot-client.gob
@@ -125,32 +125,74 @@ class Gnome:Pilot:Client from Gtk:Object {
                 dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_UINT,
                                            G_TYPE_NONE,
                                            G_TYPE_STRING,
-                                           G_TYPE_INT,
+                                           G_TYPE_UINT,
+                                           G_TYPE_INVALID);
+                dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_UINT_STRING,
+                                           G_TYPE_NONE,
+                                           G_TYPE_STRING,
+                                           G_TYPE_UINT,
+                                           G_TYPE_STRING,
                                            G_TYPE_INVALID);
                 dbus_g_proxy_add_signal (self->proxy,
                                          "RequestCompleted",
                                          G_TYPE_STRING,
-                                         G_TYPE_INT,
+                                         G_TYPE_UINT,
                                          G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "Connected",
+                                         G_TYPE_STRING,
+                                         G_TYPE_UINT,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "Disconnected",
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+
                 dbus_g_proxy_connect_signal (self->proxy,
                                      "RequestCompleted",
                                      G_CALLBACK (self_dbus_request_completed),
                                      self,
                                      NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "Connected",
+                                     G_CALLBACK (self_dbus_connect),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "Disconnected",
+                                     G_CALLBACK (self_dbus_disconnect),
+                                     self,
+                                     NULL);
 
 		return GPILOTD_OK;
 	}
 
 	private void
-	dbus_connect (self,
+	dbus_connect (DBusGProxy  *proxy,
 		      const gchar *pilot_id,
-		      const GNOME_Pilot_UserInfo *user) {
-		self_pilot_connect (self, pilot_id, user);
+                      guint32      uid,
+                      const gchar *username,
+                      gpointer     data) {
+                Self *self = SELF(data);
+                GNOME_Pilot_UserInfo user;
+
+                user.userID = uid;
+                user.username = g_strdup (username);
+
+                g_message ("Get signal 'Connected' pilot_id=%s, userid=%d, username=%s", pilot_id, user.userID, user.username);
+		self_pilot_connect (self, pilot_id, &user);
+
+                g_free (user.username);
 	}
 
 	private void
-	dbus_disconnect (self,
-			 const gchar *pilot_id) {
+	dbus_disconnect (DBusGProxy  *proxy,
+			 const gchar *pilot_id,
+                         gpointer     data) {
+                Self *self = SELF(data);
+
+                g_message ("Get signal 'Disconnected' pilot_id=%s", pilot_id);
 		self_pilot_disconnect (self, pilot_id);
 	}
  
@@ -161,7 +203,7 @@ class Gnome:Pilot:Client from Gtk:Object {
                                 gpointer     data) {
                 Self *self = SELF(data);
 
-                g_debug ("Get signal 'RequestCompleted'");
+                g_message ("Get signal 'RequestCompleted'");
 		self_completed_request (self, pilot_id, id);
 	}
 
@@ -174,7 +216,7 @@ class Gnome:Pilot:Client from Gtk:Object {
                 Self *self = SELF(data);
                 GNOME_Pilot_UserInfo user;
 
-                g_debug ("Get signal 'UserInfoRequested'");
+                g_message ("Get signal 'UserInfoRequested'");
                 user.userID = uid;
                 user.username = g_strdup (username);
 
@@ -197,7 +239,7 @@ class Gnome:Pilot:Client from Gtk:Object {
                 Self *self = SELF(data);
                 GNOME_Pilot_SysInfo sysinfo;
 
-                g_debug ("Get signal 'SysInfoRequested'");
+                g_message ("Get signal 'SysInfoRequested'");
                 sysinfo.romSize = rom_size;
                 sysinfo.ramSize = ram_size;
                 sysinfo.ramFree = ram_free;
@@ -613,13 +655,13 @@ error:		if (file_copied == FALSE) {
                 dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_UINT_STRING,
                                            G_TYPE_NONE,
                                            G_TYPE_STRING,
-                                           G_TYPE_INT,
+                                           G_TYPE_UINT,
                                            G_TYPE_STRING,
                                            G_TYPE_INVALID);
                 dbus_g_proxy_add_signal (self->proxy,
                                          "UserInfoRequested",
                                          G_TYPE_STRING,
-                                         G_TYPE_INT,
+                                         G_TYPE_UINT,
                                          G_TYPE_STRING,
                                          G_TYPE_INVALID);
                 dbus_g_proxy_connect_signal (self->proxy,
@@ -701,24 +743,24 @@ error:		if (file_copied == FALSE) {
                 dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_UINT_UINT_UINT_STRING_STRING_UINT_UINT,
                                            G_TYPE_NONE,
                                            G_TYPE_STRING,
-                                           G_TYPE_INT,
-                                           G_TYPE_INT,
-                                           G_TYPE_INT,
+                                           G_TYPE_UINT,
+                                           G_TYPE_UINT,
+                                           G_TYPE_UINT,
                                            G_TYPE_STRING,
                                            G_TYPE_STRING,
-                                           G_TYPE_INT,
-                                           G_TYPE_INT,
+                                           G_TYPE_UINT,
+                                           G_TYPE_UINT,
                                            G_TYPE_INVALID);
                 dbus_g_proxy_add_signal (self->proxy,
                                          "SysInfoRequested",
                                          G_TYPE_STRING,
-                                         G_TYPE_INT,
-                                         G_TYPE_INT,
-                                         G_TYPE_INT,
+                                         G_TYPE_UINT,
+                                         G_TYPE_UINT,
+                                         G_TYPE_UINT,
                                          G_TYPE_STRING,
                                          G_TYPE_STRING,
-                                         G_TYPE_INT,
-                                         G_TYPE_INT,
+                                         G_TYPE_UINT,
+                                         G_TYPE_UINT,
                                          G_TYPE_INVALID);
                 dbus_g_proxy_connect_signal (self->proxy,
                                      "SysInfoRequested",
@@ -1216,7 +1258,7 @@ error:		if (file_copied == FALSE) {
 					&error,
 					G_TYPE_STRING, pilot_name,
 					G_TYPE_INVALID,
-					G_TYPE_INT, output,
+					G_TYPE_UINT, output,
 					G_TYPE_INVALID);
 
 		if (!res) {
@@ -1238,7 +1280,7 @@ error:		if (file_copied == FALSE) {
 		res = dbus_g_proxy_call (self->proxy,
 					"GetPilotNameFromId",
 					&error,
-					G_TYPE_INT, &pilot_id,
+					G_TYPE_UINT, &pilot_id,
 					G_TYPE_INVALID,
 					G_TYPE_STRING, output,
 					G_TYPE_INVALID);
diff --git a/gpilotd/gpilot-daemon.c b/gpilotd/gpilot-daemon.c
index 5deed05..4426e05 100644
--- a/gpilotd/gpilot-daemon.c
+++ b/gpilotd/gpilot-daemon.c
@@ -2309,9 +2309,9 @@ gpilot_daemon_get_databases_from_cache (GpilotDaemon   *daemon,
                                           "databases", &num_bases, NULL);
         *databases = g_new (char *, num_bases + 1);
         for (i=0; i<num_bases; i++) {
-                *databases[i] = g_strdup (arr[i]);
+                (*databases)[i] = g_strdup (arr[i]);
         }
-        *databases[num_bases] = NULL;
+        (*databases)[num_bases] = NULL;
 
         ret = TRUE;
  out:
@@ -2402,14 +2402,57 @@ gpilot_daemon_set_user_info (GpilotDaemon   *daemon,
 }
 
 void
-dbus_notify_connected (const gchar    *pilot_id,
+dbus_notify_connected (const gchar     *pilot_id,
                        struct PilotUser user_info)
 {
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+        gchar          *username;
+
+        /* do a strcpy for username to sending sending too long
+         string by dbus */
+        username = g_strdup (user_info.username);
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "Connected");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_id);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &user_info.userID);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &username);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+
+        g_free (username);
 }
 
 void
 dbus_notify_disconnected (const gchar    *pilot_id)
 {
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "Disconnected");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_id);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
 }
 
 void
@@ -2433,7 +2476,7 @@ dbus_notify_completion (GPilotRequest **req)
 
         dbus_message_iter_init_append (message, &iter);
         dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_name);
-        dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &(*req)->handle);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &(*req)->handle);
 
         connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
         dbus_connection_send (connection, message, NULL);
@@ -2465,7 +2508,7 @@ dbus_notify_userinfo (struct PilotUser    user_info,
 
         dbus_message_iter_init_append (message, &iter);
         dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &(*req)->cradle);
-        dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &user_info.userID);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &user_info.userID);
         dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &username);
 
         connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
@@ -2503,13 +2546,13 @@ dbus_notify_sysinfo (const gchar      *pilot_id,
 
         dbus_message_iter_init_append (message, &iter);
         dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &pilot_id);
-        dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &_sysinfo.romSize);
-        dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &_sysinfo.ramSize);
-        dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &_sysinfo.ramFree);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &_sysinfo.romSize);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &_sysinfo.ramSize);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &_sysinfo.ramFree);
         dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &_sysinfo.name);
         dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &_sysinfo.manufacturer);
-        dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &_sysinfo.creation);
-        dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &_sysinfo.romVersion);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &_sysinfo.creation);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &_sysinfo.romVersion);
 
         connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
         dbus_connection_send (connection, message, NULL);



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