Home | History | Annotate | Download | only in server
      1 /* Copyright (c) 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_BT,
     18 	CRAS_MAIN_METRICS,
     19 	CRAS_MAIN_MONITOR_DEVICE,
     20 };
     21 
     22 /* Structure of the header of the message handled by main thread.
     23  * Args:
     24  *    length - Size of the whole message.
     25  *    type - Type of the message.
     26  */
     27 struct cras_main_message {
     28 	size_t length;
     29 	enum CRAS_MAIN_MESSAGE_TYPE type;
     30 };
     31 
     32 /* Callback function to handle main thread message. */
     33 typedef void (*cras_message_callback)(struct cras_main_message *msg,
     34 				      void *arg);
     35 
     36 /* Sends a message to main thread. */
     37 int cras_main_message_send(struct cras_main_message *msg);
     38 
     39 /* Registers the handler function for specific type of message. */
     40 int cras_main_message_add_handler(enum CRAS_MAIN_MESSAGE_TYPE type,
     41 				  cras_message_callback callback,
     42 				  void *callback_data);
     43 
     44 /* Initialize the message handling mechanism in main thread. */
     45 void cras_main_message_init();
     46 
     47 #endif /* CRAS_MAIN_MESSAGE_H_ */
     48