1 /* 2 * Copyright © 2013 David Herrmann <dh.herrmann@gmail.com> 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files (the 6 * "Software"), to deal in the Software without restriction, including 7 * without limitation the rights to use, copy, modify, merge, publish, 8 * distribute, sublicense, and/or sell copies of the Software, and to 9 * permit persons to whom the Software is furnished to do so, subject to 10 * the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the 13 * next paragraph) shall be included in all copies or substantial 14 * portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 * SOFTWARE. 24 */ 25 26 #ifndef _WESTON_DBUS_H_ 27 #define _WESTON_DBUS_H_ 28 29 #include "config.h" 30 31 #include <errno.h> 32 #include <wayland-server.h> 33 34 #include <libweston/libweston.h> 35 36 #ifdef HAVE_DBUS 37 38 #include <dbus/dbus.h> 39 40 /* 41 * weston_dbus_open() - Open new dbus connection 42 * 43 * Opens a new dbus connection to the bus given as @bus. It automatically 44 * integrates the new connection into the main-loop @loop. The connection 45 * itself is returned in @out. 46 * This also returns a context source used for dbus dispatching. It is 47 * returned on success in @ctx_out and must be passed to weston_dbus_close() 48 * unchanged. You must not access it from outside of a dbus helper! 49 * 50 * Returns 0 on success, negative error code on failure. 51 */ 52 int weston_dbus_open(struct wl_event_loop *loop, DBusBusType bus, 53 DBusConnection **out, struct wl_event_source **ctx_out); 54 55 /* 56 * weston_dbus_close() - Close dbus connection 57 * 58 * Closes a dbus connection that was previously opened via weston_dbus_open(). 59 * It unbinds the connection from the main-loop it was previously bound to, 60 * closes the dbus connection and frees all resources. If you want to access 61 * @c after this call returns, you must hold a dbus-reference to it. But 62 * notice that the connection is closed after this returns so it cannot be 63 * used to spawn new dbus requests. 64 * You must pass the context source returns by weston_dbus_open() as @ctx. 65 */ 66 void weston_dbus_close(DBusConnection *c, struct wl_event_source *ctx); 67 68 /* 69 * weston_dbus_add_match() - Add dbus match 70 * 71 * Configure a dbus-match on the given dbus-connection. This match is saved 72 * on the dbus-server as long as the connection is open. See dbus-manual 73 * for information. Compared to the dbus_bus_add_match() this allows a 74 * var-arg formatted match-string. 75 */ 76 int weston_dbus_add_match(DBusConnection *c, const char *format, ...); 77 78 /* 79 * weston_dbus_add_match_signal() - Add dbus signal match 80 * 81 * Same as weston_dbus_add_match() but does the dbus-match formatting for 82 * signals internally. 83 */ 84 int weston_dbus_add_match_signal(DBusConnection *c, const char *sender, 85 const char *iface, const char *member, 86 const char *path); 87 88 /* 89 * weston_dbus_remove_match() - Remove dbus match 90 * 91 * Remove a previously configured dbus-match from the dbus server. There is 92 * no need to remove dbus-matches if you close the connection, anyway. 93 * Compared to dbus_bus_remove_match() this allows a var-arg formatted 94 * match string. 95 */ 96 void weston_dbus_remove_match(DBusConnection *c, const char *format, ...); 97 98 /* 99 * weston_dbus_remove_match_signal() - Remove dbus signal match 100 * 101 * Same as weston_dbus_remove_match() but does the dbus-match formatting for 102 * signals internally. 103 */ 104 void weston_dbus_remove_match_signal(DBusConnection *c, const char *sender, 105 const char *iface, const char *member, 106 const char *path); 107 108 #endif /* HAVE_DBUS */ 109 110 #endif // _WESTON_DBUS_H_ 111