summaryrefslogtreecommitdiffstats
path: root/src/modules/module-session-manager/proxy-session-manager.c
blob: cd418e191bf1ae75c99ce8e75e0051c0567f854c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* PipeWire
 *
 * Copyright © 2020 Collabora Ltd.
 *   @author George Kiagiadakis <george.kiagiadakis@collabora.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include "pipewire/pipewire.h"
#include "pipewire/extensions/session-manager.h"

struct object_data {
	struct spa_hook object_listener;
	struct spa_hook object_methods;
	struct spa_hook proxy_listener;
};

static void proxy_object_destroy(void *_data)
{
	struct object_data *data = _data;
	spa_hook_remove(&data->object_listener);
}

static const struct pw_proxy_events proxy_events = {
	PW_VERSION_PROXY_EVENTS,
	.destroy = proxy_object_destroy,
};

struct pw_proxy *pw_core_endpoint_export(struct pw_core *core,
		const char *type, const struct spa_dict *props, void *object,
		size_t user_data_size)
{
	struct pw_endpoint *endpoint = object;
	struct spa_interface *remote_iface, *local_iface;
	struct pw_proxy *proxy;
	struct object_data *data;

	proxy = pw_core_create_object(core,
				    "endpoint",
				    PW_TYPE_INTERFACE_Endpoint,
				    PW_VERSION_ENDPOINT,
				    props,
				    user_data_size + sizeof(struct object_data));
        if (proxy == NULL)
		return NULL;

	data = pw_proxy_get_user_data(proxy);
	data = SPA_PTROFF(data, user_data_size, struct object_data);

	remote_iface = (struct spa_interface*)proxy;
	local_iface = (struct spa_interface*)endpoint;

	pw_proxy_install_marshal(proxy, true);

	pw_proxy_add_listener(proxy, &data->proxy_listener, &proxy_events, data);

	pw_proxy_add_object_listener(proxy, &data->object_methods,
			local_iface->cb.funcs, local_iface->cb.data);
	pw_endpoint_add_listener(endpoint, &data->object_listener,
			remote_iface->cb.funcs, remote_iface->cb.data);

	return proxy;
}

struct pw_proxy *pw_core_endpoint_stream_export(struct pw_core *core,
		const char *type, const struct spa_dict *props, void *object,
		size_t user_data_size)
{
	struct pw_endpoint_stream *endpoint_stream = object;
	struct spa_interface *remote_iface, *local_iface;
	struct pw_proxy *proxy;
	struct object_data *data;

	proxy = pw_core_create_object(core,
				    "endpoint-stream",
				    PW_TYPE_INTERFACE_EndpointStream,
				    PW_VERSION_ENDPOINT_STREAM,
				    props,
				    user_data_size + sizeof(struct object_data));
        if (proxy == NULL)
		return NULL;

	data = pw_proxy_get_user_data(proxy);
	data = SPA_PTROFF(data, user_data_size, struct object_data);

	remote_iface = (struct spa_interface*)proxy;
	local_iface = (struct spa_interface*)endpoint_stream;

	pw_proxy_install_marshal(proxy, true);

	pw_proxy_add_listener(proxy, &data->proxy_listener, &proxy_events, data);

	pw_proxy_add_object_listener(proxy, &data->object_methods,
			local_iface->cb.funcs, local_iface->cb.data);
	pw_endpoint_stream_add_listener(endpoint_stream, &data->object_listener,
			remote_iface->cb.funcs, remote_iface->cb.data);

	return proxy;
}

struct pw_proxy *pw_core_endpoint_link_export(struct pw_core *core,
		const char *type, const struct spa_dict *props, void *object,
		size_t user_data_size)
{
	struct pw_endpoint_link *endpoint_link = object;
	struct spa_interface *remote_iface, *local_iface;
	struct pw_proxy *proxy;
	struct object_data *data;

	proxy = pw_core_create_object(core,
				    "endpoint-link",
				    PW_TYPE_INTERFACE_EndpointLink,
				    PW_VERSION_ENDPOINT_LINK,
				    props,
				    user_data_size + sizeof(struct object_data));
        if (proxy == NULL)
		return NULL;

	data = pw_proxy_get_user_data(proxy);
	data = SPA_PTROFF(data, user_data_size, struct object_data);

	remote_iface = (struct spa_interface*)proxy;
	local_iface = (struct spa_interface*)endpoint_link;

	pw_proxy_install_marshal(proxy, true);

	pw_proxy_add_listener(proxy, &data->proxy_listener, &proxy_events, data);

	pw_proxy_add_object_listener(proxy, &data->object_methods,
			local_iface->cb.funcs, local_iface->cb.data);
	pw_endpoint_link_add_listener(endpoint_link, &data->object_listener,
			remote_iface->cb.funcs, remote_iface->cb.data);

	return proxy;
}

struct pw_proxy *pw_core_session_export(struct pw_core *core,
		const char *type, const struct spa_dict *props, void *object,
		size_t user_data_size)
{
	struct pw_session *session = object;
	struct spa_interface *remote_iface, *local_iface;
	struct pw_proxy *proxy;
	struct object_data *data;

	proxy = pw_core_create_object(core,
				    "session",
				    PW_TYPE_INTERFACE_Session,
				    PW_VERSION_SESSION,
				    props,
				    user_data_size + sizeof(struct object_data));
        if (proxy == NULL)
		return NULL;

	data = pw_proxy_get_user_data(proxy);
	data = SPA_PTROFF(data, user_data_size, struct object_data);

	remote_iface = (struct spa_interface*)proxy;
	local_iface = (struct spa_interface*)session;

	pw_proxy_install_marshal(proxy, true);

	pw_proxy_add_listener(proxy, &data->proxy_listener, &proxy_events, data);

	pw_proxy_add_object_listener(proxy, &data->object_methods,
			local_iface->cb.funcs, local_iface->cb.data);
	pw_session_add_listener(session, &data->object_listener,
			remote_iface->cb.funcs, remote_iface->cb.data);

	return proxy;
}