core_proxy: prepare to rename pw_remote -> pw_core_proxy

The pw_remote object is really a wrapper around the pw_core_proxy.
The events it emits are also available in the core proxy and are
generally awkward to use.

With some clever new pw_core_proxy_* methods and a pw_core_connect
to create the core_proxy, we can convert all code away from pw_remote.

This is a first step in this conversion, using the pw_remote behind
the scenes. It leaks into some places because it really needs to become
its own struct in a next step.
This commit is contained in:
Wim Taymans 2019-12-06 11:48:40 +01:00
parent f8aabe69fe
commit 8a959ea7a1
37 changed files with 919 additions and 1185 deletions

View file

@ -91,14 +91,11 @@ struct impl {
struct pw_main_loop *loop;
struct spa_dbus *dbus;
struct pw_remote *monitor_remote;
struct spa_hook monitor_listener;
struct pw_core_proxy *monitor_core;
struct spa_hook monitor_listener;
struct pw_remote *policy_remote;
struct spa_hook policy_listener;
struct pw_core_proxy *policy_core;
struct spa_hook core_listener;
struct spa_hook policy_listener;
struct pw_registry_proxy *registry_proxy;
struct spa_hook registry_listener;
@ -1216,7 +1213,7 @@ struct pw_proxy *sm_media_session_export(struct sm_media_session *sess,
void *object, size_t user_data_size)
{
struct impl *impl = SPA_CONTAINER_OF(sess, struct impl, this);
return pw_remote_export(impl->monitor_remote, type,
return pw_core_proxy_export(impl->monitor_core, type,
properties, object, user_data_size);
}
@ -1229,7 +1226,7 @@ struct sm_device *sm_media_session_export_device(struct sm_media_session *sess,
pw_log_debug(NAME " %p: device %p", impl, object);
proxy = pw_remote_export(impl->monitor_remote, SPA_TYPE_INTERFACE_Device,
proxy = pw_core_proxy_export(impl->monitor_core, SPA_TYPE_INTERFACE_Device,
properties, object, sizeof(struct sm_device));
device = (struct sm_device *) create_object(impl, proxy, &properties->dict);
@ -1526,6 +1523,12 @@ static const struct pw_proxy_events client_session_proxy_events = {
static int start_session(struct impl *impl)
{
impl->monitor_core = pw_core_connect(impl->this.core, NULL, 0);
if (impl->monitor_core == NULL) {
pw_log_error("can't start monitor: %m");
return -errno;
}
impl->client_session = pw_core_proxy_create_object(impl->monitor_core,
"client-session",
PW_TYPE_INTERFACE_ClientSession,
@ -1543,11 +1546,6 @@ static int start_session(struct impl *impl)
return 0;
}
static int start_policy(struct impl *impl)
{
return sm_policy_ep_start(&impl->this);
}
static void core_done(void *data, uint32_t id, int seq)
{
struct impl *impl = data;
@ -1567,91 +1565,50 @@ static void core_done(void *data, uint32_t id, int seq)
}
}
static void on_monitor_state_changed(void *_data, enum pw_remote_state old,
enum pw_remote_state state, const char *error)
static void core_error(void *data, uint32_t id, int seq, int res, const char *message)
{
struct impl *impl = _data;
struct impl *impl = data;
switch (state) {
case PW_REMOTE_STATE_ERROR:
pw_log_error(NAME" %p: remote error: %s", impl, error);
pw_log_error("error id:%u seq:%d res:%d (%s): %s",
id, seq, res, spa_strerror(res), message);
if (id == 0) {
pw_main_loop_quit(impl->loop);
break;
case PW_REMOTE_STATE_CONNECTED:
pw_log_info(NAME" %p: connected", impl);
impl->monitor_core = pw_remote_get_core_proxy(impl->monitor_remote);
start_session(impl);
break;
case PW_REMOTE_STATE_UNCONNECTED:
pw_log_info(NAME" %p: disconnected", impl);
pw_main_loop_quit(impl->loop);
break;
default:
printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
break;
}
}
static const struct pw_remote_events monitor_remote_events = {
PW_VERSION_REMOTE_EVENTS,
.state_changed = on_monitor_state_changed,
};
static const struct pw_core_proxy_events core_events = {
PW_VERSION_CORE_EVENTS,
.done = core_done
.done = core_done,
.error = core_error
};
static void on_policy_state_changed(void *_data, enum pw_remote_state old,
enum pw_remote_state state, const char *error)
static int start_policy(struct impl *impl)
{
struct impl *impl = _data;
switch (state) {
case PW_REMOTE_STATE_ERROR:
pw_log_error(NAME" %p: remote error: %s", impl, error);
pw_main_loop_quit(impl->loop);
break;
case PW_REMOTE_STATE_CONNECTED:
pw_log_info(NAME" %p: connected", impl);
impl->policy_core = pw_remote_get_core_proxy(impl->policy_remote);
pw_core_proxy_add_listener(impl->policy_core,
&impl->core_listener,
&core_events, impl);
impl->registry_proxy = pw_core_proxy_get_registry(impl->policy_core,
PW_VERSION_REGISTRY_PROXY, 0);
pw_registry_proxy_add_listener(impl->registry_proxy,
&impl->registry_listener,
&registry_events, impl);
start_policy(impl);
break;
case PW_REMOTE_STATE_UNCONNECTED:
pw_log_info(NAME" %p: disconnected", impl);
pw_main_loop_quit(impl->loop);
break;
default:
printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
break;
impl->policy_core = pw_core_connect(impl->this.core, NULL, 0);
if (impl->policy_core == NULL) {
pw_log_error("can't start policy: %m");
return -errno;
}
}
static const struct pw_remote_events policy_remote_events = {
PW_VERSION_REMOTE_EVENTS,
.state_changed = on_policy_state_changed,
};
pw_core_proxy_add_listener(impl->policy_core,
&impl->policy_listener,
&core_events, impl);
impl->registry_proxy = pw_core_proxy_get_registry(impl->policy_core,
PW_VERSION_REGISTRY_PROXY, 0);
pw_registry_proxy_add_listener(impl->registry_proxy,
&impl->registry_listener,
&registry_events, impl);
return sm_policy_ep_start(&impl->this);
}
int main(int argc, char *argv[])
{
struct impl impl = { 0, };
const struct spa_support *support;
uint32_t n_support;
int res;
pw_init(&argc, &argv);
@ -1663,12 +1620,6 @@ int main(int argc, char *argv[])
pw_core_add_spa_lib(impl.this.core, "api.alsa.*", "alsa/libspa-alsa");
pw_core_add_spa_lib(impl.this.core, "api.v4l2.*", "v4l2/libspa-v4l2");
impl.monitor_remote = pw_remote_new(impl.this.core, NULL, 0);
pw_remote_add_listener(impl.monitor_remote, &impl.monitor_listener, &monitor_remote_events, &impl);
impl.policy_remote = pw_remote_new(impl.this.core, NULL, 0);
pw_remote_add_listener(impl.policy_remote, &impl.policy_listener, &policy_remote_events, &impl);
pw_map_init(&impl.globals, 64, 64);
spa_list_init(&impl.global_list);
pw_map_init(&impl.endpoint_links, 64, 64);
@ -1686,10 +1637,10 @@ int main(int argc, char *argv[])
else
pw_log_debug("got dbus connection %p", impl.this.dbus_connection);
if ((res = pw_remote_connect(impl.monitor_remote)) < 0)
return res;
if ((res = pw_remote_connect(impl.policy_remote)) < 0)
return res;
if (start_session(&impl) < 0)
return -1;
if (start_policy(&impl) < 0)
return -1;
pw_main_loop_run(impl.loop);