2017-05-23 19:15:33 +02:00
|
|
|
/* PipeWire
|
2015-04-16 16:58:33 +02:00
|
|
|
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2017-02-24 09:28:18 +01:00
|
|
|
#include <spa/lib/debug.h>
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2017-07-11 15:57:20 +02:00
|
|
|
#include <pipewire/pipewire.h>
|
2017-07-12 18:04:00 +02:00
|
|
|
#include <pipewire/interfaces.h>
|
|
|
|
|
#include <pipewire/type.h>
|
2017-07-11 15:57:20 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct data {
|
2017-05-26 08:05:01 +02:00
|
|
|
bool running;
|
|
|
|
|
struct pw_loop *loop;
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_core *core;
|
2017-08-04 10:18:54 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_remote *remote;
|
2017-08-08 16:56:29 +02:00
|
|
|
struct spa_hook remote_listener;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
struct pw_core_proxy *core_proxy;
|
|
|
|
|
|
|
|
|
|
struct pw_registry_proxy *registry_proxy;
|
2017-08-08 16:56:29 +02:00
|
|
|
struct spa_hook registry_listener;
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct proxy_data {
|
2017-08-04 10:18:54 +02:00
|
|
|
struct pw_proxy *proxy;
|
2017-07-13 15:21:52 +02:00
|
|
|
uint32_t id;
|
2017-07-18 14:58:14 +02:00
|
|
|
uint32_t parent_id;
|
2017-08-01 17:09:57 +02:00
|
|
|
uint32_t permissions;
|
2017-07-13 15:21:52 +02:00
|
|
|
uint32_t version;
|
2017-08-04 10:18:54 +02:00
|
|
|
uint32_t type;
|
2017-07-11 12:24:03 +02:00
|
|
|
void *info;
|
2017-08-04 10:18:54 +02:00
|
|
|
pw_destroy_t destroy;
|
2017-08-08 16:56:29 +02:00
|
|
|
struct spa_hook proxy_listener;
|
|
|
|
|
struct spa_hook proxy_proxy_listener;
|
2017-05-23 19:15:33 +02:00
|
|
|
};
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
static void print_properties(struct spa_dict *props, char mark)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct spa_dict_item *item;
|
2015-07-28 17:05:03 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (props == NULL)
|
|
|
|
|
return;
|
2016-02-01 16:29:56 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("%c\tproperties:\n", mark);
|
|
|
|
|
spa_dict_for_each(item, props) {
|
|
|
|
|
printf("%c\t\t%s = \"%s\"\n", mark, item->key, item->value);
|
|
|
|
|
}
|
2016-01-07 12:15:57 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
#define MARK_CHANGE(f) ((print_mark && ((info)->change_mask & (1 << (f)))) ? '*' : ' ')
|
2016-02-01 16:29:56 +01:00
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
static void on_info_changed(void *data, const struct pw_core_info *info)
|
2016-01-07 12:15:57 +01:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
bool print_all = true, print_mark = false;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-07-13 15:21:52 +02:00
|
|
|
printf("\ttype: %s\n", PW_TYPE_INTERFACE__Core);
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("%c\tuser-name: \"%s\"\n", MARK_CHANGE(0), info->user_name);
|
|
|
|
|
printf("%c\thost-name: \"%s\"\n", MARK_CHANGE(1), info->host_name);
|
|
|
|
|
printf("%c\tversion: \"%s\"\n", MARK_CHANGE(2), info->version);
|
|
|
|
|
printf("%c\tname: \"%s\"\n", MARK_CHANGE(3), info->name);
|
|
|
|
|
printf("%c\tcookie: %u\n", MARK_CHANGE(4), info->cookie);
|
|
|
|
|
print_properties(info->props, MARK_CHANGE(5));
|
|
|
|
|
}
|
2016-12-02 13:38:43 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
static void module_event_info(void *object, struct pw_module_info *info)
|
2016-12-02 13:38:43 +01:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_proxy *proxy = object;
|
2017-08-04 10:18:54 +02:00
|
|
|
struct proxy_data *data = pw_proxy_get_user_data(proxy);
|
2017-07-11 12:24:03 +02:00
|
|
|
bool print_all, print_mark;
|
2016-12-02 13:38:43 +01:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
print_all = true;
|
|
|
|
|
if (data->info == NULL) {
|
|
|
|
|
printf("added:\n");
|
|
|
|
|
print_mark = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("changed:\n");
|
|
|
|
|
print_mark = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info = data->info = pw_module_info_update(data->info, info);
|
2016-12-02 13:38:43 +01:00
|
|
|
|
2017-07-13 15:21:52 +02:00
|
|
|
printf("\tid: %d\n", data->id);
|
2017-07-18 14:58:14 +02:00
|
|
|
printf("\tparent_id: %d\n", data->parent_id);
|
2017-08-01 17:09:57 +02:00
|
|
|
printf("\tpermissions: %c%c%c\n", data->permissions & PW_PERM_R ? 'r' : '-',
|
|
|
|
|
data->permissions & PW_PERM_W ? 'w' : '-',
|
|
|
|
|
data->permissions & PW_PERM_X ? 'x' : '-');
|
2017-07-13 15:21:52 +02:00
|
|
|
printf("\ttype: %s (version %d)\n", PW_TYPE_INTERFACE__Module, data->version);
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
|
|
|
|
printf("%c\tname: \"%s\"\n", MARK_CHANGE(0), info->name);
|
|
|
|
|
printf("%c\tfilename: \"%s\"\n", MARK_CHANGE(1), info->filename);
|
|
|
|
|
printf("%c\targs: \"%s\"\n", MARK_CHANGE(2), info->args);
|
|
|
|
|
print_properties(info->props, MARK_CHANGE(3));
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
static const struct pw_module_proxy_events module_events = {
|
|
|
|
|
PW_VERSION_MODULE_PROXY_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.info = module_event_info,
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void node_event_info(void *object, struct pw_node_info *info)
|
2016-07-20 17:55:02 +02:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_proxy *proxy = object;
|
2017-08-04 10:18:54 +02:00
|
|
|
struct proxy_data *data = pw_proxy_get_user_data(proxy);
|
2017-07-11 12:24:03 +02:00
|
|
|
bool print_all, print_mark;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
print_all = true;
|
|
|
|
|
if (data->info == NULL) {
|
|
|
|
|
printf("added:\n");
|
|
|
|
|
print_mark = false;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2017-07-11 12:24:03 +02:00
|
|
|
else {
|
|
|
|
|
printf("changed:\n");
|
|
|
|
|
print_mark = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info = data->info = pw_node_info_update(data->info, info);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-07-13 15:21:52 +02:00
|
|
|
printf("\tid: %d\n", data->id);
|
2017-07-18 14:58:14 +02:00
|
|
|
printf("\tparent_id: %d\n", data->parent_id);
|
2017-08-01 17:09:57 +02:00
|
|
|
printf("\tpermissions: %c%c%c\n", data->permissions & PW_PERM_R ? 'r' : '-',
|
|
|
|
|
data->permissions & PW_PERM_W ? 'w' : '-',
|
|
|
|
|
data->permissions & PW_PERM_X ? 'x' : '-');
|
2017-07-13 15:21:52 +02:00
|
|
|
printf("\ttype: %s (version %d)\n", PW_TYPE_INTERFACE__Node, data->version);
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
2017-05-26 08:05:01 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
printf("%c\tname: \"%s\"\n", MARK_CHANGE(0), info->name);
|
2017-06-02 10:40:43 +02:00
|
|
|
printf("%c\tinput ports: %u/%u\n", MARK_CHANGE(1), info->n_input_ports, info->max_input_ports);
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("%c\tinput formats:\n", MARK_CHANGE(2));
|
|
|
|
|
for (i = 0; i < info->n_input_formats; i++)
|
2017-06-06 13:30:34 +02:00
|
|
|
spa_debug_format(info->input_formats[i]);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-06-02 10:40:43 +02:00
|
|
|
printf("%c\toutput ports: %u/%u\n", MARK_CHANGE(3), info->n_output_ports, info->max_output_ports);
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("%c\toutput formats:\n", MARK_CHANGE(4));
|
|
|
|
|
for (i = 0; i < info->n_output_formats; i++)
|
2017-06-06 13:30:34 +02:00
|
|
|
spa_debug_format(info->output_formats[i]);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
printf("%c\tstate: \"%s\"", MARK_CHANGE(5), pw_node_state_as_string(info->state));
|
|
|
|
|
if (info->state == PW_NODE_STATE_ERROR && info->error)
|
|
|
|
|
printf(" \"%s\"\n", info->error);
|
|
|
|
|
else
|
|
|
|
|
printf("\n");
|
|
|
|
|
print_properties(info->props, MARK_CHANGE(6));
|
|
|
|
|
}
|
2016-07-20 17:55:02 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
static const struct pw_node_proxy_events node_events = {
|
|
|
|
|
PW_VERSION_NODE_PROXY_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.info = node_event_info
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void client_event_info(void *object, struct pw_client_info *info)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_proxy *proxy = object;
|
2017-08-04 10:18:54 +02:00
|
|
|
struct proxy_data *data = pw_proxy_get_user_data(proxy);
|
2017-07-11 12:24:03 +02:00
|
|
|
bool print_all, print_mark;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
print_all = true;
|
|
|
|
|
if (data->info == NULL) {
|
|
|
|
|
printf("added:\n");
|
|
|
|
|
print_mark = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("changed:\n");
|
|
|
|
|
print_mark = true;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
info = data->info = pw_client_info_update(data->info, info);
|
|
|
|
|
|
2017-07-13 15:21:52 +02:00
|
|
|
printf("\tid: %d\n", data->id);
|
2017-07-18 14:58:14 +02:00
|
|
|
printf("\tparent_id: %d\n", data->parent_id);
|
2017-08-01 17:09:57 +02:00
|
|
|
printf("\tpermissions: %c%c%c\n", data->permissions & PW_PERM_R ? 'r' : '-',
|
|
|
|
|
data->permissions & PW_PERM_W ? 'w' : '-',
|
|
|
|
|
data->permissions & PW_PERM_X ? 'x' : '-');
|
2017-07-13 15:21:52 +02:00
|
|
|
printf("\ttype: %s (version %d)\n", PW_TYPE_INTERFACE__Client, data->version);
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
|
|
|
|
print_properties(info->props, MARK_CHANGE(0));
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
static const struct pw_client_proxy_events client_events = {
|
|
|
|
|
PW_VERSION_CLIENT_PROXY_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.info = client_event_info
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void link_event_info(void *object, struct pw_link_info *info)
|
2016-07-20 17:55:02 +02:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_proxy *proxy = object;
|
2017-08-04 10:18:54 +02:00
|
|
|
struct proxy_data *data = pw_proxy_get_user_data(proxy);
|
2017-07-11 12:24:03 +02:00
|
|
|
bool print_all, print_mark;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
print_all = true;
|
|
|
|
|
if (data->info == NULL) {
|
|
|
|
|
printf("added:\n");
|
|
|
|
|
print_mark = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("changed:\n");
|
|
|
|
|
print_mark = true;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
info = data->info = pw_link_info_update(data->info, info);
|
|
|
|
|
|
2017-07-13 15:21:52 +02:00
|
|
|
printf("\tid: %d\n", data->id);
|
2017-07-18 14:58:14 +02:00
|
|
|
printf("\tparent_id: %d\n", data->parent_id);
|
2017-08-01 17:09:57 +02:00
|
|
|
printf("\tpermissions: %c%c%c\n", data->permissions & PW_PERM_R ? 'r' : '-',
|
|
|
|
|
data->permissions & PW_PERM_W ? 'w' : '-',
|
|
|
|
|
data->permissions & PW_PERM_X ? 'x' : '-');
|
2017-07-13 15:21:52 +02:00
|
|
|
printf("\ttype: %s (version %d)\n", PW_TYPE_INTERFACE__Link, data->version);
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("%c\toutput-node-id: %u\n", MARK_CHANGE(0), info->output_node_id);
|
|
|
|
|
printf("%c\toutput-port-id: %u\n", MARK_CHANGE(1), info->output_port_id);
|
|
|
|
|
printf("%c\tinput-node-id: %u\n", MARK_CHANGE(2), info->input_node_id);
|
|
|
|
|
printf("%c\tinput-port-id: %u\n", MARK_CHANGE(3), info->input_port_id);
|
2017-06-02 10:40:43 +02:00
|
|
|
printf("%c\tformat:\n", MARK_CHANGE(4));
|
|
|
|
|
if (info->format)
|
2017-06-06 13:30:34 +02:00
|
|
|
spa_debug_format(info->format);
|
2017-06-02 10:40:43 +02:00
|
|
|
else
|
|
|
|
|
printf("\t none\n");
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
static const struct pw_link_proxy_events link_events = {
|
|
|
|
|
PW_VERSION_LINK_PROXY_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.info = link_event_info
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
2015-07-28 17:05:03 +02:00
|
|
|
static void
|
2017-07-11 12:24:03 +02:00
|
|
|
destroy_proxy (void *data)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2017-08-04 10:18:54 +02:00
|
|
|
struct proxy_data *user_data = data;
|
2017-07-11 12:24:03 +02:00
|
|
|
|
|
|
|
|
if (user_data->info == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
if (user_data->destroy)
|
|
|
|
|
user_data->destroy(user_data->info);
|
2017-07-11 12:24:03 +02:00
|
|
|
user_data->info = NULL;
|
|
|
|
|
}
|
2016-12-02 13:38:43 +01:00
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
static const struct pw_proxy_events proxy_events = {
|
|
|
|
|
PW_VERSION_PROXY_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.destroy = destroy_proxy,
|
|
|
|
|
};
|
2017-01-10 17:12:53 +01:00
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
static void registry_event_global(void *data, uint32_t id, uint32_t parent_id,
|
2017-08-01 17:09:57 +02:00
|
|
|
uint32_t permissions, uint32_t type, uint32_t version)
|
2017-07-11 12:24:03 +02:00
|
|
|
{
|
2017-08-04 10:18:54 +02:00
|
|
|
struct data *d = data;
|
|
|
|
|
struct pw_proxy *proxy;
|
2017-07-11 18:41:22 +02:00
|
|
|
uint32_t client_version;
|
2017-07-13 15:21:52 +02:00
|
|
|
const void *events;
|
2017-08-04 10:18:54 +02:00
|
|
|
struct pw_core *core = d->core;
|
|
|
|
|
struct pw_type *t = pw_core_get_type(core);
|
2017-07-13 15:21:52 +02:00
|
|
|
struct proxy_data *pd;
|
2017-08-04 10:18:54 +02:00
|
|
|
pw_destroy_t destroy;
|
2017-07-11 12:24:03 +02:00
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
if (type == t->node) {
|
2017-07-13 15:21:52 +02:00
|
|
|
events = &node_events;
|
|
|
|
|
client_version = PW_VERSION_NODE;
|
2017-08-04 10:18:54 +02:00
|
|
|
destroy = (pw_destroy_t) pw_node_info_free;
|
2017-07-11 18:41:22 +02:00
|
|
|
}
|
2017-08-04 10:18:54 +02:00
|
|
|
else if (type == t->module) {
|
2017-07-13 15:21:52 +02:00
|
|
|
events = &module_events;
|
|
|
|
|
client_version = PW_VERSION_MODULE;
|
2017-08-04 10:18:54 +02:00
|
|
|
destroy = (pw_destroy_t) pw_module_info_free;
|
2017-07-11 18:41:22 +02:00
|
|
|
}
|
2017-08-04 10:18:54 +02:00
|
|
|
else if (type == t->client) {
|
2017-07-13 15:21:52 +02:00
|
|
|
events = &client_events;
|
|
|
|
|
client_version = PW_VERSION_CLIENT;
|
2017-08-04 10:18:54 +02:00
|
|
|
destroy = (pw_destroy_t) pw_client_info_free;
|
2017-07-11 18:41:22 +02:00
|
|
|
}
|
2017-08-04 10:18:54 +02:00
|
|
|
else if (type == t->link) {
|
2017-07-13 15:21:52 +02:00
|
|
|
events = &link_events;
|
|
|
|
|
client_version = PW_VERSION_LINK;
|
2017-08-04 10:18:54 +02:00
|
|
|
destroy = (pw_destroy_t) pw_link_info_free;
|
2017-07-13 15:21:52 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("added:\n");
|
|
|
|
|
printf("\tid: %u\n", id);
|
2017-07-18 14:58:14 +02:00
|
|
|
printf("\tparent_id: %d\n", parent_id);
|
2017-08-01 17:09:57 +02:00
|
|
|
printf("\tpermissions: %c%c%c\n", permissions & PW_PERM_R ? 'r' : '-',
|
|
|
|
|
permissions & PW_PERM_W ? 'w' : '-',
|
|
|
|
|
permissions & PW_PERM_X ? 'x' : '-');
|
2017-08-04 10:18:54 +02:00
|
|
|
printf("\ttype: %s (version %d)\n", spa_type_map_get_type(t->map, type), version);
|
2017-07-13 15:21:52 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2017-07-11 12:24:03 +02:00
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
proxy = pw_registry_proxy_bind(d->registry_proxy, id, type,
|
|
|
|
|
client_version,
|
|
|
|
|
sizeof(struct proxy_data));
|
2017-07-11 12:24:03 +02:00
|
|
|
if (proxy == NULL)
|
|
|
|
|
goto no_mem;
|
|
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
pd = pw_proxy_get_user_data(proxy);
|
|
|
|
|
pd->proxy = proxy;
|
2017-07-13 15:21:52 +02:00
|
|
|
pd->id = id;
|
2017-07-18 14:58:14 +02:00
|
|
|
pd->parent_id = parent_id;
|
2017-08-01 17:09:57 +02:00
|
|
|
pd->permissions = permissions;
|
2017-07-13 15:21:52 +02:00
|
|
|
pd->version = version;
|
2017-08-04 10:18:54 +02:00
|
|
|
pd->destroy = destroy;
|
2017-08-04 16:49:13 +02:00
|
|
|
pw_proxy_add_proxy_listener(proxy, &pd->proxy_proxy_listener, events, pd);
|
|
|
|
|
pw_proxy_add_listener(proxy, &pd->proxy_listener, &proxy_events, pd);
|
2017-07-11 12:24:03 +02:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
no_mem:
|
|
|
|
|
printf("failed to create proxy");
|
|
|
|
|
return;
|
2015-04-27 09:05:14 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
static void registry_event_global_remove(void *object, uint32_t id)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
printf("removed:\n");
|
|
|
|
|
printf("\tid: %u\n", id);
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
static const struct pw_registry_proxy_events registry_events = {
|
|
|
|
|
PW_VERSION_REGISTRY_PROXY_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.global = registry_event_global,
|
|
|
|
|
.global_remove = registry_event_global_remove,
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
static void on_state_changed(void *_data, enum pw_remote_state old,
|
|
|
|
|
enum pw_remote_state state, const char *error)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2017-08-04 10:18:54 +02:00
|
|
|
struct data *data = _data;
|
|
|
|
|
struct pw_type *t = pw_core_get_type(data->core);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
switch (state) {
|
2017-07-11 15:57:20 +02:00
|
|
|
case PW_REMOTE_STATE_ERROR:
|
2017-08-04 10:18:54 +02:00
|
|
|
printf("remote error: %s\n", error);
|
2017-05-26 08:05:01 +02:00
|
|
|
data->running = false;
|
|
|
|
|
break;
|
|
|
|
|
|
2017-07-11 15:57:20 +02:00
|
|
|
case PW_REMOTE_STATE_CONNECTED:
|
2017-08-04 10:18:54 +02:00
|
|
|
printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
|
2017-07-11 12:24:03 +02:00
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
data->core_proxy = pw_remote_get_core_proxy(data->remote);
|
|
|
|
|
data->registry_proxy = pw_core_proxy_get_registry(data->core_proxy,
|
|
|
|
|
t->registry,
|
|
|
|
|
PW_VERSION_REGISTRY, 0);
|
2017-07-13 15:21:52 +02:00
|
|
|
pw_registry_proxy_add_listener(data->registry_proxy,
|
2017-08-04 10:18:54 +02:00
|
|
|
&data->registry_listener,
|
|
|
|
|
®istry_events, data);
|
2017-07-11 12:24:03 +02:00
|
|
|
break;
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
default:
|
2017-08-04 10:18:54 +02:00
|
|
|
printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
|
2017-05-26 08:05:01 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
static const struct pw_remote_events remote_events = {
|
|
|
|
|
PW_VERSION_REMOTE_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.info_changed = on_info_changed,
|
|
|
|
|
.state_changed = on_state_changed,
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
int main(int argc, char *argv[])
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
struct data data = { 0 };
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
pw_init(&argc, &argv);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
data.loop = pw_loop_new();
|
|
|
|
|
data.running = true;
|
2017-07-11 12:24:03 +02:00
|
|
|
data.core = pw_core_new(data.loop, NULL);
|
|
|
|
|
data.remote = pw_remote_new(data.core, NULL);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data);
|
2017-07-11 12:24:03 +02:00
|
|
|
pw_remote_connect(data.remote);
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
pw_loop_enter(data.loop);
|
|
|
|
|
while (data.running) {
|
|
|
|
|
pw_loop_iterate(data.loop, -1);
|
|
|
|
|
}
|
|
|
|
|
pw_loop_leave(data.loop);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
pw_remote_destroy(data.remote);
|
2017-05-26 08:05:01 +02:00
|
|
|
pw_loop_destroy(data.loop);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
return 0;
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|