node: change send_command() to take a string

Use the spa type system to locate the enumeration value that corresponds
to that string and send that
This commit is contained in:
George Kiagiadakis 2021-02-05 11:05:26 +02:00
parent b32072a2ed
commit ce66025846
3 changed files with 9 additions and 24 deletions

View file

@ -502,16 +502,17 @@ wp_node_lookup_port_full (WpNode * self, WpObjectInterest * interest)
*
* Sends a command to a node
*/
void wp_node_send_command (WpNode * self, WpNodeCommand command)
void wp_node_send_command (WpNode * self, const gchar * command)
{
struct pw_node *pwp;
struct spa_command cmd =
SPA_NODE_COMMAND_INIT((enum spa_node_command) command);
WpSpaIdValue command_value = wp_spa_id_value_from_short_name (
"Spa:Pod:Object:Command:Node", command);
g_return_if_fail (WP_IS_NODE (self));
g_return_if_fail (command_value != NULL);
pwp = (struct pw_node *) wp_proxy_get_pw_proxy (WP_PROXY (self));
pw_node_send_command (pwp, &cmd);
struct spa_command cmd =
SPA_NODE_COMMAND_INIT(wp_spa_id_value_number (command_value));
pw_node_send_command (wp_proxy_get_pw_proxy (WP_PROXY (self)), &cmd);
}

View file

@ -34,22 +34,6 @@ typedef enum {
WP_NODE_STATE_RUNNING = 3,
} WpNodeState;
/**
* WpNodeCommand:
* @WP_NODE_COMMAND_SUSPEND: suspends the node, the device might close
* @WP_NODE_COMMAND_PAUSE: pauses the node, the device will not close
* @WP_NODE_COMMAND_START: starts procesing data
* @WP_NODE_COMMAND_ENABLE: enables the node
* @WP_NODE_COMMAND_DISABLE: disables the node
*/
typedef enum {
WP_NODE_COMMAND_SUSPEND = 0,
WP_NODE_COMMAND_PAUSE = 1,
WP_NODE_COMMAND_START = 2,
WP_NODE_COMMAND_ENABLE = 3,
WP_NODE_COMMAND_DISABLE = 4,
} WpNodeCommand;
/**
* WpNodeFeatures:
* @WP_NODE_FEATURE_PORTS: caches information about ports, enabling
@ -105,7 +89,7 @@ WP_API
WpPort * wp_node_lookup_port_full (WpNode * self, WpObjectInterest * interest);
WP_API
void wp_node_send_command (WpNode * self, WpNodeCommand command);
void wp_node_send_command (WpNode * self, const gchar *command);
/**
* WP_TYPE_IMPL_NODE:

View file

@ -39,7 +39,7 @@ timeout_suspend_node_callback (WpNode *node)
wp_info_object (node, "was idle for a while; suspending ...");
/* Suspend and unref the source */
wp_node_send_command (node, WP_NODE_COMMAND_SUSPEND);
wp_node_send_command (node, "Suspend");
source = g_object_steal_qdata (G_OBJECT (node), source_quark ());
if (source)
g_source_unref (source);