mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
Add client info message
Update client info and improve core info
This commit is contained in:
parent
2f18af1fb2
commit
ff5e260d67
11 changed files with 165 additions and 21 deletions
|
|
@ -87,6 +87,17 @@ connection_add_fd (PinosConnection *conn,
|
||||||
#define PINOS_DEBUG_MESSAGE(format,args...)
|
#define PINOS_DEBUG_MESSAGE(format,args...)
|
||||||
#endif
|
#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
|
static void
|
||||||
connection_parse_notify_global (PinosConnection *conn, PinosMessageNotifyGlobal *ng)
|
connection_parse_notify_global (PinosConnection *conn, PinosMessageNotifyGlobal *ng)
|
||||||
{
|
{
|
||||||
|
|
@ -340,6 +351,29 @@ connection_add_message (PinosConnection *conn,
|
||||||
return p;
|
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
|
static void
|
||||||
connection_add_notify_global (PinosConnection *conn,
|
connection_add_notify_global (PinosConnection *conn,
|
||||||
uint32_t dest_id,
|
uint32_t dest_id,
|
||||||
|
|
@ -1019,6 +1053,10 @@ pinos_connection_parse_message (PinosConnection *conn,
|
||||||
spa_return_val_if_fail (conn != NULL, false);
|
spa_return_val_if_fail (conn != NULL, false);
|
||||||
|
|
||||||
switch (conn->in.type) {
|
switch (conn->in.type) {
|
||||||
|
case PINOS_MESSAGE_CLIENT_UPDATE:
|
||||||
|
connection_parse_client_update (conn, message);
|
||||||
|
break;
|
||||||
|
|
||||||
case PINOS_MESSAGE_SYNC:
|
case PINOS_MESSAGE_SYNC:
|
||||||
if (conn->in.size < sizeof (PinosMessageSync))
|
if (conn->in.size < sizeof (PinosMessageSync))
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1213,6 +1251,10 @@ pinos_connection_add_message (PinosConnection *conn,
|
||||||
spa_return_val_if_fail (message != NULL, false);
|
spa_return_val_if_fail (message != NULL, false);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case PINOS_MESSAGE_CLIENT_UPDATE:
|
||||||
|
connection_add_client_update (conn, dest_id, message);
|
||||||
|
break;
|
||||||
|
|
||||||
case PINOS_MESSAGE_SYNC:
|
case PINOS_MESSAGE_SYNC:
|
||||||
p = connection_add_message (conn, dest_id, type, sizeof (PinosMessageSync));
|
p = connection_add_message (conn, dest_id, type, sizeof (PinosMessageSync));
|
||||||
memcpy (p, message, sizeof (PinosMessageSync));
|
memcpy (p, message, sizeof (PinosMessageSync));
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ typedef struct _PinosConnection PinosConnection;
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PINOS_MESSAGE_INVALID = 0,
|
PINOS_MESSAGE_INVALID = 0,
|
||||||
|
|
||||||
|
PINOS_MESSAGE_CLIENT_UPDATE,
|
||||||
|
|
||||||
PINOS_MESSAGE_SYNC,
|
PINOS_MESSAGE_SYNC,
|
||||||
PINOS_MESSAGE_NOTIFY_DONE,
|
PINOS_MESSAGE_NOTIFY_DONE,
|
||||||
PINOS_MESSAGE_GET_REGISTRY,
|
PINOS_MESSAGE_GET_REGISTRY,
|
||||||
|
|
@ -86,6 +88,11 @@ typedef enum {
|
||||||
|
|
||||||
#include <pinos/client/introspect.h>
|
#include <pinos/client/introspect.h>
|
||||||
|
|
||||||
|
/* PINOS_MESSAGE_CLIENT_UPDATE */
|
||||||
|
typedef struct {
|
||||||
|
SpaDict *props;
|
||||||
|
} PinosMessageClientUpdate;
|
||||||
|
|
||||||
/* PINOS_MESSAGE_SYNC */
|
/* PINOS_MESSAGE_SYNC */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t seq;
|
uint32_t seq;
|
||||||
|
|
|
||||||
|
|
@ -551,6 +551,7 @@ pinos_context_connect (PinosContext *context)
|
||||||
socklen_t size;
|
socklen_t size;
|
||||||
const char *runtime_dir, *name = NULL;
|
const char *runtime_dir, *name = NULL;
|
||||||
int name_size, fd;
|
int name_size, fd;
|
||||||
|
PinosMessageClientUpdate cu;
|
||||||
PinosMessageGetRegistry grm;
|
PinosMessageGetRegistry grm;
|
||||||
|
|
||||||
context_set_state (context, PINOS_CONTEXT_STATE_CONNECTING, NULL);
|
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_func = core_dispatch_func;
|
||||||
context->core_proxy->dispatch_data = impl;
|
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,
|
context->registry_proxy = pinos_proxy_new (context,
|
||||||
SPA_ID_INVALID,
|
SPA_ID_INVALID,
|
||||||
context->uri.registry);
|
context->uri.registry);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
#include "pinos/client/pinos.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)
|
pinos_get_application_name (void)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
const char *
|
||||||
pinos_get_prgname (void)
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
const char *
|
||||||
pinos_get_user_name (void)
|
pinos_get_user_name (void)
|
||||||
{
|
{
|
||||||
|
struct passwd *pw;
|
||||||
|
|
||||||
|
if ((pw = getpwuid (getuid ())))
|
||||||
|
return pw->pw_name;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
const char *
|
||||||
pinos_get_host_name (void)
|
pinos_get_host_name (void)
|
||||||
{
|
{
|
||||||
|
static char hname[256];
|
||||||
|
|
||||||
|
if (gethostname (hname, 256) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
hname[255] = 0;
|
||||||
|
return hname;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -68,11 +87,12 @@ char *
|
||||||
pinos_client_name (void)
|
pinos_client_name (void)
|
||||||
{
|
{
|
||||||
char *c;
|
char *c;
|
||||||
|
const char *cc;
|
||||||
|
|
||||||
if ((c = pinos_get_application_name ()))
|
if ((cc = pinos_get_application_name ()))
|
||||||
return strdup (c);
|
return strdup (cc);
|
||||||
else if ((c = pinos_get_prgname ()))
|
else if ((cc = pinos_get_prgname ()))
|
||||||
return strdup (c);
|
return strdup (cc);
|
||||||
else {
|
else {
|
||||||
asprintf (&c, "pinos-pid-%zd", (size_t) getpid ());
|
asprintf (&c, "pinos-pid-%zd", (size_t) getpid ());
|
||||||
return c;
|
return c;
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,11 @@ extern "C" {
|
||||||
|
|
||||||
void pinos_init (int *argc, char **argv[]);
|
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);
|
char * pinos_client_name (void);
|
||||||
|
|
||||||
void pinos_fill_context_properties (PinosProperties *properties);
|
void pinos_fill_context_properties (PinosProperties *properties);
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,29 @@ pinos_properties_new (const char *key, ...)
|
||||||
return &impl->this;
|
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:
|
* pinos_properties_copy:
|
||||||
* @properties: a #PinosProperties
|
* @properties: a #PinosProperties
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ struct _PinosProperties {
|
||||||
};
|
};
|
||||||
|
|
||||||
PinosProperties * pinos_properties_new (const char *key, ...);
|
PinosProperties * pinos_properties_new (const char *key, ...);
|
||||||
|
PinosProperties * pinos_properties_new_dict (const SpaDict *dict);
|
||||||
PinosProperties * pinos_properties_copy (PinosProperties *properties);
|
PinosProperties * pinos_properties_copy (PinosProperties *properties);
|
||||||
PinosProperties * pinos_properties_merge (PinosProperties *oldprops,
|
PinosProperties * pinos_properties_merge (PinosProperties *oldprops,
|
||||||
PinosProperties *newprops);
|
PinosProperties *newprops);
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@ typedef struct {
|
||||||
static void
|
static void
|
||||||
try_link_port (PinosNode *node, PinosPort *port, ModuleImpl *impl)
|
try_link_port (PinosNode *node, PinosPort *port, ModuleImpl *impl)
|
||||||
{
|
{
|
||||||
//PinosClient *client;
|
|
||||||
PinosProperties *props;
|
PinosProperties *props;
|
||||||
const char *path;
|
const char *path;
|
||||||
char *error = NULL;
|
char *error = NULL;
|
||||||
|
|
@ -77,12 +76,6 @@ try_link_port (PinosNode *node, PinosPort *port, ModuleImpl *impl)
|
||||||
if (link == NULL)
|
if (link == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
#if 0
|
|
||||||
client = pinos_node_get_client (node);
|
|
||||||
if (client)
|
|
||||||
pinos_client_add_object (client, &link->object);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pinos_link_activate (link);
|
pinos_link_activate (link);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -179,3 +179,36 @@ pinos_client_destroy (PinosClient * client)
|
||||||
sync_destroy,
|
sync_destroy,
|
||||||
client);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,8 @@ struct _PinosClient {
|
||||||
PinosClient * pinos_client_new (PinosCore *core,
|
PinosClient * pinos_client_new (PinosCore *core,
|
||||||
PinosProperties *properties);
|
PinosProperties *properties);
|
||||||
void pinos_client_destroy (PinosClient *client);
|
void pinos_client_destroy (PinosClient *client);
|
||||||
|
void pinos_client_update_properties (PinosClient *client,
|
||||||
|
const SpaDict *dict);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include <pinos/client/pinos.h>
|
#include <pinos/client/pinos.h>
|
||||||
#include <pinos/server/core.h>
|
#include <pinos/server/core.h>
|
||||||
|
|
@ -87,6 +88,15 @@ core_dispatch_func (void *object,
|
||||||
PinosCore *this = data;
|
PinosCore *this = data;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case PINOS_MESSAGE_CLIENT_UPDATE:
|
||||||
|
{
|
||||||
|
PinosMessageClientUpdate *m = message;
|
||||||
|
|
||||||
|
pinos_client_update_properties (client,
|
||||||
|
m->props);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case PINOS_MESSAGE_GET_REGISTRY:
|
case PINOS_MESSAGE_GET_REGISTRY:
|
||||||
{
|
{
|
||||||
PinosMessageGetRegistry *m = message;
|
PinosMessageGetRegistry *m = message;
|
||||||
|
|
@ -189,11 +199,12 @@ core_bind_func (PinosGlobal *global,
|
||||||
m.info = &info;
|
m.info = &info;
|
||||||
info.id = global->id;
|
info.id = global->id;
|
||||||
info.change_mask = ~0;
|
info.change_mask = ~0;
|
||||||
info.user_name = "wim";
|
info.user_name = pinos_get_user_name ();
|
||||||
info.host_name = "wtay";
|
info.host_name = pinos_get_host_name ();
|
||||||
info.version = 0;
|
info.version = "0";
|
||||||
info.name = "pinos-0";
|
info.name = "pinos-0";
|
||||||
info.cookie = 0;
|
srandom (time (NULL));
|
||||||
|
info.cookie = random ();
|
||||||
info.props = NULL;
|
info.props = NULL;
|
||||||
|
|
||||||
pinos_resource_send_message (resource,
|
pinos_resource_send_message (resource,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue