From 8ce3f949e293d82c78da278fd5ce556d72d27d01 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 15 Dec 2016 20:09:48 +0100 Subject: [PATCH] Add core introspection Use global ids in info messages to refer to global objects. --- pinos/client/context.c | 23 +++++++++++++ pinos/client/introspect.c | 69 ++++++++++++++++++++++++++++++++++++- pinos/client/serialize.c | 1 - pinos/client/stream.c | 1 - pinos/server/client.c | 2 +- pinos/server/core.c | 2 +- pinos/server/link.c | 2 +- pinos/server/module.c | 2 +- pinos/server/node.c | 4 +-- pinos/tools/pinos-monitor.c | 5 +++ 10 files changed, 102 insertions(+), 9 deletions(-) diff --git a/pinos/client/context.c b/pinos/client/context.c index 965bff37e..93330884b 100644 --- a/pinos/client/context.c +++ b/pinos/client/context.c @@ -103,8 +103,31 @@ core_dispatch_func (void *object, { PinosContextImpl *impl = data; PinosContext *this = &impl->this; + PinosProxy *proxy = object; switch (type) { + case PINOS_MESSAGE_CORE_INFO: + { + PinosMessageCoreInfo *m = message; + PinosSubscriptionEvent event; + + pinos_log_debug ("got core info %d", type); + if (proxy->user_data == NULL) + event = PINOS_SUBSCRIPTION_EVENT_NEW; + else + event = PINOS_SUBSCRIPTION_EVENT_CHANGE; + + proxy->user_data = pinos_core_info_update (proxy->user_data, m->info); + + if (impl->subscribe_func) { + impl->subscribe_func (this, + event, + proxy->type, + proxy->id, + impl->subscribe_data); + } + break; + } case PINOS_MESSAGE_NOTIFY_DONE: { PinosMessageNotifyDone *nd = message; diff --git a/pinos/client/introspect.c b/pinos/client/introspect.c index 806b294ef..a87a24a1f 100644 --- a/pinos/client/introspect.c +++ b/pinos/client/introspect.c @@ -137,6 +137,73 @@ pinos_spa_dict_copy (SpaDict *dict) return copy; } +PinosCoreInfo * +pinos_core_info_update (PinosCoreInfo *info, + const PinosCoreInfo *update) +{ + uint64_t change_mask; + + if (update == NULL) + return info; + + if (info == NULL) { + info = calloc (1, sizeof (PinosCoreInfo)); + change_mask = ~0; + } else { + change_mask = info->change_mask | update->change_mask; + } + info->id = update->id; + info->change_mask = change_mask; + + if (update->change_mask & (1 << 0)) { + if (info->user_name) + free ((void*)info->user_name); + info->user_name = update->user_name ? strdup (update->user_name) : NULL; + } + if (update->change_mask & (1 << 1)) { + if (info->host_name) + free ((void*)info->host_name); + info->host_name = update->host_name ? strdup (update->host_name) : NULL; + } + if (update->change_mask & (1 << 2)) { + if (info->version) + free ((void*)info->version); + info->version = update->version ? strdup (update->version) : NULL; + } + if (update->change_mask & (1 << 3)) { + if (info->name) + free ((void*)info->name); + info->name = update->name ? strdup (update->name) : NULL; + } + if (update->change_mask & (1 << 4)) + info->cookie = update->cookie; + if (update->change_mask & (1 << 5)) { + if (info->props) + pinos_spa_dict_destroy (info->props); + info->props = pinos_spa_dict_copy (update->props); + } + return info; +} + +void +pinos_core_info_free (PinosCoreInfo *info) +{ + if (info == NULL) + return; + + if (info->user_name) + free ((void*)info->user_name); + if (info->host_name) + free ((void*)info->host_name); + if (info->version) + free ((void*)info->version); + if (info->name) + free ((void*)info->name); + if (info->props) + pinos_spa_dict_destroy (info->props); + free (info); +} + PinosNodeInfo * pinos_node_info_update (PinosNodeInfo *info, const PinosNodeInfo *update) @@ -225,7 +292,7 @@ pinos_module_info_update (PinosModuleInfo *info, } void -pinos_module_info_free (PinosModuleInfo *info) +pinos_module_info_free (PinosModuleInfo *info) { if (info == NULL) return; diff --git a/pinos/client/serialize.c b/pinos/client/serialize.c index 214162242..43f890481 100644 --- a/pinos/client/serialize.c +++ b/pinos/client/serialize.c @@ -69,7 +69,6 @@ SpaBuffer * pinos_serialize_buffer_deserialize (void *src, off_t offset) { SpaBuffer *b; - unsigned int i; b = SPA_MEMBER (src, offset, SpaBuffer); if (b->metas) diff --git a/pinos/client/stream.c b/pinos/client/stream.c index 01df9e020..1476aa67e 100644 --- a/pinos/client/stream.c +++ b/pinos/client/stream.c @@ -1080,7 +1080,6 @@ pinos_stream_send_buffer (PinosStream *stream, { PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this); BufferId *bid; - unsigned int i; if ((bid = find_buffer (stream, id))) { uint8_t cmd = PINOS_TRANSPORT_CMD_HAVE_DATA; diff --git a/pinos/server/client.c b/pinos/server/client.c index 5ec7fa622..1e0436d5d 100644 --- a/pinos/server/client.c +++ b/pinos/server/client.c @@ -78,7 +78,7 @@ client_bind_func (PinosGlobal *global, spa_list_insert (this->resource_list.prev, &resource->link); m.info = &info; - info.id = resource->id; + info.id = global->id; info.change_mask = ~0; info.props = this->properties ? &this->properties->dict : NULL; diff --git a/pinos/server/core.c b/pinos/server/core.c index e05dee76a..593923aca 100644 --- a/pinos/server/core.c +++ b/pinos/server/core.c @@ -187,7 +187,7 @@ core_bind_func (PinosGlobal *global, pinos_log_debug ("core %p: bound to %d", global->object, resource->id); m.info = &info; - info.id = resource->id; + info.id = global->id; info.change_mask = ~0; info.user_name = "wim"; info.host_name = "wtay"; diff --git a/pinos/server/link.c b/pinos/server/link.c index 2b316b1e0..9ae4f2480 100644 --- a/pinos/server/link.c +++ b/pinos/server/link.c @@ -775,7 +775,7 @@ link_bind_func (PinosGlobal *global, spa_list_insert (this->resource_list.prev, &resource->link); m.info = &info; - info.id = resource->id; + info.id = global->id; info.change_mask = ~0; info.output_node_id = this->output ? this->output->node->global->id : -1; info.output_port_id = this->output ? this->output->port_id : -1; diff --git a/pinos/server/module.c b/pinos/server/module.c index 8cef364a8..9316842fe 100644 --- a/pinos/server/module.c +++ b/pinos/server/module.c @@ -130,7 +130,7 @@ module_bind_func (PinosGlobal *global, pinos_log_debug ("module %p: bound to %d", global->object, resource->id); m.info = &info; - info.id = resource->id; + info.id = global->id; info.change_mask = ~0; info.name = this->name; info.filename = this->filename; diff --git a/pinos/server/node.c b/pinos/server/node.c index 33bf19c32..d79ce3ace 100644 --- a/pinos/server/node.c +++ b/pinos/server/node.c @@ -432,7 +432,7 @@ node_bind_func (PinosGlobal *global, spa_list_insert (this->resource_list.prev, &resource->link); m.info = &info; - info.id = resource->id; + info.id = global->id; info.change_mask = ~0; info.name = this->name; info.state = this->state; @@ -817,7 +817,7 @@ pinos_node_update_state (PinosNode *node, info.state = node->state; spa_list_for_each (resource, &node->resource_list, link) { - info.id = resource->id; + info.id = node->global->id; pinos_resource_send_message (resource, PINOS_MESSAGE_NODE_INFO, &m, diff --git a/pinos/tools/pinos-monitor.c b/pinos/tools/pinos-monitor.c index 280279444..93d6a4f94 100644 --- a/pinos/tools/pinos-monitor.c +++ b/pinos/tools/pinos-monitor.c @@ -169,6 +169,11 @@ dump_object (PinosContext *context, uint32_t id, DumpData *data) { + if (type == context->uri.core) { + pinos_context_get_core_info (context, + dump_core_info, + data); + } if (type == context->uri.node) { pinos_context_get_node_info_by_id (context, id,