PipeWire: protocol.h Source File

PipeWire 0.1.7

protocol.h
Go to the documentation of this file.
1 /* PipeWire
2 * Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #ifndef __PIPEWIRE_PROTOCOL_H__
21 #define __PIPEWIRE_PROTOCOL_H__
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #include <spa/utils/list.h>
28
29 struct pw_protocol;
30
31 #include <pipewire/core.h>
32 #include <pipewire/properties.h>
33 #include <pipewire/utils.h>
34
35 #define PW_TYPE__Protocol "PipeWire:Protocol"
36 #define PW_TYPE_PROTOCOL_BASE PW_TYPE__Protocol ":"
37
38 struct pw_protocol_client {
39 struct spa_list link;
40 struct pw_protocol *protocol;
42 struct pw_remote *remote;
44 int (*connect) (struct pw_protocol_client *client);
45 int (*connect_fd) (struct pw_protocol_client *client, int fd);
46 void (*disconnect) (struct pw_protocol_client *client);
47 void (*destroy) (struct pw_protocol_client *client);
48 };
49
50 #define pw_protocol_client_connect(c) ((c)->connect(c))
51 #define pw_protocol_client_connect_fd(c,fd) ((c)->connect_fd(c,fd))
52 #define pw_protocol_client_disconnect(c) ((c)->disconnect(c))
53 #define pw_protocol_client_destroy(c) ((c)->destroy(c))
54
55 struct pw_protocol_server {
56 struct spa_list link;
57 struct pw_protocol *protocol;
59 struct spa_list client_list;
61 void (*destroy) (struct pw_protocol_server *listen);
62 };
63
64 #define pw_protocol_server_destroy(l) ((l)->destroy(l))
65
66 struct pw_protocol_marshal {
67 const char *type;
68 uint32_t version;
69 const void *method_marshal;
70 const void *method_demarshal;
71 uint32_t n_methods;
72 const void *event_marshal;
73 const void *event_demarshal;
74 uint32_t n_events;
75 };
76
77 struct pw_protocol_implementaton {
78 #define PW_VERSION_PROTOCOL_IMPLEMENTATION 0
79 uint32_t version;
80
81 struct pw_protocol_client * (*new_client) (struct pw_protocol *protocol,
82 struct pw_remote *remote,
83 struct pw_properties *properties);
84 struct pw_protocol_server * (*add_server) (struct pw_protocol *protocol,
85 struct pw_core *core,
86 struct pw_properties *properties);
87 };
88
89 struct pw_protocol_events {
90 #define PW_VERSION_PROTOCOL_EVENTS 0
91 uint32_t version;
92
93 void (*destroy) (void *data);
94 };
95
96 #define pw_protocol_new_client(p,...) (pw_protocol_get_implementation(p)->new_client(p,__VA_ARGS__))
97 #define pw_protocol_add_server(p,...) (pw_protocol_get_implementation(p)->add_server(p,__VA_ARGS__))
98 #define pw_protocol_ext(p,type,method,...) (((type*)pw_protocol_get_extension(p))->method( __VA_ARGS__))
99
100 struct pw_protocol *pw_protocol_new(struct pw_core *core, const char *name, size_t user_data_size);
101
102 void pw_protocol_destroy(struct pw_protocol *protocol);
103
104 void *pw_protocol_get_user_data(struct pw_protocol *protocol);
105
106 const struct pw_protocol_implementaton *
107 pw_protocol_get_implementation(struct pw_protocol *protocol);
108
109 const void *
110 pw_protocol_get_extension(struct pw_protocol *protocol);
111
112
113 void pw_protocol_add_listener(struct pw_protocol *protocol,
114 struct spa_hook *listener,
115 const struct pw_protocol_events *events,
116 void *data);
117
122 void pw_protocol_add_marshal(struct pw_protocol *protocol,
123 const struct pw_protocol_marshal *marshal);
124
125 const struct pw_protocol_marshal *
126 pw_protocol_get_marshal(struct pw_protocol *protocol, uint32_t type);
127
128 struct pw_protocol * pw_core_find_protocol(struct pw_core *core, const char *name);
129
130 #ifdef __cplusplus
131 } /* extern "C" */
132 #endif
133
134 #endif /* __PIPEWIRE_PROTOCOL_H__ */
pw_protocol_marshal::version
uint32_t version
version
Definition: protocol.h:68
pw_protocol
Manages protocols and their implementation.
pw_protocol_client::disconnect
void(* disconnect)(struct pw_protocol_client *client)
Definition: protocol.h:46
pw_properties
A collection of key/value pairs.
Definition: properties.h:38
pw_protocol_new
struct pw_protocol * pw_protocol_new(struct pw_core *core, const char *name, size_t user_data_size)
Definition: protocol.c:35
pw_protocol_implementaton
Definition: protocol.h:77
pw_protocol_marshal
Definition: protocol.h:66
pw_protocol_events::version
uint32_t version
Definition: protocol.h:91
pw_protocol_marshal::type
const char * type
interface type
Definition: protocol.h:67
pw_protocol_marshal::n_events
uint32_t n_events
number of events in the interface
Definition: protocol.h:74
pw_protocol_client
Definition: protocol.h:38
pw_protocol_client::connect
int(* connect)(struct pw_protocol_client *client)
Definition: protocol.h:44
core.h
pw_core
the core PipeWire object
pw_protocol_client::protocol
struct pw_protocol * protocol
the owner protocol
Definition: protocol.h:40
pw_protocol_client::connect_fd
int(* connect_fd)(struct pw_protocol_client *client, int fd)
Definition: protocol.h:45
pw_protocol_get_extension
const void * pw_protocol_get_extension(struct pw_protocol *protocol)
Definition: protocol.c:75
utils.h
pw_protocol_get_implementation
const struct pw_protocol_implementaton * pw_protocol_get_implementation(struct pw_protocol *protocol)
Definition: protocol.c:69
pw_remote
Represents a connection with a remote PipeWire instance.
pw_protocol_server
Definition: protocol.h:55
pw_protocol_marshal::event_demarshal
const void * event_demarshal
Definition: protocol.h:73
pw_protocol_implementaton::version
uint32_t version
Definition: protocol.h:79
pw_protocol_events
Definition: protocol.h:89
pw_protocol_client::remote
struct pw_remote * remote
the associated remote
Definition: protocol.h:42
pw_protocol_client::destroy
void(* destroy)(struct pw_protocol_client *client)
Definition: protocol.h:47
pw_protocol_client::link
struct spa_list link
link in protocol client_list
Definition: protocol.h:39
pw_protocol_get_user_data
void * pw_protocol_get_user_data(struct pw_protocol *protocol)
Definition: protocol.c:63
properties.h
pw_protocol_get_marshal
const struct pw_protocol_marshal * pw_protocol_get_marshal(struct pw_protocol *protocol, uint32_t type)
Definition: protocol.c:131
pw_core_find_protocol
struct pw_protocol * pw_core_find_protocol(struct pw_core *core, const char *name)
Definition: protocol.c:145
pw_protocol_server::protocol
struct pw_protocol * protocol
the owner protocol
Definition: protocol.h:57
pw_protocol_destroy
void pw_protocol_destroy(struct pw_protocol *protocol)
Definition: protocol.c:80
pw_protocol_marshal::event_marshal
const void * event_marshal
Definition: protocol.h:72
pw_protocol_marshal::n_methods
uint32_t n_methods
number of methods in the interface
Definition: protocol.h:71
pw_protocol_add_marshal
void pw_protocol_add_marshal(struct pw_protocol *protocol, const struct pw_protocol_marshal *marshal)
Definition: protocol.c:115
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:106
pw_protocol_marshal::method_demarshal
const void * method_demarshal
Definition: protocol.h:70
pw_protocol_marshal::method_marshal
const void * method_marshal
Definition: protocol.h:69