PipeWire  0.3.15
resource.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_RESOURCE_H
26 #define PIPEWIRE_RESOURCE_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <spa/utils/hook.h>
33 
59 struct pw_resource;
60 
61 #include <pipewire/impl-client.h>
62 
65 #define PW_VERSION_RESOURCE_EVENTS 0
66  uint32_t version;
67 
69  void (*destroy) (void *data);
70 
72  void (*pong) (void *data, int seq);
73 
75  void (*error) (void *data, int seq, int res, const char *message);
76 };
77 
79 struct pw_resource *
80 pw_resource_new(struct pw_impl_client *client,
81  uint32_t id,
82  uint32_t permissions,
83  const char *type,
84  uint32_t version,
85  size_t user_data_size );
86 
88 void pw_resource_destroy(struct pw_resource *resource);
89 
92 void pw_resource_remove(struct pw_resource *resource);
93 
95 struct pw_impl_client *pw_resource_get_client(struct pw_resource *resource);
96 
98 uint32_t pw_resource_get_id(struct pw_resource *resource);
99 
101 uint32_t pw_resource_get_permissions(struct pw_resource *resource);
102 
104 const char *pw_resource_get_type(struct pw_resource *resource, uint32_t *version);
105 
107 struct pw_protocol *pw_resource_get_protocol(struct pw_resource *resource);
108 
110 void *pw_resource_get_user_data(struct pw_resource *resource);
111 
113 void pw_resource_add_listener(struct pw_resource *resource,
114  struct spa_hook *listener,
115  const struct pw_resource_events *events,
116  void *data);
117 
119 void pw_resource_add_object_listener(struct pw_resource *resource,
120  struct spa_hook *listener,
121  const void *funcs,
122  void *data);
123 
126 int pw_resource_ping(struct pw_resource *resource, int seq);
127 
129 int pw_resource_set_bound_id(struct pw_resource *resource, uint32_t global_id);
130 
132 uint32_t pw_resource_get_bound_id(struct pw_resource *resource);
133 
135 void pw_resource_error(struct pw_resource *resource, int res, const char *error);
136 void pw_resource_errorf(struct pw_resource *resource, int res, const char *error, ...) SPA_PRINTF_FUNC(3, 4);
137 void pw_resource_errorf_id(struct pw_resource *resource, uint32_t id, int res, const char *error, ...) SPA_PRINTF_FUNC(4, 5);
138 
140 struct spa_hook_list *pw_resource_get_object_listeners(struct pw_resource *resource);
141 
143 const struct pw_protocol_marshal *pw_resource_get_marshal(struct pw_resource *resource);
144 
146 int pw_resource_install_marshal(struct pw_resource *resource, bool implementor);
147 
148 #define pw_resource_notify(r,type,event,version,...) \
149  spa_hook_list_call(pw_resource_get_object_listeners(r), \
150  type, event, version, ## __VA_ARGS__)
151 
152 #define pw_resource_call(r,type,method,version,...) \
153  spa_interface_call((struct spa_interface*)r, \
154  type, method, version, ##__VA_ARGS__)
155 
156 #define pw_resource_call_res(r,type,method,version,...) \
157 ({ \
158  int _res = -ENOTSUP; \
159  spa_interface_call_res((struct spa_interface*)r, \
160  type, _res, method, version, ##__VA_ARGS__); \
161  _res; \
162 })
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 
168 #endif /* PIPEWIRE_RESOURCE_H */
res
static uint32_t int int res
Definition: core.h:326
pw_resource_destroy
SPA_EXPORT void pw_resource_destroy(struct pw_resource *resource)
Destroy a resource.
Definition: resource.c:264
id
static uint32_t id
Definition: core.h:325
pw_resource_events::destroy
void(* destroy)(void *data)
The resource is destroyed.
Definition: resource.h:69
pw_resource_get_object_listeners
SPA_EXPORT struct spa_hook_list * pw_resource_get_object_listeners(struct pw_resource *resource)
Get the list of object listeners from a resource.
Definition: resource.c:183
NAME
#define NAME
Definition: resource.c:34
pw_log::pw_log_error
#define pw_log_error(...)
pw_resource_install_marshal
int pw_resource_install_marshal(struct pw_resource *resource, bool implementor)
install a marshal function on a resource
Definition: resource.c:105
pw_resource_get_type
const SPA_EXPORT char * pw_resource_get_type(struct pw_resource *resource, uint32_t *version)
Get the type and optionally the version of this resource.
Definition: resource.c:145
pw_resource_errorf
SPA_EXPORT void pw_resource_errorf(struct pw_resource *resource, int res, const char *error,...)
Definition: resource.c:237
pw_protocol
Manages protocols and their implementation.
data
Definition: filter.c:71
pw_resource_remove
void pw_resource_remove(struct pw_resource *resource)
Remove a resource, like pw_resource_destroy but without sending a remove_id message to the client.
Definition: resource.c:291
pw_resource_get_client
SPA_EXPORT struct pw_impl_client * pw_resource_get_client(struct pw_resource *resource)
Get the client owning this resource.
Definition: resource.c:127
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:162
pw_impl_client
PipeWire client object class.
pw_resource_get_id
uint32_t pw_resource_get_id(struct pw_resource *resource)
Get the unique id of this resource.
Definition: resource.c:133
pw_resource_errorf
void pw_resource_errorf(struct pw_resource *resource, int res, const char *error,...) SPA_PRINTF_FUNC(3
pw_resource_events::pong
void(* pong)(void *data, int seq)
a reply to a ping event completed
Definition: resource.h:72
pw_resource_error
SPA_EXPORT void pw_resource_error(struct pw_resource *resource, int res, const char *error)
Generate an error for a resource.
Definition: resource.c:255
impl
Definition: control.c:33
pw_resource_get_bound_id
uint32_t pw_resource_get_bound_id(struct pw_resource *resource)
Get the global id this resource is bound to or SPA_ID_INVALID when not bound.
Definition: resource.c:222
pw_resource_get_permissions
SPA_EXPORT uint32_t pw_resource_get_permissions(struct pw_resource *resource)
Get the permissions of this resource.
Definition: resource.c:139
pw_resource_new
SPA_EXPORT struct pw_resource * pw_resource_new(struct pw_impl_client *client, uint32_t id, uint32_t permissions, const char *type, uint32_t version, size_t user_data_size)
Make a new resource for client.
Definition: resource.c:43
type.h
impl-client.h
protocol.h
pw_resource_error
void pw_resource_error(struct pw_resource *resource, int res, const char *error)
Generate an error for a resource.
Definition: resource.c:255
pw_map::pw_map_insert_at
static int pw_map_insert_at(struct pw_map *map, uint32_t id, void *data)
Insert data in the map at an index.
Definition: map.h:133
pw_resource_set_bound_id
SPA_EXPORT int pw_resource_set_bound_id(struct pw_resource *resource, uint32_t global_id)
Notify global id this resource is bound to.
Definition: resource.c:209
pw_resource_get_protocol
SPA_EXPORT struct pw_protocol * pw_resource_get_protocol(struct pw_resource *resource)
Get the protocol used for this resource.
Definition: resource.c:153
pw_resource_events::error
void(* error)(void *data, int seq, int res, const char *message)
an error occurred on the resource
Definition: resource.h:75
pw_resource_get_protocol
struct pw_protocol * pw_resource_get_protocol(struct pw_resource *resource)
Get the protocol used for this resource.
Definition: resource.c:153
pw_resource_add_listener
SPA_EXPORT void pw_resource_add_listener(struct pw_resource *resource, struct spa_hook *listener, const struct pw_resource_events *events, void *data)
Add an event listener.
Definition: resource.c:165
message
static uint32_t int int const char * message
Definition: core.h:326
va_start
va_start(args, message)
pw_resource_errorf_id
void void pw_resource_errorf_id(struct pw_resource *resource, uint32_t id, int res, const char *error,...) SPA_PRINTF_FUNC(4
pw_resource_get_permissions
uint32_t pw_resource_get_permissions(struct pw_resource *resource)
Get the permissions of this resource.
Definition: resource.c:139
pw_log::pw_log_debug
#define pw_log_debug(...)
resource.h
pw_resource_set_bound_id
int pw_resource_set_bound_id(struct pw_resource *resource, uint32_t global_id)
Notify global id this resource is bound to.
Definition: resource.c:209
pw_resource_errorf_id
SPA_EXPORT void pw_resource_errorf_id(struct pw_resource *resource, uint32_t id, int res, const char *error,...)
Definition: resource.c:246
pw_resource_add_object_listener
SPA_EXPORT void pw_resource_add_object_listener(struct pw_resource *resource, struct spa_hook *listener, const void *funcs, void *data)
Set the resource implementation.
Definition: resource.c:174
pw_resource_get_user_data
void * pw_resource_get_user_data(struct pw_resource *resource)
Get the user data for the resource, the size was given in pw_resource_new.
Definition: resource.c:159
pw_resource_get_id
SPA_EXPORT uint32_t pw_resource_get_id(struct pw_resource *resource)
Get the unique id of this resource.
Definition: resource.c:133
pw_resource_install_marshal
SPA_EXPORT int pw_resource_install_marshal(struct pw_resource *this, bool implementor)
install a marshal function on a resource
Definition: resource.c:105
pw_resource
Client owned objects.
pw_resource_add_object_listener
void pw_resource_add_object_listener(struct pw_resource *resource, struct spa_hook *listener, const void *funcs, void *data)
Set the resource implementation.
Definition: resource.c:174
pw_resource_destroy
void pw_resource_destroy(struct pw_resource *resource)
Destroy a resource.
Definition: resource.c:264
pw_resource_ping
int pw_resource_ping(struct pw_resource *resource, int seq)
Generate an ping event for a resource.
Definition: resource.c:195
pw_resource_get_client
struct pw_impl_client * pw_resource_get_client(struct pw_resource *resource)
Get the client owning this resource.
Definition: resource.c:127
va_end
va_end(args)
pw_resource_new
struct pw_resource * pw_resource_new(struct pw_impl_client *client, uint32_t id, uint32_t permissions, const char *type, uint32_t version, size_t user_data_size)
Make a new resource for client.
Definition: resource.c:43
impl::this
struct pw_control this
Definition: control.c:34
pw_protocol_marshal
Definition: protocol.h:80
pw_resource_get_marshal
SPA_EXPORT const struct pw_protocol_marshal * pw_resource_get_marshal(struct pw_resource *resource)
Get the marshal functions for the resource.
Definition: resource.c:189
pw_resource_remove
SPA_EXPORT void pw_resource_remove(struct pw_resource *resource)
Remove a resource, like pw_resource_destroy but without sending a remove_id message to the client.
Definition: resource.c:291
seq
static uint32_t int seq
Definition: core.h:325
PW_PROTOCOL_MARSHAL_FLAG_IMPL
#define PW_PROTOCOL_MARSHAL_FLAG_IMPL
marshal for implementations
Definition: protocol.h:83
pw_resource_get_user_data
SPA_EXPORT void * pw_resource_get_user_data(struct pw_resource *resource)
Get the user data for the resource, the size was given in pw_resource_new.
Definition: resource.c:159
pw_resource_get_type
const char * pw_resource_get_type(struct pw_resource *resource, uint32_t *version)
Get the type and optionally the version of this resource.
Definition: resource.c:145
pw_resource_events
Resource events.
Definition: resource.h:64
pw_resource_ping
SPA_EXPORT int pw_resource_ping(struct pw_resource *resource, int seq)
Generate an ping event for a resource.
Definition: resource.c:195
pw_protocol_marshal::type
const char * type
interface type
Definition: protocol.h:81
pw_resource_add_listener
void pw_resource_add_listener(struct pw_resource *resource, struct spa_hook *listener, const struct pw_resource_events *events, void *data)
Add an event listener.
Definition: resource.c:165
pw_resource_events::version
uint32_t version
Definition: resource.h:66
pw_protocol_marshal::version
uint32_t version
version
Definition: protocol.h:82
pw_resource_get_object_listeners
void void struct spa_hook_list * pw_resource_get_object_listeners(struct pw_resource *resource)
Get the list of object listeners from a resource.
Definition: resource.c:183
pw_resource_get_marshal
const struct pw_protocol_marshal * pw_resource_get_marshal(struct pw_resource *resource)
Get the marshal functions for the resource.
Definition: resource.c:189
pw_resource_get_bound_id
SPA_EXPORT uint32_t pw_resource_get_bound_id(struct pw_resource *resource)
Get the global id this resource is bound to or SPA_ID_INVALID when not bound.
Definition: resource.c:222