Add client info message

Update client info and improve core info
This commit is contained in:
Wim Taymans 2016-12-21 17:19:06 +01:00
parent 2f18af1fb2
commit ff5e260d67
11 changed files with 165 additions and 21 deletions

View file

@ -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));

View file

@ -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/client/introspect.h>
/* PINOS_MESSAGE_CLIENT_UPDATE */
typedef struct {
SpaDict *props;
} PinosMessageClientUpdate;
/* PINOS_MESSAGE_SYNC */
typedef struct {
uint32_t seq;

View file

@ -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);

View file

@ -19,6 +19,8 @@
#include <unistd.h>
#include <stdio.h>
#include <sys/prctl.h>
#include <pwd.h>
#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;

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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
}

View file

@ -16,6 +16,7 @@
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <time.h>
#include <pinos/client/pinos.h>
#include <pinos/server/core.h>
@ -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,