-
Notifications
You must be signed in to change notification settings - Fork 9
/
datapipe.c
2392 lines (2040 loc) · 80.2 KB
/
datapipe.c
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file datapipe.c
* This file implements the sinmple datapipe framework;
* this can be used to filter data and to setup data triggers
* <p>
* Copyright (c) 2007 - 2008 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2014 - 2021 Jolla Ltd.
* Copyright (c) 2019 - 2020 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/>.
*/
#include "mce.h"
#include "mce-log.h"
#include "mce-lib.h"
#include "evdev.h"
#include <mce/mode-names.h>
#include <linux/input.h>
#include <stdio.h>
/* ========================================================================= *
* Macros
* ========================================================================= */
#define cat2(a,b) a##b
#define cat3(a,b,c) a##b##c
#define datapipe_log(PIPE_, FMT_, ARGS_...)\
do {\
if( mce_log_p(LL_DEBUG) || \
mce_log_p_(LL_DEBUG,__FILE__,PIPE_->dp_name) ) {\
mce_log_unconditional(LL_DEBUG, __FILE__, __func__,\
FMT_ , ## ARGS_);\
}\
} while(0)
/* ========================================================================= *
* Types
* ========================================================================= */
struct datapipe_t
{
const char *dp_name; /**< Name of the datapipe */
GSList *dp_filters; /**< The filters */
GSList *dp_input_triggers; /**< Triggers called on indata */
GSList *dp_output_triggers; /**< Triggers called on outdata */
gconstpointer dp_cached_data; /**< Latest cached data */
gsize dp_datasize; /**< Size of data; NULL == automagic */
datapipe_filtering_t dp_read_only; /**< Datapipe is read only */
datapipe_cache_t dp_cache;
guint dp_gc_id;
guint dp_token;
const char *(*dp_value_repr_cb)(gconstpointer value);
const char *(*dp_change_repr_cb)(gconstpointer prev, gconstpointer curr);
};
#define DATAPIPE_INIT(NAME_,TYPE_,VALUE_,SIZE_,FILTERING_,CACHING_)\
{\
.dp_name = #NAME_ "_pipe",\
.dp_filters = 0,\
.dp_input_triggers = 0,\
.dp_output_triggers = 0,\
.dp_cached_data = GINT_TO_POINTER(VALUE_),\
.dp_datasize = SIZE_,\
.dp_read_only = FILTERING_,\
.dp_cache = CACHING_,\
.dp_gc_id = 0,\
.dp_token = 0,\
.dp_value_repr_cb = cat3(datapipe_hook_,TYPE_,_value),\
.dp_change_repr_cb = cat3(datapipe_hook_,TYPE_,_change),\
}
/* ========================================================================= *
* Prototypes
* ========================================================================= */
/* ------------------------------------------------------------------------- *
* DATAPIPE_HOOK
* ------------------------------------------------------------------------- */
static const char *datapipe_hook_int_value (gconstpointer data);
static const char *datapipe_hook_boolean_value (gconstpointer data);
static const char *datapipe_hook_string_value (gconstpointer data);
static const char *datapipe_hook_impulse_value (gconstpointer data);
static const char *datapipe_hook_input_event_value (gconstpointer data);
static const char *datapipe_hook_input_event_ptr_value (gconstpointer data);
static const char *datapipe_hook_display_state_value (gconstpointer data);
static const char *datapipe_hook_uiexception_type_value (gconstpointer data);
static const char *datapipe_hook_lockkey_state_value (gconstpointer data);
static const char *datapipe_hook_tristate_value (gconstpointer data);
static const char *datapipe_hook_cover_state_value (gconstpointer data);
static const char *datapipe_hook_orientation_state_value (gconstpointer data);
static const char *datapipe_hook_alarm_ui_state_value (gconstpointer data);
static const char *datapipe_hook_system_state_value (gconstpointer data);
static const char *datapipe_hook_submode_value (gconstpointer data);
static const char *datapipe_hook_submode_change (gconstpointer prev, gconstpointer curr);
static const char *datapipe_hook_call_state_value (gconstpointer data);
static const char *datapipe_hook_call_type_value (gconstpointer data);
static const char *datapipe_hook_tklock_request_value (gconstpointer data);
static const char *datapipe_hook_charger_state_value (gconstpointer data);
static const char *datapipe_hook_charger_type_value (gconstpointer data);
static const char *datapipe_hook_battery_status_value (gconstpointer data);
static const char *datapipe_hook_battery_state_value (gconstpointer data);
static const char *datapipe_hook_camera_button_state_value(gconstpointer data);
static const char *datapipe_hook_audio_route_value (gconstpointer data);
static const char *datapipe_hook_usb_cable_state_value (gconstpointer data);
static const char *datapipe_hook_thermal_state_value (gconstpointer data);
static const char *datapipe_hook_service_state_value (gconstpointer data);
static const char *datapipe_hook_devicelock_state_value (gconstpointer data);
static const char *datapipe_hook_fpstate_value (gconstpointer data);
static const char *datapipe_hook_memnotify_level_value (gconstpointer data);
/* ------------------------------------------------------------------------- *
* DATAPIPE
* ------------------------------------------------------------------------- */
const char *datapipe_name (const datapipe_t *self);
gconstpointer datapipe_value (const datapipe_t *self);
void datapipe_set_value (datapipe_t *self, gconstpointer data);
static void datapipe_gc (datapipe_t *self);
static gboolean datapipe_gc_cb (gpointer aptr);
static void datapipe_schedule_gc (datapipe_t *self);
static void datapipe_cancel_gc (datapipe_t *self);
gconstpointer datapipe_exec_full_real (datapipe_t *self, gconstpointer indata, const char *file, const char *func);
static void datapipe_add_filter (datapipe_t *self, gpointer (*filter)(gpointer data));
static void datapipe_remove_filter (datapipe_t *self, gpointer (*filter)(gpointer data));
static void datapipe_add_input_trigger (datapipe_t *self, void (*trigger)(gconstpointer data));
static void datapipe_remove_input_trigger (datapipe_t *self, void (*trigger)(gconstpointer data));
static void datapipe_add_output_trigger (datapipe_t *self, void (*trigger)(gconstpointer data));
static void datapipe_remove_output_trigger(datapipe_t *self, void (*trigger)(gconstpointer data));
static void datapipe_free (datapipe_t *self);
/* ------------------------------------------------------------------------- *
* MCE_DATAPIPE
* ------------------------------------------------------------------------- */
void mce_datapipe_init (void);
void mce_datapipe_quit (void);
static void mce_datapipe_install_handlers (datapipe_handler_t *bindings);
static void mce_datapipe_remove_handlers (datapipe_handler_t *bindings);
static void mce_datapipe_execute_handlers (datapipe_handler_t *bindings);
static gboolean mce_datapipe_execute_handlers_cb(gpointer aptr);
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);
/* ------------------------------------------------------------------------- *
* SUBMODE
* ------------------------------------------------------------------------- */
const char *submode_change_repr(submode_t prev, submode_t curr);
const char *submode_repr (submode_t submode);
/* ------------------------------------------------------------------------- *
* SYSTEM_STATE
* ------------------------------------------------------------------------- */
const char *system_state_repr(system_state_t state);
/* ------------------------------------------------------------------------- *
* DEVICELOCK_STATE
* ------------------------------------------------------------------------- */
const char *devicelock_state_repr(devicelock_state_t state);
/* ------------------------------------------------------------------------- *
* THERMAL_STATE
* ------------------------------------------------------------------------- */
const char *thermal_state_repr(thermal_state_t state);
/* ------------------------------------------------------------------------- *
* UIEXCEPTION_TYPE
* ------------------------------------------------------------------------- */
const char *uiexception_type_repr (uiexception_type_t type);
const char *uiexception_type_to_dbus(uiexception_type_t type);
/* ------------------------------------------------------------------------- *
* SERVICE_STATE
* ------------------------------------------------------------------------- */
const char *service_state_repr(service_state_t state);
/* ------------------------------------------------------------------------- *
* USB_CABLE_STATE
* ------------------------------------------------------------------------- */
const char *usb_cable_state_repr (usb_cable_state_t state);
const char *usb_cable_state_to_dbus(usb_cable_state_t state);
/* ------------------------------------------------------------------------- *
* CHARGER_TYPE
* ------------------------------------------------------------------------- */
const char *charger_type_repr (charger_type_t type);
const char *charger_type_to_dbus(charger_type_t type);
/* ------------------------------------------------------------------------- *
* CHARGER_STATE
* ------------------------------------------------------------------------- */
const char *charger_state_repr (charger_state_t state);
const char *charger_state_to_dbus(charger_state_t state);
/* ------------------------------------------------------------------------- *
* CAMERA_BUTTON_STATE
* ------------------------------------------------------------------------- */
const char *camera_button_state_repr(camera_button_state_t state);
/* ------------------------------------------------------------------------- *
* AUDIO_ROUTE
* ------------------------------------------------------------------------- */
const char *audio_route_repr(audio_route_t state);
/* ------------------------------------------------------------------------- *
* TKLOCK_REQUEST
* ------------------------------------------------------------------------- */
const char *tklock_request_repr(tklock_request_t state);
/* ------------------------------------------------------------------------- *
* TKLOCK_STATUS
* ------------------------------------------------------------------------- */
const char *tklock_status_repr(int status);
/* ------------------------------------------------------------------------- *
* BATTERY_STATUS
* ------------------------------------------------------------------------- */
const char *battery_status_repr (battery_status_t state);
const char *battery_status_to_dbus(battery_status_t state);
/* ------------------------------------------------------------------------- *
* BATTERY_STATE
* ------------------------------------------------------------------------- */
const char *battery_state_repr (battery_state_t state);
const char *battery_state_to_dbus(battery_state_t state);
/* ------------------------------------------------------------------------- *
* ALARM_STATE
* ------------------------------------------------------------------------- */
const char *alarm_state_repr(alarm_ui_state_t state);
/* ------------------------------------------------------------------------- *
* CALL_STATE
* ------------------------------------------------------------------------- */
const char *call_state_to_dbus (call_state_t state);
call_state_t call_state_from_dbus(const char *name);
const char *call_state_repr (call_state_t state);
/* ------------------------------------------------------------------------- *
* CALL_TYPE
* ------------------------------------------------------------------------- */
const char *call_type_repr (call_type_t type);
call_type_t call_type_parse(const char *name);
/* ------------------------------------------------------------------------- *
* COVER_STATE
* ------------------------------------------------------------------------- */
const char *cover_state_repr(cover_state_t state);
/* ------------------------------------------------------------------------- *
* PROXIMITY_STATE
* ------------------------------------------------------------------------- */
const char *proximity_state_repr(cover_state_t state);
/* ------------------------------------------------------------------------- *
* DISPLAY_STATE
* ------------------------------------------------------------------------- */
const char *display_state_repr(display_state_t state);
/* ------------------------------------------------------------------------- *
* ORIENTATION_STATE
* ------------------------------------------------------------------------- */
const char *orientation_state_repr(orientation_state_t state);
/* ------------------------------------------------------------------------- *
* KEY_STATE
* ------------------------------------------------------------------------- */
const char *key_state_repr(key_state_t state);
/* ------------------------------------------------------------------------- *
* TRISTATE
* ------------------------------------------------------------------------- */
const char *tristate_repr(tristate_t state);
/* ------------------------------------------------------------------------- *
* FPSTATE
* ------------------------------------------------------------------------- */
fpstate_t fpstate_parse(const char *name);
const char *fpstate_repr (fpstate_t state);
/* ========================================================================= *
* DATAPIPE_HOOK
* ========================================================================= */
/* For each datatype used in datapipes there exist:
* - datapipe_hook_<type>_value
* - datapipe_hook_<type>_changes
*
* These are used in expansion of #DATAPIPE_INIT() macro and must resolve
* either to a valid callback function or null pointer.
*/
static const char *
datapipe_hook_int_value(gconstpointer data)
{
static char buf[32];
snprintf(buf, sizeof buf, "%d", GPOINTER_TO_INT(data));
return buf;
}
#define datapipe_hook_int_change 0
static const char *
datapipe_hook_boolean_value(gconstpointer data)
{
return data ? "true" : "false";
}
#define datapipe_hook_boolean_change 0
static const char *
datapipe_hook_string_value(gconstpointer data)
{
return data;
}
#define datapipe_hook_string_change 0
static const char *
datapipe_hook_impulse_value(gconstpointer data)
{
(void)data;
return "impulse";
}
#define datapipe_hook_impulse_change 0
static const char *
datapipe_hook_input_event_value(gconstpointer data)
{
static char buf[64];
const struct input_event *ev = data;
if( !ev )
return "NULL event!";
snprintf(buf, sizeof buf, "type: %s, code: %s, value: %d",
evdev_get_event_type_name(ev->type),
evdev_get_event_code_name(ev->type, ev->code),
ev->value);
return buf;
}
#define datapipe_hook_input_event_change 0
static const char *
datapipe_hook_input_event_ptr_value(gconstpointer data)
{
const struct input_event *const*evp = data;
if( !evp )
return "NULL event ptr!";
return datapipe_hook_input_event_value(*evp);
}
#define datapipe_hook_input_event_ptr_change 0
static const char *
datapipe_hook_display_state_value(gconstpointer data)
{
display_state_t display_state = GPOINTER_TO_INT(data);
return display_state_repr(display_state);
}
#define datapipe_hook_display_state_change 0
static const char *
datapipe_hook_uiexception_type_value(gconstpointer data)
{
uiexception_type_t value = GPOINTER_TO_INT(data);
return uiexception_type_repr(value);
}
#define datapipe_hook_uiexception_type_change 0
static const char *
datapipe_hook_lockkey_state_value(gconstpointer data)
{
key_state_t key_state = GPOINTER_TO_INT(data);
return key_state_repr(key_state);
}
#define datapipe_hook_lockkey_state_change 0
static const char *
datapipe_hook_tristate_value(gconstpointer data)
{
tristate_t value = GPOINTER_TO_INT(data);
return tristate_repr(value);
}
#define datapipe_hook_tristate_change 0
static const char *
datapipe_hook_cover_state_value(gconstpointer data)
{
cover_state_t value = GPOINTER_TO_INT(data);
return cover_state_repr(value);
}
#define datapipe_hook_cover_state_change 0
static const char *
datapipe_hook_orientation_state_value(gconstpointer data)
{
orientation_state_t value = GPOINTER_TO_INT(data);
return orientation_state_repr(value);
}
#define datapipe_hook_orientation_state_change 0
static const char *
datapipe_hook_alarm_ui_state_value(gconstpointer data)
{
alarm_ui_state_t value = GPOINTER_TO_INT(data);
return alarm_state_repr(value);
}
#define datapipe_hook_alarm_ui_state_change 0
static const char *
datapipe_hook_system_state_value(gconstpointer data)
{
system_state_t value = GPOINTER_TO_INT(data);
return system_state_repr(value);
}
#define datapipe_hook_system_state_change 0
static const char *
datapipe_hook_submode_value(gconstpointer data)
{
submode_t value = GPOINTER_TO_INT(data);
return submode_repr(value);
}
static const char *
datapipe_hook_submode_change(gconstpointer prev, gconstpointer curr)
{
submode_t v1 = GPOINTER_TO_INT(prev);
submode_t v2 = GPOINTER_TO_INT(curr);
return submode_change_repr(v1, v2);
}
static const char *
datapipe_hook_call_state_value(gconstpointer data)
{
call_state_t value = GPOINTER_TO_INT(data);
return call_state_repr(value);
}
#define datapipe_hook_call_state_change 0
static const char *
datapipe_hook_call_type_value(gconstpointer data)
{
call_type_t value = GPOINTER_TO_INT(data);
return call_type_repr(value);
}
#define datapipe_hook_call_type_change 0
static const char *
datapipe_hook_tklock_request_value(gconstpointer data)
{
tklock_request_t value = GPOINTER_TO_INT(data);
return tklock_request_repr(value);
}
#define datapipe_hook_tklock_request_change 0
static const char *
datapipe_hook_charger_type_value(gconstpointer data)
{
charger_type_t value = GPOINTER_TO_INT(data);
return charger_type_repr(value);
}
#define datapipe_hook_charger_type_change 0
static const char *
datapipe_hook_charger_state_value(gconstpointer data)
{
charger_state_t value = GPOINTER_TO_INT(data);
return charger_state_repr(value);
}
#define datapipe_hook_charger_state_change 0
static const char *
datapipe_hook_battery_status_value(gconstpointer data)
{
battery_status_t value = GPOINTER_TO_INT(data);
return battery_status_repr(value);
}
#define datapipe_hook_battery_status_change 0
static const char *
datapipe_hook_battery_state_value(gconstpointer data)
{
battery_state_t value = GPOINTER_TO_INT(data);
return battery_state_repr(value);
}
#define datapipe_hook_battery_state_change 0
static const char *
datapipe_hook_camera_button_state_value(gconstpointer data)
{
camera_button_state_t value = GPOINTER_TO_INT(data);
return camera_button_state_repr(value);
}
#define datapipe_hook_camera_button_state_change 0
static const char *
datapipe_hook_audio_route_value(gconstpointer data)
{
audio_route_t value = GPOINTER_TO_INT(data);
return audio_route_repr(value);
}
#define datapipe_hook_audio_route_change 0
static const char *
datapipe_hook_usb_cable_state_value(gconstpointer data)
{
usb_cable_state_t value = GPOINTER_TO_INT(data);
return usb_cable_state_repr(value);
}
#define datapipe_hook_usb_cable_state_change 0
static const char *
datapipe_hook_thermal_state_value(gconstpointer data)
{
thermal_state_t value = GPOINTER_TO_INT(data);
return thermal_state_repr(value);
}
#define datapipe_hook_thermal_state_change 0
static const char *
datapipe_hook_service_state_value(gconstpointer data)
{
service_state_t value = GPOINTER_TO_INT(data);
return service_state_repr(value);
}
#define datapipe_hook_service_state_change 0
static const char *
datapipe_hook_devicelock_state_value(gconstpointer data)
{
devicelock_state_t value = GPOINTER_TO_INT(data);
return devicelock_state_repr(value);
}
#define datapipe_hook_devicelock_state_change 0
static const char *
datapipe_hook_fpstate_value(gconstpointer data)
{
fpstate_t value = GPOINTER_TO_INT(data);
return fpstate_repr(value);
}
#define datapipe_hook_fpstate_change 0
static const char *
datapipe_hook_memnotify_level_value(gconstpointer data)
{
memnotify_level_t value = GPOINTER_TO_INT(data);
return memnotify_level_repr(value);
}
#define datapipe_hook_memnotify_level_change 0
/* ========================================================================= *
* Data
* ========================================================================= */
/* Available datapipes */
/** LED brightness */
datapipe_t led_brightness_pipe = DATAPIPE_INIT(led_brightness, int, 0, 0, DATAPIPE_FILTERING_ALLOWED, DATAPIPE_CACHE_INDATA);
/** LPM brightness */
datapipe_t lpm_brightness_pipe = DATAPIPE_INIT(lpm_brightness, int, 0, 0, DATAPIPE_FILTERING_ALLOWED, DATAPIPE_CACHE_INDATA);
/** State of device; read only */
datapipe_t device_inactive_pipe = DATAPIPE_INIT(device_inactive, boolean, true, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Device inactivity events; read only */
datapipe_t inactivity_event_pipe = DATAPIPE_INIT(inactivity_event, boolean, true, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** LED pattern to activate; read only */
datapipe_t led_pattern_activate_pipe = DATAPIPE_INIT(led_pattern_activate, string, 0, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_NOTHING);
/** LED pattern to deactivate; read only */
datapipe_t led_pattern_deactivate_pipe = DATAPIPE_INIT(led_pattern_deactivate, string, 0, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_NOTHING);
/** resumed from suspend notification; read only */
datapipe_t resume_detected_event_pipe = DATAPIPE_INIT(resume_detected_event, impulse, 0, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_NOTHING);
/** Non-synthetized user activity; read only */
datapipe_t user_activity_event_pipe = DATAPIPE_INIT(user_activity_event, input_event, 0, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_NOTHING);
/** State of display; read only */
datapipe_t display_state_curr_pipe = DATAPIPE_INIT(display_state_curr, display_state, MCE_DISPLAY_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Desired state of display; write only */
datapipe_t display_state_request_pipe = DATAPIPE_INIT(display_state_request, display_state, MCE_DISPLAY_UNDEF, 0, DATAPIPE_FILTERING_ALLOWED, DATAPIPE_CACHE_DEFAULT);
/** Next (non-transitional) state of display; read only */
datapipe_t display_state_next_pipe = DATAPIPE_INIT(display_state_next, display_state, MCE_DISPLAY_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** exceptional ui state; read write */
datapipe_t uiexception_type_pipe = DATAPIPE_INIT(uiexception_type, uiexception_type, UIEXCEPTION_TYPE_NONE, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/**
* Display brightness;
* bits 0-7 is brightness in percent (0-100)
* upper 8 bits is high brightness boost (0-2)
*/
datapipe_t display_brightness_pipe = DATAPIPE_INIT(display_brightness, int, 3, 0, DATAPIPE_FILTERING_ALLOWED, DATAPIPE_CACHE_INDATA);
/** Key backlight */
datapipe_t key_backlight_brightness_pipe = DATAPIPE_INIT(key_backlight_brightness, int, 0, 0, DATAPIPE_FILTERING_ALLOWED, DATAPIPE_CACHE_INDATA);
/** A key has been pressed */
datapipe_t keypress_event_pipe = DATAPIPE_INIT(keypress_event, input_event_ptr, 0, sizeof (struct input_event), DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_NOTHING);
/** Touchscreen activity took place */
datapipe_t touchscreen_event_pipe = DATAPIPE_INIT(touchscreen_event, input_event_ptr, 0, sizeof (struct input_event), DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_NOTHING);
/** The lock-key has been pressed; read only */
datapipe_t lockkey_state_pipe = DATAPIPE_INIT(lockkey_state, lockkey_state, KEY_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** The init-done condition has been reached; read only */
datapipe_t init_done_pipe = DATAPIPE_INIT(init_done, tristate, TRISTATE_UNKNOWN, 0, DATAPIPE_FILTERING_ALLOWED, DATAPIPE_CACHE_DEFAULT);
/** Keyboard open/closed; read only */
datapipe_t keyboard_slide_state_pipe = DATAPIPE_INIT(keyboard_slide_state, cover_state, COVER_CLOSED, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Keyboard available; read only */
datapipe_t keyboard_available_state_pipe = DATAPIPE_INIT(keyboard_available_state, cover_state, COVER_CLOSED, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Mouse available; read only */
datapipe_t mouse_available_state_pipe = DATAPIPE_INIT(mouse_available_state, cover_state, COVER_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Lid sensor is working state; read/write */
datapipe_t lid_sensor_is_working_pipe = DATAPIPE_INIT(lid_sensor_is_working, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Lid cover sensor open/closed; read only */
datapipe_t lid_sensor_actual_pipe = DATAPIPE_INIT(lid_sensor_actual, cover_state, COVER_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Lid cover policy state; read only */
datapipe_t lid_sensor_filtered_pipe = DATAPIPE_INIT(lid_sensor_filtered, cover_state, COVER_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Lens cover open/closed; read only */
datapipe_t lens_cover_state_pipe = DATAPIPE_INIT(lens_cover_state, cover_state, COVER_CLOSED, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Proximity sensor; read only */
datapipe_t proximity_sensor_actual_pipe = DATAPIPE_INIT(proximity_sensor_actual, cover_state, COVER_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Proximity sensor; read only */
datapipe_t proximity_sensor_effective_pipe = DATAPIPE_INIT(proximity_sensor_effective, cover_state, COVER_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Proximity sensor on-demand control; write only
*
* The data fed into proximity_sensor_required_pipe needs to
* be a statically allocated const string with format like:
*
* "<PREFIX><NAME>"
*
* Where <PREFIX> is one of:
*
* - PROXIMITY_SENSOR_REQUIRED_ADD: <NAME> is added to the
* list of resons to keep on-demand proximity sensor mode
* active.
*
* - PROXIMITY_SENSOR_REQUIRED_REM: <NAME> is from the the
* list of resons to keep on-demand proximity sensor mode
* active.
*/
datapipe_t proximity_sensor_required_pipe = DATAPIPE_INIT(proximity_sensor_required, string, 0, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_NOTHING);
/** proximity blanking; read only */
datapipe_t proximity_blanked_pipe = DATAPIPE_INIT(proximity_blanked, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Ambient light sensor; read only */
datapipe_t light_sensor_actual_pipe = DATAPIPE_INIT(light_sensor_actual, int, 400, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Filtered ambient light level; read only */
datapipe_t light_sensor_filtered_pipe = DATAPIPE_INIT(light_sensor_filtered, int, 400, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Temporary ambient light sensor enable; read/write */
datapipe_t light_sensor_poll_request_pipe = DATAPIPE_INIT(light_sensor_poll_request, boolean, false, 0, DATAPIPE_FILTERING_ALLOWED, DATAPIPE_CACHE_DEFAULT);
/** Orientation sensor; read only */
datapipe_t orientation_sensor_actual_pipe = DATAPIPE_INIT(orientation_sensor_actual, orientation_state, MCE_ORIENTATION_UNDEFINED, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** The alarm UI state */
datapipe_t alarm_ui_state_pipe = DATAPIPE_INIT(alarm_ui_state, alarm_ui_state, MCE_ALARM_UI_INVALID_INT32, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** The device state; read only */
datapipe_t system_state_pipe = DATAPIPE_INIT(system_state, system_state, MCE_SYSTEM_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Enable/disable radios */
datapipe_t master_radio_enabled_pipe = DATAPIPE_INIT(master_radio_enabled, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** The device submode */
datapipe_t submode_pipe = DATAPIPE_INIT(submode, submode, MCE_SUBMODE_NORMAL, 0, DATAPIPE_FILTERING_ALLOWED, DATAPIPE_CACHE_DEFAULT);
/** The call state */
datapipe_t call_state_pipe = DATAPIPE_INIT(call_state, call_state, CALL_STATE_NONE, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** The ignore incoming call "state".
*
* Note: Related actions happen when true is executed on the
* datapipe, but the cached value always remains at false.
*/
datapipe_t ignore_incoming_call_event_pipe = DATAPIPE_INIT(ignore_incoming_call_event, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_NOTHING);
/** The call type */
datapipe_t call_type_pipe = DATAPIPE_INIT(call_type, call_type, CALL_TYPE_NORMAL, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** The touchscreen/keypad lock state */
datapipe_t tklock_request_pipe = DATAPIPE_INIT(tklock_request, tklock_request, TKLOCK_REQUEST_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** UI side is in a state where user interaction is expected */
datapipe_t interaction_expected_pipe = DATAPIPE_INIT(interaction_expected, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Charger type; read only */
datapipe_t charger_type_pipe = DATAPIPE_INIT(charger_type, charger_type, CHARGER_TYPE_NONE, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Charger state; read only */
datapipe_t charger_state_pipe = DATAPIPE_INIT(charger_state, charger_state, CHARGER_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Battery status; read only */
datapipe_t battery_status_pipe = DATAPIPE_INIT(battery_status, battery_status, BATTERY_STATUS_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Battery state; read only */
datapipe_t battery_state_pipe = DATAPIPE_INIT(battery_state, battery_state, BATTERY_STATE_UNKNOWN, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Battery charge level; read only */
datapipe_t battery_level_pipe = DATAPIPE_INIT(battery_level, int, MCE_BATTERY_LEVEL_UNKNOWN, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Topmost window PID; read only */
datapipe_t topmost_window_pid_pipe = DATAPIPE_INIT(topmost_window_pid, int, -1, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Camera button; read only */
datapipe_t camera_button_state_pipe = DATAPIPE_INIT(camera_button_state, camera_button_state, CAMERA_BUTTON_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** The inactivity timeout; read only */
datapipe_t inactivity_delay_pipe = DATAPIPE_INIT(inactivity_delay, int, DEFAULT_INACTIVITY_DELAY, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Audio routing state; read only */
datapipe_t audio_route_pipe = DATAPIPE_INIT(audio_route, audio_route, AUDIO_ROUTE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** USB cable has been connected/disconnected; read only */
datapipe_t usb_cable_state_pipe = DATAPIPE_INIT(usb_cable_state, usb_cable_state, USB_CABLE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** A jack connector has been connected/disconnected; read only */
datapipe_t jack_sense_state_pipe = DATAPIPE_INIT(jack_sense_state, cover_state, COVER_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Power save mode is active; read only */
datapipe_t power_saving_mode_active_pipe = DATAPIPE_INIT(power_saving_mode_active, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Thermal state; read only */
datapipe_t thermal_state_pipe = DATAPIPE_INIT(thermal_state, thermal_state, THERMAL_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Heartbeat; read only */
datapipe_t heartbeat_event_pipe = DATAPIPE_INIT(heartbeat_event, impulse, 0, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_NOTHING);
/** compositor availability; read only */
datapipe_t compositor_service_state_pipe = DATAPIPE_INIT(compositor_service_state, service_state, SERVICE_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** lipstick availability; read only */
datapipe_t lipstick_service_state_pipe = DATAPIPE_INIT(lipstick_service_state, service_state, SERVICE_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** devicelock availability; read only */
datapipe_t devicelock_service_state_pipe = DATAPIPE_INIT(devicelock_service_state, service_state, SERVICE_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** usbmoded availability; read only */
datapipe_t usbmoded_service_state_pipe = DATAPIPE_INIT(usbmoded_service_state, service_state, SERVICE_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** ngfd availability; read only */
datapipe_t ngfd_service_state_pipe = DATAPIPE_INIT(ngfd_service_state, service_state, SERVICE_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Request ngfd event playing */
datapipe_t ngfd_event_request_pipe = DATAPIPE_INIT(ngfd_event_request, string, 0, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_NOTHING);
/** dsme availability; read only */
datapipe_t dsme_service_state_pipe = DATAPIPE_INIT(dsme_service_state, service_state, SERVICE_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** thermalmanager availability; read only */
datapipe_t thermalmanager_service_state_pipe = DATAPIPE_INIT(thermalmanager_service_state, service_state, SERVICE_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** bluez availability; read only */
datapipe_t bluez_service_state_pipe = DATAPIPE_INIT(bluez_service_state, service_state, SERVICE_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** PackageKit Locked status; read only */
datapipe_t packagekit_locked_pipe = DATAPIPE_INIT(packagekit_locked, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Update mode active status; read only */
datapipe_t osupdate_running_pipe = DATAPIPE_INIT(osupdate_running, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Shutting down; read only */
datapipe_t shutting_down_pipe = DATAPIPE_INIT(shutting_down, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Device Lock state; read only */
datapipe_t devicelock_state_pipe = DATAPIPE_INIT(devicelock_state, devicelock_state, DEVICELOCK_STATE_UNDEFINED, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** touchscreen input detected; read only */
datapipe_t touch_detected_pipe = DATAPIPE_INIT(touch_detected, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** touchscreen input grab required; read/write */
datapipe_t touch_grab_wanted_pipe = DATAPIPE_INIT(touch_grab_wanted, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** touchscreen input grab active; read only */
datapipe_t touch_grab_active_pipe = DATAPIPE_INIT(touch_grab_active, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** keypad input grab required; read/write */
datapipe_t keypad_grab_wanted_pipe = DATAPIPE_INIT(keypad_grab_wanted, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** keypad input grab active; read only */
datapipe_t keypad_grab_active_pipe = DATAPIPE_INIT(keypad_grab_active, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** music playback active; read only */
datapipe_t music_playback_ongoing_pipe = DATAPIPE_INIT(music_playback_ongoing, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** fingerprint daemon availability; read only */
datapipe_t fpd_service_state_pipe = DATAPIPE_INIT(fpd_service_state, service_state, SERVICE_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** fingerprint daemon state; read only */
datapipe_t fpstate_pipe = DATAPIPE_INIT(fpstate, fpstate, FPSTATE_UNSET, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** fingerprint is enrolling; read only */
datapipe_t enroll_in_progress_pipe = DATAPIPE_INIT(enroll_in_progress, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Memory pressure level; read only */
datapipe_t memnotify_level_pipe = DATAPIPE_INIT(memnotify_level, memnotify_level, MEMNOTIFY_LEVEL_UNKNOWN, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/* ========================================================================= *
* Functions
* ========================================================================= */
/** Get name of datapipe
*
* @param self The datapipe, or NULL
*
* @return datapipe name, or suitable placeholder value
*/
const char *
datapipe_name(const datapipe_t *self)
{
const char *name = "invalid";
if( self )
name = self->dp_name ?: "unnamed";
return name;
}
/** Get value of datapipe
*
* @param self The datapipe
*
* @return datapipe value, as void pointer
*/
gconstpointer
datapipe_value(const datapipe_t *self)
{
return self->dp_cached_data;
}
/** Set value of datapipe
*
* Note: Do not call this function from outside datapipe.c.
*
* While such calls exist to facilitate legacy hacks in the
* display plugin - no new code like that should be added.
*
* FIXME: Remove offending call sites and make this function
* static.
*
* The proper way to modify datapipe content is to use
* #datapipe_exec_full() function.
*
* @param self The datapipe
* @paran data The value, as void pointer
*/
void
datapipe_set_value(datapipe_t *self, gconstpointer data)
{
gconstpointer prev = self->dp_cached_data;
self->dp_cached_data = data;
if( prev != data ) {
if( self->dp_change_repr_cb ) {
datapipe_log(self, "%s: %s",
datapipe_name(self),
self->dp_change_repr_cb(prev, data));
}
else if( self->dp_value_repr_cb ) {
gchar *saved = g_strdup(self->dp_value_repr_cb(prev));
datapipe_log(self, "%s: %s -> %s",
datapipe_name(self),
saved,
self->dp_value_repr_cb(data));
g_free(saved);
}
else {
datapipe_log(self, "%s: %p -> %p",
datapipe_name(self),
prev, data);
}
}
}
/** Garbage collect stale callback slots
*
* While it can be assumed to be extremely rare, filters and triggers can end
* up being added/removed due to datapipe activity. In order to allow O(N)
* traversal in datapipe_exec_full() slots with removed callbacks are
* zeroed and left behind to be collected from idle callback.
*
* @param self The datapipe
*/
static void
datapipe_gc(datapipe_t *self)
{
/* Cancel pending idle callback */
datapipe_cancel_gc(self);
/* Flush out slots with null callback */
self->dp_input_triggers = g_slist_remove_all(self->dp_input_triggers, 0);
self->dp_filters = g_slist_remove_all(self->dp_filters, 0);
self->dp_output_triggers = g_slist_remove_all(self->dp_output_triggers, 0);
}
/** Garbage collect idle callback
*
* @param self The datapipe, as void pointer
*
* @return G_SOURCE_REMOVE
*/
static gboolean
datapipe_gc_cb(gpointer aptr)
{
datapipe_t *self = aptr;
self->dp_gc_id = 0;
datapipe_gc(self);
return G_SOURCE_REMOVE;
}
/** Schedule garbage collection
*
* @param self The datapipe, as void pointer
*/
static void
datapipe_schedule_gc(datapipe_t *self)
{
if( !self->dp_gc_id ) {
self->dp_gc_id = g_idle_add(datapipe_gc_cb, self);
}
}
/** Cancel garbage collection
*
* @param self The datapipe, as void pointer
*/
static void
datapipe_cancel_gc(datapipe_t *self)
{
if( self->dp_gc_id ) {
g_source_remove(self->dp_gc_id),
self->dp_gc_id = 0;
}
}
/** Execute the datapipe
*
* Note: Use #datapipe_exec_full() macro instead of calling
* this function directly.
*
* @param self The datapipe to execute
* @param indata The input data to run through the datapipe
* @return The processed data