PipeWire: protocol.h Source File

PipeWire 0.3.5

protocol.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_PROTOCOL_H
26 #define PIPEWIRE_PROTOCOL_H
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #include <spa/utils/list.h>
33
34 struct pw_protocol;
35
36 #include <pipewire/context.h>
37 #include <pipewire/properties.h>
38 #include <pipewire/utils.h>
39
40 #define PW_TYPE_INFO_Protocol "PipeWire:Protocol"
41 #define PW_TYPE_INFO_PROTOCOL_BASE PW_TYPE_INFO_Protocol ":"
42
43 struct pw_protocol_client {
44 struct spa_list link;
45 struct pw_protocol *protocol;
47 struct pw_core *core;
48
49 int (*connect) (struct pw_protocol_client *client,
50 const struct spa_dict *props,
51 void (*done_callback) (void *data, int result),
52 void *data);
53 int (*connect_fd) (struct pw_protocol_client *client, int fd, bool close);
54 int (*steal_fd) (struct pw_protocol_client *client);
55 void (*disconnect) (struct pw_protocol_client *client);
56 void (*destroy) (struct pw_protocol_client *client);
57 int (*set_paused) (struct pw_protocol_client *client, bool paused);
58 };
59
60 #define pw_protocol_client_connect(c,p,cb,d) ((c)->connect(c,p,cb,d))
61 #define pw_protocol_client_connect_fd(c,fd,cl) ((c)->connect_fd(c,fd,cl))
62 #define pw_protocol_client_steal_fd(c) ((c)->steal_fd(c))
63 #define pw_protocol_client_disconnect(c) ((c)->disconnect(c))
64 #define pw_protocol_client_destroy(c) ((c)->destroy(c))
65 #define pw_protocol_client_set_paused(c,p) ((c)->set_paused(c,p))
66
67 struct pw_protocol_server {
68 struct spa_list link;
69 struct pw_protocol *protocol;
71 struct pw_impl_core *core;
72
73 struct spa_list client_list;
75 void (*destroy) (struct pw_protocol_server *listen);
76 };
77
78 #define pw_protocol_server_destroy(l) ((l)->destroy(l))
79
80 struct pw_protocol_marshal {
81 const char *type;
82 uint32_t version;
83 #define PW_PROTOCOL_MARSHAL_FLAG_IMPL (1 << 0)
84 uint32_t flags;
85 uint32_t n_client_methods;
86 uint32_t n_server_methods;
87 const void *client_marshal;
88 const void *server_demarshal;
89 const void *server_marshal;
90 const void *client_demarshal;
91 };
92
93 struct pw_protocol_implementaton {
94 #define PW_VERSION_PROTOCOL_IMPLEMENTATION 0
95 uint32_t version;
96
97 struct pw_protocol_client * (*new_client) (struct pw_protocol *protocol,
98 struct pw_core *core,
99 const struct spa_dict *props);
100 struct pw_protocol_server * (*add_server) (struct pw_protocol *protocol,
101 struct pw_impl_core *core,
102 const struct spa_dict *props);
103 };
104
105 struct pw_protocol_events {
106 #define PW_VERSION_PROTOCOL_EVENTS 0
107 uint32_t version;
108
109 void (*destroy) (void *data);
110 };
111
112 #define pw_protocol_new_client(p,...) (pw_protocol_get_implementation(p)->new_client(p,__VA_ARGS__))
113 #define pw_protocol_add_server(p,...) (pw_protocol_get_implementation(p)->add_server(p,__VA_ARGS__))
114 #define pw_protocol_ext(p,type,method,...) (((type*)pw_protocol_get_extension(p))->method( __VA_ARGS__))
115
116 struct pw_protocol *pw_protocol_new(struct pw_context *context, const char *name, size_t user_data_size);
117
118 void pw_protocol_destroy(struct pw_protocol *protocol);
119
120 struct pw_context *pw_protocol_get_context(struct pw_protocol *protocol);
121
122 void *pw_protocol_get_user_data(struct pw_protocol *protocol);
123
124 const struct pw_protocol_implementaton *
125 pw_protocol_get_implementation(struct pw_protocol *protocol);
126
127 const void *
128 pw_protocol_get_extension(struct pw_protocol *protocol);
129
130
131 void pw_protocol_add_listener(struct pw_protocol *protocol,
132 struct spa_hook *listener,
133 const struct pw_protocol_events *events,
134 void *data);
135
140 int pw_protocol_add_marshal(struct pw_protocol *protocol,
141 const struct pw_protocol_marshal *marshal);
142
143 const struct pw_protocol_marshal *
144 pw_protocol_get_marshal(struct pw_protocol *protocol, const char *type, uint32_t version, uint32_t flags);
145
146 struct pw_protocol * pw_context_find_protocol(struct pw_context *context, const char *name);
147
148 #ifdef __cplusplus
149 } /* extern "C" */
150 #endif
151
152 #endif /* PIPEWIRE_PROTOCOL_H */
pw_protocol_get_extension
const void * pw_protocol_get_extension(struct pw_protocol *protocol)
Definition: protocol.c:96
pw_protocol_client::core
struct pw_core * core
Definition: protocol.h:47
pw_protocol_get_user_data
SPA_EXPORT void * pw_protocol_get_user_data(struct pw_protocol *protocol)
Definition: protocol.c:82
pw_protocol_get_context
struct pw_context * pw_protocol_get_context(struct pw_protocol *protocol)
Definition: protocol.c:76
pw_protocol_events::version
uint32_t version
Definition: protocol.h:107
pw_context_find_protocol
struct pw_protocol * pw_context_find_protocol(struct pw_context *context, const char *name)
Definition: protocol.c:176
pw_protocol_client
Definition: protocol.h:43
pw_protocol
Manages protocols and their implementation.
pw_protocol_marshal::flags
uint32_t flags
version
Definition: protocol.h:84
data
Definition: filter.c:70
pw_protocol_get_implementation
SPA_EXPORT const struct pw_protocol_implementaton * pw_protocol_get_implementation(struct pw_protocol *protocol)
Definition: protocol.c:89
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:160
impl
Definition: control.c:33
NAME
#define NAME
Definition: protocol.c:33
type.h
pw_protocol_client::connect_fd
int(* connect_fd)(struct pw_protocol_client *client, int fd, bool close)
Definition: protocol.h:53
pw_protocol_server::core
struct pw_impl_core * core
Definition: protocol.h:71
protocol.h
pw_protocol_client::disconnect
void(* disconnect)(struct pw_protocol_client *client)
Definition: protocol.h:55
pw_protocol_server::client_list
struct spa_list client_list
list of clients of this protocol
Definition: protocol.h:73
utils.h
pw_protocol_implementaton::version
uint32_t version
Definition: protocol.h:95
pw_protocol_client::protocol
struct pw_protocol * protocol
the owner protocol
Definition: protocol.h:45
pw_protocol_add_listener
SPA_EXPORT void pw_protocol_add_listener(struct pw_protocol *protocol, struct spa_hook *listener, const struct pw_protocol_events *events, void *data)
Definition: protocol.c:129
pw_protocol_client::destroy
void(* destroy)(struct pw_protocol_client *client)
Definition: protocol.h:56
pw_log::pw_log_debug
#define pw_log_debug(...)
pw_protocol_get_implementation
const struct pw_protocol_implementaton * pw_protocol_get_implementation(struct pw_protocol *protocol)
Definition: protocol.c:89
pw_protocol_server_destroy
#define pw_protocol_server_destroy(l)
Definition: protocol.h:78
pw_impl_core
PipeWire core interface.
pw_protocol_new
struct pw_protocol * pw_protocol_new(struct pw_context *context, const char *name, size_t user_data_size)
Definition: protocol.c:47
pw_protocol_get_user_data
void * pw_protocol_get_user_data(struct pw_protocol *protocol)
Definition: protocol.c:82
pw_protocol_add_marshal
SPA_EXPORT int pw_protocol_add_marshal(struct pw_protocol *protocol, const struct pw_protocol_marshal *marshal)
Definition: protocol.c:139
pw_protocol_server
Definition: protocol.h:67
pw_protocol_destroy
void pw_protocol_destroy(struct pw_protocol *protocol)
Definition: protocol.c:102
pw_protocol_server::protocol
struct pw_protocol * protocol
the owner protocol
Definition: protocol.h:69
pw_context
the PipeWire context
pw_protocol_server::destroy
void(* destroy)(struct pw_protocol_server *listen)
Definition: protocol.h:75
pw_protocol_marshal::client_demarshal
const void * client_demarshal
Definition: protocol.h:90
pw_protocol_client::link
struct spa_list link
link in protocol client_list
Definition: protocol.h:44
pw_protocol_client::set_paused
int(* set_paused)(struct pw_protocol_client *client, bool paused)
Definition: protocol.h:57
pw_protocol_marshal::server_demarshal
const void * server_demarshal
Definition: protocol.h:88
pw_protocol_get_context
SPA_EXPORT struct pw_context * pw_protocol_get_context(struct pw_protocol *protocol)
Definition: protocol.c:76
pw_protocol_server::link
struct spa_list link
link in protocol server_list
Definition: protocol.h:68
pw_protocol_events::destroy
void(* destroy)(void *data)
Definition: protocol.h:109
pw_protocol_add_marshal
int pw_protocol_add_marshal(struct pw_protocol *protocol, const struct pw_protocol_marshal *marshal)
Definition: protocol.c:139
pw_protocol_destroy
SPA_EXPORT void pw_protocol_destroy(struct pw_protocol *protocol)
Definition: protocol.c:102
pw_protocol_events
Definition: protocol.h:105
context.h
impl::this
struct pw_control this
Definition: control.c:34
pw_protocol_marshal
Definition: protocol.h:80
pw_protocol_marshal::server_marshal
const void * server_marshal
Definition: protocol.h:89
pw_protocol_new
SPA_EXPORT struct pw_protocol * pw_protocol_new(struct pw_context *context, const char *name, size_t user_data_size)
Definition: protocol.c:47
pw_protocol_implementaton
Definition: protocol.h:93
properties.h
pw_protocol_get_marshal
SPA_EXPORT 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:160
pw_protocol_add_listener
void pw_protocol_add_listener(struct pw_protocol *protocol, struct spa_hook *listener, const struct pw_protocol_events *events, void *data)
Definition: protocol.c:129
pw_protocol_client_destroy
#define pw_protocol_client_destroy(c)
Definition: protocol.h:64
pw_protocol_marshal::type
const char * type
interface type
Definition: protocol.h:81
pw_protocol_marshal::version
uint32_t version
version
Definition: protocol.h:82
pw_protocol_client::steal_fd
int(* steal_fd)(struct pw_protocol_client *client)
Definition: protocol.h:54
pw_protocol_client::connect
int(* connect)(struct pw_protocol_client *client, const struct spa_dict *props, void(*done_callback)(void *data, int result), void *data)
Definition: protocol.h:49
pw_protocol_get_extension
SPA_EXPORT const void * pw_protocol_get_extension(struct pw_protocol *protocol)
Definition: protocol.c:96
pw_context_find_protocol
SPA_EXPORT struct pw_protocol * pw_context_find_protocol(struct pw_context *context, const char *name)
Definition: protocol.c:176