PipeWire  0.2.0
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 
39  struct spa_list link;
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 
60  struct spa_list link;
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 
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 
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 
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 *
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__ */
uint32_t version
version
Definition: protocol.h:72
Manages protocols and their implementation.
void(* disconnect)(struct pw_protocol_client *client)
Definition: protocol.h:49
A collection of key/value pairs.
Definition: properties.h:38
struct pw_protocol * pw_protocol_new(struct pw_core *core, const char *name, size_t user_data_size)
Definition: protocol.c:37
Definition: protocol.h:81
Definition: protocol.h:70
uint32_t version
Definition: protocol.h:95
int(* steal_fd)(struct pw_protocol_client *client)
Definition: protocol.h:48
int pw_protocol_add_marshal(struct pw_protocol *protocol, const struct pw_protocol_marshal *marshal)
Definition: protocol.c:117
const char * type
interface type
Definition: protocol.h:71
uint32_t n_events
number of events in the interface
Definition: protocol.h:78
Definition: protocol.h:38
the core PipeWire object
struct pw_protocol * protocol
the owner protocol
Definition: protocol.h:40
int(* connect_fd)(struct pw_protocol_client *client, int fd)
Definition: protocol.h:47
const void * pw_protocol_get_extension(struct pw_protocol *protocol)
Definition: protocol.c:77
void(* destroy)(struct pw_protocol_server *listen)
Definition: protocol.h:65
const struct pw_protocol_implementaton * pw_protocol_get_implementation(struct pw_protocol *protocol)
Definition: protocol.c:71
Represents a connection with a remote PipeWire instance.
struct spa_list link
link in protocol server_list
Definition: protocol.h:60
void(* destroy)(void *data)
Definition: protocol.h:97
Definition: protocol.h:59
const void * event_demarshal
Definition: protocol.h:77
uint32_t version
Definition: protocol.h:83
Definition: protocol.h:93
struct pw_remote * remote
the associated remote
Definition: protocol.h:42
void(* destroy)(struct pw_protocol_client *client)
Definition: protocol.h:50
struct spa_list link
link in protocol client_list
Definition: protocol.h:39
struct spa_list client_list
list of clients of this protocol
Definition: protocol.h:63
void * pw_protocol_get_user_data(struct pw_protocol *protocol)
Definition: protocol.c:65
int(* connect)(struct pw_protocol_client *client, void(*done_callback)(void *data, int result), void *data)
Definition: protocol.h:44
const struct pw_protocol_marshal * pw_protocol_get_marshal(struct pw_protocol *protocol, uint32_t type)
Definition: protocol.c:138
struct pw_protocol * pw_core_find_protocol(struct pw_core *core, const char *name)
Definition: protocol.c:152
struct pw_protocol * protocol
the owner protocol
Definition: protocol.h:61
void pw_protocol_destroy(struct pw_protocol *protocol)
Definition: protocol.c:82
const void * event_marshal
Definition: protocol.h:76
uint32_t n_methods
number of methods in the interface
Definition: protocol.h:75
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
const void * method_demarshal
Definition: protocol.h:74
const void * method_marshal
Definition: protocol.h:73