summaryrefslogtreecommitdiff
path: root/cras/src/server/cras_main_message.h
blob: fd63488b234fc9fddf8aa4736e7783eea4e275c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Copyright 2015 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef CRAS_MAIN_MESSAGE_H_
#define CRAS_MAIN_MESSAGE_H_

#include <stdio.h>

#include "utlist.h"

/* The types of message main thread can handle. */
enum CRAS_MAIN_MESSAGE_TYPE {
	/* Audio thread -> main thread */
	CRAS_MAIN_A2DP,
	CRAS_MAIN_AUDIO_THREAD_EVENT,
	CRAS_MAIN_BT,
	CRAS_MAIN_METRICS,
	CRAS_MAIN_MONITOR_DEVICE,
	CRAS_MAIN_HOTWORD_TRIGGERED,
	CRAS_MAIN_NON_EMPTY_AUDIO_STATE,
};

/* Structure of the header of the message handled by main thread.
 * Args:
 *    length - Size of the whole message.
 *    type - Type of the message.
 */
struct cras_main_message {
	size_t length;
	enum CRAS_MAIN_MESSAGE_TYPE type;
};

/* Callback function to handle main thread message. */
typedef void (*cras_message_callback)(struct cras_main_message *msg, void *arg);

/* Sends a message to main thread. */
int cras_main_message_send(struct cras_main_message *msg);

/* Registers the handler function for specific type of message. */
int cras_main_message_add_handler(enum CRAS_MAIN_MESSAGE_TYPE type,
				  cras_message_callback callback,
				  void *callback_data);

/* Initialize the message handling mechanism in main thread. */
void cras_main_message_init();

#endif /* CRAS_MAIN_MESSAGE_H_ */