[gnome-pilot/dbus] Move logic from orbit_daemon_glue.c to gpilot-daemon.c



commit adeab11d7d66b37a6af21f3f0922576c3bd0cd14
Author: Halton Huo <halton huo sun com>
Date:   Tue Mar 2 16:45:20 2010 +0800

    Move logic from orbit_daemon_glue.c to gpilot-daemon.c
    
    Done for rest includes:
            gpilot_daemon_get_system_info,
            gpilot_daemon_get_users,
            gpilot_daemon_get_cradles,
            gpilot_daemon_get_pilots,
            gpilot_daemon_get_pilot_ids,
            gpilot_daemon_get_pilots_by_user_name,
            gpilot_daemon_get_pilots_by_user_login,
            gpilot_daemon_get_user_name_by_pilot_name,
            gpilot_daemon_get_user_login_by_pilot_name,
            gpilot_daemon_get_pilot_base_dir,
            gpilot_daemon_get_pilot_id_from_name,
            gpilot_daemon_get_pilot_name_from_id,
            gpilot_daemon_get_databases_from_cache,
            gpilot_daemon_get_user_info,
            gpilot_daemon_set_user_info,
            gpilot_daemon_monitor,
            gpilot_daemon_event_notify

 gpilotd/gpilot-daemon.c   |  619 +++++++++++++++++++++++++++++++++++++++++++--
 gpilotd/gpilot-daemon.h   |   16 +-
 gpilotd/gpilot-daemon.xml |    2 +-
 3 files changed, 605 insertions(+), 32 deletions(-)
---
diff --git a/gpilotd/gpilot-daemon.c b/gpilotd/gpilot-daemon.c
index 55e7031..02421e1 100644
--- a/gpilotd/gpilot-daemon.c
+++ b/gpilotd/gpilot-daemon.c
@@ -22,12 +22,16 @@
 #include "config.h"
 
 #include <unistd.h>
+#include <pwd.h>
 #include <glib.h>
 
 #include "gpilot-daemon.h"
 #include "gpilot-daemon-glue.h"
 #include "gnome-pilot-structures.h"
 #include "queue_io.h"
+#include "gnome-pilot-config.h"
+
+#define DEBUG_CODE
 
 static void     gpilot_daemon_class_init  (GpilotDaemonClass *klass);
 static void     gpilot_daemon_init        (GpilotDaemon      *daemon);
@@ -44,6 +48,21 @@ struct GpilotDaemonPrivate
         GHashTable *monitors;
 };
 
+/** structure that carries a GSList to gchar*  (IORs) for
+    each notification type */
+
+typedef struct {
+        GSList* connect;
+        GSList* disconnect;
+        GSList* request_complete;
+        GSList* request_timeout;
+        GSList* backup;
+        GSList* conduit;
+        GSList* userinfo_requested;
+        GSList* sysinfo_requested;
+        GSList* userinfo_sent;
+} PilotNotifications;
+
 static void
 gpilot_daemon_pause_device (GPilotDevice *device,
                             gpointer      data)
@@ -64,6 +83,15 @@ match_pilot_and_name(const GPilotPilot *pilot,
         return -1; 
 }
 
+static gint
+match_pilot_userID (const GPilotPilot   *p,
+                    const guint32       *id)
+{
+        if(p->pilot_id == *id)
+                return 0;
+        return -1;
+}
+
 static guint32
 pilot_id_from_name (const gchar   *name,
                     GPilotContext *context)
@@ -76,6 +104,21 @@ pilot_id_from_name (const gchar   *name,
         return 0;
 }
 
+static gchar*
+pilot_name_from_id (guint32 id,
+                    GPilotContext *context)
+{
+        GList *pilot;
+        pilot = g_list_find_custom (context->pilots, (gpointer)&id,
+                                   (GCompareFunc)match_pilot_userID);
+
+        if(pilot)
+                return g_strdup (((GPilotPilot*)pilot->data)->name);
+
+        return NULL;
+}
+
+
 GQuark
 gpilot_daemon_error_quark (void)
 {
@@ -236,12 +279,12 @@ gpilot_daemon_request_restore (GpilotDaemon   *daemon,
         GET_AND_CHECK_CLIENT_ID(client_id,cb,0); 
          */
 
-        LOG(("request_restore(pilot_name=%s (%d), directory=%s,survival=%d,timeout=%d)",
-            pilot_name,
-            pilot_id_from_name (pilot_name, priv->gpilotd_context),
-            directory,
-            survival,
-            timeout));
+        LOG (("request_restore(pilot_name=%s (%d), directory=%s,survival=%d,timeout=%d)",
+              pilot_name,
+              pilot_id_from_name (pilot_name, priv->gpilotd_context),
+              directory,
+              survival,
+              timeout));
 
         req.type = GREQ_RESTORE;
         req.pilot_id = pilot_id_from_name (pilot_name, priv->gpilotd_context);
@@ -298,10 +341,10 @@ gpilot_daemon_request_conduit (GpilotDaemon   *daemon,
         GET_AND_CHECK_CLIENT_ID(client_id,cb,0); 
          */
 
-        LOG(("request_conduit(pilot=%s (%d), conduit=%s)",
-            pilot_name,
-            pilot_id_from_name (pilot_name, priv->gpilotd_context),
-            conduit_name));
+        LOG (("request_conduit(pilot=%s (%d), conduit=%s)",
+              pilot_name,
+              pilot_id_from_name (pilot_name, priv->gpilotd_context),
+              conduit_name));
 
         req.pilot_id = pilot_id_from_name (pilot_name, priv->gpilotd_context);
         if(req.pilot_id == 0) {
@@ -368,7 +411,30 @@ gpilot_daemon_get_system_info (GpilotDaemon   *daemon,
                                unsigned long  *handle,
                                GError        **error)
 {
-        return TRUE;
+        GpilotDaemonPrivate *priv;
+        GPilotRequest        req;
+        gchar               *client_id;
+        gboolean             ret;
+        
+        ret = FALSE;
+        priv = daemon->priv;
+
+        /* TODO
+        GET_AND_CHECK_CLIENT_ID(client_id,cb,0); 
+         */
+        LOG (("get_system_info(cradle=%s,survival=%d,timeout=%d)",
+              cradle, survival, timeout));
+
+        req.type = GREQ_GET_SYSINFO;
+        req.pilot_id = 0;
+        req.cradle = g_strdup (cradle);
+        req.client_id = g_strdup (client_id);
+
+        *handle = gpc_queue_store_request (req);
+        ret = TRUE;
+ out:
+        g_free(client_id);
+        return ret;
 }
 
 gboolean
@@ -376,6 +442,15 @@ gpilot_daemon_get_users (GpilotDaemon   *daemon,
                          GPtrArray     **users,
                          GError        **error)
 {
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_users()"));
+
+        if (users == NULL)
+                return FALSE;
+
+        *users = g_ptr_array_new ();
+        g_ptr_array_add (*users, g_strdup (daemon->priv->gpilotd_context->user->username));
         return TRUE;
 }
 
@@ -384,6 +459,25 @@ gpilot_daemon_get_cradles (GpilotDaemon   *daemon,
                            GPtrArray     **cradles,
                            GError        **error)
 {
+        int    i;
+        GList *l;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_cradles()"));
+
+        if (cradles == NULL)
+                return FALSE;
+
+        *cradles = g_ptr_array_new ();
+        l = daemon->priv->gpilotd_context->devices;
+
+        for(i=0; i < g_list_length (l); i++) {
+                GPilotDevice *device = GPILOT_DEVICE (g_list_nth (l, i)->data);
+                g_ptr_array_add (*cradles,
+                                 g_strdup (device->name));
+        }
+
         return TRUE;
 }
 
@@ -392,6 +486,25 @@ gpilot_daemon_get_pilots (GpilotDaemon   *daemon,
                           GPtrArray     **pilots,
                           GError        **error)
 {
+        int    i;
+        GList *l;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_pilot_ids()"));
+
+        if (pilots == NULL)
+                return FALSE;
+
+        *pilots = g_ptr_array_new ();
+        l = daemon->priv->gpilotd_context->pilots;
+
+        for(i=0; i < g_list_length (l); i++) {
+                GPilotPilot *pilot = GPILOT_PILOT (g_list_nth (l, i)->data);
+                g_ptr_array_add (*pilots,
+                                 g_strdup (pilot->name));
+        }
+
         return TRUE;
 }
 
@@ -400,6 +513,25 @@ gpilot_daemon_get_pilot_ids (GpilotDaemon   *daemon,
                              GPtrArray     **pilots,
                              GError        **error)
 {
+        int    i;
+        GList *l;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_pilot_ids()"));
+
+        if (pilots == NULL)
+                return FALSE;
+
+        *pilots = g_ptr_array_new ();
+        l = daemon->priv->gpilotd_context->pilots;
+
+        for(i=0; i < g_list_length (l); i++) {
+                GPilotPilot *pilot = GPILOT_PILOT (g_list_nth (l, i)->data);
+                g_ptr_array_add (*pilots,
+                                 &pilot->pilot_id);
+        }
+
         return TRUE;
 }
 
@@ -409,6 +541,28 @@ gpilot_daemon_get_pilots_by_user_name (GpilotDaemon   *daemon,
                                        GPtrArray     **pilots,
                                        GError        **error)
 {
+        int    i;
+        GList *l;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_pilots_by_user_name(%s)", username));
+
+        if (pilots == NULL)
+                return FALSE;
+
+        *pilots = g_ptr_array_new ();
+        l = daemon->priv->gpilotd_context->pilots;
+
+        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));
+                }
+        }
+
         return TRUE;
 }
 
@@ -418,60 +572,171 @@ gpilot_daemon_get_pilots_by_user_login (GpilotDaemon   *daemon,
                                         GPtrArray     **pilots,
                                         GError        **error)
 {
-        return TRUE;
+        int      i;
+        GList   *l;
+        gchar   *username;
+        gboolean ret;
+        struct passwd *pwdent;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_pilots_by_user_login(%s)", uid));
+
+        /* find the pwdent matching the login */
+        username = NULL;
+        setpwent ();
+        do {
+                pwdent = getpwent ();
+                if (pwdent) {
+                        if(strcmp (pwdent->pw_name,uid) == 0) {
+                                username = strdup (pwdent->pw_gecos);
+                                pwdent = NULL; /* end the loop */
+                        }
+                }
+        } while (pwdent);
+        endpwent();
+
+        /* no luck ? */
+        if(!username) {
+                LOG (("no realname for %s", uid));
+                return TRUE;
+        }
+
+        /* FIXME: uhm, is this use of username safe ? 
+           or should it be CORBA::strdup'ed ? */
+        ret = gpilot_daemon_get_pilots_by_user_name (daemon, username, pilots, error);
+        g_free (username);
+        return ret ;
 }
 
 gboolean
 gpilot_daemon_get_user_name_by_pilot_name (GpilotDaemon   *daemon,
-                                           const char     *pilot_id,
+                                           const char     *pilot_name,
                                            char          **username,
                                            GError        **error)
 {
+        LOG (("FIXME %s:%d get_user_name_by_pilot_name", __FILE__, __LINE__));
+
+        /* FIXME: not implemented yet */
         return TRUE;
 }
 
 gboolean
 gpilot_daemon_get_user_login_by_pilot_name (GpilotDaemon   *daemon,
-                                            const char     *pilot_id,
+                                            const char     *pilot_name,
                                             char          **uid,
                                             GError        **error)
 {
+        LOG (("FIXME %s:%d get_user_login_by_pilot_name", __FILE__, __LINE__));
+
+        /* FIXME: not implemented yet */
         return TRUE;
 }
 
 gboolean
 gpilot_daemon_get_pilot_base_dir (GpilotDaemon   *daemon,
-                                  const char     *pilot_id,
+                                  const char     *pilot_name,
                                   char          **base_dir,
                                   GError        **error)
 {
+        int    i;
+        GList *l;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_pilot_base_dir()"));
+
+        if (base_dir == NULL)
+                return FALSE;
+
+        l = daemon->priv->gpilotd_context->pilots;
+
+        for(i=0; i < g_list_length (l); i++) {
+                GPilotPilot *pilot = GPILOT_PILOT (g_list_nth (l, i)->data);
+                if( g_str_equal (pilot->name, pilot_name)) {
+                        LOG(("match on %s", pilot->name));
+                        *base_dir = g_strdup (pilot->sync_options.basedir);
+                }
+        }
+
         return TRUE;
 }
 
 gboolean
 gpilot_daemon_get_pilot_id_from_name (GpilotDaemon   *daemon,
                                       const char     *pilot_name,
-                                      char          **pilot_id,
+                                      guint          *pilot_id,
                                       GError        **error)
 {
+        LOG(("get_user_pilot_id_from_name"));
+
+        *pilot_id = pilot_id_from_name (pilot_name,
+                                        daemon->priv->gpilotd_context);
+
         return TRUE;
 }
 
 gboolean
 gpilot_daemon_get_pilot_name_from_id (GpilotDaemon   *daemon,
-                                      const char     *pilot_id,
+                                      guint           pilot_id,
                                       char          **pilot_name,
                                       GError        **error)
 {
+        gchar *tmp;
+        LOG(("corba: get_pilot_name_from_id(id=%d)",pilot_name));
+                                       
+        *pilot_name = pilot_name_from_id (pilot_id,
+                                          daemon->priv->gpilotd_context);
         return TRUE;
 }
 
 gboolean
 gpilot_daemon_get_databases_from_cache (GpilotDaemon   *daemon,
-                                        const char     *pilot_id,
+                                        const char     *pilot_name,
                                         GPtrArray     **databases,
                                         GError        **error)
 {
+        int       i;
+        GList    *l;
+        gboolean  ret;
+        guint32   pilot_id;
+        GKeyFile *kfile;
+        gsize     num_bases;
+        char    **arr;
+
+        g_return_val_if_fail (GPILOT_IS_DAEMON (daemon), FALSE);
+        
+        LOG (("get_databases_from_cache(...)"));
+
+        ret = FALSE;
+        if (databases == NULL)
+                return FALSE;
+
+        *databases = g_ptr_array_new ();
+
+        pilot_id = pilot_id_from_name (pilot_name,
+                                       daemon->priv->gpilotd_context);
+
+        if (pilot_id == 0) {
+                g_set_error (error,
+                             GPILOT_DAEMON_ERROR,
+                             GPILOT_DAEMON_ERROR_GENERAL,
+                             "Unknow pilot %s",
+                             pilot_name);
+                goto out;
+        }
+
+        kfile = get_pilot_cache_kfile (pilot_id);
+        arr = g_key_file_get_string_list (kfile, "Databases",
+                                          "databases", &num_bases, NULL);
+        for (i=0; i<num_bases; i++) {
+                g_ptr_array_add (*databases,
+                                 g_strdup (arr[i]));
+        }
+
+        ret = TRUE;
+ out:
+        g_strfreev (arr);
         return TRUE;
 }
 
@@ -484,7 +749,30 @@ gpilot_daemon_get_user_info (GpilotDaemon   *daemon,
                              unsigned long  *handle,
                              GError        **error)
 {
-        return TRUE;
+        GpilotDaemonPrivate *priv;
+        GPilotRequest        req;
+        gchar               *client_id;
+        gboolean             ret;
+        
+        ret = FALSE;
+        priv = daemon->priv;
+
+        /* TODO
+        GET_AND_CHECK_CLIENT_ID(client_id,cb,0); 
+         */
+        LOG (("get_user_info(cradle=%s,survival=%d,timeout=%d)",
+             cradle, survival, timeout));
+
+        req.type = GREQ_GET_USERINFO;
+        req.pilot_id = 0;
+        req.cradle = g_strdup (cradle);
+        req.client_id = g_strdup (client_id);
+
+        *handle = gpc_queue_store_request (req);
+        ret = TRUE;
+ out:
+        g_free(client_id);
+        return ret;
 }
 
 gboolean
@@ -498,17 +786,288 @@ gpilot_daemon_set_user_info (GpilotDaemon   *daemon,
                              unsigned long  *handle,
                              GError        **error)
 {
-        return TRUE;
+        GpilotDaemonPrivate *priv;
+        GPilotRequest        req;
+        gchar               *client_id;
+        gboolean             ret;
+        
+        ret = FALSE;
+        priv = daemon->priv;
+
+        /* TODO
+        GET_AND_CHECK_CLIENT_ID(client_id,cb,0); 
+         */
+        LOG (("set_user_info(cradle=%s,survival=%d,timeout=%d",
+            cradle,survival,timeout));
+        LOG (("              device = %s,", cradle));
+        LOG (("              user_id = %d,", uid));
+        LOG (("              user    = %s)", username));
+
+        *handle = gpc_queue_store_set_userinfo_request (
+                        survival==PERSISTENT?0:timeout, 
+                        cradle,
+                        client_id,
+                        username,
+                        uid,
+                        continue_sync);
+        ret = TRUE;
+ out:
+        g_free(client_id);
+        return ret;
 }
 
 /* Notification operations */
+static gboolean
+monitor_on (GpilotDaemon   *daemon,
+            const char     *pilot_name,
+            GError         **error)
+{
+        GpilotDaemonPrivate *priv;
+        gchar               *client_id;
+        gboolean             ret;
+        GSList             **pilots;
+        GSList              *element;
+        
+        ret = FALSE;
+        priv = daemon->priv;
+
+        /* TODO
+        GET_AND_CHECK_CLIENT_ID(client_id,cb,0); 
+         */
+        LOG (("monitor_on(pilot_name=\"%s\",client_id = %.20s...)",
+              pilot_name, client_id));       
+                
+        if ((pilots = g_hash_table_lookup (priv->monitors, client_id)) == NULL) {
+                pilots = g_new0 (GSList*, 1);
+                *pilots = g_slist_prepend (*pilots, g_strdup (pilot_name));
+                g_hash_table_insert (priv->monitors, g_strdup (client_id), pilots);
+        } else {
+                element = g_slist_find_custom (*pilots, (gchar*)pilot_name,
+                                              (GCompareFunc)strcmp);
+                *pilots = g_slist_prepend (*pilots, g_strdup(pilot_name));
+        }
+        ret = TRUE;
+ out:
+        g_free(client_id);
+        return ret;
+}
+ 
+/* used by monitor_off_helper to remove callback IORs from a GSList* */
+static void 
+monitor_off_remover (GSList      **list,
+		     const gchar  *client_id) 
+{
+	GSList *element;
+
+	/* No, these will often be called with NULL pointers, so don't change these
+	   to g_return..., too much output */
+	if (list == NULL) return;
+	if (*list == NULL) return;
+	g_assert (client_id != NULL);
+
+	element = g_slist_find_custom (*list, (gpointer)client_id,
+                                       (GCompareFunc)strcmp);
+	if (element) {
+		g_free (element->data);
+		*list = g_slist_remove (*list, element->data); 
+	}
+
+	if (g_slist_length (*list) == 0) {
+		g_slist_free (*list);
+		*list = NULL;
+	} 
+}
+
+/* used by monitor_off to erase callback IORs from the 
+   PilotNotifications object for the given pilot_id */
+static void 
+monitor_off_helper_2 (GpilotDaemon *daemon,
+                      const gchar  *pilot,
+		      const gchar  *client_id) 
+{
+        GpilotDaemonPrivate *priv;
+	PilotNotifications  *notifications;
+
+        g_return_if_fail (GPILOT_IS_DAEMON (daemon));
+	g_return_if_fail (pilot != NULL);
+	g_return_if_fail (client_id != NULL);
+
+        priv = daemon->priv;
+
+	LOG (("removing monitor on %s for %.10s", pilot, client_id));
+	notifications = g_hash_table_lookup (priv->notifications, pilot);
+	if (notifications == NULL)
+                return;
+
+	monitor_off_remover (&notifications->connect, client_id);
+	monitor_off_remover (&notifications->disconnect, client_id);
+	monitor_off_remover (&notifications->backup, client_id);
+	monitor_off_remover (&notifications->conduit, client_id);
+	monitor_off_remover (&notifications->request_complete, client_id);
+	monitor_off_remover (&notifications->request_timeout, client_id);
+	monitor_off_remover (&notifications->userinfo_requested, client_id);
+	monitor_off_remover (&notifications->sysinfo_requested, client_id);
+	monitor_off_remover (&notifications->userinfo_sent, client_id);
+
+	if(notifications->connect == NULL &&
+	   notifications->disconnect == NULL &&
+	   notifications->backup == NULL &&
+	   notifications->conduit == NULL &&
+	   notifications->request_complete == NULL &&
+	   notifications->request_timeout == NULL &&
+	   notifications->userinfo_requested == NULL &&
+	   notifications->sysinfo_requested == NULL &&
+	   notifications->userinfo_sent == NULL) {
+		gpointer key,elem;
+ 
+		key = NULL; elem = NULL;
+		g_hash_table_lookup_extended (priv->notifications, pilot, 
+                                              &key, &elem);
+		g_hash_table_remove (priv->notifications, key);
+		g_free (key);
+		g_free(elem);
+	}
+}
+
+#ifdef DEBUG_CODE
+static void
+debug_monitors (gchar    *key,
+                GSList  **value,
+                gpointer  data)
+{
+        GpilotDaemon        *daemon;
+        GpilotDaemonPrivate *priv;
+	GSList *e;
+	PilotNotifications *nots;
+
+        daemon = GPILOT_DAEMON (data);
+        priv = daemon->priv;
+
+	for (e = *value; e; e = g_slist_next (e)) {
+		g_print ("%s is monitoring %s", key, (char*)e->data);
+		nots = g_hash_table_lookup (priv->notifications, e->data);
+		if (nots == NULL)
+			g_print (" - no notifications");
+		else {
+			g_print (" - ");
+			if (nots->connect) g_print("connect,");
+			if (nots->disconnect) g_print("disconnect,");
+		}
+		g_print("\n");
+	}
+}
+#endif
+
+static void 
+monitor_off_helper (GpilotDaemon *daemon,
+                    const gchar  *pilot,
+		    const gchar  *client_id) 
+{
+        GpilotDaemonPrivate *priv;
+	GSList **pilots;
+
+        priv = daemon->priv;
+
+	if((pilots = g_hash_table_lookup (priv->monitors, client_id)) != NULL) {
+		GSList *element;
+		if((element = g_slist_find_custom(*pilots,
+						  (gpointer)pilot,
+						  (GCompareFunc)strcmp))!=NULL) {
+			/* random nuking in the notification lists */
+			monitor_off_helper_2 (daemon, pilot, client_id);
+
+			/* nuke pilot from list */
+			g_free (element->data);
+			*pilots = g_slist_remove (*pilots, element->data);
+			
+			/* if pilots is empty now, nuke fom priv->monitors */
+			if(g_slist_length (*pilots) == 0) {
+				gpointer key;
+				gpointer elem;
+				
+				key = NULL; elem = NULL;
+				g_hash_table_lookup_extended (priv->monitors,
+							      client_id,
+							      &key,
+							      &elem);
+				g_hash_table_remove (priv->monitors, (gchar *)key);
+				g_free ((gchar *)key);
+				g_slist_free (*(GSList **)elem);
+				g_free ((GSList **)elem); 
+			} 
+		} else {
+			GSList *e;
+			/* This really shouldn't happen, dump list for debug purposes */
+			LOG (("Could not find any link for %s",pilot));
+			for(e=*pilots; e; e = g_slist_next (e)) {
+				LOG(("pilots slist dump: %s",
+				    e->data==NULL?"(null)":(char*)e->data));
+			}			
+		}
+		
+	} else {
+		LOG (("couldn't find any monitor for %.10s",client_id));
+	}
+
+#ifdef DEBUG_CODE
+        g_print ("\n");
+        g_hash_table_foreach (priv->monitors,
+                             (GHFunc)debug_monitors, daemon);
+#endif
+}
+
+static gboolean
+monitor_off (GpilotDaemon   *daemon,
+             const char     *pilot_name,
+             GError         **error)
+{
+        GpilotDaemonPrivate *priv;
+        gchar               *client_id;
+        gboolean             ret;
+        
+        ret = FALSE;
+        priv = daemon->priv;
+
+        /* TODO
+        GET_AND_CHECK_CLIENT_ID(client_id,cb,0); 
+         */
+        LOG (("monitor_off(pilot_name=\"%.10s\",client_id = %.20s...)",
+              pilot_name, client_id));       
+                
+        monitor_off_helper (daemon, pilot_name, client_id);
+        ret = TRUE;
+ out:
+        g_free(client_id);
+        return ret;
+}
+
 gboolean
 gpilot_daemon_monitor (GpilotDaemon   *daemon,
-                       const char     *pilot_id,
+                       const char     *pilot_name,
                        gboolean        on,
                        GError        **error)
 {
-        return TRUE;
+        gboolean ret;
+        GpilotDaemonPrivate *priv;
+
+        ret = FALSE;
+        priv = daemon->priv;
+
+        if (pilot_id_from_name (pilot_name, priv->gpilotd_context) == 0) {
+                g_set_error (error,
+                             GPILOT_DAEMON_ERROR,
+                             GPILOT_DAEMON_ERROR_GENERAL,
+                             "Unknow pilot %s",
+                             pilot_name);
+                goto out;
+        }
+
+        if (on)
+                ret = monitor_on (daemon, pilot_name, error);
+        else
+                ret = monitor_off (daemon, pilot_name, error);
+ out:
+        return ret;
 }
 
 gboolean
@@ -517,7 +1076,21 @@ gpilot_daemon_event_notify (GpilotDaemon   *daemon,
                             gboolean        on,
                             GError        **error)
 {
-        return TRUE;
+        GpilotDaemonPrivate *priv;
+        GPilotRequest        req;
+        gchar               *client_id;
+        gboolean             ret;
+        
+        ret = FALSE;
+        priv = daemon->priv;
+
+        /* TODO
+        GET_AND_CHECK_CLIENT_ID(client_id,cb,0); 
+         */
+        ret = TRUE;
+ out:
+        g_free(client_id);
+        return ret;
 }
 
 static void
diff --git a/gpilotd/gpilot-daemon.h b/gpilotd/gpilot-daemon.h
index 2b8f11e..8bcfb47 100644
--- a/gpilotd/gpilot-daemon.h
+++ b/gpilotd/gpilot-daemon.h
@@ -47,7 +47,7 @@ typedef struct
 {
         GObjectClass   parent_class;
         void          (* connected)     (GpilotDaemon   *gpilot,
-                                         const char     *pilot_id,
+                                         const char     *pilot_name,
                                          unsigned long  *uid,
                                          const char     *user);
 } GpilotDaemonClass;
@@ -166,32 +166,32 @@ gboolean        gpilot_daemon_get_pilots_by_user_login
                                                  GError        **error);
 gboolean        gpilot_daemon_get_user_name_by_pilot_name
                                                 (GpilotDaemon   *daemon,
-                                                 const char     *pilot_id,
+                                                 const char     *pilot_name,
                                                  char          **username,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_user_login_by_pilot_name
                                                 (GpilotDaemon   *daemon,
-                                                 const char     *pilot_id,
+                                                 const char     *pilot_name,
                                                  char          **uid,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_pilot_base_dir
                                                 (GpilotDaemon   *daemon,
-                                                 const char     *pilot_id,
+                                                 const char     *pilot_name,
                                                  char          **base_dir,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_pilot_id_from_name
                                                 (GpilotDaemon   *daemon,
                                                  const char     *pilot_name,
-                                                 char          **pilot_id,
+                                                 guint          *pilot_id,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_pilot_name_from_id
                                                 (GpilotDaemon   *daemon,
-                                                 const char     *pilot_id,
+                                                 guint           pilot_id,
                                                  char          **pilot_name,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_databases_from_cache
                                                 (GpilotDaemon   *daemon,
-                                                 const char     *pilot_id,
+                                                 const char     *pilot_name,
                                                  GPtrArray     **databases,
                                                  GError        **error);
 /* admin operations */
@@ -212,7 +212,7 @@ gboolean        gpilot_daemon_set_user_info     (GpilotDaemon   *daemon,
                                                  GError        **error);
 /* Notification operations */
 gboolean        gpilot_daemon_monitor           (GpilotDaemon   *daemon,
-                                                 const char     *pilot_id,
+                                                 const char     *pilot_name,
                                                  gboolean        on,
                                                  GError        **error);
 gboolean        gpilot_daemon_event_notify      (GpilotDaemon   *daemon,
diff --git a/gpilotd/gpilot-daemon.xml b/gpilotd/gpilot-daemon.xml
index 4d1399a..f4f3b47 100644
--- a/gpilotd/gpilot-daemon.xml
+++ b/gpilotd/gpilot-daemon.xml
@@ -308,7 +308,7 @@
     </method>
 
     <method name="GetPilotBaseDir">
-      <arg name="pilot_id" direction="in" type="s">
+      <arg name="pilot_name" direction="in" type="s">
         <doc:doc>
           <doc:summary>The pilot name.</doc:summary>
         </doc:doc>



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