[gnome-pilot/dbus] Implement dbus signals calls:
- From: Halton Huo <haltonhuo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-pilot/dbus] Implement dbus signals calls:
- Date: Wed, 17 Mar 2010 12:28:46 +0000 (UTC)
commit 389a32b367fa2c2ed7687ab6bafe9e06627f7fcb
Author: Halton Huo <halton huo sun com>
Date: Wed Mar 17 19:34:30 2010 +0800
Implement dbus signals calls:
ConduitStart
ConduitEnd
ConduitProgress
OverallProgress
Rewirte gpilotd_client to monitor all pilots signals with argument -m
Tested with
gpilotd_client -m --conduit=Test
gpilotd/gnome-pilot-client.gob | 106 ++++++++++++++++++++++++++++++------
gpilotd/gpilot-daemon.c | 116 ++++++++++++++++++++++++++++++++++++----
gpilotd/gpilot-daemon.h | 8 ++--
utils/gpilotd-client.c | 71 +++++++++++++++---------
4 files changed, 242 insertions(+), 59 deletions(-)
---
diff --git a/gpilotd/gnome-pilot-client.gob b/gpilotd/gnome-pilot-client.gob
index e12c6a8..6188ae6 100644
--- a/gpilotd/gnome-pilot-client.gob
+++ b/gpilotd/gnome-pilot-client.gob
@@ -127,6 +127,11 @@ class Gnome:Pilot:Client from Gtk:Object {
G_TYPE_STRING,
G_TYPE_UINT,
G_TYPE_INVALID);
+ dbus_g_proxy_add_signal (self->proxy,
+ "RequestCompleted",
+ G_TYPE_STRING,
+ G_TYPE_UINT,
+ G_TYPE_INVALID);
dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_UINT_STRING,
G_TYPE_NONE,
G_TYPE_STRING,
@@ -134,20 +139,57 @@ class Gnome:Pilot:Client from Gtk:Object {
G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (self->proxy,
- "RequestCompleted",
+ "Connected",
G_TYPE_STRING,
G_TYPE_UINT,
+ G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (self->proxy,
- "Connected",
+ "Disconnected",
+ G_TYPE_STRING,
+ G_TYPE_INVALID);
+ dbus_g_proxy_add_signal (self->proxy,
+ "ConduitStart",
+ G_TYPE_STRING,
G_TYPE_STRING,
- G_TYPE_UINT,
G_TYPE_STRING,
G_TYPE_INVALID);
+ dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_STRING,
+ G_TYPE_NONE,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_INVALID);
dbus_g_proxy_add_signal (self->proxy,
- "Disconnected",
+ "ConduitEnd",
+ G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_INVALID);
+ dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_STRING_UINT_UINT,
+ G_TYPE_NONE,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_UINT,
+ G_TYPE_UINT,
+ G_TYPE_INVALID);
+ dbus_g_proxy_add_signal (self->proxy,
+ "ConduitProgress",
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_UINT,
+ G_TYPE_UINT,
+ G_TYPE_INVALID);
+ dbus_g_object_register_marshaller (gp_marshal_VOID__STRING_UINT_UINT,
+ G_TYPE_NONE,
+ G_TYPE_STRING,
+ G_TYPE_UINT,
+ G_TYPE_UINT,
+ G_TYPE_INVALID);
+ dbus_g_proxy_add_signal (self->proxy,
+ "OverallProgress",
+ G_TYPE_STRING,
+ G_TYPE_UINT,
+ G_TYPE_UINT,
+ G_TYPE_INVALID);
dbus_g_proxy_connect_signal (self->proxy,
"RequestCompleted",
@@ -164,6 +206,26 @@ class Gnome:Pilot:Client from Gtk:Object {
G_CALLBACK (self_dbus_disconnect),
self,
NULL);
+ dbus_g_proxy_connect_signal (self->proxy,
+ "ConduitStart",
+ G_CALLBACK (self_dbus_conduit_start),
+ self,
+ NULL);
+ dbus_g_proxy_connect_signal (self->proxy,
+ "ConduitEnd",
+ G_CALLBACK (self_dbus_conduit_end),
+ self,
+ NULL);
+ dbus_g_proxy_connect_signal (self->proxy,
+ "ConduitProgress",
+ G_CALLBACK (self_dbus_conduit_progress),
+ self,
+ NULL);
+ dbus_g_proxy_connect_signal (self->proxy,
+ "OverallProgress",
+ G_CALLBACK (self_dbus_overall_progress),
+ self,
+ NULL);
return GPILOTD_OK;
}
@@ -255,35 +317,43 @@ class Gnome:Pilot:Client from Gtk:Object {
}
private void
- dbus_conduit_start (self,
+ dbus_conduit_start (DBusGProxy *proxy,
const gchar *pilot_id,
const gchar *conduit_name,
- const gchar *database) {
- self_start_conduit (self,pilot_id,conduit_name,database);
+ const gchar *database,
+ gpointer data) {
+ Self *self = SELF(data);
+ self_start_conduit (self, pilot_id, conduit_name, database);
}
private void
- dbus_conduit_end (self,
+ dbus_conduit_end (DBusGProxy *proxy,
const gchar *pilot_id,
- const gchar *conduit_name) {
- self_end_conduit (self,pilot_id,conduit_name);
+ const gchar *conduit_name,
+ gpointer data) {
+ Self *self = SELF(data);
+ self_end_conduit (self, pilot_id, conduit_name);
}
-
+
private void
- dbus_overall_progress (self,
- const gchar *pilot_id,
- const unsigned long current,
- const unsigned long total) {
+ dbus_overall_progress (DBusGProxy *proxy,
+ const gchar *pilot_id,
+ const unsigned long current,
+ const unsigned long total,
+ gpointer data) {
+ Self *self = SELF(data);
self_progress_overall (self,pilot_id, current, total);
}
private void
- dbus_conduit_progress (self,
+ dbus_conduit_progress (DBusGProxy *proxy,
const gchar *pilot_id,
const gchar *conduit_name,
const unsigned long current,
- const unsigned long total) {
- self_progress_conduit (self,pilot_id,conduit_name,current,total);
+ const unsigned long total,
+ gpointer data) {
+ Self *self = SELF(data);
+ self_progress_conduit (self, pilot_id, conduit_name, current, total);
}
private void
diff --git a/gpilotd/gpilot-daemon.c b/gpilotd/gpilot-daemon.c
index add5f95..db0f466 100644
--- a/gpilotd/gpilot-daemon.c
+++ b/gpilotd/gpilot-daemon.c
@@ -46,6 +46,7 @@
#include "gpilot-daemon.h"
#include "gpilot-daemon-glue.h"
#include "gnome-pilot-structures.h"
+#include "gnome-pilot-conduit-standard.h"
#include "queue_io.h"
#include "gnome-pilot-config.h"
#include "gpmarshal.h"
@@ -2141,8 +2142,6 @@ gpilot_daemon_get_pilots_by_user_login (GpilotDaemon *daemon,
char ***pilots,
GError **error)
{
- int i;
- GList *l;
gchar *username;
gboolean ret;
struct passwd *pwdent;
@@ -2272,7 +2271,6 @@ gpilot_daemon_get_pilot_name_from_id (GpilotDaemon *daemon,
char **pilot_name,
GError **error)
{
- gchar *tmp;
LOG(("get_pilot_name_from_id(id=%d)", pilot_id));
*pilot_name = pilot_name_from_id (pilot_id,
@@ -2294,7 +2292,6 @@ gpilot_daemon_get_databases_from_cache (GpilotDaemon *daemon,
GError **error)
{
int i;
- GList *l;
gboolean ret;
guint32 pilot_id;
GKeyFile *kfile;
@@ -2394,7 +2391,6 @@ gpilot_daemon_set_user_info (GpilotDaemon *daemon,
GError **error)
{
GpilotDaemonPrivate *priv;
- GPilotRequest req;
gboolean ret;
ret = FALSE;
@@ -2483,7 +2479,10 @@ dbus_notify_completion (GPilotRequest **req)
g_return_if_fail(req!=NULL);
g_return_if_fail(*req!=NULL);
- pilot_name = g_strdup ((*req)->cradle);
+ if ((*req)->cradle)
+ pilot_name = g_strdup ((*req)->cradle);
+ else
+ pilot_name = g_strdup ("");
message = dbus_message_new_signal (GP_DBUS_PATH,
GP_DBUS_INTERFACE,
@@ -2582,12 +2581,65 @@ dbus_notify_conduit_start (const gchar *pilot_id,
GnomePilotConduit *conduit,
GnomePilotConduitSyncType type)
{
+ DBusMessage *message;
+ DBusConnection *connection;
+ DBusMessageIter iter;
+ gchar *name;
+ gchar *database;
+
+ name = gnome_pilot_conduit_get_name (conduit);
+ if(GNOME_IS_PILOT_CONDUIT_STANDARD(conduit))
+ database = g_strdup (gnome_pilot_conduit_standard_get_db_name(GNOME_PILOT_CONDUIT_STANDARD(conduit)));
+ else
+ database = g_strdup (_("(unknown DB)"));
+
+ message = dbus_message_new_signal (GP_DBUS_PATH,
+ GP_DBUS_INTERFACE,
+ "ConduitStart");
+
+ 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_STRING, &name);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &database);
+
+ 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);
+ g_free (database);
}
void
dbus_notify_conduit_end (const gchar *pilot_id,
GnomePilotConduit *conduit)
{
+ DBusMessage *message;
+ DBusConnection *connection;
+ DBusMessageIter iter;
+ gchar *name;
+
+ name = gnome_pilot_conduit_get_name (conduit);
+
+ message = dbus_message_new_signal (GP_DBUS_PATH,
+ GP_DBUS_INTERFACE,
+ "ConduitEnd");
+
+ 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_STRING, &name);
+
+ 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
@@ -2607,16 +2659,60 @@ dbus_notify_conduit_message (const gchar *pilot_id,
void
dbus_notify_conduit_progress (const gchar *pilot_id,
GnomePilotConduit *conduit,
- gint current,
- gint total)
+ guint32 current,
+ guint32 total)
{
+ DBusMessage *message;
+ DBusConnection *connection;
+ DBusMessageIter iter;
+ gchar *name;
+
+ name = gnome_pilot_conduit_get_name (conduit);
+
+ message = dbus_message_new_signal (GP_DBUS_PATH,
+ GP_DBUS_INTERFACE,
+ "ConduitProgress");
+
+ 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_STRING, &name);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, ¤t);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &total);
+
+ 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_overall_progress (const gchar *pilot_id,
- gint current,
- gint total)
+ guint32 current,
+ guint32 total)
{
+ DBusMessage *message;
+ DBusConnection *connection;
+ DBusMessageIter iter;
+
+ message = dbus_message_new_signal (GP_DBUS_PATH,
+ GP_DBUS_INTERFACE,
+ "OverallProgress");
+
+ 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, ¤t);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &total);
+
+ connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+ dbus_connection_send (connection, message, NULL);
+ dbus_connection_unref (connection);
+ dbus_message_unref (message);
}
void
diff --git a/gpilotd/gpilot-daemon.h b/gpilotd/gpilot-daemon.h
index 4b333de..358cd03 100644
--- a/gpilotd/gpilot-daemon.h
+++ b/gpilotd/gpilot-daemon.h
@@ -297,11 +297,11 @@ void dbus_notify_conduit_message (const gchar *pilot_id,
const gchar *message);
void dbus_notify_conduit_progress (const gchar *pilot_id,
GnomePilotConduit *conduit,
- gint current,
- gint total);
+ guint32 current,
+ guint32 total);
void dbus_notify_overall_progress (const gchar *pilot_id,
- gint current,
- gint total);
+ guint32 current,
+ guint32 total);
void dbus_notify_daemon_message (const gchar *pilot_id,
GnomePilotConduit *conduit,
const gchar *message);
diff --git a/utils/gpilotd-client.c b/utils/gpilotd-client.c
index bf4b22c..c3e2c16 100644
--- a/utils/gpilotd-client.c
+++ b/utils/gpilotd-client.c
@@ -22,7 +22,6 @@ int arg_pause=0,
arg_listbases = 0,
arg_listusers = 0,
arg_listcradles = 0,
- arg_monitorall=0,
arg_monitor,
arg_getinfo = 0;
char
@@ -49,8 +48,7 @@ static GOptionEntry options[] = {
{"restore", '\0', 0, G_OPTION_ARG_STRING, &arg_restore, N_("Restore directory"), N_("DIRECTORY")},
{"conduit", '\0', 0, G_OPTION_ARG_STRING, &arg_conduit, N_("Run conduit"), N_("CONDUIT")},
{"userid", '\0', 0, G_OPTION_ARG_STRING, &arg_username, N_("Username to set"), N_("USERNAME")},
- {"monitor", 'm', 0, G_OPTION_ARG_NONE, &arg_monitor, N_("Monitor the specified PDA's actions"), NULL},
- {"monitorall", 'A', 0, G_OPTION_ARG_NONE, &arg_monitorall, N_("Monitor all PDAs"), NULL},
+ {"monitor", 'm', 0, G_OPTION_ARG_NONE, &arg_monitor, N_("Monitor all PDAs"), NULL},
{"listpilots", '\0', 0, G_OPTION_ARG_STRING, &arg_list_by_login, N_("list PDAs by login (all for all pilots)"), N_("LOGIN")},
{"pilot", '\0', 0, G_OPTION_ARG_STRING, &arg_pilot, N_("Specify PDA to operate on (defaults to MyPDA)"), N_("PILOTNAME")},
{"cradle", '\0', 0, G_OPTION_ARG_STRING, &arg_cradle, N_("Specify a cradle to operate on (defaults to Cradle0)"), N_("CRADLENAME")},
@@ -78,6 +76,42 @@ pilot_disconnect (GnomePilotClient *gpc,
};
static void
+start_conduit (GnomePilotClient *gpc,
+ const gchar *pilot_id,
+ const gchar *conduit,
+ const gchar *database,
+ gpointer data) {
+ g_message ("start_conduit: pilot_id=%s, conduit=%s, database=%s", pilot_id, conduit, database);
+};
+
+static void
+end_conduit (GnomePilotClient *gpc,
+ const gchar *pilot_id,
+ const gchar *conduit,
+ gpointer data) {
+ g_message ("end_conduit: pilot_id=%s, conduit=%s", pilot_id, conduit);
+};
+
+static void
+progress_conduit (GnomePilotClient *gpc,
+ const gchar *pilot_id,
+ const gchar *conduit,
+ guint32 current,
+ guint32 total,
+ gpointer data) {
+ g_message ("progress_conduit: pilot_id=%s, conduit=%s, current=%u, total=%u", pilot_id, conduit, current, total);
+};
+
+static void
+progress_overall (GnomePilotClient *gpc,
+ const gchar *pilot_id,
+ guint32 current,
+ guint32 total,
+ gpointer data) {
+ g_message ("progress_overall: pilot_id=%s, current=%u, total=%u", pilot_id, current, total);
+};
+
+static void
pilot_request_completed (GnomePilotClient *gpc, gchar *pilot_id, gint handle, gpointer data) {
GList *iterator;
gint outstanding_request = 0;
@@ -422,7 +456,7 @@ main (int argc, char *argv[]) {
revive (NULL);
} else if (arg_restore!=NULL) {
restore (arg_restore);
- } else if (arg_conduit!=NULL) {
+ } else if (arg_conduit!=NULL && !arg_monitor) {
conduit (arg_conduit);
} else if (arg_setuser) {
set_user ();
@@ -436,35 +470,18 @@ main (int argc, char *argv[]) {
list_by_login ();
} else if (arg_monitor) {
g_message ("Monitor on %s",arg_pilot);
- /*TODO turn on notify with dbus
- gnome_pilot_client_monitor_on (gpc,arg_pilot);
- gnome_pilot_client_notify_on (gpc,GNOME_Pilot_NOTIFY_CONNECT);
- gnome_pilot_client_notify_on (gpc,GNOME_Pilot_NOTIFY_DISCONNECT);
- */
gnome_pilot_client_connect__pilot_connect (gpc, pilot_connect, NULL);
gnome_pilot_client_connect__pilot_disconnect (gpc, pilot_disconnect, &stay_alive);
+ if (arg_conduit) {
+ gnome_pilot_client_connect__start_conduit (gpc, start_conduit, NULL);
+ gnome_pilot_client_connect__end_conduit (gpc, end_conduit, NULL);
+ gnome_pilot_client_connect__progress_conduit (gpc, progress_conduit, NULL);
+ gnome_pilot_client_connect__progress_overall (gpc, progress_overall, NULL);
+ }
the_loop ();
- /*TODO turn off notify with dbus
- gnome_pilot_client_notify_off (gpc,GNOME_Pilot_NOTIFY_CONNECT);
- gnome_pilot_client_notify_off (gpc,GNOME_Pilot_NOTIFY_DISCONNECT);
- gnome_pilot_client_monitor_off (gpc,arg_pilot);
- */
- } else if (arg_monitorall) {
- g_message ("Monitor on all");
- /*TODO turn on notify with dbus
- gnome_pilot_client_monitor_on_all_pilots (gpc);
- */
-
- gnome_pilot_client_connect__pilot_connect (gpc, pilot_connect, NULL);
- gnome_pilot_client_connect__pilot_disconnect (gpc, pilot_disconnect, &stay_alive);
-
- the_loop ();
- /*TODO turn on notify with dbus
- gnome_pilot_client_monitor_off_all_pilots (gpc);
- */
} else if (arg_getinfo) {
g_message ("Get SystemInfo");
get_system_info ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]