libreport
2.1.3
A tool to inform users about various problems on the running system
|
00001 /* 00002 Copyright (C) 2010 ABRT team 00003 Copyright (C) 2010 RedHat Inc 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 #ifndef LIBREPORT_INTERNAL_ABRT_DBUS_H 00020 #define LIBREPORT_INTERNAL_ABRT_DBUS_H 00021 00022 #include <dbus/dbus.h> 00023 #include "internal_libreport.h" 00024 00025 #ifdef __cplusplus 00026 extern "C" { 00027 #endif 00028 00029 extern DBusConnection* g_dbus_conn; 00030 00031 /* 00032 * Glib integration machinery 00033 */ 00034 00035 /* Hook up to DBus and to glib main loop. 00036 * Usage cases: 00037 * 00038 * - server: 00039 * conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err); 00040 * attach_dbus_conn_to_glib_main_loop(conn, "/some/path", handler_of_calls_to_some_path); 00041 * rc = dbus_bus_request_name(conn, "server.name", DBUS_NAME_FLAG_REPLACE_EXISTING, &err); 00042 * 00043 * - client which does not receive signals (only makes calls and emits signals): 00044 * conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err); 00045 * // needed only if you need to use async dbus calls (not shown below): 00046 * attach_dbus_conn_to_glib_main_loop(conn, NULL, NULL); 00047 * // synchronous method call: 00048 * msg = dbus_message_new_method_call("some.serv", "/path/on/serv", "optional.iface.on.serv", "method_name"); 00049 * reply = dbus_connection_send_with_reply_and_block(conn, msg, timeout, &err); 00050 * // emitting signal: 00051 * msg = dbus_message_new_signal("/path/sig/emitted/from", "iface.sig.emitted.from", "sig_name"); 00052 * // (note: "iface.sig.emitted.from" is not optional for signals!) 00053 * dbus_message_set_destination(msg, "peer"); // optional 00054 * dbus_connection_send(conn, msg, &serial); // &serial can be NULL 00055 * dbus_connection_unref(conn); // if you don't want to *stay* connected 00056 * 00057 * - client which receives and processes signals: 00058 * conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err); 00059 * attach_dbus_conn_to_glib_main_loop(conn, NULL, NULL); 00060 * dbus_connection_add_filter(conn, handle_message, NULL, NULL) 00061 * dbus_bus_add_match(system_conn, "type='signal',...", &err); 00062 * // signal is a dbus message which looks like this: 00063 * // sender=XXX dest=YYY(or null) path=/path/sig/emitted/from interface=iface.sig.emitted.from member=sig_name 00064 * // and handler_for_signals(conn,msg,opaque) will be called by glib 00065 * // main loop to process received signals (and other messages 00066 * // if you ask for them in dbus_bus_add_match[es], but this 00067 * // would turn you into a server if you handle them too) ;] 00068 */ 00069 void attach_dbus_conn_to_glib_main_loop(DBusConnection* conn, 00070 /* NULL if you are just a client */ 00071 const char* object_path_to_register, 00072 /* makes sense only if you use object_path_to_register: */ 00073 DBusHandlerResult (*message_received_func)(DBusConnection *conn, DBusMessage *msg, void* data) 00074 ); 00075 00076 00077 /* 00078 * Helpers for building DBus messages 00079 */ 00080 //void store_bool(DBusMessageIter* iter, bool val); 00081 void store_int32(DBusMessageIter* iter, int32_t val); 00082 void store_uint32(DBusMessageIter* iter, uint32_t val); 00083 void store_int64(DBusMessageIter* iter, int64_t val); 00084 void store_uint64(DBusMessageIter* iter, uint64_t val); 00085 void store_string(DBusMessageIter* iter, const char* val); 00086 00087 /* 00088 * Helpers for parsing DBus messages 00089 */ 00090 enum { 00091 ABRT_DBUS_ERROR = -1, 00092 ABRT_DBUS_LAST_FIELD = 0, 00093 ABRT_DBUS_MORE_FIELDS = 1, 00094 /* note that dbus_message_iter_next() returns FALSE on last field 00095 * and TRUE if there are more fields. 00096 * It maps exactly on the above constants. */ 00097 }; 00098 /* Checks type, loads data, advances to the next arg. 00099 * Returns TRUE if next arg exists. 00100 */ 00101 //int load_bool(DBusMessageIter* iter, bool& val); 00102 int load_int32(DBusMessageIter* iter, int32_t *val); 00103 int load_uint32(DBusMessageIter* iter, uint32_t *val); 00104 int load_int64(DBusMessageIter* iter, int64_t *val); 00105 int load_uint64(DBusMessageIter* iter, uint64_t *val); 00106 int load_charp(DBusMessageIter* iter, const char **val); 00107 00108 #ifdef __cplusplus 00109 } 00110 #endif 00111 00112 #endif