Fix proxy ids

The proxy/resource ids are generated by the client and so we need to
used them as index in the client resource map instead of making our own
number.
Fix stream disconnect and client-node destroy
Fix gstreamer device provider
Make all sockets non-blocking to avoid errors with bad clients
Advertise the subsystems we monitor and disable the gstreamer monitors.
Implement core properties updates
Make sure we send REMOVE_ID after we are done with the resource.
This commit is contained in:
Wim Taymans 2017-01-20 15:53:03 +01:00
parent e579efea10
commit 4b55d7c4da
18 changed files with 222 additions and 69 deletions

View file

@ -195,7 +195,6 @@ typedef struct {
/* PINOS_MESSAGE_DESTROY */
typedef struct {
uint32_t seq;
uint32_t id;
} PinosMessageDestroy;
/* PINOS_MESSAGE_NODE_UPDATE */

View file

@ -443,6 +443,7 @@ on_context_data (SpaSource *source,
pinos_log_error ("context %p: could not find proxy %u", this, id);
continue;
}
pinos_log_debug ("context %p: object dispatch %u", this, id);
pinos_proxy_dispatch (proxy, type, p);
}
@ -588,7 +589,7 @@ pinos_context_connect (PinosContext *context)
if (name == NULL)
name = "pinos-0";
if ((fd = socket (PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0)) < 0)
if ((fd = socket (PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) < 0)
return false;
memset (&addr, 0, sizeof (addr));

View file

@ -118,6 +118,13 @@ const char * pinos_link_state_as_string (PinosLinkState state);
struct _PinosCoreInfo {
uint32_t id;
uint64_t change_mask;
#define PINOS_CORE_CHANGE_MASK_USER_NAME (1 << 0)
#define PINOS_CORE_CHANGE_MASK_HOST_NAME (1 << 1)
#define PINOS_CORE_CHANGE_MASK_VERSION (1 << 2)
#define PINOS_CORE_CHANGE_MASK_NAME (1 << 3)
#define PINOS_CORE_CHANGE_MASK_COOKIE (1 << 4)
#define PINOS_CORE_CHANGE_MASK_PROPS (1 << 5)
#define PINOS_CORE_CHANGE_MASK_ALL (~0)
const char *user_name;
const char *host_name;
const char *version;

View file

@ -302,7 +302,6 @@ loop_iterate (SpaLoopControl *ctrl,
SpaSource *source = ep[i].data.ptr;
if (source->rmask) {
source->func (source);
source->rmask = 0;
}
}
return SPA_RESULT_OK;
@ -311,8 +310,8 @@ loop_iterate (SpaLoopControl *ctrl,
static void
source_io_func (SpaSource *source)
{
SpaSourceImpl *s = SPA_CONTAINER_OF (source, SpaSourceImpl, source);
s->func.io (source, source->fd, source->rmask, source->data);
SpaSourceImpl *impl = SPA_CONTAINER_OF (source, SpaSourceImpl, source);
impl->func.io (source, source->fd, source->rmask, source->data);
}
static SpaSource *
@ -357,8 +356,8 @@ loop_update_io (SpaSource *source,
static void
source_idle_func (SpaSource *source)
{
SpaSourceImpl *s = SPA_CONTAINER_OF (source, SpaSourceImpl, source);
s->func.idle (source, source->data);
SpaSourceImpl *impl = SPA_CONTAINER_OF (source, SpaSourceImpl, source);
impl->func.idle (source, source->data);
}
static SpaSource *
@ -409,13 +408,13 @@ loop_enable_idle (SpaSource *source,
static void
source_event_func (SpaSource *source)
{
SpaSourceImpl *s = SPA_CONTAINER_OF (source, SpaSourceImpl, source);
SpaSourceImpl *impl = SPA_CONTAINER_OF (source, SpaSourceImpl, source);
uint64_t count;
if (read (source->fd, &count, sizeof (uint64_t)) != sizeof (uint64_t))
pinos_log_warn ("loop %p: failed to read event fd: %s", source, strerror (errno));
s->func.event (source, source->data);
impl->func.event (source, source->data);
}
static SpaSource *
@ -457,13 +456,13 @@ loop_signal_event (SpaSource *source)
static void
source_timer_func (SpaSource *source)
{
SpaSourceImpl *s = SPA_CONTAINER_OF (source, SpaSourceImpl, source);
SpaSourceImpl *impl = SPA_CONTAINER_OF (source, SpaSourceImpl, source);
uint64_t expires;
if (read (source->fd, &expires, sizeof (uint64_t)) != sizeof (uint64_t))
pinos_log_warn ("loop %p: failed to read timer fd: %s", source, strerror (errno));
s->func.timer (source, source->data);
impl->func.timer (source, source->data);
}
static SpaSource *
@ -519,13 +518,13 @@ loop_update_timer (SpaSource *source,
static void
source_signal_func (SpaSource *source)
{
SpaSourceImpl *s = SPA_CONTAINER_OF (source, SpaSourceImpl, source);
SpaSourceImpl *impl = SPA_CONTAINER_OF (source, SpaSourceImpl, source);
struct signalfd_siginfo signal_info;
if (read (source->fd, &signal_info, sizeof (signal_info)) != sizeof (signal_info))
pinos_log_warn ("loop %p: failed to read signal fd: %s", source, strerror (errno));
s->func.signal (source, s->signal_number, source->data);
impl->func.signal (source, impl->signal_number, source->data);
}
static SpaSource *
@ -564,15 +563,15 @@ loop_add_signal (SpaLoopUtils *utils,
static void
loop_destroy_source (SpaSource *source)
{
SpaSourceImpl *s = SPA_CONTAINER_OF (source, SpaSourceImpl, source);
SpaSourceImpl *impl = SPA_CONTAINER_OF (source, SpaSourceImpl, source);
spa_list_remove (&s->link);
spa_list_remove (&impl->link);
spa_loop_remove_source (source->loop, source);
if (source->fd != -1 && s->close)
if (source->fd != -1 && impl->close)
close (source->fd);
free (s);
free (impl);
}
PinosLoop *

View file

@ -88,6 +88,25 @@ pinos_map_insert_new (PinosMap *map,
return id;
}
static inline bool
pinos_map_insert_at (PinosMap *map,
uint32_t id,
void *data)
{
size_t size = pinos_map_get_size (map);
PinosMapItem *item;
if (id > size)
return false;
else if (id == size)
item = pinos_array_add (&map->items, sizeof (PinosMapItem));
else
item = pinos_map_get_item (map, id);
item->data = data;
return true;
}
static inline void
pinos_map_remove (PinosMap *map,
uint32_t id)

View file

@ -40,16 +40,16 @@ pinos_proxy_new (PinosContext *context,
return NULL;
this = &impl->this;
this->context = context;
this->type = type;
pinos_signal_init (&this->destroy_signal);
this->id = pinos_map_insert_new (&context->objects, this);
spa_list_insert (&this->context->proxy_list, &this->link);
pinos_log_debug ("proxy %p: new %u", this, this->id);
return this;
}
@ -58,10 +58,13 @@ pinos_proxy_destroy (PinosProxy *proxy)
{
PinosProxyImpl *impl = SPA_CONTAINER_OF (proxy, PinosProxyImpl, this);
pinos_log_debug ("proxy %p: destroy %u", proxy, proxy->id);
pinos_signal_emit (&proxy->destroy_signal, proxy);
pinos_map_remove (&proxy->context->objects, proxy->id);
spa_list_remove (&proxy->link);
pinos_log_debug ("proxy %p: free", proxy);
free (impl);
}

View file

@ -74,14 +74,15 @@ typedef struct
PinosStreamFlags flags;
bool disconnecting;
PinosStreamMode mode;
int rtfd;
SpaSource *rtsocket_source;
PinosProxy *node_proxy;
bool disconnecting;
PinosListener node_proxy_destroy;
PinosTransport *trans;
SpaSource *timeout_source;
@ -845,6 +846,18 @@ stream_dispatch_func (void *object,
return SPA_RESULT_OK;
}
static void
on_node_proxy_destroy (PinosListener *listener,
PinosProxy *proxy)
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (listener, PinosStreamImpl, node_proxy_destroy);
PinosStream *this = &impl->this;
impl->disconnecting = false;
impl->node_proxy = NULL;
stream_set_state (this, PINOS_STREAM_STATE_UNCONNECTED, NULL);
}
/**
* pinos_stream_connect:
* @stream: a #PinosStream
@ -897,6 +910,10 @@ pinos_stream_connect (PinosStream *stream,
if (impl->node_proxy == NULL)
return false;
pinos_signal_add (&impl->node_proxy->destroy_signal,
&impl->node_proxy_destroy,
on_node_proxy_destroy);
pinos_proxy_set_dispatch (impl->node_proxy,
stream_dispatch_func,
impl);
@ -1002,9 +1019,18 @@ bool
pinos_stream_disconnect (PinosStream *stream)
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
PinosMessageDestroy msg;
impl->disconnecting = true;
unhandle_socket (stream);
msg.seq = ++impl->seq;
pinos_proxy_send_message (impl->node_proxy,
PINOS_MESSAGE_DESTROY,
&msg,
true);
return true;
}