PipeWire  0.3.40
dbus.h
Go to the documentation of this file.
1 /* Simple Plugin API
2  *
3  * Copyright © 2018 Wim Taymans
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef SPA_DBUS_H
26 #define SPA_DBUS_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <spa/support/loop.h>
33 
43 #define SPA_TYPE_INTERFACE_DBus SPA_TYPE_INFO_INTERFACE_BASE "DBus"
44 
45 #define SPA_VERSION_DBUS 0
46 struct spa_dbus { struct spa_interface iface; };
47 
48 enum spa_dbus_type {
52 };
53 
54 #define SPA_DBUS_CONNECTION_EVENT_DESTROY 0
55 #define SPA_DBUS_CONNECTION_EVENT_DISCONNECTED 1
56 #define SPA_DBUS_CONNECTION_EVENT_NUM 2
57 
59 #define SPA_VERSION_DBUS_CONNECTION_EVENTS 0
60  uint32_t version;
61 
62  /* a connection is destroyed */
63  void (*destroy) (void *data);
64 
65  /* a connection disconnected */
66  void (*disconnected) (void *data);
67 };
68 
69 struct spa_dbus_connection {
70 #define SPA_VERSION_DBUS_CONNECTION 1
71  uint32_t version;
83  void *(*get) (struct spa_dbus_connection *conn);
89  void (*destroy) (struct spa_dbus_connection *conn);
90 
96  void (*add_listener) (struct spa_dbus_connection *conn,
97  struct spa_hook *listener,
98  const struct spa_dbus_connection_events *events,
99  void *data);
100 };
101 
102 #define spa_dbus_connection_call(c,method,vers,...) \
103 ({ \
104  if (SPA_LIKELY(SPA_CALLBACK_CHECK(c,method,vers))) \
105  c->method((c), ## __VA_ARGS__); \
106 })
107 
108 #define spa_dbus_connection_call_vp(c,method,vers,...) \
109 ({ \
110  void *_res = NULL; \
111  if (SPA_LIKELY(SPA_CALLBACK_CHECK(c,method,vers))) \
112  _res = c->method((c), ## __VA_ARGS__); \
113  _res; \
114 })
115 
118 #define spa_dbus_connection_get(c) spa_dbus_connection_call_vp(c,get,0)
121 #define spa_dbus_connection_destroy(c) spa_dbus_connection_call(c,destroy,0)
124 #define spa_dbus_connection_add_listener(c,...) spa_dbus_connection_call(c,add_listener,1,__VA_ARGS__)
125 
126 struct spa_dbus_methods {
127 #define SPA_VERSION_DBUS_METHODS 0
128  uint32_t version;
129 
142  struct spa_dbus_connection * (*get_connection) (void *object,
143  enum spa_dbus_type type);
144 };
145 
149 static inline struct spa_dbus_connection *
150 spa_dbus_get_connection(struct spa_dbus *dbus, enum spa_dbus_type type)
151 {
152  struct spa_dbus_connection *res = NULL;
154  struct spa_dbus_methods, res,
155  get_connection, 0, type);
156  return res;
157 }
158 
163 #ifdef __cplusplus
164 } /* extern "C" */
165 #endif
166 
167 #endif /* SPA_DBUS_H */
spa_dbus_type
Definition: dbus.h:55
static struct spa_dbus_connection * spa_dbus_get_connection(struct spa_dbus *dbus, enum spa_dbus_type type)
Get a new connection wrapper for the given bus type.
Definition: dbus.h:163
@ SPA_DBUS_TYPE_SESSION
The login session bus.
Definition: dbus.h:56
@ SPA_DBUS_TYPE_STARTER
The bus that started us, if any.
Definition: dbus.h:58
@ SPA_DBUS_TYPE_SYSTEM
The systemwide bus.
Definition: dbus.h:57
#define spa_interface_call_res(iface, method_type, res, method, vers,...)
Invoke method named method in the callbacks on the given interface object.
Definition: hook.h:255
spa/support/loop.h
Definition: dbus.h:68
void(* destroy)(void *data)
Definition: dbus.h:74
uint32_t version
Definition: dbus.h:71
void(* disconnected)(void *data)
Definition: dbus.h:77
Definition: dbus.h:80
void(* destroy)(struct spa_dbus_connection *conn)
Destroy a dbus connection wrapper.
Definition: dbus.h:101
void(* add_listener)(struct spa_dbus_connection *conn, struct spa_hook *listener, const struct spa_dbus_connection_events *events, void *data)
Add a listener for events.
Definition: dbus.h:108
Definition: dbus.h:138
uint32_t version
Definition: dbus.h:141
Definition: dbus.h:53
struct spa_interface iface
Definition: dbus.h:53
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:342
Definition: hook.h:158