libreport  2.9.5
A tool to inform users about various problems on the running system
internal_abrt_dbus.h
1 /*
2  Copyright (C) 2010 ABRT team
3  Copyright (C) 2010 RedHat Inc
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 #ifndef LIBREPORT_INTERNAL_ABRT_DBUS_H
20 #define LIBREPORT_INTERNAL_ABRT_DBUS_H
21 
22 #include <dbus/dbus.h>
23 #include "internal_libreport.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 extern DBusConnection* g_dbus_conn;
30 
31 /*
32  * Glib integration machinery
33  */
34 
35 /* Hook up to DBus and to glib main loop.
36  * Usage cases:
37  *
38  * - server:
39  * conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err);
40  * attach_dbus_conn_to_glib_main_loop(conn, "/some/path", handler_of_calls_to_some_path);
41  * rc = dbus_bus_request_name(conn, "server.name", DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
42  *
43  * - client which does not receive signals (only makes calls and emits signals):
44  * conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err);
45  * // needed only if you need to use async dbus calls (not shown below):
46  * attach_dbus_conn_to_glib_main_loop(conn, NULL, NULL);
47  * // synchronous method call:
48  * msg = dbus_message_new_method_call("some.serv", "/path/on/serv", "optional.iface.on.serv", "method_name");
49  * reply = dbus_connection_send_with_reply_and_block(conn, msg, timeout, &err);
50  * // emitting signal:
51  * msg = dbus_message_new_signal("/path/sig/emitted/from", "iface.sig.emitted.from", "sig_name");
52  * // (note: "iface.sig.emitted.from" is not optional for signals!)
53  * dbus_message_set_destination(msg, "peer"); // optional
54  * dbus_connection_send(conn, msg, &serial); // &serial can be NULL
55  * dbus_connection_unref(conn); // if you don't want to *stay* connected
56  *
57  * - client which receives and processes signals:
58  * conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err);
59  * attach_dbus_conn_to_glib_main_loop(conn, NULL, NULL);
60  * dbus_connection_add_filter(conn, handle_message, NULL, NULL)
61  * dbus_bus_add_match(system_conn, "type='signal',...", &err);
62  * // signal is a dbus message which looks like this:
63  * // sender=XXX dest=YYY(or null) path=/path/sig/emitted/from interface=iface.sig.emitted.from member=sig_name
64  * // and handler_for_signals(conn,msg,opaque) will be called by glib
65  * // main loop to process received signals (and other messages
66  * // if you ask for them in dbus_bus_add_match[es], but this
67  * // would turn you into a server if you handle them too) ;]
68  */
69 void attach_dbus_conn_to_glib_main_loop(DBusConnection* conn,
70  /* NULL if you are just a client */
71  const char* object_path_to_register,
72  /* makes sense only if you use object_path_to_register: */
73  DBusHandlerResult (*message_received_func)(DBusConnection *conn, DBusMessage *msg, void* data)
74 );
75 
76 
77 /*
78  * Helpers for building DBus messages
79  */
80 //void store_bool(DBusMessageIter* iter, bool val);
81 void store_int32(DBusMessageIter* iter, int32_t val);
82 void store_uint32(DBusMessageIter* iter, uint32_t val);
83 void store_int64(DBusMessageIter* iter, int64_t val);
84 void store_uint64(DBusMessageIter* iter, uint64_t val);
85 void store_string(DBusMessageIter* iter, const char* val);
86 
87 /*
88  * Helpers for parsing DBus messages
89  */
90 enum {
91  ABRT_DBUS_ERROR = -1,
92  ABRT_DBUS_LAST_FIELD = 0,
93  ABRT_DBUS_MORE_FIELDS = 1,
94  /* note that dbus_message_iter_next() returns FALSE on last field
95  * and TRUE if there are more fields.
96  * It maps exactly on the above constants. */
97 };
98 /* Checks type, loads data, advances to the next arg.
99  * Returns TRUE if next arg exists.
100  */
101 //int load_bool(DBusMessageIter* iter, bool& val);
102 int load_int32(DBusMessageIter* iter, int32_t *val);
103 int load_uint32(DBusMessageIter* iter, uint32_t *val);
104 int load_int64(DBusMessageIter* iter, int64_t *val);
105 int load_uint64(DBusMessageIter* iter, uint64_t *val);
106 int load_charp(DBusMessageIter* iter, const char **val);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif