node: add enabled state

Add method to enable/disable a node. Disabled nodes will SUSPEND and not
be available for automatic connections, it is intented for handling
the monitor node state.
This commit is contained in:
Wim Taymans 2018-01-30 15:05:23 +01:00
parent 95b3cba3c3
commit bd1fea49c2
4 changed files with 43 additions and 3 deletions

View file

@ -610,6 +610,9 @@ struct pw_port *pw_core_find_port(struct pw_core *core,
!PW_PERM_IS_R(pw_global_get_permissions(n->global, core->current_client))) !PW_PERM_IS_R(pw_global_get_permissions(n->global, core->current_client)))
continue; continue;
if (!n->enabled)
continue;
pw_log_debug("node id \"%d\"", n->global->id); pw_log_debug("node id \"%d\"", n->global->id);
if (have_id) { if (have_id) {

View file

@ -394,6 +394,7 @@ struct pw_node *pw_node_new(struct pw_core *core,
if (properties == NULL) if (properties == NULL)
goto no_mem; goto no_mem;
this->enabled = true;
this->properties = properties; this->properties = properties;
impl->work = pw_work_queue_new(this->core->main_loop); impl->work = pw_work_queue_new(this->core->main_loop);
@ -882,8 +883,10 @@ int pw_node_set_active(struct pw_node *node, bool active)
pw_log_debug("node %p: %s", node, active ? "activate" : "deactivate"); pw_log_debug("node %p: %s", node, active ? "activate" : "deactivate");
node->active = active; node->active = active;
spa_hook_list_call(&node->listener_list, struct pw_node_events, active_changed, active); spa_hook_list_call(&node->listener_list, struct pw_node_events, active_changed, active);
if (active) if (active) {
node_activate(node); if (node->enabled)
node_activate(node);
}
else else
pw_node_set_state(node, PW_NODE_STATE_IDLE); pw_node_set_state(node, PW_NODE_STATE_IDLE);
} }
@ -894,3 +897,28 @@ bool pw_node_is_active(struct pw_node *node)
{ {
return node->active; return node->active;
} }
int pw_node_set_enabled(struct pw_node *node, bool enabled)
{
bool old = node->enabled;
if (old != enabled) {
pw_log_debug("node %p: %s", node, enabled ? "enable" : "disable");
node->enabled = enabled;
spa_hook_list_call(&node->listener_list, struct pw_node_events, enabled_changed, enabled);
if (enabled) {
if (node->active)
node_activate(node);
}
else {
pw_node_set_state(node, PW_NODE_STATE_SUSPENDED);
}
}
return 0;
}
bool pw_node_is_enabled(struct pw_node *node)
{
return node->enabled;
}

View file

@ -68,6 +68,8 @@ struct pw_node_events {
void (*info_changed) (void *data, struct pw_node_info *info); void (*info_changed) (void *data, struct pw_node_info *info);
/** the node active state changed */ /** the node active state changed */
void (*active_changed) (void *data, bool active); void (*active_changed) (void *data, bool active);
/** the node enabled state changed */
void (*enabled_changed) (void *data, bool enabled);
/** a new state is requested on the node */ /** a new state is requested on the node */
void (*state_request) (void *data, enum pw_node_state state); void (*state_request) (void *data, enum pw_node_state state);
@ -164,9 +166,15 @@ struct pw_port * pw_node_get_free_port(struct pw_node *node, enum pw_direction d
* nodes and start data transport */ * nodes and start data transport */
int pw_node_set_active(struct pw_node *node, bool active); int pw_node_set_active(struct pw_node *node, bool active);
/** Check is a node is active */ /** Check if a node is active */
bool pw_node_is_active(struct pw_node *node); bool pw_node_is_active(struct pw_node *node);
/** Set a node enabled. The node will be able to be activated */
int pw_node_set_enabled(struct pw_node *node, bool enabled);
/** Check if a node is enabled */
bool pw_node_is_enabled(struct pw_node *node);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -243,6 +243,7 @@ struct pw_node {
struct pw_node_info info; /**< introspectable node info */ struct pw_node_info info; /**< introspectable node info */
bool enabled; /**< if the node is enabled */
bool active; /**< if the node is active */ bool active; /**< if the node is active */
bool live; /**< if the node is live */ bool live; /**< if the node is live */
struct spa_clock *clock; /**< handle to SPA clock if any */ struct spa_clock *clock; /**< handle to SPA clock if any */