1 /* Copyright 2015 The Chromium OS Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6 #ifndef CRAS_MAIN_MESSAGE_H_ 7 #define CRAS_MAIN_MESSAGE_H_ 8 9 #include <stdio.h> 10 11 #include "utlist.h" 12 13 /* The types of message main thread can handle. */ 14 enum CRAS_MAIN_MESSAGE_TYPE { 15 /* Audio thread -> main thread */ 16 CRAS_MAIN_A2DP, 17 CRAS_MAIN_AUDIO_THREAD_EVENT, 18 CRAS_MAIN_BT, 19 CRAS_MAIN_METRICS, 20 CRAS_MAIN_MONITOR_DEVICE, 21 CRAS_MAIN_HOTWORD_TRIGGERED, 22 CRAS_MAIN_NON_EMPTY_AUDIO_STATE, 23 }; 24 25 /* Structure of the header of the message handled by main thread. 26 * Args: 27 * length - Size of the whole message. 28 * type - Type of the message. 29 */ 30 struct cras_main_message { 31 size_t length; 32 enum CRAS_MAIN_MESSAGE_TYPE type; 33 }; 34 35 /* Callback function to handle main thread message. */ 36 typedef void (*cras_message_callback)(struct cras_main_message *msg, 37 void *arg); 38 39 /* Sends a message to main thread. */ 40 int cras_main_message_send(struct cras_main_message *msg); 41 42 /* Registers the handler function for specific type of message. */ 43 int cras_main_message_add_handler(enum CRAS_MAIN_MESSAGE_TYPE type, 44 cras_message_callback callback, 45 void *callback_data); 46 47 /* Initialize the message handling mechanism in main thread. */ 48 void cras_main_message_init(); 49 50 #endif /* CRAS_MAIN_MESSAGE_H_ */ 51