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



commit eb1c49ff2d17f232d0cdfd67f585da887f7fde70
Author: Halton Huo <halton huo sun com>
Date:   Mon Mar 1 17:53:37 2010 +0800

    Move logic from orbit_daemon_glue.c to gpilot-daemon.c
    
    Done for gpilot_daemon_pause(),
             gpilot_daemon_reread_config() and
             gpilot_daemon_noop()

 .gitignore                |    1 +
 gpilotd/Makefile.am       |    2 +-
 gpilotd/gpilot-daemon.c   |  132 +++++++++++++++++++++++++++++++++++----------
 gpilotd/gpilot-daemon.h   |   88 ++++++++++++++++++------------
 gpilotd/gpilot-daemon.xml |    2 +-
 gpilotd/gpilotd.c         |    1 +
 6 files changed, 162 insertions(+), 64 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index fbc2da7..b60e21b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -91,3 +91,4 @@ utils/gpilotd-client
 utils/gpilotdcm-client
 po/*.gmo
 cscope*
+*.swp
diff --git a/gpilotd/Makefile.am b/gpilotd/Makefile.am
index 868e048..ff8be43 100644
--- a/gpilotd/Makefile.am
+++ b/gpilotd/Makefile.am
@@ -107,7 +107,7 @@ DBUS_SRCLIST = 		\
 BUILT_SOURCES = $(DBUS_SRCLIST) $(GOB_BUILT_SRCS) gpmarshal.c gpmarshal.h
 
 gpilot-daemon-glue.h: gpilot-daemon.xml Makefile.am
-	dbus-binding-tool --prefix=gdm_daemon --mode=glib-server --output=gpilot-daemon-glue.h $(srcdir)/gpilot-daemon.xml
+	dbus-binding-tool --prefix=gpilot_daemon --mode=glib-server --output=gpilot-daemon-glue.h $(srcdir)/gpilot-daemon.xml
 
 CLEANFILES = $(DBUS_SRCLIST) $(service_DATA)
 MAINTAINERCLEANFILES = $(GOB_BUILT_SRCS)
diff --git a/gpilotd/gpilot-daemon.c b/gpilotd/gpilot-daemon.c
index 94b152c..bd3f0b8 100644
--- a/gpilotd/gpilot-daemon.c
+++ b/gpilotd/gpilot-daemon.c
@@ -21,43 +21,86 @@
 
 #include "config.h"
 
+#include <unistd.h>
+#include <glib.h>
+
 #include "gpilot-daemon.h"
 #include "gpilot-daemon-glue.h"
+#include "gnome-pilot-structures.h"
 
 static void     gpilot_daemon_class_init  (GpilotDaemonClass *klass);
-static void     gpilot_daemon_init        (GpilotDaemon      *display);
-static void     gpilot_daemon_finalize    (GObject         *object);
+static void     gpilot_daemon_init        (GpilotDaemon      *daemon);
+static void     gpilot_daemon_finalize    (GObject           *object);
 
-G_DEFINE_ABSTRACT_TYPE (GpilotDaemon, gpilot_daemon, G_TYPE_OBJECT)
+G_DEFINE_TYPE (GpilotDaemon, gpilot_daemon, G_TYPE_OBJECT)
 
 struct GpilotDaemonPrivate
 {
+        GPilotContext *gpilotd_context;
+        /* maps from a pilot name GPilotd_Orb_Pilot_Notifications* */
+        GHashTable *notifications;
+        /* maps from a client_id to GSList** of pilotnames begin monitored */
+        GHashTable *monitors;
+};
+
+static void
+gpilot_daemon_pause_device (GPilotDevice *device,
+                            gpointer      data)
+{
+        if (device->io) {
+                g_source_remove(device->in_handle);
+                g_source_remove(device->err_handle);
+        }
 }
 
 gboolean
-gpilot_daemon_pause (gboolean        on,
+gpilot_daemon_pause (GpilotDaemon   *daemon,
+                     gboolean        on_off,
                      GError        **error)
 {
+        GpilotDaemonPrivate *priv;
+        if (priv->gpilotd_context->paused == on_off)
+                return TRUE;
+
+        priv->gpilotd_context->paused = on_off;
+
+        /* TODO
+        g_hash_table_foreach (priv->monitors,
+                              (GHFunc)gpilotd_corba_pause_notify_monitor,
+                              &on_off);
+        */
+
+        if (priv->gpilotd_context->paused) {
+                g_list_foreach (priv->gpilotd_context->devices,
+                                (GFunc)gpilot_daemon_pause_device,
+                                NULL);
+        } else {
+                kill (getpid (), SIGHUP);
+        }
+
         return TRUE;
 }
 
 gboolean
-gpilot_daemon_reread_config (GError        **error)
+gpilot_daemon_reread_config (GpilotDaemon   *daemon,
+                             GError        **error)
 {
+        kill(getpid (), SIGHUP);
         return TRUE;
 }
 
 /* A no-operation call, used by client to occasionally
    check to see if the daemon has blown up */
 gboolean
-gpilot_daemon_noop ()
+gpilot_daemon_noop (GpilotDaemon   *daemon)
 {
         return TRUE;
 }
 
 /* request operations */
 gboolean
-gpilot_daemon_request_install (const char     *pilot_id,
+gpilot_daemon_request_install (GpilotDaemon   *daemon,
+                               const char     *pilot_id,
                                const char     *file_name,
                                const char     *description,
                                Survival        survival,
@@ -69,7 +112,8 @@ gpilot_daemon_request_install (const char     *pilot_id,
 }
 
 gboolean
-gpilot_daemon_request_restore (const char     *pilot_id,
+gpilot_daemon_request_restore (GpilotDaemon   *daemon,
+                               const char     *pilot_id,
                                const char     *directory,
                                Survival        survival,
                                unsigned long   timeout,
@@ -80,7 +124,8 @@ gpilot_daemon_request_restore (const char     *pilot_id,
 }
 
 gboolean
-gpilot_daemon_request_conduit (const char     *pilot_id,
+gpilot_daemon_request_conduit (GpilotDaemon   *daemon,
+                               const char     *pilot_id,
                                const char     *conduit_name,
                                ConduitOperation operation,
                                Survival        survival,
@@ -92,7 +137,8 @@ gpilot_daemon_request_conduit (const char     *pilot_id,
 }
 
 gboolean
-gpilot_daemon_remove_request (unsigned long  *handler,
+gpilot_daemon_remove_request (GpilotDaemon   *daemon,
+                              unsigned long  *handler,
                               GError        **error)
 {
         return TRUE;
@@ -101,7 +147,8 @@ gpilot_daemon_remove_request (unsigned long  *handler,
 
 /* information operations */
 gboolean
-gpilot_daemon_get_system_info (const char     *cradle,
+gpilot_daemon_get_system_info (GpilotDaemon   *daemon,
+                               const char     *cradle,
                                Survival        survival,
                                unsigned long   timeout,
                                unsigned long  *handler,
@@ -111,35 +158,40 @@ gpilot_daemon_get_system_info (const char     *cradle,
 }
 
 gboolean
-gpilot_daemon_get_users (GPtrArray     **users,
+gpilot_daemon_get_users (GpilotDaemon   *daemon,
+                         GPtrArray     **users,
                          GError        **error)
 {
         return TRUE;
 }
 
 gboolean
-gpilot_daemon_get_cradles (GPtrArray     **cradles,
+gpilot_daemon_get_cradles (GpilotDaemon   *daemon,
+                           GPtrArray     **cradles,
                            GError        **error)
 {
         return TRUE;
 }
 
 gboolean
-gpilot_daemon_get_pilots (GPtrArray     **pilots,
+gpilot_daemon_get_pilots (GpilotDaemon   *daemon,
+                          GPtrArray     **pilots,
                           GError        **error)
 {
         return TRUE;
 }
 
 gboolean
-gpilot_daemon_get_pilot_ids (GPtrArray     **pilots,
+gpilot_daemon_get_pilot_ids (GpilotDaemon   *daemon,
+                             GPtrArray     **pilots,
                              GError        **error)
 {
         return TRUE;
 }
 
 gboolean
-gpilot_daemon_get_pilots_by_user_name (const char     *username,
+gpilot_daemon_get_pilots_by_user_name (GpilotDaemon   *daemon,
+                                       const char     *username,
                                        GPtrArray     **pilots,
                                        GError        **error)
 {
@@ -147,7 +199,8 @@ gpilot_daemon_get_pilots_by_user_name (const char     *username,
 }
 
 gboolean
-gpilot_daemon_get_pilots_by_user_login (const char     *uid,
+gpilot_daemon_get_pilots_by_user_login (GpilotDaemon   *daemon,
+                                        const char     *uid,
                                         GPtrArray     **pilots,
                                         GError        **error)
 {
@@ -155,7 +208,8 @@ gpilot_daemon_get_pilots_by_user_login (const char     *uid,
 }
 
 gboolean
-gpilot_daemon_get_user_name_by_pilot_name (const char     *pilot_id,
+gpilot_daemon_get_user_name_by_pilot_name (GpilotDaemon   *daemon,
+                                           const char     *pilot_id,
                                            char          **username,
                                            GError        **error)
 {
@@ -163,7 +217,8 @@ gpilot_daemon_get_user_name_by_pilot_name (const char     *pilot_id,
 }
 
 gboolean
-gpilot_daemon_get_user_login_by_pilot_name (const char     *pilot_id,
+gpilot_daemon_get_user_login_by_pilot_name (GpilotDaemon   *daemon,
+                                            const char     *pilot_id,
                                             char          **uid,
                                             GError        **error)
 {
@@ -171,7 +226,8 @@ gpilot_daemon_get_user_login_by_pilot_name (const char     *pilot_id,
 }
 
 gboolean
-gpilot_daemon_get_pilot_base_dir (const char     *pilot_id,
+gpilot_daemon_get_pilot_base_dir (GpilotDaemon   *daemon,
+                                  const char     *pilot_id,
                                   char          **base_dir,
                                   GError        **error)
 {
@@ -179,7 +235,8 @@ gpilot_daemon_get_pilot_base_dir (const char     *pilot_id,
 }
 
 gboolean
-gpilot_daemon_get_pilot_id_from_name (const char     *pilot_name,
+gpilot_daemon_get_pilot_id_from_name (GpilotDaemon   *daemon,
+                                      const char     *pilot_name,
                                       char          **pilot_id,
                                       GError        **error)
 {
@@ -187,7 +244,8 @@ gpilot_daemon_get_pilot_id_from_name (const char     *pilot_name,
 }
 
 gboolean
-gpilot_daemon_get_pilot_name_from_id (const char     *pilot_id,
+gpilot_daemon_get_pilot_name_from_id (GpilotDaemon   *daemon,
+                                      const char     *pilot_id,
                                       char          **pilot_name,
                                       GError        **error)
 {
@@ -195,7 +253,8 @@ gpilot_daemon_get_pilot_name_from_id (const char     *pilot_id,
 }
 
 gboolean
-gpilot_daemon_get_databases_from_cache (const char     *pilot_id,
+gpilot_daemon_get_databases_from_cache (GpilotDaemon   *daemon,
+                                        const char     *pilot_id,
                                         GPtrArray     **databases,
                                         GError        **error)
 {
@@ -204,7 +263,8 @@ gpilot_daemon_get_databases_from_cache (const char     *pilot_id,
 
 /* admin operations */
 gboolean
-gpilot_daemon_get_user_info (const char     *cradle,
+gpilot_daemon_get_user_info (GpilotDaemon   *daemon,
+                             const char     *cradle,
                              Survival        survival,
                              unsigned long   timeout,
                              unsigned long  *handler,
@@ -214,7 +274,8 @@ gpilot_daemon_get_user_info (const char     *cradle,
 }
 
 gboolean
-gpilot_daemon_set_user_info (const char     *cradle,
+gpilot_daemon_set_user_info (GpilotDaemon   *daemon,
+                             const char     *cradle,
                              gboolean        continue_sync,
                              Survival        survival,
                              unsigned long   timeout,
@@ -228,7 +289,8 @@ gpilot_daemon_set_user_info (const char     *cradle,
 
 /* Notification operations */
 gboolean
-gpilot_daemon_monitor (const char     *pilot_id,
+gpilot_daemon_monitor (GpilotDaemon   *daemon,
+                       const char     *pilot_id,
                        gboolean        on,
                        GError        **error)
 {
@@ -236,7 +298,8 @@ gpilot_daemon_monitor (const char     *pilot_id,
 }
 
 gboolean
-gpilot_daemon_event_nofify (EventType       event_type,
+gpilot_daemon_event_notify (GpilotDaemon   *daemon,
+                            EventType       event_type,
                             gboolean        on,
                             GError        **error)
 {
@@ -248,12 +311,16 @@ gpilot_daemon_class_init (GpilotDaemonClass *klass)
 {
         GObjectClass   *object_class = G_OBJECT_CLASS (klass);
 
-        object_class->finalize = gdm_display_finalize;
+        object_class->finalize = gpilot_daemon_finalize;
 }
 
 static void
 gpilot_daemon_init (GpilotDaemon *daemon)
 {
+        daemon->priv->monitors = g_hash_table_new (g_str_hash,g_str_equal);
+        daemon->priv->notifications = g_hash_table_new (g_str_hash,g_str_equal);
+        daemon->priv->gpilotd_context = gpilot_context_new ();
+        gpilot_context_init_user (daemon->priv->gpilotd_context);
 }
 
 static void
@@ -262,3 +329,12 @@ gpilot_daemon_finalize (GObject *object)
         G_OBJECT_CLASS (gpilot_daemon_parent_class)->finalize (object);
 }
 
+GpilotDaemon*
+gpilot_daemon_new ()
+{
+        GObject *object;
+
+        object = g_object_new (GPILOT_TYPE_DAEMON, NULL);
+
+        return GPILOT_DAEMON (object);
+}
diff --git a/gpilotd/gpilot-daemon.h b/gpilotd/gpilot-daemon.h
index ff22fb9..a37cf8e 100644
--- a/gpilotd/gpilot-daemon.h
+++ b/gpilotd/gpilot-daemon.h
@@ -27,12 +27,12 @@
 
 G_BEGIN_DECLS
 
-#define GPILOT_TYPE_DISPLAY         (gpilotd_daemon_get_type ())
-#define GPILOT_DAEMON(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GPILOT_TYPE_DISPLAY, GpilotDaemon))
-#define GPILOT_DAEMON_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GPILOT_TYPE_DISPLAY, GpilotDaemonClass))
-#define GDM_IS_DISPLAY(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPILOT_TYPE_DISPLAY))
-#define GDM_IS_DISPLAY_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GPILOT_TYPE_DISPLAY))
-#define GPILOT_DAEMON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPILOT_TYPE_DISPLAY, GpilotDaemonClass))
+#define GPILOT_TYPE_DAEMON         (gpilot_daemon_get_type ())
+#define GPILOT_DAEMON(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GPILOT_TYPE_DAEMON, GpilotDaemon))
+#define GPILOT_DAEMON_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GPILOT_TYPE_DAEMON, GpilotDaemonClass))
+#define GPILOT_IS_DAEMON(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPILOT_TYPE_DAEMON))
+#define GPILOT_IS_DAEMON_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GPILOT_TYPE_DAEMON))
+#define GPILOT_DAEMON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPILOT_TYPE_DAEMON, GpilotDaemonClass))
 
 typedef enum
 {
@@ -80,95 +80,115 @@ typedef struct
 } GpilotDaemonClass;
 
 GType           gpilot_daemon_get_type          (void);
+GpilotDaemon*   gpilot_daemon_new               ();
 
 /* exported to bus */
 
 /* adm calls */
-gboolean        gpilot_daemon_pause             (gboolean        on,
+gboolean        gpilot_daemon_pause             (GpilotDaemon   *daemon,
+                                                 gboolean        on_off,
+                                                 GError        **error);
+gboolean        gpilot_daemon_reread_config     (GpilotDaemon   *daemon,
                                                  GError        **error);
-gboolean        gpilot_daemon_reread_config     (GError        **error);
 
 /* A no-operation call, used by client to occasionally
    check to see if the daemon has blown up */
-gboolean        gpilot_daemon_noop              ();
-
+gboolean        gpilot_daemon_noop              (GpilotDaemon   *daemon);
 /* request operations */
-gboolean        gpilot_daemon_request_install   (const char     *pilot_id,
+gboolean        gpilot_daemon_request_install   (GpilotDaemon   *daemon,
+                                                 const char     *pilot_id,
                                                  const char     *file_name,
                                                  const char     *description,
                                                  Survival        survival,
                                                  unsigned long   timeout,
                                                  unsigned long  *handler,
                                                  GError        **error);
-gboolean        gpilot_daemon_request_restore   (const char     *pilot_id,
+gboolean        gpilot_daemon_request_restore   (GpilotDaemon   *daemon,
+                                                 const char     *pilot_id,
                                                  const char     *directory,
                                                  Survival        survival,
                                                  unsigned long   timeout,
                                                  unsigned long  *handler,
                                                  GError        **error);
-gboolean        gpilot_daemon_request_conduit   (const char     *pilot_id,
+gboolean        gpilot_daemon_request_conduit   (GpilotDaemon   *daemon,
+                                                 const char     *pilot_id,
                                                  const char     *conduit_name,
                                                  ConduitOperation operation,
                                                  Survival        survival,
                                                  unsigned long   timeout,
                                                  unsigned long  *handler,
                                                  GError        **error);
-gboolean        gpilot_daemon_remove_request    (unsigned long  *handler,
+gboolean        gpilot_daemon_remove_request    (GpilotDaemon   *daemon,
+                                                 unsigned long  *handler,
                                                  GError        **error);
-
 /* information operations */
-gboolean        gpilot_daemon_get_system_info   (const char     *cradle,
+gboolean        gpilot_daemon_get_system_info   (GpilotDaemon   *daemon,
+                                                 const char     *cradle,
                                                  Survival        survival,
                                                  unsigned long   timeout,
                                                  unsigned long  *handler,
                                                  GError        **error);
-gboolean        gpilot_daemon_get_users         (GPtrArray     **users,
+gboolean        gpilot_daemon_get_users         (GpilotDaemon   *daemon,
+                                                 GPtrArray     **users,
                                                  GError        **error);
-gboolean        gpilot_daemon_get_cradles       (GPtrArray     **cradles,
+gboolean        gpilot_daemon_get_cradles       (GpilotDaemon   *daemon,
+                                                 GPtrArray     **cradles,
                                                  GError        **error);
-gboolean        gpilot_daemon_get_pilots        (GPtrArray     **pilots,
+gboolean        gpilot_daemon_get_pilots        (GpilotDaemon   *daemon,
+                                                 GPtrArray     **pilots,
                                                  GError        **error);
-gboolean        gpilot_daemon_get_pilot_ids     (GPtrArray     **pilots,
+gboolean        gpilot_daemon_get_pilot_ids     (GpilotDaemon   *daemon,
+                                                 GPtrArray     **pilots,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_pilots_by_user_name
-                                                (const char     *username,
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *username,
                                                  GPtrArray     **pilots,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_pilots_by_user_login
-                                                (const char     *uid,
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *uid,
                                                  GPtrArray     **pilots,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_user_name_by_pilot_name
-                                                (const char     *pilot_id,
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *pilot_id,
                                                  char          **username,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_user_login_by_pilot_name
-                                                (const char     *pilot_id,
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *pilot_id,
                                                  char          **uid,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_pilot_base_dir
-                                                (const char     *pilot_id,
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *pilot_id,
                                                  char          **base_dir,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_pilot_id_from_name
-                                                (const char     *pilot_name,
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *pilot_name,
                                                  char          **pilot_id,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_pilot_name_from_id
-                                                (const char     *pilot_id,
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *pilot_id,
                                                  char          **pilot_name,
                                                  GError        **error);
 gboolean        gpilot_daemon_get_databases_from_cache
-                                                (const char     *pilot_id,
+                                                (GpilotDaemon   *daemon,
+                                                 const char     *pilot_id,
                                                  GPtrArray     **databases,
                                                  GError        **error);
 /* admin operations */
-gboolean        gpilot_daemon_get_user_info     (const char     *cradle,
+gboolean        gpilot_daemon_get_user_info     (GpilotDaemon   *daemon,
+                                                 const char     *cradle,
                                                  Survival        survival,
                                                  unsigned long   timeout,
                                                  unsigned long  *handler,
                                                  GError        **error);
-gboolean        gpilot_daemon_set_user_info     (const char     *cradle,
+gboolean        gpilot_daemon_set_user_info     (GpilotDaemon   *daemon,
+                                                 const char     *cradle,
                                                  gboolean        continue_sync,
                                                  Survival        survival,
                                                  unsigned long   timeout,
@@ -177,14 +197,14 @@ gboolean        gpilot_daemon_set_user_info     (const char     *cradle,
                                                  unsigned long  *handler,
                                                  GError        **error);
 /* Notification operations */
-gboolean        gpilot_daemon_monitor           (const char     *pilot_id,
+gboolean        gpilot_daemon_monitor           (GpilotDaemon   *daemon,
+                                                 const char     *pilot_id,
                                                  gboolean        on,
                                                  GError        **error);
-gboolean        gpilot_daemon_event_nofify      (EventType       event_type,
+gboolean        gpilot_daemon_event_notify      (GpilotDaemon   *daemon,
+                                                 EventType       event_type,
                                                  gboolean        on,
                                                  GError        **error);
-
-
 G_END_DECLS
 
 #endif /* __GPILOT_DAEMON_H */
diff --git a/gpilotd/gpilot-daemon.xml b/gpilotd/gpilot-daemon.xml
index 40ada13..160f3a9 100644
--- a/gpilotd/gpilot-daemon.xml
+++ b/gpilotd/gpilot-daemon.xml
@@ -2,7 +2,7 @@
 <node>
   <interface name="org.gnome.GnomePilot.Daemon">
     <method name="Pause">
-      <arg name="on" direction="in" type="b"/>
+      <arg name="on_off" direction="in" type="b"/>
       <doc:doc>
         <doc:description>
           <doc:para>This method initiates a request to pause or continue the daemon.</doc:para>
diff --git a/gpilotd/gpilotd.c b/gpilotd/gpilotd.c
index efbe90f..81f5472 100644
--- a/gpilotd/gpilotd.c
+++ b/gpilotd/gpilotd.c
@@ -74,6 +74,7 @@
 #include "manager.h"
 #include "gnome-pilot-structures.h"
 #include "gpilot-daemon.h"
+#include "queue_io.h"
 #include "gpilot-gui.h"
 #include "gnome-pilot-conduit-backup.h"
 #include "gnome-pilot-config.h"



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