1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains D-Bus helpers
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <dbus/dbus.h>
29 #include <dbus/dbus-glib.h>
30 #include <dbus/dbus-glib-lowlevel.h>
32 #include "dbus_helpers.h"
33 #include "../dbus/helpers.h"
38 dbus_error_init(&g_dbus_error
);
41 g_dbus_connection
= dbus_bus_get(DBUS_BUS_SESSION
, &g_dbus_error
);
42 if (dbus_error_is_set(&g_dbus_error
))
44 //error_msg("dbus_bus_get() failed");
45 //error_msg(g_dbus_error.message);
46 dbus_error_free(&g_dbus_error
);
49 dbus_connection_setup_with_g_main(g_dbus_connection
, NULL
);
53 patchage_dbus_call_valist(
54 bool response_expected
,
59 DBusMessage
** reply_ptr_ptr
,
63 DBusMessage
* request_ptr
;
64 DBusMessage
* reply_ptr
;
66 request_ptr
= dbus_message_new_method_call(
73 //throw std::runtime_error("dbus_message_new_method_call() returned 0");
76 dbus_message_append_args_valist(request_ptr
, in_type
, ap
);
78 // send message and get a handle for a reply
79 reply_ptr
= dbus_connection_send_with_reply_and_block(
82 DBUS_CALL_DEFAULT_TIMEOUT
,
85 dbus_message_unref(request_ptr
);
89 if (response_expected
)
91 //error_msg("no reply from server when calling method '%s', error is '%s'", method, _error.message);
93 dbus_error_free(&g_dbus_error
);
97 *reply_ptr_ptr
= reply_ptr
;
105 bool response_expected
,
106 const char * service
,
110 DBusMessage
** reply_ptr_ptr
,
117 va_start(ap
, in_type
);
119 ret
= patchage_dbus_call_valist(
135 patchage_dbus_add_match(
138 dbus_bus_add_match(g_dbus_connection
, rule
, NULL
);
142 patchage_dbus_add_filter(
143 DBusHandleMessageFunction function
,
146 dbus_connection_add_filter(g_dbus_connection
, function
, user_data
, NULL
);
150 patchage_dbus_uninit()
152 if (g_dbus_connection
)
154 dbus_connection_flush(g_dbus_connection
);
157 if (dbus_error_is_set(&g_dbus_error
))
159 dbus_error_free(&g_dbus_error
);