531.1.2
by Rodrigo Moya
Added SyncdaemonEventsInterface class |
1 |
/*
|
2 |
* Syncdaemon API
|
|
3 |
*
|
|
4 |
* Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
|
|
5 |
*
|
|
6 |
* Copyright 2010 Canonical Ltd.
|
|
7 |
*
|
|
8 |
* This program is free software: you can redistribute it and/or modify it
|
|
9 |
* under the terms of the GNU General Public License version 3, as published
|
|
10 |
* by the Free Software Foundation.
|
|
11 |
*
|
|
12 |
* This program is distributed in the hope that it will be useful, but
|
|
13 |
* WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
14 |
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
|
|
15 |
* PURPOSE. See the GNU General Public License for more details.
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License along
|
|
18 |
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19 |
*
|
|
20 |
*/
|
|
21 |
||
22 |
#include "config.h" |
|
23 |
#ifdef HAVE_GDBUS
|
|
24 |
#else
|
|
25 |
#include <dbus/dbus-glib.h> |
|
26 |
#endif
|
|
27 |
#include "syncdaemon-events-interface.h" |
|
28 |
||
29 |
G_DEFINE_TYPE(SyncdaemonEventsInterface, syncdaemon_events_interface, SYNCDAEMON_TYPE_INTERFACE) |
|
30 |
||
31 |
struct _SyncdaemonEventsInterfacePrivate { |
|
32 |
GObject *proxy; |
|
33 |
};
|
|
34 |
||
35 |
static void |
|
36 |
syncdaemon_events_interface_finalize (GObject *object) |
|
37 |
{
|
|
38 |
SyncdaemonEventsInterface *interface = SYNCDAEMON_EVENTS_INTERFACE (object); |
|
39 |
||
40 |
if (interface->priv != NULL) { |
|
41 |
g_free (interface->priv); |
|
42 |
}
|
|
43 |
||
44 |
G_OBJECT_CLASS (syncdaemon_events_interface_parent_class)->finalize (object); |
|
45 |
}
|
|
46 |
||
47 |
static void |
|
48 |
syncdaemon_events_interface_class_init (SyncdaemonEventsInterfaceClass *klass) |
|
49 |
{
|
|
50 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
|
51 |
||
52 |
object_class->finalize = syncdaemon_events_interface_finalize; |
|
53 |
}
|
|
54 |
||
55 |
static void |
|
56 |
event_cb (DBusGProxy *proxy, GHashTable *event_dict, gpointer user_data) |
|
57 |
{
|
|
58 |
SyncdaemonDaemon *daemon = NULL; |
|
59 |
SyncdaemonEventsInterface *interface = SYNCDAEMON_EVENTS_INTERFACE (user_data); |
|
60 |
||
61 |
g_object_get (G_OBJECT (interface), "daemon", &daemon, NULL); |
|
62 |
if (daemon != NULL) |
|
63 |
g_signal_emit_by_name (daemon, "event", event_dict); |
|
64 |
}
|
|
65 |
||
66 |
static void |
|
67 |
syncdaemon_events_interface_init (SyncdaemonEventsInterface *interface) |
|
68 |
{
|
|
69 |
interface->priv = g_new0 (SyncdaemonEventsInterfacePrivate, 1); |
|
70 |
||
71 |
/* Setup DBus proxy */
|
|
72 |
interface->priv->proxy = syncdaemon_interface_setup_proxy (SYNCDAEMON_INTERFACE (interface), |
|
534.1.3
by Rodrigo Moya
Fixed typos in DBus service names |
73 |
"com.ubuntuone.SyncDaemon", |
74 |
"/events", "com.ubuntuone.SyncDaemon.Events"); |
|
531.1.2
by Rodrigo Moya
Added SyncdaemonEventsInterface class |
75 |
if (interface->priv->proxy != NULL) { |
76 |
dbus_g_proxy_add_signal (DBUS_G_PROXY (interface->priv->proxy), "Event", |
|
77 |
dbus_g_type_get_map ("GHashTable", |
|
78 |
G_TYPE_STRING, |
|
79 |
G_TYPE_STRING), |
|
80 |
G_TYPE_INVALID); |
|
81 |
dbus_g_proxy_connect_signal (DBUS_G_PROXY (interface->priv->proxy), "Event", |
|
82 |
G_CALLBACK (event_cb), interface, NULL); |
|
83 |
}
|
|
84 |
}
|
|
85 |
||
86 |
/**
|
|
87 |
* syncdaemon_events_interface_new:
|
|
88 |
*/
|
|
89 |
SyncdaemonEventsInterface * |
|
90 |
syncdaemon_events_interface_new (SyncdaemonDaemon *daemon) |
|
91 |
{
|
|
92 |
g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL); |
|
93 |
||
94 |
return g_object_new (SYNCDAEMON_TYPE_EVENTS_INTERFACE, "daemon", daemon, NULL); |
|
95 |
}
|
|
96 |
||
97 |
/**
|
|
98 |
* syncdaemon_events_interface_push_event:
|
|
99 |
*/
|
|
100 |
void
|
|
101 |
syncdaemon_events_interface_push_event (SyncdaemonEventsInterface *interface, |
|
102 |
const gchar *event_name, |
|
103 |
const gchar **args) |
|
104 |
{
|
|
105 |
GError *error = NULL; |
|
106 |
||
107 |
g_return_if_fail (SYNCDAEMON_IS_EVENTS_INTERFACE (interface)); |
|
108 |
||
109 |
if (!dbus_g_proxy_call (DBUS_G_PROXY (interface->priv->proxy), "push_event", &error, |
|
110 |
G_TYPE_STRING, event_name, |
|
111 |
G_TYPE_STRV, args, |
|
531.1.4
by Rodrigo Moya
Added SyncdaemonFoldersInterface class |
112 |
G_TYPE_INVALID, |
531.1.2
by Rodrigo Moya
Added SyncdaemonEventsInterface class |
113 |
G_TYPE_INVALID)) { |
531.1.3
by Rodrigo Moya
Added SyncdaemonFilesystemInterface class |
114 |
g_warning ("Failed calling push_event: %s", error->message); |
115 |
g_error_free (error); |
|
531.1.2
by Rodrigo Moya
Added SyncdaemonEventsInterface class |
116 |
}
|
117 |
}
|