|
Packit |
4f15d5 |
/*
|
|
Packit |
4f15d5 |
Copyright (C) 2010 ABRT team
|
|
Packit |
4f15d5 |
Copyright (C) 2010 RedHat Inc
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
This program is free software; you can redistribute it and/or modify
|
|
Packit |
4f15d5 |
it under the terms of the GNU General Public License as published by
|
|
Packit |
4f15d5 |
the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
4f15d5 |
(at your option) any later version.
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
4f15d5 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
4f15d5 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
4f15d5 |
GNU General Public License for more details.
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
You should have received a copy of the GNU General Public License along
|
|
Packit |
4f15d5 |
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit |
4f15d5 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit |
4f15d5 |
*/
|
|
Packit |
4f15d5 |
#ifndef LIBREPORT_INTERNAL_ABRT_DBUS_H
|
|
Packit |
4f15d5 |
#define LIBREPORT_INTERNAL_ABRT_DBUS_H
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
#include <dbus/dbus.h>
|
|
Packit |
4f15d5 |
#include "internal_libreport.h"
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
#ifdef __cplusplus
|
|
Packit |
4f15d5 |
extern "C" {
|
|
Packit |
4f15d5 |
#endif
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
extern DBusConnection* g_dbus_conn;
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
/*
|
|
Packit |
4f15d5 |
* Glib integration machinery
|
|
Packit |
4f15d5 |
*/
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
/* Hook up to DBus and to glib main loop.
|
|
Packit |
4f15d5 |
* Usage cases:
|
|
Packit |
4f15d5 |
*
|
|
Packit |
4f15d5 |
* - server:
|
|
Packit |
4f15d5 |
* conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err;;
|
|
Packit |
4f15d5 |
* attach_dbus_conn_to_glib_main_loop(conn, "/some/path", handler_of_calls_to_some_path);
|
|
Packit |
4f15d5 |
* rc = dbus_bus_request_name(conn, "server.name", DBUS_NAME_FLAG_REPLACE_EXISTING, &err;;
|
|
Packit |
4f15d5 |
*
|
|
Packit |
4f15d5 |
* - client which does not receive signals (only makes calls and emits signals):
|
|
Packit |
4f15d5 |
* conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err;;
|
|
Packit |
4f15d5 |
* // needed only if you need to use async dbus calls (not shown below):
|
|
Packit |
4f15d5 |
* attach_dbus_conn_to_glib_main_loop(conn, NULL, NULL);
|
|
Packit |
4f15d5 |
* // synchronous method call:
|
|
Packit |
4f15d5 |
* msg = dbus_message_new_method_call("some.serv", "/path/on/serv", "optional.iface.on.serv", "method_name");
|
|
Packit |
4f15d5 |
* reply = dbus_connection_send_with_reply_and_block(conn, msg, timeout, &err;;
|
|
Packit |
4f15d5 |
* // emitting signal:
|
|
Packit |
4f15d5 |
* msg = dbus_message_new_signal("/path/sig/emitted/from", "iface.sig.emitted.from", "sig_name");
|
|
Packit |
4f15d5 |
* // (note: "iface.sig.emitted.from" is not optional for signals!)
|
|
Packit |
4f15d5 |
* dbus_message_set_destination(msg, "peer"); // optional
|
|
Packit |
4f15d5 |
* dbus_connection_send(conn, msg, &serial); // &serial can be NULL
|
|
Packit |
4f15d5 |
* dbus_connection_unref(conn); // if you don't want to *stay* connected
|
|
Packit |
4f15d5 |
*
|
|
Packit |
4f15d5 |
* - client which receives and processes signals:
|
|
Packit |
4f15d5 |
* conn = dbus_bus_get(DBUS_BUS_SYSTEM/SESSION, &err;;
|
|
Packit |
4f15d5 |
* attach_dbus_conn_to_glib_main_loop(conn, NULL, NULL);
|
|
Packit |
4f15d5 |
* dbus_connection_add_filter(conn, handle_message, NULL, NULL)
|
|
Packit |
4f15d5 |
* dbus_bus_add_match(system_conn, "type='signal',...", &err;;
|
|
Packit |
4f15d5 |
* // signal is a dbus message which looks like this:
|
|
Packit |
4f15d5 |
* // sender=XXX dest=YYY(or null) path=/path/sig/emitted/from interface=iface.sig.emitted.from member=sig_name
|
|
Packit |
4f15d5 |
* // and handler_for_signals(conn,msg,opaque) will be called by glib
|
|
Packit |
4f15d5 |
* // main loop to process received signals (and other messages
|
|
Packit |
4f15d5 |
* // if you ask for them in dbus_bus_add_match[es], but this
|
|
Packit |
4f15d5 |
* // would turn you into a server if you handle them too) ;]
|
|
Packit |
4f15d5 |
*/
|
|
Packit |
4f15d5 |
void attach_dbus_conn_to_glib_main_loop(DBusConnection* conn,
|
|
Packit |
4f15d5 |
/* NULL if you are just a client */
|
|
Packit |
4f15d5 |
const char* object_path_to_register,
|
|
Packit |
4f15d5 |
/* makes sense only if you use object_path_to_register: */
|
|
Packit |
4f15d5 |
DBusHandlerResult (*message_received_func)(DBusConnection *conn, DBusMessage *msg, void* data)
|
|
Packit |
4f15d5 |
);
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
/*
|
|
Packit |
4f15d5 |
* Helpers for building DBus messages
|
|
Packit |
4f15d5 |
*/
|
|
Packit |
4f15d5 |
//void store_bool(DBusMessageIter* iter, bool val);
|
|
Packit |
4f15d5 |
void store_int32(DBusMessageIter* iter, int32_t val);
|
|
Packit |
4f15d5 |
void store_uint32(DBusMessageIter* iter, uint32_t val);
|
|
Packit |
4f15d5 |
void store_int64(DBusMessageIter* iter, int64_t val);
|
|
Packit |
4f15d5 |
void store_uint64(DBusMessageIter* iter, uint64_t val);
|
|
Packit |
4f15d5 |
void store_string(DBusMessageIter* iter, const char* val);
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
/*
|
|
Packit |
4f15d5 |
* Helpers for parsing DBus messages
|
|
Packit |
4f15d5 |
*/
|
|
Packit |
4f15d5 |
enum {
|
|
Packit |
4f15d5 |
ABRT_DBUS_ERROR = -1,
|
|
Packit |
4f15d5 |
ABRT_DBUS_LAST_FIELD = 0,
|
|
Packit |
4f15d5 |
ABRT_DBUS_MORE_FIELDS = 1,
|
|
Packit |
4f15d5 |
/* note that dbus_message_iter_next() returns FALSE on last field
|
|
Packit |
4f15d5 |
* and TRUE if there are more fields.
|
|
Packit |
4f15d5 |
* It maps exactly on the above constants. */
|
|
Packit |
4f15d5 |
};
|
|
Packit |
4f15d5 |
/* Checks type, loads data, advances to the next arg.
|
|
Packit |
4f15d5 |
* Returns TRUE if next arg exists.
|
|
Packit |
4f15d5 |
*/
|
|
Packit |
4f15d5 |
//int load_bool(DBusMessageIter* iter, bool& val);
|
|
Packit |
4f15d5 |
int load_int32(DBusMessageIter* iter, int32_t *val);
|
|
Packit |
4f15d5 |
int load_uint32(DBusMessageIter* iter, uint32_t *val);
|
|
Packit |
4f15d5 |
int load_int64(DBusMessageIter* iter, int64_t *val);
|
|
Packit |
4f15d5 |
int load_uint64(DBusMessageIter* iter, uint64_t *val);
|
|
Packit |
4f15d5 |
int load_charp(DBusMessageIter* iter, const char **val);
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
#ifdef __cplusplus
|
|
Packit |
4f15d5 |
}
|
|
Packit |
4f15d5 |
#endif
|
|
Packit |
4f15d5 |
|
|
Packit |
4f15d5 |
#endif
|