cras: Add preliminary message for notifying of hardware changes
Details
gavd needs to be able to communicate device information to cras.
This will be accomplished through the cras command socket.
This change adds a 'device information' notification to the set of
commands that cras can receive.
At present, this API is not used, and it does nothing internally
other than logging the information provided by gavd. It is also not
yet used.
Testing
Using an upcoming change to gavd which publishes the device info to
cras, this change has been shown to function as expected.
BUG=NONE
TEST=See above
Change-Id: I3f8ece5571f2ddca48a4aae884a7b2f9e287605d
Signed-off-by: Taylor Hutt <thutt@chromium.org>
diff --git a/cras/src/common/cras_messages.h b/cras/src/common/cras_messages.h
index 4ae66a4..e09cec0 100644
--- a/cras/src/common/cras_messages.h
+++ b/cras/src/common/cras_messages.h
@@ -26,6 +26,7 @@
CRAS_SERVER_SWITCH_STREAM_TYPE_IODEV,
CRAS_SERVER_SET_SYSTEM_VOLUME,
CRAS_SERVER_SET_SYSTEM_MUTE,
+ CRAS_SERVER_NOTIFY_DEVICE_INFO,
};
enum CRAS_CLIENT_MESSAGE_ID {
@@ -147,6 +148,39 @@
m->header.length = sizeof(*m);
}
+enum cras_notify_device_action { /* Must match gavd action definitions. */
+ CRAS_DEVICE_ACTION_ADD = 0,
+ CRAS_DEVICE_ACTION_REMOVE = 1,
+ CRAS_DEVICE_ACTION_CHANGE = 2,
+};
+
+struct cras_notify_device_info {
+ struct cras_server_message header;
+ enum cras_notify_device_action action;
+ unsigned card_number;
+ unsigned device_number;
+ unsigned active;
+ unsigned internal;
+ unsigned primary;
+};
+static inline void cras_set_device_info(struct cras_notify_device_info *m,
+ unsigned action,
+ unsigned card_number,
+ unsigned device_number,
+ unsigned active,
+ unsigned internal,
+ unsigned primary)
+{
+ m->action = action;
+ m->card_number = card_number;
+ m->device_number = device_number;
+ m->active = active;
+ m->internal = internal;
+ m->primary = primary;
+ m->header.id = CRAS_SERVER_NOTIFY_DEVICE_INFO;
+ m->header.length = sizeof(*m);
+}
+
/*
* Messages sent from server to client.
*/
diff --git a/cras/src/libcras/cras_client.c b/cras/src/libcras/cras_client.c
index ca54ab2..c4f4f32 100644
--- a/cras/src/libcras/cras_client.c
+++ b/cras/src/libcras/cras_client.c
@@ -1224,6 +1224,24 @@
return write_message_to_server(client, &msg.header);
}
+int cras_client_notify_device(struct cras_client *client,
+ unsigned action,
+ unsigned card_number,
+ unsigned device_number,
+ unsigned active,
+ unsigned internal,
+ unsigned primary)
+{
+ struct cras_notify_device_info msg;
+
+ if (client == NULL)
+ return -EINVAL;
+
+ cras_set_device_info(&msg, action, card_number, device_number,
+ active, internal, primary);
+ return write_message_to_server(client, &msg.header);
+}
+
int cras_client_run_thread(struct cras_client *client)
{
if (client == NULL)
diff --git a/cras/src/libcras/cras_client.h b/cras/src/libcras/cras_client.h
index d1ba4c8..9c8a287 100644
--- a/cras/src/libcras/cras_client.h
+++ b/cras/src/libcras/cras_client.h
@@ -196,6 +196,13 @@
*/
int cras_client_set_system_mute(struct cras_client *client, int mute);
+int cras_client_notify_device(struct cras_client *client,
+ unsigned action,
+ unsigned card_number,
+ unsigned device_number,
+ unsigned active,
+ unsigned internal,
+ unsigned primary);
/*
* Utility functions.
*/
diff --git a/cras/src/server/cras_rclient.c b/cras/src/server/cras_rclient.c
index d8bd877..769fc26 100644
--- a/cras/src/server/cras_rclient.c
+++ b/cras/src/server/cras_rclient.c
@@ -3,6 +3,7 @@
* found in the LICENSE file.
*/
+#include <assert.h>
#include <stdlib.h>
#include <syslog.h>
@@ -159,6 +160,14 @@
return cras_iodev_move_stream_type(msg->stream_type, msg->iodev_idx);
}
+static void handle_notify_device_info(const struct cras_notify_device_info *msg)
+{
+ syslog(LOG_DEBUG,
+ "action: %u card: %u device: %u act: %u int: %u pri: %u",
+ msg->action, msg->card_number, msg->device_number,
+ msg->active, msg->internal, msg->primary);
+}
+
/*
* Exported Functions.
*/
@@ -220,6 +229,12 @@
cras_system_set_mute(
((const struct cras_set_system_mute *)msg)->mute);
break;
+ case CRAS_SERVER_NOTIFY_DEVICE_INFO: {
+ const struct cras_notify_device_info *m =
+ (const struct cras_notify_device_info *)msg;
+ handle_notify_device_info(m);
+ break;
+ }
default:
break;
}