PipeWire: pipewire/resource.h Source File

PipeWire 0.3.51

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
29extern "C" {
30#endif
31
32#include <spa/utils/hook.h>
33
55struct pw_resource;
56
57#include <pipewire/impl-client.h>
58
60struct pw_resource_events {
61#define PW_VERSION_RESOURCE_EVENTS 0
62 uint32_t version;
63
65 void (*destroy) (void *data);
66
68 void (*pong) (void *data, int seq);
69
71 void (*error) (void *data, int seq, int res, const char *message);
72};
73
75struct pw_resource *
76 pw_resource_new(struct pw_impl_client *client,
77 uint32_t id,
78 uint32_t permissions,
79 const char *type,
80 uint32_t version,
81 size_t user_data_size );
82
84void pw_resource_destroy(struct pw_resource *resource);
85
88void pw_resource_remove(struct pw_resource *resource);
89
91struct pw_impl_client *pw_resource_get_client(struct pw_resource *resource);
92
94uint32_t pw_resource_get_id(struct pw_resource *resource);
95
97uint32_t pw_resource_get_permissions(struct pw_resource *resource);
98
100const char *pw_resource_get_type(struct pw_resource *resource, uint32_t *version);
101
103struct pw_protocol *pw_resource_get_protocol(struct pw_resource *resource);
104
106void *pw_resource_get_user_data(struct pw_resource *resource);
107
109void pw_resource_add_listener(struct pw_resource *resource,
110 struct spa_hook *listener,
111 const struct pw_resource_events *events,
112 void *data);
113
115void pw_resource_add_object_listener(struct pw_resource *resource,
116 struct spa_hook *listener,
117 const void *funcs,
118 void *data);
119
122int pw_resource_ping(struct pw_resource *resource, int seq);
123
125int pw_resource_set_bound_id(struct pw_resource *resource, uint32_t global_id);
126
128uint32_t pw_resource_get_bound_id(struct pw_resource *resource);
129
131void pw_resource_error(struct pw_resource *resource, int res, const char *error);
132void pw_resource_errorf(struct pw_resource *resource, int res, const char *error, ...) SPA_PRINTF_FUNC(3, 4);
133void pw_resource_errorf_id(struct pw_resource *resource, uint32_t id, int res, const char *error, ...) SPA_PRINTF_FUNC(4, 5);
134
136struct spa_hook_list *pw_resource_get_object_listeners(struct pw_resource *resource);
137
139const struct pw_protocol_marshal *pw_resource_get_marshal(struct pw_resource *resource);
140
142int pw_resource_install_marshal(struct pw_resource *resource, bool implementor);
143
144#define pw_resource_notify(r,type,event,version,...) \
145 spa_hook_list_call(pw_resource_get_object_listeners(r), \
146 type, event, version, ## __VA_ARGS__)
147
148#define pw_resource_call(r,type,method,version,...) \
149 spa_interface_call((struct spa_interface*)r, \
150 type, method, version, ##__VA_ARGS__)
151
152#define pw_resource_call_res(r,type,method,version,...) \
153({ \
154 int _res = -ENOTSUP; \
155 spa_interface_call_res((struct spa_interface*)r, \
156 type, _res, method, version, ##__VA_ARGS__); \
157 _res; \
158})
159
160
166#ifdef __cplusplus
167}
168#endif
169
170#endif /* PIPEWIRE_RESOURCE_H */
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:166
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:309
pw_resource_errorf_id
void void pw_resource_errorf_id(struct pw_resource *resource, uint32_t id, int res, const char *error,...) 1(4
pw_resource_get_permissions
uint32_t pw_resource_get_permissions(struct pw_resource *resource)
Get the permissions of this resource.
Definition: resource.c:140
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:154
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:106
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:223
pw_resource_errorf
void pw_resource_errorf(struct pw_resource *resource, int res, const char *error,...) 1(3
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:128
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:190
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:268
pw_resource_ping
int pw_resource_ping(struct pw_resource *resource, int seq)
Generate an ping event for a resource.
Definition: resource.c:196
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:175
pw_resource_destroy
void pw_resource_destroy(struct pw_resource *resource)
Destroy a resource.
Definition: resource.c:282
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:184
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:44
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:210
pw_resource_get_id
uint32_t pw_resource_get_id(struct pw_resource *resource)
Get the unique id of this resource.
Definition: resource.c:134
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:160
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:146
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:260
hook.h
spa/utils/hook.h
impl-client.h
pipewire/impl-client.h
pw_impl_client
pw_protocol_marshal
Definition: protocol.h:97
pw_protocol
pw_resource_events
Resource events.
Definition: resource.h:65
pw_resource_events::destroy
void(* destroy)(void *data)
The resource is destroyed.
Definition: resource.h:71
pw_resource_events::pong
void(* pong)(void *data, int seq)
a reply to a ping event completed
Definition: resource.h:74
pw_resource_events::version
uint32_t version
Definition: resource.h:68
pw_resource_events::error
void(* error)(void *data, int seq, int res, const char *message)
an error occurred on the resource
Definition: resource.h:77
pw_resource
Definition: impl.h:49
spa_hook_list
A list of hooks.
Definition: hook.h:340
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:351