PipeWire  0.3.33
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 
44 struct pw_protocol;
45 
46 #include <pipewire/context.h>
47 #include <pipewire/properties.h>
48 #include <pipewire/utils.h>
49 
50 #define PW_TYPE_INFO_Protocol "PipeWire:Protocol"
51 #define PW_TYPE_INFO_PROTOCOL_BASE PW_TYPE_INFO_Protocol ":"
52 
54  struct spa_list link;
55  struct pw_protocol *protocol;
57  struct pw_core *core;
58 
60  const struct spa_dict *props,
61  void (*done_callback) (void *data, int result),
62  void *data);
63  int (*connect_fd) (struct pw_protocol_client *client, int fd, bool close);
66  void (*destroy) (struct pw_protocol_client *client);
67  int (*set_paused) (struct pw_protocol_client *client, bool paused);
68 };
69 
70 #define pw_protocol_client_connect(c,p,cb,d) ((c)->connect(c,p,cb,d))
71 #define pw_protocol_client_connect_fd(c,fd,cl) ((c)->connect_fd(c,fd,cl))
72 #define pw_protocol_client_steal_fd(c) ((c)->steal_fd(c))
73 #define pw_protocol_client_disconnect(c) ((c)->disconnect(c))
74 #define pw_protocol_client_destroy(c) ((c)->destroy(c))
75 #define pw_protocol_client_set_paused(c,p) ((c)->set_paused(c,p))
76 
78  struct spa_list link;
79  struct pw_protocol *protocol;
81  struct pw_impl_core *core;
82 
83  struct spa_list client_list;
85  void (*destroy) (struct pw_protocol_server *listen);
86 };
87 
88 #define pw_protocol_server_destroy(l) ((l)->destroy(l))
89 
91  const char *type;
92  uint32_t version;
93 #define PW_PROTOCOL_MARSHAL_FLAG_IMPL (1 << 0)
94  uint32_t flags;
95  uint32_t n_client_methods;
96  uint32_t n_server_methods;
97  const void *client_marshal;
98  const void *server_demarshal;
99  const void *server_marshal;
100  const void *client_demarshal;
101 };
102 
104 #define PW_VERSION_PROTOCOL_IMPLEMENTATION 0
105  uint32_t version;
106 
107  struct pw_protocol_client * (*new_client) (struct pw_protocol *protocol,
108  struct pw_core *core,
109  const struct spa_dict *props);
110  struct pw_protocol_server * (*add_server) (struct pw_protocol *protocol,
111  struct pw_impl_core *core,
112  const struct spa_dict *props);
113 };
114 
116 #define PW_VERSION_PROTOCOL_EVENTS 0
117  uint32_t version;
118 
119  void (*destroy) (void *data);
120 };
121 
122 #define pw_protocol_new_client(p,...) (pw_protocol_get_implementation(p)->new_client(p,__VA_ARGS__))
123 #define pw_protocol_add_server(p,...) (pw_protocol_get_implementation(p)->add_server(p,__VA_ARGS__))
124 #define pw_protocol_ext(p,type,method,...) (((type*)pw_protocol_get_extension(p))->method( __VA_ARGS__))
125 
126 struct pw_protocol *pw_protocol_new(struct pw_context *context, const char *name, size_t user_data_size);
127 
128 void pw_protocol_destroy(struct pw_protocol *protocol);
129 
130 struct pw_context *pw_protocol_get_context(struct pw_protocol *protocol);
131 
132 void *pw_protocol_get_user_data(struct pw_protocol *protocol);
133 
134 const struct pw_protocol_implementation *
135 pw_protocol_get_implementation(struct pw_protocol *protocol);
136 
137 const void *
138 pw_protocol_get_extension(struct pw_protocol *protocol);
139 
140 
141 void pw_protocol_add_listener(struct pw_protocol *protocol,
142  struct spa_hook *listener,
143  const struct pw_protocol_events *events,
144  void *data);
145 
146 int pw_protocol_add_marshal(struct pw_protocol *protocol,
147  const struct pw_protocol_marshal *marshal);
148 
149 const struct pw_protocol_marshal *
150 pw_protocol_get_marshal(struct pw_protocol *protocol, const char *type, uint32_t version, uint32_t flags);
151 
152 struct pw_protocol * pw_context_find_protocol(struct pw_context *context, const char *name);
153 
158 #ifdef __cplusplus
159 } /* extern "C" */
160 #endif
161 
162 #endif /* PIPEWIRE_PROTOCOL_H */
pw_protocol_client::core
struct pw_core * core
Definition: protocol.h:57
pw_protocol_events::version
uint32_t version
Definition: protocol.h:117
types.h
pw_protocol_client
Definition: protocol.h:53
name
const char * name
Definition: media-session.c:2379
string.h
pw_protocol_marshal::flags
uint32_t flags
version
Definition: protocol.h:94
data
user data to add to an object
Definition: filter.c:75
spa_streq
bool spa_streq(const char *s1, const char *s2)
Definition: string.h:50
pw_protocol_destroy
void pw_protocol_destroy(struct pw_protocol *protocol)
Definition: protocol.c:103
spa_list_for_each
#define spa_list_for_each(pos, head, member)
Definition: list.h:111
pw_protocol_add_marshal
int pw_protocol_add_marshal(struct pw_protocol *protocol, const struct pw_protocol_marshal *marshal)
Definition: protocol.c:142
SPA_EXPORT
#define SPA_EXPORT
Definition: defs.h:208
pw_protocol_get_implementation
const struct pw_protocol_implementation * pw_protocol_get_implementation(struct pw_protocol *protocol)
Definition: protocol.c:90
impl
Definition: control.c:33
pw_protocol_client_destroy
#define pw_protocol_client_destroy(c)
Definition: protocol.h:74
NAME
#define NAME
Definition: protocol.c:34
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_list
Definition: list.h:37
SPA_PTROFF
#define SPA_PTROFF(ptr_, offset_, type_)
Return the address (buffer + offset) as pointer of type.
Definition: defs.h:159
pw_protocol_get_context
struct pw_context * pw_protocol_get_context(struct pw_protocol *protocol)
Definition: protocol.c:77
props
const char * props
Definition: media-session.c:2382
SPA_CONTAINER_OF
#define SPA_CONTAINER_OF(p, t, m)
Definition: defs.h:170
pw_protocol_client::connect_fd
int(* connect_fd)(struct pw_protocol_client *client, int fd, bool close)
Definition: protocol.h:63
spa_list_consume
#define spa_list_consume(pos, head, member)
Definition: list.h:96
pw_protocol_server::core
struct pw_impl_core * core
Definition: protocol.h:81
protocol.h
pw_protocol_client::disconnect
void(* disconnect)(struct pw_protocol_client *client)
Definition: protocol.h:65
pw_protocol_server::client_list
struct spa_list client_list
list of clients of this protocol
Definition: protocol.h:83
pw_protocol_client::protocol
struct pw_protocol * protocol
the owner protocol
Definition: protocol.h:55
spa_list_remove
void spa_list_remove(struct spa_list *elem)
Definition: list.h:69
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:132
pw_protocol_client::destroy
void(* destroy)(struct pw_protocol_client *client)
Definition: protocol.h:66
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:295
pw_protocol_implementation
Definition: protocol.h:103
utils.h
type.h
pw_protocol_server
Definition: protocol.h:77
spa_list_init
void spa_list_init(struct spa_list *list)
Definition: list.h:44
spa_list_for_each_safe
#define spa_list_for_each_safe(pos, tmp, head, member)
Definition: list.h:129
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
spa_dict
Definition: utils/dict.h:48
pw_context_find_protocol
struct pw_protocol * pw_context_find_protocol(struct pw_context *context, const char *name)
Definition: protocol.c:179
pw_protocol_server::protocol
struct pw_protocol * protocol
the owner protocol
Definition: protocol.h:79
pw_protocol_get_user_data
void * pw_protocol_get_user_data(struct pw_protocol *protocol)
Definition: protocol.c:83
pw_protocol_server::destroy
void(* destroy)(struct pw_protocol_server *listen)
Definition: protocol.h:85
pw_protocol_marshal::client_demarshal
const void * client_demarshal
Definition: protocol.h:100
pw_log_debug
#define pw_log_debug(...)
Definition: src/pipewire/log.h:89
client
Definition: module-protocol-native.c:103
pw_protocol_client::set_paused
int(* set_paused)(struct pw_protocol_client *client, bool paused)
Definition: protocol.h:67
pw_protocol_implementation::version
uint32_t version
Definition: protocol.h:105
pw_protocol_marshal::server_demarshal
const void * server_demarshal
Definition: protocol.h:98
pw_protocol_events::destroy
void(* destroy)(void *data)
Definition: protocol.h:119
pw_protocol_events
Definition: protocol.h:115
server
Definition: module-protocol-native.c:126
context.h
impl::this
struct pw_control this
Definition: control.c:34
pw_protocol_marshal
Definition: protocol.h:90
pw_protocol_marshal::server_marshal
const void * server_marshal
Definition: protocol.h:99
pw_protocol_get_extension
const void * pw_protocol_get_extension(struct pw_protocol *protocol)
Definition: protocol.c:97
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
properties.h
list.h
pw_protocol_new
struct pw_protocol * pw_protocol_new(struct pw_context *context, const char *name, size_t user_data_size)
Definition: protocol.c:48
pw_protocol_server_destroy
#define pw_protocol_server_destroy(l)
Definition: protocol.h:88
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_protocol_client::steal_fd
int(* steal_fd)(struct pw_protocol_client *client)
Definition: protocol.h:64
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:59
spa_hook_list_clean
void spa_hook_list_clean(struct spa_hook_list *list)
Remove all hooks from the list.
Definition: hook.h:344
spa_list_append
#define spa_list_append(list, item)
Definition: list.h:81