link: improve introspection

This commit is contained in:
Wim Taymans 2017-08-27 17:58:25 +02:00
parent 174d34ada6
commit 6afcb4981f
8 changed files with 64 additions and 32 deletions

View file

@ -292,7 +292,8 @@ static void core_marshal_info(void *object, struct pw_core_info *info)
SPA_POD_TYPE_STRING, info->host_name, SPA_POD_TYPE_STRING, info->host_name,
SPA_POD_TYPE_STRING, info->version, SPA_POD_TYPE_STRING, info->version,
SPA_POD_TYPE_STRING, info->name, SPA_POD_TYPE_STRING, info->name,
SPA_POD_TYPE_INT, info->cookie, SPA_POD_TYPE_INT, n_items, 0); SPA_POD_TYPE_INT, info->cookie,
SPA_POD_TYPE_INT, n_items, 0);
for (i = 0; i < n_items; i++) { for (i = 0; i < n_items; i++) {
spa_pod_builder_add(b, spa_pod_builder_add(b,
@ -779,16 +780,28 @@ static void link_marshal_info(void *object, struct pw_link_info *info)
struct pw_resource *resource = object; struct pw_resource *resource = object;
struct spa_pod_builder *b; struct spa_pod_builder *b;
struct spa_pod_frame f; struct spa_pod_frame f;
uint32_t i, n_items;
b = pw_protocol_native_begin_resource(resource, PW_LINK_PROXY_EVENT_INFO); b = pw_protocol_native_begin_resource(resource, PW_LINK_PROXY_EVENT_INFO);
spa_pod_builder_struct(b, &f, n_items = info->props ? info->props->n_items : 0;
SPA_POD_TYPE_LONG, info->change_mask,
SPA_POD_TYPE_INT, info->output_node_id, spa_pod_builder_add(b,
SPA_POD_TYPE_INT, info->output_port_id, SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, info->input_node_id, SPA_POD_TYPE_LONG, info->change_mask,
SPA_POD_TYPE_INT, info->input_port_id, SPA_POD_TYPE_INT, info->output_node_id,
SPA_POD_TYPE_POD, info->format); SPA_POD_TYPE_INT, info->output_port_id,
SPA_POD_TYPE_INT, info->input_node_id,
SPA_POD_TYPE_INT, info->input_port_id,
SPA_POD_TYPE_POD, info->format,
SPA_POD_TYPE_INT, n_items, 0);
for (i = 0; i < n_items; i++) {
spa_pod_builder_add(b,
SPA_POD_TYPE_STRING, info->props->items[i].key,
SPA_POD_TYPE_STRING, info->props->items[i].value, 0);
}
spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0);
pw_protocol_native_end_resource(resource, b); pw_protocol_native_end_resource(resource, b);
} }
@ -797,7 +810,9 @@ static bool link_demarshal_info(void *object, void *data, size_t size)
{ {
struct pw_proxy *proxy = object; struct pw_proxy *proxy = object;
struct spa_pod_iter it; struct spa_pod_iter it;
struct spa_dict props;
struct pw_link_info info = { 0, }; struct pw_link_info info = { 0, };
int i;
if (!spa_pod_iter_struct(&it, data, size) || if (!spa_pod_iter_struct(&it, data, size) ||
!spa_pod_iter_get(&it, !spa_pod_iter_get(&it,
@ -806,9 +821,18 @@ static bool link_demarshal_info(void *object, void *data, size_t size)
SPA_POD_TYPE_INT, &info.output_port_id, SPA_POD_TYPE_INT, &info.output_port_id,
SPA_POD_TYPE_INT, &info.input_node_id, SPA_POD_TYPE_INT, &info.input_node_id,
SPA_POD_TYPE_INT, &info.input_port_id, SPA_POD_TYPE_INT, &info.input_port_id,
-SPA_POD_TYPE_OBJECT, &info.format, 0)) -SPA_POD_TYPE_OBJECT, &info.format,
SPA_POD_TYPE_INT, &props.n_items, 0))
return false; return false;
info.props = &props;
props.items = alloca(props.n_items * sizeof(struct spa_dict_item));
for (i = 0; i < props.n_items; i++) {
if (!spa_pod_iter_get(&it,
SPA_POD_TYPE_STRING, &props.items[i].key,
SPA_POD_TYPE_STRING, &props.items[i].value, 0))
return false;
}
pw_proxy_notify(proxy, struct pw_link_proxy_events, info, &info); pw_proxy_notify(proxy, struct pw_link_proxy_events, info, &info);
return true; return true;
} }

View file

@ -245,7 +245,7 @@ void pw_client_update_properties(struct pw_client *client, const struct spa_dict
dict->items[i].key, dict->items[i].value); dict->items[i].key, dict->items[i].value);
} }
client->info.change_mask |= 1 << 0; client->info.change_mask |= PW_CLIENT_CHANGE_MASK_PROPS;
client->info.props = client->properties ? &client->properties->dict : NULL; client->info.props = client->properties ? &client->properties->dict : NULL;
spa_hook_list_call(&client->listener_list, struct pw_client_events, info_changed, &client->info); spa_hook_list_call(&client->listener_list, struct pw_client_events, info_changed, &client->info);

View file

@ -127,29 +127,29 @@ struct pw_core_info *pw_core_info_update(struct pw_core_info *info,
} }
info->change_mask = update->change_mask; info->change_mask = update->change_mask;
if (update->change_mask & (1 << 0)) { if (update->change_mask & PW_CORE_CHANGE_MASK_USER_NAME) {
if (info->user_name) if (info->user_name)
free((void *) info->user_name); free((void *) info->user_name);
info->user_name = update->user_name ? strdup(update->user_name) : NULL; info->user_name = update->user_name ? strdup(update->user_name) : NULL;
} }
if (update->change_mask & (1 << 1)) { if (update->change_mask & PW_CORE_CHANGE_MASK_HOST_NAME) {
if (info->host_name) if (info->host_name)
free((void *) info->host_name); free((void *) info->host_name);
info->host_name = update->host_name ? strdup(update->host_name) : NULL; info->host_name = update->host_name ? strdup(update->host_name) : NULL;
} }
if (update->change_mask & (1 << 2)) { if (update->change_mask & PW_CORE_CHANGE_MASK_VERSION) {
if (info->version) if (info->version)
free((void *) info->version); free((void *) info->version);
info->version = update->version ? strdup(update->version) : NULL; info->version = update->version ? strdup(update->version) : NULL;
} }
if (update->change_mask & (1 << 3)) { if (update->change_mask & PW_CORE_CHANGE_MASK_NAME) {
if (info->name) if (info->name)
free((void *) info->name); free((void *) info->name);
info->name = update->name ? strdup(update->name) : NULL; info->name = update->name ? strdup(update->name) : NULL;
} }
if (update->change_mask & (1 << 4)) if (update->change_mask & PW_CORE_CHANGE_MASK_COOKIE)
info->cookie = update->cookie; info->cookie = update->cookie;
if (update->change_mask & (1 << 5)) { if (update->change_mask & PW_CORE_CHANGE_MASK_PROPS) {
if (info->props) if (info->props)
pw_spa_dict_destroy(info->props); pw_spa_dict_destroy(info->props);
info->props = pw_spa_dict_copy(update->props); info->props = pw_spa_dict_copy(update->props);
@ -283,22 +283,22 @@ struct pw_module_info *pw_module_info_update(struct pw_module_info *info,
} }
info->change_mask = update->change_mask; info->change_mask = update->change_mask;
if (update->change_mask & (1 << 0)) { if (update->change_mask & PW_MODULE_CHANGE_MASK_NAME) {
if (info->name) if (info->name)
free((void *) info->name); free((void *) info->name);
info->name = update->name ? strdup(update->name) : NULL; info->name = update->name ? strdup(update->name) : NULL;
} }
if (update->change_mask & (1 << 1)) { if (update->change_mask & PW_MODULE_CHANGE_MASK_FILENAME) {
if (info->filename) if (info->filename)
free((void *) info->filename); free((void *) info->filename);
info->filename = update->filename ? strdup(update->filename) : NULL; info->filename = update->filename ? strdup(update->filename) : NULL;
} }
if (update->change_mask & (1 << 2)) { if (update->change_mask & PW_MODULE_CHANGE_MASK_ARGS) {
if (info->args) if (info->args)
free((void *) info->args); free((void *) info->args);
info->args = update->args ? strdup(update->args) : NULL; info->args = update->args ? strdup(update->args) : NULL;
} }
if (update->change_mask & (1 << 3)) { if (update->change_mask & PW_MODULE_CHANGE_MASK_PROPS) {
if (info->props) if (info->props)
pw_spa_dict_destroy(info->props); pw_spa_dict_destroy(info->props);
info->props = pw_spa_dict_copy(update->props); info->props = pw_spa_dict_copy(update->props);
@ -333,7 +333,7 @@ struct pw_client_info *pw_client_info_update(struct pw_client_info *info,
} }
info->change_mask = update->change_mask; info->change_mask = update->change_mask;
if (update->change_mask & (1 << 0)) { if (update->change_mask & PW_CLIENT_CHANGE_MASK_PROPS) {
if (info->props) if (info->props)
pw_spa_dict_destroy(info->props); pw_spa_dict_destroy(info->props);
info->props = pw_spa_dict_copy(update->props); info->props = pw_spa_dict_copy(update->props);
@ -361,15 +361,15 @@ struct pw_link_info *pw_link_info_update(struct pw_link_info *info,
} }
info->change_mask = update->change_mask; info->change_mask = update->change_mask;
if (update->change_mask & (1 << 0)) if (update->change_mask & PW_LINK_CHANGE_MASK_OUTPUT) {
info->output_node_id = update->output_node_id; info->output_node_id = update->output_node_id;
if (update->change_mask & (1 << 1))
info->output_port_id = update->output_port_id; info->output_port_id = update->output_port_id;
if (update->change_mask & (1 << 2)) }
if (update->change_mask & PW_LINK_CHANGE_MASK_INPUT) {
info->input_node_id = update->input_node_id; info->input_node_id = update->input_node_id;
if (update->change_mask & (1 << 3))
info->input_port_id = update->input_port_id; info->input_port_id = update->input_port_id;
if (update->change_mask & (1 << 4)) { }
if (update->change_mask & PW_LINK_CHANGE_MASK_FORMAT) {
if (info->format) if (info->format)
free(info->format); free(info->format);
info->format = spa_format_copy(update->format); info->format = spa_format_copy(update->format);

View file

@ -100,6 +100,10 @@ void pw_core_info_free(struct pw_core_info *info);
/** The module information. Extra information can be added in later versions \memberof pw_introspect */ /** The module information. Extra information can be added in later versions \memberof pw_introspect */
struct pw_module_info { struct pw_module_info {
#define PW_MODULE_CHANGE_MASK_NAME (1 << 0)
#define PW_MODULE_CHANGE_MASK_FILENAME (1 << 1)
#define PW_MODULE_CHANGE_MASK_ARGS (1 << 2)
#define PW_MODULE_CHANGE_MASK_PROPS (1 << 3)
uint64_t change_mask; /**< bitfield of changed fields since last call */ uint64_t change_mask; /**< bitfield of changed fields since last call */
const char *name; /**< name of the module */ const char *name; /**< name of the module */
const char *filename; /**< filename of the module */ const char *filename; /**< filename of the module */

View file

@ -1120,6 +1120,7 @@ struct pw_link *pw_link_new(struct pw_core *core,
this->info.input_node_id = input_node->global->id; this->info.input_node_id = input_node->global->id;
this->info.input_port_id = input->port_id; this->info.input_port_id = input->port_id;
this->info.format = NULL; this->info.format = NULL;
this->info.props = this->properties ? &this->properties->dict : NULL;
spa_graph_port_init(&this->rt.out_port, spa_graph_port_init(&this->rt.out_port,
PW_DIRECTION_OUTPUT, PW_DIRECTION_OUTPUT,

View file

@ -315,6 +315,7 @@ struct pw_node *pw_node_new(struct pw_core *core,
spa_hook_list_init(&this->listener_list); spa_hook_list_init(&this->listener_list);
this->info.state = PW_NODE_STATE_CREATING; this->info.state = PW_NODE_STATE_CREATING;
this->info.props = &this->properties->dict;
spa_list_init(&this->input_ports); spa_list_init(&this->input_ports);
pw_map_init(&this->input_port_map, 64, 64); pw_map_init(&this->input_port_map, 64, 64);

View file

@ -268,13 +268,13 @@ bool pw_port_add(struct pw_port *port, struct pw_node *node)
spa_list_insert(&node->input_ports, &port->link); spa_list_insert(&node->input_ports, &port->link);
pw_map_insert_at(&node->input_port_map, port_id, port); pw_map_insert_at(&node->input_port_map, port_id, port);
node->info.n_input_ports++; node->info.n_input_ports++;
node->info.change_mask |= 1 << 1; node->info.change_mask |= PW_NODE_CHANGE_MASK_INPUT_PORTS;
} }
else { else {
spa_list_insert(&node->output_ports, &port->link); spa_list_insert(&node->output_ports, &port->link);
pw_map_insert_at(&node->output_port_map, port_id, port); pw_map_insert_at(&node->output_port_map, port_id, port);
node->info.n_output_ports++; node->info.n_output_ports++;
node->info.change_mask |= 1 << 3; node->info.change_mask |= PW_NODE_CHANGE_MASK_OUTPUT_PORTS;
} }
spa_node_port_set_io(node->node, port->direction, port_id, &port->io); spa_node_port_set_io(node->node, port->direction, port_id, &port->io);

View file

@ -56,10 +56,12 @@ static void print_properties(struct spa_dict *props, char mark)
{ {
struct spa_dict_item *item; struct spa_dict_item *item;
if (props == NULL)
return;
printf("%c\tproperties:\n", mark); printf("%c\tproperties:\n", mark);
if (props == NULL || props->n_items == 0) {
printf("\t\tnone\n");
return;
}
spa_dict_for_each(item, props) { spa_dict_for_each(item, props) {
printf("%c\t\t%s = \"%s\"\n", mark, item->key, item->value); printf("%c\t\t%s = \"%s\"\n", mark, item->key, item->value);
} }
@ -238,7 +240,7 @@ static void link_event_info(void *object, struct pw_link_info *info)
if (info->format) if (info->format)
spa_debug_format(info->format); spa_debug_format(info->format);
else else
printf("\t none\n"); printf("\t\tnone\n");
print_properties(info->props, MARK_CHANGE(3)); print_properties(info->props, MARK_CHANGE(3));
} }
} }