-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdatapipe.h
297 lines (266 loc) · 10.5 KB
/
datapipe.h
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/**
* @file datapipe.h
* Headers for the simple filter framework
* <p>
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2014 - 2021 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <[email protected]>
* @author: Simo Piiroinen <[email protected]>
*
* mce is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* mce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with mce. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _DATAPIPE_H_
# define _DATAPIPE_H_
# include <stdbool.h>
# include <stdint.h>
# include <glib.h>
/* ========================================================================= *
* Types
* ========================================================================= */
/** Device lock states used in devicelock_state_pipe */
typedef enum
{
/** Device lock is not active */
DEVICELOCK_STATE_UNLOCKED = 0,
/** Device lock is active */
DEVICELOCK_STATE_LOCKED = 1,
/** Initial startup value; from mce p.o.v. equals not active */
DEVICELOCK_STATE_UNDEFINED = 2,
} devicelock_state_t;
const char *devicelock_state_repr(devicelock_state_t state);
/**
* Read only policy type
*/
typedef enum {
DATAPIPE_FILTERING_ALLOWED = FALSE, /**< The pipe is read/write */
DATAPIPE_FILTERING_DENIED = TRUE, /**< The pipe is read only */
} datapipe_filtering_t;
/**
* Policy used for caching indata
*/
typedef enum {
/** Data is passed through datapipe, but is not cached
*
* Suitable for stateless impulse and event data.
*/
DATAPIPE_CACHE_NOTHING = 0,
/** Update cache with unfiltered input value
*
* The cached value is set to unfiltered input value.
*
* Suitable for datapipes designed to be re-run in mind - in practice
* this would be brightness control pipes where the input is setting
* value and output is light sensor filtered hw brightness level.
*/
DATAPIPE_CACHE_INDATA = 1<<0,
/** Update cache with filtered input value
*
* The cached value is set to filtered input value.
*/
DATAPIPE_CACHE_OUTDATA = 1<<1,
/* Update cache both with unfiltered and filtered input value
*
* The cached value is updated both before and after filtering.
*
* As this is the least likely option to cause differences between
* direct datapipe polling and following notifications, it should
* be used unless there is some specific reason not to.
*/
DATAPIPE_CACHE_DEFAULT = (DATAPIPE_CACHE_INDATA |
DATAPIPE_CACHE_OUTDATA),
} datapipe_cache_t;
/**
* Datapipe structure
*
* Only access this struct through the functions
*/
typedef struct datapipe_t datapipe_t;
typedef struct
{
datapipe_t *datapipe;
void (*output_cb)(gconstpointer data);
void (*input_cb)(gconstpointer data);
gpointer (*filter_cb)(gpointer data);
bool bound;
} datapipe_handler_t;
typedef struct
{
const char *module;
datapipe_handler_t *handlers;
guint execute_id;
} datapipe_bindings_t;
/* ========================================================================= *
* Functions
* ========================================================================= */
/* ------------------------------------------------------------------------- *
* DATAPIPE
* ------------------------------------------------------------------------- */
const char *datapipe_name (const datapipe_t *self);
gconstpointer datapipe_value (const datapipe_t *self);
gconstpointer datapipe_exec_full_real(datapipe_t *self, gconstpointer indata,
const char *file, const char *func);
void datapipe_set_value(datapipe_t *self, gconstpointer data);
#define datapipe_exec_full(PIPE_,DATA_)\
datapipe_exec_full_real(PIPE_,DATA_,__FILE__,__func__)
/* ------------------------------------------------------------------------- *
* MCE_DATAPIPE
* ------------------------------------------------------------------------- */
void mce_datapipe_init (void);
void mce_datapipe_quit (void);
void mce_datapipe_init_bindings(datapipe_bindings_t *self);
void mce_datapipe_quit_bindings(datapipe_bindings_t *self);
void mce_datapipe_generate_activity (void);
void mce_datapipe_generate_inactivity (void);
/* ========================================================================= *
* Macros
* ========================================================================= */
/** Retrieve a gint from a datapipe */
# define datapipe_get_gint(_datapipe) ((gint)(intptr_t)(void*)datapipe_value(&(_datapipe)))
/** Retrieve a guint from a datapipe */
# define datapipe_get_guint(_datapipe) ((guint)(uintptr_t)(void*)datapipe_value(&(_datapipe)))
/* Helper for making display state requests
*
* This needs to be macro so that logging context stays
* at the point of call.
*/
# define mce_datapipe_request_display_state(state_) do {\
display_state_t cur_target = datapipe_get_gint(display_state_next_pipe);\
display_state_t req_target = (display_state_t)(state_);\
/* Use elevated logginng verbosity for requests that \
* are likely to result in display power up. */ \
int level = LL_DEBUG; \
if( cur_target != req_target ) {\
switch( req_target ) {\
case MCE_DISPLAY_ON:\
case MCE_DISPLAY_LPM_ON:\
level = LL_CRUCIAL;\
break;\
default:\
break;\
}\
}\
mce_log(level, "display state req: %s",\
display_state_repr(req_target));\
/* But the request must always be fed to the datapipe \
* because during already ongoing transition something \
* else might be already queued up and we want't the \
* last request to reach the queue to "win". */ \
datapipe_exec_full(&display_state_request_pipe,\
GINT_TO_POINTER(req_target));\
} while(0)
/** Execute tklock request
*
* @param tklock_request Value from tklock_request_t
*/
#define mce_datapipe_request_tklock(tklock_request) do {\
mce_log(LL_DEBUG, "Requesting tklock=%s",\
tklock_request_repr(tklock_request));\
datapipe_exec_full(&tklock_request_pipe,\
GINT_TO_POINTER(tklock_request));\
}while(0)
/** Add reason -prefix for executing proximity_sensor_required_pipe request
*
* See #proximity_sensor_required_pipe for details.
*/
#define PROXIMITY_SENSOR_REQUIRED_ADD "+"
/** Remove reason -prefix for executing proximity_sensor_required_pipe request
*
* See #proximity_sensor_required_pipe for details.
*/
#define PROXIMITY_SENSOR_REQUIRED_REM "-"
/* ========================================================================= *
* Datapipes
* ========================================================================= */
/* Available datapipes */
extern datapipe_t led_brightness_pipe;
extern datapipe_t lpm_brightness_pipe;
extern datapipe_t device_inactive_pipe;
extern datapipe_t inactivity_event_pipe;
extern datapipe_t led_pattern_activate_pipe;
extern datapipe_t led_pattern_deactivate_pipe;
extern datapipe_t resume_detected_event_pipe;
extern datapipe_t user_activity_event_pipe;
extern datapipe_t display_state_curr_pipe;
extern datapipe_t display_state_request_pipe;
extern datapipe_t display_state_next_pipe;
extern datapipe_t uiexception_type_pipe;
extern datapipe_t display_brightness_pipe;
extern datapipe_t key_backlight_brightness_pipe;
extern datapipe_t keypress_event_pipe;
extern datapipe_t touchscreen_event_pipe;
extern datapipe_t lockkey_state_pipe;
extern datapipe_t init_done_pipe;
extern datapipe_t keyboard_slide_state_pipe;
extern datapipe_t keyboard_available_state_pipe;
extern datapipe_t mouse_available_state_pipe;
extern datapipe_t lid_sensor_is_working_pipe;
extern datapipe_t lid_sensor_actual_pipe;
extern datapipe_t lid_sensor_filtered_pipe;
extern datapipe_t lens_cover_state_pipe;
extern datapipe_t proximity_sensor_actual_pipe;
extern datapipe_t proximity_sensor_effective_pipe;
extern datapipe_t proximity_sensor_required_pipe;
extern datapipe_t proximity_blanked_pipe;
extern datapipe_t light_sensor_actual_pipe;
extern datapipe_t light_sensor_filtered_pipe;
extern datapipe_t light_sensor_poll_request_pipe;
extern datapipe_t orientation_sensor_actual_pipe;
extern datapipe_t alarm_ui_state_pipe;
extern datapipe_t system_state_pipe;
extern datapipe_t master_radio_enabled_pipe;
extern datapipe_t submode_pipe;
extern datapipe_t call_state_pipe;
extern datapipe_t ignore_incoming_call_event_pipe;
extern datapipe_t call_type_pipe;
extern datapipe_t tklock_request_pipe;
extern datapipe_t interaction_expected_pipe;
extern datapipe_t charger_type_pipe;
extern datapipe_t charger_state_pipe;
extern datapipe_t battery_status_pipe;
extern datapipe_t battery_state_pipe;
extern datapipe_t battery_level_pipe;
extern datapipe_t topmost_window_pid_pipe;
extern datapipe_t camera_button_state_pipe;
extern datapipe_t inactivity_delay_pipe;
extern datapipe_t audio_route_pipe;
extern datapipe_t usb_cable_state_pipe;
extern datapipe_t jack_sense_state_pipe;
extern datapipe_t power_saving_mode_active_pipe;
extern datapipe_t thermal_state_pipe;
extern datapipe_t heartbeat_event_pipe;
extern datapipe_t compositor_service_state_pipe;
extern datapipe_t lipstick_service_state_pipe;
extern datapipe_t devicelock_service_state_pipe;
extern datapipe_t usbmoded_service_state_pipe;
extern datapipe_t ngfd_service_state_pipe;
extern datapipe_t ngfd_event_request_pipe;
extern datapipe_t dsme_service_state_pipe;
extern datapipe_t thermalmanager_service_state_pipe;
extern datapipe_t bluez_service_state_pipe;
extern datapipe_t packagekit_locked_pipe;
extern datapipe_t osupdate_running_pipe;
extern datapipe_t shutting_down_pipe;
extern datapipe_t devicelock_state_pipe;
extern datapipe_t touch_detected_pipe;
extern datapipe_t touch_grab_wanted_pipe;
extern datapipe_t touch_grab_active_pipe;
extern datapipe_t keypad_grab_wanted_pipe;
extern datapipe_t keypad_grab_active_pipe;
extern datapipe_t music_playback_ongoing_pipe;
extern datapipe_t fpd_service_state_pipe;
extern datapipe_t fpstate_pipe;
extern datapipe_t enroll_in_progress_pipe;
extern datapipe_t memnotify_level_pipe;
#endif /* _DATAPIPE_H_ */