Commit 814d49f0 authored by David Herrmann's avatar David Herrmann Committed by Kristian Høgsberg

dbus: add dbus-match helpers

These helpers simplify adding dbus-matches by allowing var-arg arguments
to assemble the matching rules.
parent 59ab9004
......@@ -334,3 +334,71 @@ void weston_dbus_close(DBusConnection *c, struct wl_event_source *ctx)
dbus_connection_close(c);
dbus_connection_unref(c);
}
int weston_dbus_add_match(DBusConnection *c, const char *format, ...)
{
DBusError err;
int r;
va_list list;
char *str;
va_start(list, format);
r = vasprintf(&str, format, list);
va_end(list);
if (r < 0)
return -ENOMEM;
dbus_error_init(&err);
dbus_bus_add_match(c, str, &err);
free(str);
if (dbus_error_is_set(&err)) {
dbus_error_free(&err);
return -EIO;
}
return 0;
}
int weston_dbus_add_match_signal(DBusConnection *c, const char *sender,
const char *iface, const char *member,
const char *path)
{
return weston_dbus_add_match(c,
"type='signal',"
"sender='%s',"
"interface='%s',"
"member='%s',"
"path='%s'",
sender, iface, member, path);
}
void weston_dbus_remove_match(DBusConnection *c, const char *format, ...)
{
int r;
va_list list;
char *str;
va_start(list, format);
r = vasprintf(&str, format, list);
va_end(list);
if (r < 0)
return;
dbus_bus_remove_match(c, str, NULL);
free(str);
}
void weston_dbus_remove_match_signal(DBusConnection *c, const char *sender,
const char *iface, const char *member,
const char *path)
{
return weston_dbus_remove_match(c,
"type='signal',"
"sender='%s',"
"interface='%s',"
"member='%s',"
"path='%s'",
sender, iface, member, path);
}
......@@ -62,6 +62,46 @@ int weston_dbus_open(struct wl_event_loop *loop, DBusBusType bus,
*/
void weston_dbus_close(DBusConnection *c, struct wl_event_source *ctx);
/*
* weston_dbus_add_match() - Add dbus match
*
* Configure a dbus-match on the given dbus-connection. This match is saved
* on the dbus-server as long as the connection is open. See dbus-manual
* for information. Compared to the dbus_bus_add_match() this allows a
* var-arg formatted match-string.
*/
int weston_dbus_add_match(DBusConnection *c, const char *format, ...);
/*
* weston_dbus_add_match_signal() - Add dbus signal match
*
* Same as weston_dbus_add_match() but does the dbus-match formatting for
* signals internally.
*/
int weston_dbus_add_match_signal(DBusConnection *c, const char *sender,
const char *iface, const char *member,
const char *path);
/*
* weston_dbus_remove_match() - Remove dbus match
*
* Remove a previously configured dbus-match from the dbus server. There is
* no need to remove dbus-matches if you close the connection, anyway.
* Compared to dbus_bus_remove_match() this allows a var-arg formatted
* match string.
*/
void weston_dbus_remove_match(DBusConnection *c, const char *format, ...);
/*
* weston_dbus_remove_match_signal() - Remove dbus signal match
*
* Same as weston_dbus_remove_match() but does the dbus-match formatting for
* signals internally.
*/
void weston_dbus_remove_match_signal(DBusConnection *c, const char *sender,
const char *iface, const char *member,
const char *path);
#endif /* HAVE_DBUS */
#endif // _WESTON_DBUS_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment