PipeWire 0.1.9

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 void (*done_callback) (void *data, int result),
46 void *data);
47 int (*connect_fd) (struct pw_protocol_client *client, int fd);
48 int (*steal_fd) (struct pw_protocol_client *client);
49 void (*disconnect) (struct pw_protocol_client *client);
50 void (*destroy) (struct pw_protocol_client *client);
51 };
52
53 #define pw_protocol_client_connect(c,cb,d) ((c)->connect(c,cb,d))
54 #define pw_protocol_client_connect_fd(c,fd) ((c)->connect_fd(c,fd))
55 #define pw_protocol_client_steal_fd(c) ((c)->steal_fd(c))
56 #define pw_protocol_client_disconnect(c) ((c)->disconnect(c))
57 #define pw_protocol_client_destroy(c) ((c)->destroy(c))
58
59 struct pw_protocol_server {
60 struct spa_list link;
61 struct pw_protocol *protocol;
63 struct spa_list client_list;
65 void (*destroy) (struct pw_protocol_server *listen);
66 };
67
68 #define pw_protocol_server_destroy(l) ((l)->destroy(l))
69
70 struct pw_protocol_marshal {
71 const char *type;
72 uint32_t version;
73 const void *method_marshal;
74 const void *method_demarshal;
75 uint32_t n_methods;
76 const void *event_marshal;
77 const void *event_demarshal;
78 uint32_t n_events;
79 };
80
81 struct pw_protocol_implementaton {
82 #define PW_VERSION_PROTOCOL_IMPLEMENTATION 0
83 uint32_t version;
84
85 struct pw_protocol_client * (*new_client) (struct pw_protocol *protocol,
86 struct pw_remote *remote,
87 struct pw_properties *properties);
88 struct pw_protocol_server * (*add_server) (struct pw_protocol *protocol,
89 struct pw_core *core,
90 struct pw_properties *properties);
91 };
92
93 struct pw_protocol_events {
94 #define PW_VERSION_PROTOCOL_EVENTS 0
95 uint32_t version;
96
97 void (*destroy) (void *data);
98 };
99
100 #define pw_protocol_new_client(p,...) (pw_protocol_get_implementation(p)->new_client(p,__VA_ARGS__))
101 #define pw_protocol_add_server(p,...) (pw_protocol_get_implementation(p)->add_server(p,__VA_ARGS__))
102 #define pw_protocol_ext(p,type,method,...) (((type*)pw_protocol_get_extension(p))->method( __VA_ARGS__))
103
104 struct pw_protocol *pw_protocol_new(struct pw_core *core, const char *name, size_t user_data_size);
105
106 void pw_protocol_destroy(struct pw_protocol *protocol);
107
108 void *pw_protocol_get_user_data(struct pw_protocol *protocol);
109
110 const struct pw_protocol_implementaton *
111 pw_protocol_get_implementation(struct pw_protocol *protocol);
112
113 const void *
114 pw_protocol_get_extension(struct pw_protocol *protocol);
115
116
117 void pw_protocol_add_listener(struct pw_protocol *protocol,
118 struct spa_hook *listener,
119 const struct pw_protocol_events *events,
120 void *data);
121
126 int pw_protocol_add_marshal(struct pw_protocol *protocol,
127 const struct pw_protocol_marshal *marshal);
128
129 const struct pw_protocol_marshal *
130 pw_protocol_get_marshal(struct pw_protocol *protocol, uint32_t type);
131
132 struct pw_protocol * pw_core_find_protocol(struct pw_core *core, const char *name);
133
134 #ifdef __cplusplus
135 } /* extern "C" */
136 #endif
137
138 #endif /* __PIPEWIRE_PROTOCOL_H__ */
pw_protocol_marshal::version
uint32_t version
version
Definition: protocol.h:72
pw_protocol
Manages protocols and their implementation.
pw_protocol_client::disconnect
void(* disconnect)(struct pw_protocol_client *client)
Definition: protocol.h:49
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:37
pw_protocol_implementaton
Definition: protocol.h:81
pw_protocol_marshal
Definition: protocol.h:70
pw_protocol_events::version
uint32_t version
Definition: protocol.h:95
pw_protocol_client::steal_fd
int(* steal_fd)(struct pw_protocol_client *client)
Definition: protocol.h:48
pw_protocol_add_marshal
int pw_protocol_add_marshal(struct pw_protocol *protocol, const struct pw_protocol_marshal *marshal)
Definition: protocol.c:117
pw_protocol_marshal::type
const char * type
interface type
Definition: protocol.h:71
pw_protocol_marshal::n_events
uint32_t n_events
number of events in the interface
Definition: protocol.h:78
pw_protocol_client
Definition: protocol.h:38
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:47
pw_protocol_get_extension
const void * pw_protocol_get_extension(struct pw_protocol *protocol)
Definition: protocol.c:77
utils.h
pw_protocol_server::destroy
void(* destroy)(struct pw_protocol_server *listen)
Definition: protocol.h:65
pw_protocol_get_implementation
const struct pw_protocol_implementaton * pw_protocol_get_implementation(struct pw_protocol *protocol)
Definition: protocol.c:71
pw_remote
Represents a connection with a remote PipeWire instance.
pw_protocol_server::link
struct spa_list link
link in protocol server_list
Definition: protocol.h:60
pw_protocol_events::destroy
void(* destroy)(void *data)
Definition: protocol.h:97
pw_protocol_server
Definition: protocol.h:59
pw_protocol_marshal::event_demarshal
const void * event_demarshal
Definition: protocol.h:77
pw_protocol_implementaton::version
uint32_t version
Definition: protocol.h:83
pw_protocol_events
Definition: protocol.h:93
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:50
pw_protocol_client::link
struct spa_list link
link in protocol client_list
Definition: protocol.h:39
pw_protocol_server::client_list
struct spa_list client_list
list of clients of this protocol
Definition: protocol.h:63
pw_protocol_get_user_data
void * pw_protocol_get_user_data(struct pw_protocol *protocol)
Definition: protocol.c:65
properties.h
pw_protocol_client::connect
int(* connect)(struct pw_protocol_client *client, void(*done_callback)(void *data, int result), void *data)
Definition: protocol.h:44
pw_protocol_get_marshal
const struct pw_protocol_marshal * pw_protocol_get_marshal(struct pw_protocol *protocol, uint32_t type)
Definition: protocol.c:138
pw_core_find_protocol
struct pw_protocol * pw_core_find_protocol(struct pw_core *core, const char *name)
Definition: protocol.c:152
pw_protocol_server::protocol
struct pw_protocol * protocol
the owner protocol
Definition: protocol.h:61
pw_protocol_destroy
void pw_protocol_destroy(struct pw_protocol *protocol)
Definition: protocol.c:82
pw_protocol_marshal::event_marshal
const void * event_marshal
Definition: protocol.h:76
pw_protocol_marshal::n_methods
uint32_t n_methods
number of methods in the interface
Definition: protocol.h:75
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:108
pw_protocol_marshal::method_demarshal
const void * method_demarshal
Definition: protocol.h:74
pw_protocol_marshal::method_marshal
const void * method_marshal
Definition: protocol.h:73