diff --git a/pinos/client/connection.c b/pinos/client/connection.c index 7b53cf933..fa7299bf1 100644 --- a/pinos/client/connection.c +++ b/pinos/client/connection.c @@ -87,6 +87,17 @@ connection_add_fd (PinosConnection *conn, #define PINOS_DEBUG_MESSAGE(format,args...) #endif +static void +connection_parse_client_update (PinosConnection *conn, PinosMessageClientUpdate *m) +{ + void *p; + + p = conn->in.data; + memcpy (m, p, sizeof (PinosMessageClientUpdate)); + if (m->props) + m->props = pinos_serialize_dict_deserialize (p, SPA_PTR_TO_INT (m->props)); +} + static void connection_parse_notify_global (PinosConnection *conn, PinosMessageNotifyGlobal *ng) { @@ -340,6 +351,29 @@ connection_add_message (PinosConnection *conn, return p; } +static void +connection_add_client_update (PinosConnection *conn, + uint32_t dest_id, + PinosMessageClientUpdate *m) +{ + size_t len; + void *p; + PinosMessageClientUpdate *d; + + len = sizeof (PinosMessageClientUpdate); + len += pinos_serialize_dict_get_size (m->props); + + p = connection_add_message (conn, dest_id, PINOS_MESSAGE_CLIENT_UPDATE, len); + memcpy (p, m, sizeof (PinosMessageClientUpdate)); + d = p; + + p = SPA_MEMBER (d, sizeof (PinosMessageClientUpdate), void); + if (m->props) { + len = pinos_serialize_dict_serialize (p, m->props); + d->props = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d)); + } +} + static void connection_add_notify_global (PinosConnection *conn, uint32_t dest_id, @@ -1019,6 +1053,10 @@ pinos_connection_parse_message (PinosConnection *conn, spa_return_val_if_fail (conn != NULL, false); switch (conn->in.type) { + case PINOS_MESSAGE_CLIENT_UPDATE: + connection_parse_client_update (conn, message); + break; + case PINOS_MESSAGE_SYNC: if (conn->in.size < sizeof (PinosMessageSync)) return false; @@ -1213,6 +1251,10 @@ pinos_connection_add_message (PinosConnection *conn, spa_return_val_if_fail (message != NULL, false); switch (type) { + case PINOS_MESSAGE_CLIENT_UPDATE: + connection_add_client_update (conn, dest_id, message); + break; + case PINOS_MESSAGE_SYNC: p = connection_add_message (conn, dest_id, type, sizeof (PinosMessageSync)); memcpy (p, message, sizeof (PinosMessageSync)); diff --git a/pinos/client/connection.h b/pinos/client/connection.h index 4ea926d57..4f8abb0e1 100644 --- a/pinos/client/connection.h +++ b/pinos/client/connection.h @@ -35,6 +35,8 @@ typedef struct _PinosConnection PinosConnection; typedef enum { PINOS_MESSAGE_INVALID = 0, + PINOS_MESSAGE_CLIENT_UPDATE, + PINOS_MESSAGE_SYNC, PINOS_MESSAGE_NOTIFY_DONE, PINOS_MESSAGE_GET_REGISTRY, @@ -86,6 +88,11 @@ typedef enum { #include +/* PINOS_MESSAGE_CLIENT_UPDATE */ +typedef struct { + SpaDict *props; +} PinosMessageClientUpdate; + /* PINOS_MESSAGE_SYNC */ typedef struct { uint32_t seq; diff --git a/pinos/client/context.c b/pinos/client/context.c index 93330884b..41bbc0778 100644 --- a/pinos/client/context.c +++ b/pinos/client/context.c @@ -551,6 +551,7 @@ pinos_context_connect (PinosContext *context) socklen_t size; const char *runtime_dir, *name = NULL; int name_size, fd; + PinosMessageClientUpdate cu; PinosMessageGetRegistry grm; context_set_state (context, PINOS_CONTEXT_STATE_CONNECTING, NULL); @@ -608,6 +609,12 @@ pinos_context_connect (PinosContext *context) context->core_proxy->dispatch_func = core_dispatch_func; context->core_proxy->dispatch_data = impl; + cu.props = &context->properties->dict; + pinos_proxy_send_message (context->core_proxy, + PINOS_MESSAGE_CLIENT_UPDATE, + &cu, + true); + context->registry_proxy = pinos_proxy_new (context, SPA_ID_INVALID, context->uri.registry); diff --git a/pinos/client/pinos.c b/pinos/client/pinos.c index ceac1de57..ed34f36cd 100644 --- a/pinos/client/pinos.c +++ b/pinos/client/pinos.c @@ -19,6 +19,8 @@ #include #include +#include +#include #include "pinos/client/pinos.h" @@ -35,28 +37,45 @@ pinos_init (int *argc, char **argv[]) { } -static char * +const char * pinos_get_application_name (void) { return NULL; } -static char * +const char * pinos_get_prgname (void) { + static char tcomm[16+1]; + spa_zero(tcomm); + + if (prctl (PR_GET_NAME, (unsigned long) tcomm, 0, 0, 0) == 0) + return tcomm; + return NULL; } -static char * +const char * pinos_get_user_name (void) { + struct passwd *pw; + + if ((pw = getpwuid (getuid ()))) + return pw->pw_name; + return NULL; } -static char * +const char * pinos_get_host_name (void) { - return NULL; + static char hname[256]; + + if (gethostname (hname, 256) < 0) + return NULL; + + hname[255] = 0; + return hname; } /** @@ -68,11 +87,12 @@ char * pinos_client_name (void) { char *c; + const char *cc; - if ((c = pinos_get_application_name ())) - return strdup (c); - else if ((c = pinos_get_prgname ())) - return strdup (c); + if ((cc = pinos_get_application_name ())) + return strdup (cc); + else if ((cc = pinos_get_prgname ())) + return strdup (cc); else { asprintf (&c, "pinos-pid-%zd", (size_t) getpid ()); return c; diff --git a/pinos/client/pinos.h b/pinos/client/pinos.h index e4cb7e9fd..a20a9d098 100644 --- a/pinos/client/pinos.h +++ b/pinos/client/pinos.h @@ -39,6 +39,11 @@ extern "C" { void pinos_init (int *argc, char **argv[]); +const char * pinos_get_application_name (void); +const char * pinos_get_prgname (void); +const char * pinos_get_user_name (void); +const char * pinos_get_host_name (void); + char * pinos_client_name (void); void pinos_fill_context_properties (PinosProperties *properties); diff --git a/pinos/client/properties.c b/pinos/client/properties.c index 26326fb60..e6e376172 100644 --- a/pinos/client/properties.c +++ b/pinos/client/properties.c @@ -91,6 +91,29 @@ pinos_properties_new (const char *key, ...) return &impl->this; } +/** + * pinos_properties_new_dict: + * @dict: a dict + * + * Make a new #PinosProperties with given @dict. + * + * Returns: a new #PinosProperties + */ +PinosProperties * +pinos_properties_new_dict (const SpaDict *dict) +{ + unsigned int i; + PinosPropertiesImpl *impl; + + impl = calloc (1, sizeof (PinosPropertiesImpl)); + pinos_array_init (&impl->items); + + for (i = 0; i < dict->n_items; i++) + add_func (&impl->this, strdup (dict->items[i].key), strdup (dict->items[i].value)); + + return &impl->this; +} + /** * pinos_properties_copy: * @properties: a #PinosProperties diff --git a/pinos/client/properties.h b/pinos/client/properties.h index e0bffd18f..74d87bb50 100644 --- a/pinos/client/properties.h +++ b/pinos/client/properties.h @@ -31,6 +31,7 @@ struct _PinosProperties { }; PinosProperties * pinos_properties_new (const char *key, ...); +PinosProperties * pinos_properties_new_dict (const SpaDict *dict); PinosProperties * pinos_properties_copy (PinosProperties *properties); PinosProperties * pinos_properties_merge (PinosProperties *oldprops, PinosProperties *newprops); diff --git a/pinos/modules/module-autolink.c b/pinos/modules/module-autolink.c index 252469a79..3d22702f3 100644 --- a/pinos/modules/module-autolink.c +++ b/pinos/modules/module-autolink.c @@ -41,7 +41,6 @@ typedef struct { static void try_link_port (PinosNode *node, PinosPort *port, ModuleImpl *impl) { - //PinosClient *client; PinosProperties *props; const char *path; char *error = NULL; @@ -77,12 +76,6 @@ try_link_port (PinosNode *node, PinosPort *port, ModuleImpl *impl) if (link == NULL) goto error; -#if 0 - client = pinos_node_get_client (node); - if (client) - pinos_client_add_object (client, &link->object); -#endif - pinos_link_activate (link); } return; @@ -170,7 +163,7 @@ on_port_removed (PinosListener *listener, } static void -on_node_created (PinosNode *node, +on_node_created (PinosNode *node, ModuleImpl *impl) { PinosPort *port; diff --git a/pinos/server/client.c b/pinos/server/client.c index 1e0436d5d..c9f634581 100644 --- a/pinos/server/client.c +++ b/pinos/server/client.c @@ -179,3 +179,36 @@ pinos_client_destroy (PinosClient * client) sync_destroy, client); } + +void +pinos_client_update_properties (PinosClient *client, + const SpaDict *dict) +{ + PinosMessageClientInfo m; + PinosClientInfo info; + PinosResource *resource; + + if (client->properties == NULL) { + if (dict) + client->properties = pinos_properties_new_dict (dict); + } else { + unsigned int i; + + for (i = 0; i < dict->n_items; i++) + pinos_properties_set (client->properties, + dict->items[i].key, + dict->items[i].value); + } + + m.info = &info; + info.id = client->global->id; + info.change_mask = 1 << 0; + info.props = client->properties ? &client->properties->dict : NULL; + + spa_list_for_each (resource, &client->resource_list, link) { + pinos_resource_send_message (resource, + PINOS_MESSAGE_CLIENT_INFO, + &m, + true); + } +} diff --git a/pinos/server/client.h b/pinos/server/client.h index 7131a1724..fa99be903 100644 --- a/pinos/server/client.h +++ b/pinos/server/client.h @@ -57,6 +57,8 @@ struct _PinosClient { PinosClient * pinos_client_new (PinosCore *core, PinosProperties *properties); void pinos_client_destroy (PinosClient *client); +void pinos_client_update_properties (PinosClient *client, + const SpaDict *dict); #ifdef __cplusplus } diff --git a/pinos/server/core.c b/pinos/server/core.c index 593923aca..f2c19136f 100644 --- a/pinos/server/core.c +++ b/pinos/server/core.c @@ -16,6 +16,7 @@ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ +#include #include #include @@ -87,6 +88,15 @@ core_dispatch_func (void *object, PinosCore *this = data; switch (type) { + case PINOS_MESSAGE_CLIENT_UPDATE: + { + PinosMessageClientUpdate *m = message; + + pinos_client_update_properties (client, + m->props); + break; + } + case PINOS_MESSAGE_GET_REGISTRY: { PinosMessageGetRegistry *m = message; @@ -189,11 +199,12 @@ core_bind_func (PinosGlobal *global, m.info = &info; info.id = global->id; info.change_mask = ~0; - info.user_name = "wim"; - info.host_name = "wtay"; - info.version = 0; + info.user_name = pinos_get_user_name (); + info.host_name = pinos_get_host_name (); + info.version = "0"; info.name = "pinos-0"; - info.cookie = 0; + srandom (time (NULL)); + info.cookie = random (); info.props = NULL; pinos_resource_send_message (resource,