mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2026-05-08 07:48:07 +02:00
dbus: add dbus-match helpers
These helpers simplify adding dbus-matches by allowing var-arg arguments to assemble the matching rules.
This commit is contained in:
parent
59ab90049f
commit
814d49f0b4
2 changed files with 108 additions and 0 deletions
68
src/dbus.c
68
src/dbus.c
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
40
src/dbus.h
40
src/dbus.h
|
|
@ -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_
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue