[gnome-pilot/dbus] Rework gpilot_daemon_event_notify



commit b22b2c9b078eb2869babaddcddb7c3630216fb95
Author: Halton Huo <halton huo sun com>
Date:   Wed Mar 3 14:31:07 2010 +0800

    Rework gpilot_daemon_event_notify

 gpilotd/Makefile.am       |    1 -
 gpilotd/gpilot-daemon.c   |  159 +++++++++++++++++++++++++++++++++++++++++----
 gpilotd/gpilot-daemon.xml |    2 +-
 3 files changed, 148 insertions(+), 14 deletions(-)
---
diff --git a/gpilotd/Makefile.am b/gpilotd/Makefile.am
index ff8be43..608ef1c 100644
--- a/gpilotd/Makefile.am
+++ b/gpilotd/Makefile.am
@@ -133,7 +133,6 @@ libgpilotdcm_la_LDFLAGS = \
 ## LIBGPILOTD
 
 libgpilotd_la_SOURCES = 		\
-	$(CORBA_SRCLIST) 		\
 	$(GOB_LIBGPILOTD_BUILT_SRCS)	\
 	$(NULL)
 
diff --git a/gpilotd/gpilot-daemon.c b/gpilotd/gpilot-daemon.c
index 02421e1..a53504b 100644
--- a/gpilotd/gpilot-daemon.c
+++ b/gpilotd/gpilot-daemon.c
@@ -63,6 +63,12 @@ typedef struct {
         GSList* userinfo_sent;
 } PilotNotifications;
 
+typedef struct {
+  gpointer daemon;
+  gpointer client_id;
+  EventType event;
+} GPilotd_notify_on_helper_foreach_carrier;
+
 static void
 gpilot_daemon_pause_device (GPilotDevice *device,
                             gpointer      data)
@@ -1069,27 +1075,156 @@ gpilot_daemon_monitor (GpilotDaemon   *daemon,
  out:
         return ret;
 }
+ 
+static void 
+notify_on_helper (const gchar   *pilot,
+		  GPilotd_notify_on_helper_foreach_carrier *carrier) 
+{
+        GpilotDaemon        *daemon;
+        GpilotDaemonPrivate *priv;
+	PilotNotifications  *notifications;
+
+        daemon = GPILOT_DAEMON(carrier->daemon);
+        priv = daemon->priv;
+	notifications = g_hash_table_lookup (priv->notifications, pilot);
+
+	if(notifications == NULL) {
+		notifications = g_new0 (PilotNotifications,1);
+		g_hash_table_insert (priv->notifications,
+                                     g_strdup (pilot), notifications);
+	}
+	switch (carrier->event) {
+	case NOTIFY_CONNECT: 
+		notifications->connect = g_slist_prepend(notifications->connect,
+							 g_strdup(carrier->client_id));
+		break;
+	case NOTIFY_DISCONNECT: 
+		notifications->disconnect = g_slist_prepend(notifications->disconnect,
+							    g_strdup(carrier->client_id));
+		break;
+	case NOTIFY_BACKUP: 
+		notifications->backup = g_slist_prepend(notifications->backup,
+							g_strdup(carrier->client_id));
+		break;
+	case NOTIFY_CONDUIT: 
+		notifications->conduit = g_slist_prepend(notifications->conduit,
+							 g_strdup(carrier->client_id));
+		break;
+	case NOTIFY_REQUEST_COMPLETION: 
+		notifications->request_complete = g_slist_prepend(notifications->request_complete,
+								  g_strdup(carrier->client_id));
+		break;
+	case NOTIFY_REQUEST_TIMEOUT: 
+		notifications->request_timeout = g_slist_prepend(notifications->request_timeout,
+								 g_strdup(carrier->client_id));
+		break;
+	case NOTIFY_USERINFO_REQUESTED: 
+		/* FIXME: what was this request to do ? notify when the info was requested or when returned ? */
+		/*notifications->userinfo_requested = g_slist_prepend(notifications->connect,g_strdup(carrier->client_id)); */
+		break;
+	case NOTIFY_SYSINFO_REQUESTED: 
+		/* FIXME: what was this request to do ? notify when the info was requested or when returned ? */
+		/*notifications->sysinfo_requestde = g_slist_prepend(notifications->connect,g_strdup(carrier->client_id));*/
+		break;
+	case NOTIFY_USERINFO_SENT: 
+		notifications->userinfo_sent = g_slist_prepend(notifications->userinfo_sent,
+							       g_strdup(carrier->client_id));
+		break;
+	default:
+		g_assert_not_reached();
+		break;
+	}
+}
+
+static gboolean 
+notify_on (GpilotDaemon *daemon, 
+           EventType     event, 
+           char         *client_id,
+           GError      **error)
+{
+	GSList **pilots;
+        gboolean ret;
+	GPilotd_notify_on_helper_foreach_carrier carrier;
+
+        ret = FALSE;
+	if((pilots = g_hash_table_lookup (daemon->priv->monitors, client_id)) == NULL) {
+                g_set_error (error,
+                             GPILOT_DAEMON_ERROR,
+                             GPILOT_DAEMON_ERROR_GENERAL,
+                             "No monitors");
+                goto out;
+	}
+	carrier.client_id = client_id;
+	carrier.event = event;
+	g_slist_foreach (*pilots, (GFunc)notify_on_helper, (gpointer)&carrier);
+
+        ret = TRUE;
+ out:
+        return ret;
+}
+
+static gboolean 
+notify_off (GpilotDaemon *daemon, 
+            EventType     event, 
+            char         *client_id,
+            GError      **error)
+{
+	GSList **pilots;
+	GPilotd_notify_on_helper_foreach_carrier carrier;
+
+	carrier.client_id = client_id;
+	carrier.event = event;
+	g_warning ("Unimplemented method");
+	/*
+	g_slist_foreach(*pilots,(GFunc)notify_on_helper,(gpointer)&carrier);
+	*/
+
+        return TRUE;
+}
 
 gboolean
 gpilot_daemon_event_notify (GpilotDaemon   *daemon,
-                            EventType       event_type,
+                            EventType       event,
                             gboolean        on,
                             GError        **error)
 {
-        GpilotDaemonPrivate *priv;
-        GPilotRequest        req;
-        gchar               *client_id;
-        gboolean             ret;
-        
-        ret = FALSE;
-        priv = daemon->priv;
+        gchar *client_id;
+        gchar *event_type;
+        gboolean ret;
 
         /* TODO
-        GET_AND_CHECK_CLIENT_ID(client_id,cb,0); 
+	GET_AND_CHECK_CLIENT_ID_VOID(client_id,cb);
          */
-        ret = TRUE;
- out:
-        g_free(client_id);
+        event_type = NULL;
+        switch(event) {
+        case NOTIFY_CONNECT: 
+                event_type = g_strdup("CONNECT"); break;
+        case NOTIFY_DISCONNECT: 
+                event_type = g_strdup("DISCONNECT"); break;
+        case NOTIFY_BACKUP: 
+                event_type = g_strdup("BACKUP"); break;
+        case NOTIFY_CONDUIT: 
+                event_type = g_strdup("CONDUIT"); break;
+        case NOTIFY_REQUEST_COMPLETION: 
+                event_type = g_strdup("REQUEST_COMPLETION"); break;
+        case NOTIFY_REQUEST_TIMEOUT: 
+                event_type = g_strdup("REQUEST_TIMEOUT"); break;
+        case NOTIFY_USERINFO_REQUESTED: 
+                event_type = g_strdup("USERINFO_REQUESTED"); break;
+        case NOTIFY_USERINFO_SENT: 
+                event_type = g_strdup("USERINFO_SENT"); break;
+        default: g_assert_not_reached(); break;
+        }
+        LOG (("notify_off(event_type=%s,callback=%.20s...)",
+              event_type, client_id));
+        g_free (event_type);
+
+        if (on)
+                ret = notify_on (daemon, event, client_id, error);
+        else
+                ret = notify_off (daemon, event, client_id, error);
+
+        g_free (client_id);
         return ret;
 }
 
diff --git a/gpilotd/gpilot-daemon.xml b/gpilotd/gpilot-daemon.xml
index f4f3b47..a67cc71 100644
--- a/gpilotd/gpilot-daemon.xml
+++ b/gpilotd/gpilot-daemon.xml
@@ -469,7 +469,7 @@
     </method>
 
     <method name="EventNotify">
-      <arg name="event_type" direction="in" type="u">
+      <arg name="event" direction="in" type="u">
         <doc:doc>
           <doc:summary>The event type, currently we support following events:
                         0 - NOTIFY_CONNECT,



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