summaryrefslogtreecommitdiff
path: root/cras/src/server/cras_observer.h
blob: 109bd609cc70a565cd58028f95aeddd2820c114b (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Copyright 2016 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_OBSERVER_H
#define CRAS_OBSERVER_H

#include "cras_observer_ops.h"

struct cras_observer_client;

/* Add an observer.
 * Args:
 *    ops - Set callback function pointers in the operations that should be
 *          called for state changes, or NULL otherwise.
 *    context - Context pointer passed to the callbacks.
 * Returns:
 *    Valid pointer to the client reference, or NULL on memory allocation
 *    error.
 */
struct cras_observer_client *
cras_observer_add(const struct cras_observer_ops *ops, void *context);

/* Retrieve the observed state changes.
 * Args:
 *    client - The client to query.
 *    ops - Filled with the current values in the callback table.
 */
void cras_observer_get_ops(const struct cras_observer_client *client,
			   struct cras_observer_ops *ops);

/* Update the observed state changes.
 * Args:
 *    client - The client to modify.
 *    ops - Set callback function pointers in the operations that should be
 *          called for state changes, or NULL otherwise.
 */
void cras_observer_set_ops(struct cras_observer_client *client,
			   const struct cras_observer_ops *ops);

/* Returns non-zero if the given ops are empty. */
int cras_observer_ops_are_empty(const struct cras_observer_ops *ops);

/* Remove this observer client.
 * Args:
 *    client - The client to remove.
 */
void cras_observer_remove(struct cras_observer_client *client);

/* Initialize the observer server. */
int cras_observer_server_init();

/* Destroy the observer server. */
void cras_observer_server_free();

/* Notify observers of output volume change. */
void cras_observer_notify_output_volume(int32_t volume);

/* Notify observers of output mute change. */
void cras_observer_notify_output_mute(int muted, int user_muted,
				      int mute_locked);

/* Notify observers of capture gain change. */
void cras_observer_notify_capture_gain(int32_t gain);

/* Notify observers of capture mute change. */
void cras_observer_notify_capture_mute(int muted, int mute_locked);

/* Notify observers of a nodes list change. */
void cras_observer_notify_nodes(void);

/* Notify observers of active output node change. */
void cras_observer_notify_active_node(enum CRAS_STREAM_DIRECTION dir,
				      cras_node_id_t node_id);

/* Notify observers of output node volume change. */
void cras_observer_notify_output_node_volume(cras_node_id_t node_id,
					     int32_t volume);

/* Notify observers of node left-right swap change. */
void cras_observer_notify_node_left_right_swapped(cras_node_id_t node_id,
						  int swapped);

/* Notify observers of input node gain change. */
void cras_observer_notify_input_node_gain(cras_node_id_t node_id, int32_t gain);

/* Notify observers of suspend state changed. */
void cras_observer_notify_suspend_changed(int suspended);

/* Notify observers of the number of active streams. */
void cras_observer_notify_num_active_streams(enum CRAS_STREAM_DIRECTION dir,
					     uint32_t num_active_streams);

/* Notify observers of the timestamp when hotword triggered. */
void cras_observer_notify_hotword_triggered(int64_t tv_sec, int64_t tv_nsec);

/* Notify observers the non-empty audio state changed. */
void cras_observer_notify_non_empty_audio_state_changed(int active);

#endif /* CRAS_OBSERVER_H */