1
/*******************************************************************************
2
**3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
3
** 10 20 30 40 50 60 70 80
7
** dbus.c - dbus boiler-plate code for talking with libnotify
9
** Copyright 2009 Canonical Ltd.
12
** Mirco "MacSlow" Mueller <mirco.mueller@canonical.com>
13
** David Barth <david.barth@canonical.com>
15
** This program is free software: you can redistribute it and/or modify it
16
** under the terms of the GNU General Public License version 3, as published
17
** by the Free Software Foundation.
19
** This program is distributed in the hope that it will be useful, but
20
** WITHOUT ANY WARRANTY; without even the implied warranties of
21
** MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
22
** PURPOSE. See the GNU General Public License for more details.
24
** You should have received a copy of the GNU General Public License along
25
** with this program. If not, see <http://www.gnu.org/licenses/>.
27
*******************************************************************************/
31
#include <dbus/dbus.h>
32
#include <dbus/dbus-glib.h>
33
#include <dbus/dbus-glib-bindings.h>
34
#include <dbus/dbus-glib-lowlevel.h>
38
static DBusGConnection* connection = NULL;
41
dbus_get_connection (void)
43
/* usefull mostly for unit tests */
44
if (connection == NULL)
45
connection = dbus_create_service_instance (DBUS_NAME);
51
dbus_create_service_instance (const char *service_name)
53
DBusGProxy* proxy = NULL;
54
guint request_name_result;
58
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
61
g_warning ("dbus_create_service_instance(): "
68
proxy = dbus_g_proxy_new_for_name (connection,
69
"org.freedesktop.DBus",
70
"/org/freedesktop/Dbus",
71
"org.freedesktop.DBus");
73
if (!dbus_g_proxy_call (proxy,
76
G_TYPE_STRING, service_name,
79
G_TYPE_UINT, &request_name_result,
82
g_warning ("dbus_create_service_instance(): "
89
if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
91
g_warning ("Another instance has already registered %s", service_name);
100
dbus_send_close_signal (gchar *dest,
106
msg = dbus_message_new_signal ("/org/freedesktop/Notifications",
107
"org.freedesktop.Notifications",
108
"NotificationClosed");
109
dbus_message_set_destination (msg, dest);
110
dbus_message_append_args (msg, DBUS_TYPE_UINT32, &id,
112
dbus_message_append_args (msg, DBUS_TYPE_UINT32, &reason,
115
dbus_connection_send (dbus_g_connection_get_connection (connection),
119
dbus_message_unref (msg);
123
dbus_send_action_signal (gchar *dest,
125
const char *action_key)
129
msg = dbus_message_new_signal ("/org/freedesktop/Notifications",
130
"org.freedesktop.Notifications",
132
dbus_message_set_destination (msg, dest);
133
dbus_message_append_args (msg, DBUS_TYPE_UINT32, &id,
135
dbus_message_append_args (msg, DBUS_TYPE_STRING, &action_key,
138
dbus_connection_send (dbus_g_connection_get_connection (connection),
142
dbus_message_unref (msg);