[gnome-pilot/dbus] Implement dbus signals calls:



commit 47af89a82aff87ee572273305806f08a93f04d2e
Author: Halton Huo <halton huo sun com>
Date:   Wed Mar 17 20:26:54 2010 +0800

    Implement dbus signals calls:
    
            ConduitMessage
            ConduitError
            DaemonMessage
            DaemonError
            Paused
    
    Rewirte gpilotd_client to monitor above signals with argument -m
    
    Tested with
      gpilotd_client -m

 gpilotd/gnome-pilot-client.gob |   96 +++++++++++++++++++++++++++++++++-------
 gpilotd/gpilot-daemon.c        |   92 ++++++++++++++++++++++++++++++++------
 gpilotd/gpilot-daemon.h        |    1 -
 utils/gpilotd-client.c         |   50 +++++++++++++++++++++
 4 files changed, 207 insertions(+), 32 deletions(-)
---
diff --git a/gpilotd/gnome-pilot-client.gob b/gpilotd/gnome-pilot-client.gob
index 6188ae6..e9b76b5 100644
--- a/gpilotd/gnome-pilot-client.gob
+++ b/gpilotd/gnome-pilot-client.gob
@@ -190,6 +190,35 @@ class Gnome:Pilot:Client from Gtk:Object {
                                          G_TYPE_UINT,
                                          G_TYPE_UINT,
                                          G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "ConduitMessage",
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "ConduitError",
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "DaemonMessage",
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "DaemonError",
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_STRING,
+                                         G_TYPE_INVALID);
+                dbus_g_proxy_add_signal (self->proxy,
+                                         "Paused",
+                                         G_TYPE_BOOLEAN,
+                                         G_TYPE_INVALID);
+
 
                 dbus_g_proxy_connect_signal (self->proxy,
                                      "RequestCompleted",
@@ -226,6 +255,31 @@ class Gnome:Pilot:Client from Gtk:Object {
                                      G_CALLBACK (self_dbus_overall_progress),
                                      self,
                                      NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "ConduitMessage",
+                                     G_CALLBACK (self_dbus_conduit_message),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "ConduitError",
+                                     G_CALLBACK (self_dbus_conduit_error),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "DaemonMessage",
+                                     G_CALLBACK (self_dbus_daemon_message),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "DaemonError",
+                                     G_CALLBACK (self_dbus_daemon_error),
+                                     self,
+                                     NULL);
+                dbus_g_proxy_connect_signal (self->proxy,
+                                     "Paused",
+                                     G_CALLBACK (self_dbus_paused),
+                                     self,
+                                     NULL);
 
 		return GPILOTD_OK;
 	}
@@ -357,39 +411,49 @@ class Gnome:Pilot:Client from Gtk:Object {
 	}
 				
 	private void
-	dbus_conduit_message (self,
-			      const gchar *pilot_id,
-			      const gchar *conduit_name,
-			      const gchar *message) {
+	dbus_conduit_message (DBusGProxy  *proxy,
+                              const gchar *pilot_id,
+                              const gchar *conduit_name,
+                              const gchar *message,
+                              gpointer     data) {
+                Self *self = SELF(data);
 		self_message_conduit (self,pilot_id,conduit_name,message);
 	}	
 
 	private void
-	dbus_daemon_message (self,
-			      const gchar *pilot_id,
-			      const gchar *conduit_name,
-			      const gchar *message) {
-		self_message_daemon (self,pilot_id,conduit_name,message);
+	dbus_daemon_message (DBusGProxy  *proxy,
+                             const gchar *pilot_id,
+                             const gchar *conduit_name,
+                             const gchar *message,
+                             gpointer     data) {
+                Self *self = SELF(data);
+		self_message_daemon (self, pilot_id, conduit_name, message);
 	}	
 
 	private void
-	dbus_daemon_error (self,
-			    const gchar *pilot_id,
-			    const gchar *message) {
+	dbus_daemon_error (DBusGProxy  *proxy,
+                           const gchar *pilot_id,
+                           const gchar *message,
+                           gpointer     data) {
+                Self *self = SELF(data);
 		self_error_daemon (self, pilot_id, message);
 	}	
 		
 	private void
-	dbus_conduit_error (self,
+	dbus_conduit_error (DBusGProxy  *proxy,
 			    const gchar *pilot_id,
 			    const gchar *conduit_name,
-			    const gchar *message) {
+                            const gchar *message,
+                            gpointer     data) {
+                Self *self = SELF(data);
 		self_error_conduit (self,pilot_id,conduit_name,message);
 	}
 
 	private void
-	dbus_pause (self,
-		    gboolean on_off) {
+	dbus_paused (DBusGProxy  *proxy,
+		     gboolean     on_off,
+                     gpointer     data) {
+                Self *self = SELF(data);
 		self_daemon_pause (self, on_off);
 	}
 	
diff --git a/gpilotd/gpilot-daemon.c b/gpilotd/gpilot-daemon.c
index db0f466..8c73778 100644
--- a/gpilotd/gpilot-daemon.c
+++ b/gpilotd/gpilot-daemon.c
@@ -1635,6 +1635,28 @@ gpilot_daemon_error_get_type (void)
         return etype;
 }
 
+static void
+dbus_notify_paused (gboolean on_ff) 
+{
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                           GP_DBUS_INTERFACE,
+                                           "Paused");
+
+        dbus_message_set_destination (message, GP_DBUS_NAME);
+
+        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &on_ff);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+}
+
 /*
 Example:
 dbus-send --session --dest=org.gnome.GnomePilot \
@@ -1656,6 +1678,7 @@ gpilot_daemon_pause (GpilotDaemon   *daemon,
 
         priv->gpilotd_context->paused = on_off;
 
+        dbus_notify_paused (on_off);
         if (priv->gpilotd_context->paused) {
                 g_list_foreach (priv->gpilotd_context->devices,
                                 (GFunc)gpilot_daemon_pause_device,
@@ -2643,20 +2666,6 @@ dbus_notify_conduit_end (const gchar       *pilot_id,
 }
 
 void
-dbus_notify_conduit_error (const gchar       *pilot_id,
-                           GnomePilotConduit *conduit,
-                           const gchar       *message)
-{
-}
-
-void
-dbus_notify_conduit_message (const gchar       *pilot_id,
-                             GnomePilotConduit *conduit,
-                             const gchar       *message)
-{
-}
-
-void
 dbus_notify_conduit_progress (const gchar       *pilot_id,
                               GnomePilotConduit *conduit,
                               guint32            current,
@@ -2715,18 +2724,71 @@ dbus_notify_overall_progress (const gchar    *pilot_id,
         dbus_message_unref (message);
 }
 
+static void
+dbus_notify_message (const gchar       *pilot_id,
+                     GnomePilotConduit *conduit,
+                     const gchar       *msg,
+                     const gchar       *method_call)
+{
+        DBusMessage    *message;
+        DBusConnection *connection;
+        DBusMessageIter iter;
+        gchar          *name;
+
+        if (GNOME_IS_PILOT_CONDUIT (conduit))
+                name = gnome_pilot_conduit_get_name (conduit);
+        else
+                name = NULL;
+
+        message = dbus_message_new_signal (GP_DBUS_PATH,
+                                       GP_DBUS_INTERFACE,
+                                       method_call);
+
+        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);
+        if (IS_STR_SET (name))
+                dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name);
+        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &msg);
+
+        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+        dbus_connection_send (connection, message, NULL);
+        dbus_connection_unref (connection);
+        dbus_message_unref (message);
+
+        g_free (name);
+}
+
+void
+dbus_notify_conduit_error (const gchar       *pilot_id,
+                           GnomePilotConduit *conduit,
+                           const gchar       *message)
+{
+        dbus_notify_message (pilot_id, conduit, message, "ConduitError");
+}
+
+void
+dbus_notify_conduit_message (const gchar       *pilot_id,
+                             GnomePilotConduit *conduit,
+                             const gchar       *message)
+{
+        dbus_notify_message (pilot_id, conduit, message, "ConduitMessage");
+}
+
 void
 dbus_notify_daemon_message (const gchar       *pilot_id,
                             GnomePilotConduit *conduit,
                             const gchar       *message)
 {
+        dbus_notify_message (pilot_id, conduit, message, "DaemonMessage");
 }
 
 void
 dbus_notify_daemon_error (const gchar       *pilot_id,
-                          GnomePilotConduit *conduit,
                           const gchar       *message)
 {
+        dbus_notify_message (pilot_id, NULL, message, "DaemonError");
 }
 
 static void
diff --git a/gpilotd/gpilot-daemon.h b/gpilotd/gpilot-daemon.h
index 358cd03..0ebe234 100644
--- a/gpilotd/gpilot-daemon.h
+++ b/gpilotd/gpilot-daemon.h
@@ -306,7 +306,6 @@ void            dbus_notify_daemon_message      (const gchar    *pilot_id,
                                                  GnomePilotConduit *conduit,
                                                  const gchar    *message);
 void            dbus_notify_daemon_error        (const gchar    *pilot_id,
-                                                 GnomePilotConduit *conduit,
                                                  const gchar    *message);
 
 G_END_DECLS
diff --git a/utils/gpilotd-client.c b/utils/gpilotd-client.c
index c3e2c16..3cadb78 100644
--- a/utils/gpilotd-client.c
+++ b/utils/gpilotd-client.c
@@ -76,6 +76,51 @@ pilot_disconnect (GnomePilotClient *gpc,
 };
 
 static void
+daemon_pause (GnomePilotClient *gpc, 
+              gboolean          on_ff, 
+              gpointer          data) {
+	g_message ("daemon pause: %d", on_ff);
+}
+
+static void
+conduit_message (GnomePilotClient *gpc, 
+                 const gchar      *pilot_id,
+                 const gchar      *conduit,
+                 const gchar      *message,
+                 gpointer          data) {
+        g_message ("conduit message: pilot=%s, conduit=%s", pilot_id, conduit);
+        g_message ("conduit message: %s", message);
+}
+
+static void
+daemon_message (GnomePilotClient *gpc, 
+                 const gchar      *pilot_id,
+                 const gchar      *conduit,
+                 const gchar      *message,
+                 gpointer          data) {
+        g_message ("daemon message: pilot=%s, conduit=%s", pilot_id, conduit);
+        g_message ("daemon message: %s", message);
+}
+
+static void
+conduit_error (GnomePilotClient *gpc, 
+                 const gchar      *pilot_id,
+                 const gchar      *conduit,
+                 const gchar      *message,
+                 gpointer          data) {
+        g_message ("conduit error: pilot=%s, conduit=%s", pilot_id, conduit);
+        g_message ("conduit error: %s", message);
+}
+
+static void
+daemon_error (GnomePilotClient *gpc, 
+                 const gchar      *pilot_id,
+                 const gchar      *message,
+                 gpointer          data) {
+        g_message ("daemon error: pilot=%s", pilot_id);
+        g_message ("daemon error: %s", message);
+}
+static void
 start_conduit (GnomePilotClient *gpc, 
                const gchar      *pilot_id, 
                const gchar      *conduit, 
@@ -473,6 +518,11 @@ main (int argc, char *argv[]) {
 		
 		gnome_pilot_client_connect__pilot_connect (gpc, pilot_connect, NULL);
 		gnome_pilot_client_connect__pilot_disconnect (gpc, pilot_disconnect, &stay_alive);
+		gnome_pilot_client_connect__daemon_pause (gpc, daemon_pause, NULL);
+		gnome_pilot_client_connect__message_conduit (gpc, conduit_message, NULL);
+		gnome_pilot_client_connect__message_daemon (gpc, daemon_message, NULL);
+		gnome_pilot_client_connect__error_conduit (gpc, conduit_error, NULL);
+		gnome_pilot_client_connect__error_daemon (gpc, daemon_error, NULL);
 
                 if (arg_conduit) {
                         gnome_pilot_client_connect__start_conduit (gpc, start_conduit, NULL);



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