PipeWire  0.3.33
proxy.h
Go to the documentation of this file.
1 /* PipeWire
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 PIPEWIRE_PROXY_H
26 #define PIPEWIRE_PROXY_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <spa/utils/hook.h>
33 
106 struct pw_proxy;
107 
108 #include <pipewire/protocol.h>
109 
112 #define PW_VERSION_PROXY_EVENTS 0
113  uint32_t version;
114 
116  void (*destroy) (void *data);
117 
119  void (*bound) (void *data, uint32_t global_id);
120 
123  void (*removed) (void *data);
124 
126  void (*done) (void *data, int seq);
127 
129  void (*error) (void *data, int seq, int res, const char *message);
130 };
131 
132 /* Make a new proxy object. The id can be used to bind to a remote object and
133  * can be retrieved with \ref pw_proxy_get_id . */
134 struct pw_proxy *
135 pw_proxy_new(struct pw_proxy *factory,
136  const char *type, /* interface type */
137  uint32_t version, /* interface version */
138  size_t user_data_size /* size of user data */);
139 
141 void pw_proxy_add_listener(struct pw_proxy *proxy,
142  struct spa_hook *listener,
143  const struct pw_proxy_events *events,
144  void *data);
145 
148 void pw_proxy_add_object_listener(struct pw_proxy *proxy,
149  struct spa_hook *listener,
150  const void *funcs,
151  void *data );
152 
154 void pw_proxy_destroy(struct pw_proxy *proxy);
155 
157 void *pw_proxy_get_user_data(struct pw_proxy *proxy);
158 
160 uint32_t pw_proxy_get_id(struct pw_proxy *proxy);
161 
163 const char *pw_proxy_get_type(struct pw_proxy *proxy, uint32_t *version);
164 
166 struct pw_protocol *pw_proxy_get_protocol(struct pw_proxy *proxy);
167 
170 int pw_proxy_sync(struct pw_proxy *proxy, int seq);
171 
174 int pw_proxy_set_bound_id(struct pw_proxy *proxy, uint32_t global_id);
177 uint32_t pw_proxy_get_bound_id(struct pw_proxy *proxy);
178 
180 int pw_proxy_error(struct pw_proxy *proxy, int res, const char *error);
181 int pw_proxy_errorf(struct pw_proxy *proxy, int res, const char *error, ...) SPA_PRINTF_FUNC(3, 4);
182 
184 struct spa_hook_list *pw_proxy_get_object_listeners(struct pw_proxy *proxy);
185 
187 const struct pw_protocol_marshal *pw_proxy_get_marshal(struct pw_proxy *proxy);
188 
190 int pw_proxy_install_marshal(struct pw_proxy *proxy, bool implementor);
191 
192 #define pw_proxy_notify(p,type,event,version,...) \
193  spa_hook_list_call(pw_proxy_get_object_listeners(p), \
194  type, event, version, ## __VA_ARGS__)
195 
196 #define pw_proxy_call(p,type,method,version,...) \
197  spa_interface_call((struct spa_interface*)p, \
198  type, method, version, ##__VA_ARGS__)
199 
200 #define pw_proxy_call_res(p,type,method,version,...) \
201 ({ \
202  int _res = -ENOTSUP; \
203  spa_interface_call_res((struct spa_interface*)p, \
204  type, _res, method, version, ##__VA_ARGS__); \
205  _res; \
206 })
207 
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 #endif /* PIPEWIRE_PROXY_H */
pw_proxy_error
int pw_proxy_error(struct pw_proxy *proxy, int res, const char *error)
Generate an error for a proxy.
Definition: proxy.c:338
pw_proxy_events::version
uint32_t version
Definition: proxy.h:113
pw_proxy_new
struct pw_proxy * pw_proxy_new(struct pw_proxy *factory, const char *type, uint32_t version, size_t user_data_size)
Create a proxy object with a given id and type.
Definition: proxy.c:89
pw_proxy_get_type
const char * pw_proxy_get_type(struct pw_proxy *proxy, uint32_t *version)
Get the type and version of the proxy.
Definition: proxy.c:173
pw_proxy_errorf
int pw_proxy_errorf(struct pw_proxy *proxy, int res, const char *error,...) 1(3
types.h
data
user data to add to an object
Definition: filter.c:75
pw_proxy_get_user_data
void * pw_proxy_get_user_data(struct pw_proxy *proxy)
Get the user_data.
Definition: proxy.c:146
pw_proxy_events::destroy
void(* destroy)(void *data)
The proxy is destroyed.
Definition: proxy.h:116
SPA_EXPORT
#define SPA_EXPORT
Definition: defs.h:208
impl
Definition: control.c:33
pw_proxy_destroy
void pw_proxy_destroy(struct pw_proxy *proxy)
Destroy a proxy object.
Definition: proxy.c:229
pw_proxy_events
Proxy events, use pw_proxy_add_listener.
Definition: proxy.h:111
spa_hook_list_append
void spa_hook_list_append(struct spa_hook_list *list, struct spa_hook *hook, const void *funcs, void *data)
Append a hook.
Definition: hook.h:316
SPA_PTROFF
#define SPA_PTROFF(ptr_, offset_, type_)
Return the address (buffer + offset) as pointer of type.
Definition: defs.h:159
pw_core_error
#define pw_core_error(c,...)
Definition: core.h:329
pw_proxy_add_object_listener
void pw_proxy_add_object_listener(struct pw_proxy *proxy, struct spa_hook *listener, const void *funcs, void *data)
Add a listener for the events received from the remote object.
Definition: proxy.c:204
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:205
pw_core_sync
#define pw_core_sync(c,...)
Definition: core.h:327
SPA_INTERFACE_INIT
#define SPA_INTERFACE_INIT(_type, _version, _funcs, _data)
Initialize a spa_interface.
Definition: hook.h:165
pw_proxy_get_marshal
const struct pw_protocol_marshal * pw_proxy_get_marshal(struct pw_proxy *proxy)
Get the marshal functions for the proxy.
Definition: proxy.c:356
pw_proxy_remove
void pw_proxy_remove(struct pw_proxy *proxy)
called when cleaning up or when the server removed the resource.
Definition: proxy.c:265
protocol.h
pw_proxy_get_id
uint32_t pw_proxy_get_id(struct pw_proxy *proxy)
Get the local id of the proxy.
Definition: proxy.c:152
pw_proxy_unref
void pw_proxy_unref(struct pw_proxy *proxy)
Definition: proxy.c:290
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:295
pw_proxy_events::bound
void(* bound)(void *data, uint32_t global_id)
a proxy is bound to a global id
Definition: proxy.h:119
type.h
pw_proxy_events::done
void(* done)(void *data, int seq)
a reply to a sync method completed
Definition: proxy.h:126
pw_protocol_get_marshal
const struct pw_protocol_marshal * pw_protocol_get_marshal(struct pw_protocol *protocol, const char *type, uint32_t version, uint32_t flags)
Definition: protocol.c:163
pw_proxy_events::removed
void(* removed)(void *data)
a proxy is removed from the server.
Definition: proxy.h:123
pw_proxy_events::error
void(* error)(void *data, int seq, int res, const char *message)
an error occurred on the proxy
Definition: proxy.h:129
proxy.h
pw_proxy_get_bound_id
uint32_t pw_proxy_get_bound_id(struct pw_proxy *proxy)
Get the global id bound to this proxy of SPA_ID_INVALID when not bound to a global.
Definition: proxy.c:167
pw_proxy_ref
void pw_proxy_ref(struct pw_proxy *proxy)
Definition: proxy.c:303
spa_strerror
#define spa_strerror(err)
Definition: result.h:51
pw_proxy_sync
int pw_proxy_sync(struct pw_proxy *proxy, int seq)
Generate an sync method for a proxy.
Definition: proxy.c:310
pw_log_debug
#define pw_log_debug(...)
Definition: src/pipewire/log.h:89
SPA_ID_INVALID
#define SPA_ID_INVALID
Definition: defs.h:182
spa_hook_list
A list of hooks.
Definition: hook.h:284
NAME
#define NAME
Definition: proxy.c:35
pw_proxy_init
int pw_proxy_init(struct pw_proxy *proxy, const char *type, uint32_t version)
Definition: proxy.c:43
core.h
pw_proxy_get_core
struct pw_core * pw_proxy_get_core(struct pw_proxy *proxy)
Definition: proxy.c:181
impl::this
struct pw_control this
Definition: control.c:34
pw_core_destroy
#define pw_core_destroy(c,...)
Definition: core.h:382
pw_proxy_add_listener
void pw_proxy_add_listener(struct pw_proxy *proxy, struct spa_hook *listener, const struct pw_proxy_events *events, void *data)
Add an event listener to proxy.
Definition: proxy.c:195
pw_protocol_marshal
Definition: protocol.h:90
PW_PROTOCOL_MARSHAL_FLAG_IMPL
#define PW_PROTOCOL_MARSHAL_FLAG_IMPL
marshal for implementations
Definition: protocol.h:93
spa_hook_list_init
void spa_hook_list_init(struct spa_hook_list *list)
Initialize a hook list to the empty list.
Definition: hook.h:305
pw_proxy_get_object_listeners
struct spa_hook_list * pw_proxy_get_object_listeners(struct pw_proxy *proxy)
Get the listener of proxy.
Definition: proxy.c:350
pw_proxy_get_protocol
struct pw_protocol * pw_proxy_get_protocol(struct pw_proxy *proxy)
Get the protocol used for the proxy.
Definition: proxy.c:187
pw_proxy_install_marshal
int pw_proxy_install_marshal(struct pw_proxy *this, bool implementor)
Install a marshal function on a proxy.
Definition: proxy.c:121
hook.h
pw_protocol_marshal::type
const char * type
interface type
Definition: protocol.h:91
pw_protocol_marshal::version
uint32_t version
version
Definition: protocol.h:92
pw_proxy_set_bound_id
int pw_proxy_set_bound_id(struct pw_proxy *proxy, uint32_t global_id)
Set the global id this proxy is bound to.
Definition: proxy.c:158
log.h
spa_hook_list_clean
void spa_hook_list_clean(struct spa_hook_list *list)
Remove all hooks from the list.
Definition: hook.h:344
pw_proxy_errorf
int pw_proxy_errorf(struct pw_proxy *proxy, int res, const char *error,...)
Definition: proxy.c:323
pw_log_error
#define pw_log_error(...)
Definition: src/pipewire/log.h:86