/
callstate.c
1976 lines (1647 loc) · 50.1 KB
/
callstate.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 callstate.c
* Call state module -- this handles the call state for MCE
* <p>
* Copyright © 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2012-2019 Jolla Ltd.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Kalle Jokiniemi <kalle.jokiniemi@jolla.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
*
* 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-dbus.h"
#include "../mce-wltimer.h"
#include <stdlib.h>
#include <string.h>
#include <mce/dbus-names.h>
#include <gmodule.h>
#if 0 // DEBUG: make all logging from this module "critical"
# undef mce_log
# define mce_log(LEV, FMT, ARGS...) \
mce_log_file(LL_CRIT, __FILE__, __FUNCTION__, FMT , ## ARGS)
#endif
/* ========================================================================= *
* OFONO DBUS CONSTANTS
* ========================================================================= */
#define OFONO_SERVICE "org.ofono"
#define OFONO_MANAGER_INTERFACE "org.ofono.Manager"
#define OFONO_MANAGER_OBJECT "/"
#define OFONO_MANAGER_REQ_GET_MODEMS "GetModems"
#define OFONO_MANAGER_SIG_MODEM_ADDED "ModemAdded"
#define OFONO_MANAGER_SIG_MODEM_REMOVED "ModemRemoved"
#define OFONO_MODEM_INTERFACE "org.ofono.Modem"
#define OFONO_MODEM_SIG_PROPERTY_CHANGED "PropertyChanged"
#define OFONO_VCALLMANAGER_INTERFACE "org.ofono.VoiceCallManager"
#define OFONO_VCALLMANAGER_REQ_GET_CALLS "GetCalls"
#define OFONO_VCALLMANAGER_SIG_CALL_ADDED "CallAdded"
#define OFONO_VCALLMANAGER_SIG_CALL_REMOVED "CallRemoved"
#define OFONO_VCALL_INTERFACE "org.ofono.VoiceCall"
#define OFONO_VCALL_SIG_PROPERTY_CHANGED "PropertyChanged"
/* ========================================================================= *
* MODULE DETAILS
* ========================================================================= */
/** Module name */
#define MODULE_NAME "callstate"
/** Functionality provided by this module */
static const gchar *const provides[] = { MODULE_NAME, NULL };
/** Module information */
G_MODULE_EXPORT module_info_struct module_info = {
/** Name of the module */
.name = MODULE_NAME,
/** Module provides */
.provides = provides,
/** Module priority */
.priority = 250
};
/* ========================================================================= *
* MODULE DATA
* ========================================================================= */
/** Maximum number of concurrent call state requesters */
#define CLIENTS_MONITOR_COUNT 15
/** List of monitored call state requesters */
static GSList *clients_monitor_list = NULL;
/** Lookup table for state data / each call state requester */
static GHashTable *clients_state_lut = 0;
static void call_state_rethink_schedule(void);
static bool call_state_rethink_forced(void);
static void xofono_get_vcalls(const char *modem);
/* ========================================================================= *
* OFONO CALL STATE HELPERS
* ========================================================================= */
/** Enumeration of oFono voice call states */
typedef enum
{
OFONO_CALL_STATE_UNKNOWN,
OFONO_CALL_STATE_ACTIVE,
OFONO_CALL_STATE_HELD,
OFONO_CALL_STATE_DIALING,
OFONO_CALL_STATE_ALERTING,
OFONO_CALL_STATE_INCOMING,
OFONO_CALL_STATE_WAITING,
OFONO_CALL_STATE_DISCONNECTED,
OFONO_CALL_STATE_COUNT
} ofono_callstate_t;
/** Lookup table for oFono voice call states */
static const char * const ofono_callstate_lut[OFONO_CALL_STATE_COUNT] =
{
[OFONO_CALL_STATE_UNKNOWN] = "unknown",
[OFONO_CALL_STATE_ACTIVE] = "active",
[OFONO_CALL_STATE_HELD] = "held",
[OFONO_CALL_STATE_DIALING] = "dialing",
[OFONO_CALL_STATE_ALERTING] = "alerting",
[OFONO_CALL_STATE_INCOMING] = "incoming",
[OFONO_CALL_STATE_WAITING] = "waiting",
[OFONO_CALL_STATE_DISCONNECTED] = "disconnected",
};
/** oFono call state number to name
*/
#ifdef DEAD_CODE
static const char *
ofono_callstate_name(ofono_callstate_t callstate)
{
if( callstate < OFONO_CALL_STATE_COUNT )
return ofono_callstate_lut[callstate];
return ofono_callstate_lut[OFONO_CALL_STATE_UNKNOWN];
}
#endif
/** oFono call state name to number
*/
static ofono_callstate_t
ofono_callstate_lookup(const char *name)
{
ofono_callstate_t res = OFONO_CALL_STATE_UNKNOWN;
for( int i = 0; i < OFONO_CALL_STATE_COUNT; ++i ) {
if( !strcmp(ofono_callstate_lut[i], name) ) {
res = i;
break;
}
}
return res;
}
/** oFono call state name to mce call state number
*/
static call_state_t
ofono_callstate_to_mce(const char *name)
{
ofono_callstate_t ofono = ofono_callstate_lookup(name);
call_state_t mce = CALL_STATE_INVALID;
switch( ofono ) {
default:
case OFONO_CALL_STATE_UNKNOWN:
case OFONO_CALL_STATE_DISCONNECTED:
mce = CALL_STATE_NONE;
break;
case OFONO_CALL_STATE_INCOMING:
case OFONO_CALL_STATE_WAITING:
mce = CALL_STATE_RINGING;
break;
case OFONO_CALL_STATE_DIALING:
case OFONO_CALL_STATE_ALERTING:
case OFONO_CALL_STATE_ACTIVE:
case OFONO_CALL_STATE_HELD:
mce = CALL_STATE_ACTIVE;
break;
}
return mce;
}
/** oFono emergency flag to mce call type number
*/
static call_type_t ofono_calltype_to_mce(bool emergency)
{
return emergency ? CALL_TYPE_EMERGENCY : CALL_TYPE_NORMAL;
}
/* ========================================================================= *
* OFONO VOICECALL OBJECTS
* ========================================================================= */
/** oFono voice call state data
*/
typedef struct
{
char *name;
bool probed;
call_state_t state;
call_type_t type;
} ofono_vcall_t;
static void clients_merge_state_cb(gpointer key, gpointer val, gpointer aptr);
static void clients_merge_state (ofono_vcall_t *combined);
static void clients_set_state (const char *dbus_name, const ofono_vcall_t *vcall);
static void clients_get_state (const char *dbus_name, ofono_vcall_t *vcall);
static void clients_init (void);
static void clients_quit (void);
/** Mark incoming vcall as ignored
*
* @param self oFono voice call object
*/
static void
ofono_vcall_ignore_incoming_call(ofono_vcall_t *self)
{
if( self->state == CALL_STATE_RINGING ) {
mce_log(LL_DEBUG, "ignoring incoming vcall: %s",
self->name ?: "unnamed");
self->state = CALL_STATE_IGNORED;
}
}
/** Merge emergency data to oFono voice call object
*
* @param self oFono voice call object
* @param emergency emergency state to merge
*/
static void
ofono_vcall_merge_emergency(ofono_vcall_t *self, bool emergency)
{
if( emergency )
self->type = CALL_TYPE_EMERGENCY;
}
/** Merge state data from oFono voice call object to another
*
* @param self oFono voice call object
* @param emergency emergency state to merge
*/
static void
ofono_vcall_merge_vcall(ofono_vcall_t *self, const ofono_vcall_t *that)
{
/* When evaluating combined call state, we must
* give "ringing" state priority over "active"
* so that display and suspend policy works in
* expected manner. */
switch( that->state ) {
case CALL_STATE_ACTIVE:
if( self->state != CALL_STATE_RINGING )
self->state = CALL_STATE_ACTIVE;
break;
case CALL_STATE_RINGING:
self->state = CALL_STATE_RINGING;
break;
default:
break;
}
/* if any call is emergency, we have emergency call */
if( that->type == CALL_TYPE_EMERGENCY )
self->type = CALL_TYPE_EMERGENCY;
}
/** Create oFono voice call object
*
* @param name D-Bus object path
*
* @return oFono voice call object
*/
static ofono_vcall_t *
ofono_vcall_create(const char *path)
{
ofono_vcall_t *self = calloc(1, sizeof *self);
self->name = g_strdup(path);
self->probed = false;
self->state = CALL_STATE_INVALID;
self->type = CALL_TYPE_NORMAL;
mce_log(LL_DEBUG, "vcall=%s", self->name);
return self;
}
/** Delete oFono voice call object
*
* @param self oFono voice call object
*/
static void
ofono_vcall_delete(ofono_vcall_t *self)
{
if( self ) {
mce_log(LL_DEBUG, "vcall=%s", self->name);
g_free(self->name);
free(self);
}
}
/** Type agnostic callback function for deleting oFono voice call objects
*
* @param self oFono voice call object
*/
static void
ofono_vcall_delete_cb(gpointer self)
{
ofono_vcall_delete(self);
}
/** Update oFono voice call object from key string and variant
*
* @param self oFono voice call object
*/
static void
ofono_vcall_update_1(ofono_vcall_t *self, DBusMessageIter *iter)
{
const char *key = 0;
DBusMessageIter var;
if( !mce_dbus_iter_get_string(iter, &key) )
goto EXIT;
if( !mce_dbus_iter_get_variant(iter, &var) )
goto EXIT;
if( !strcmp(key, "Emergency") ) {
bool emergency = false;
if( !mce_dbus_iter_get_bool(&var, &emergency) )
goto EXIT;
self->type = ofono_calltype_to_mce(emergency);
mce_log(LL_DEBUG, "* %s = ofono:%s -> mce:%s", key,
emergency ? "true" : "false",
call_type_repr(self->type));
}
else if( !strcmp(key, "State") ) {
const char *str = 0;
if( !mce_dbus_iter_get_string(&var, &str) )
goto EXIT;
self->state = ofono_callstate_to_mce(str);
mce_log(LL_DEBUG, "* %s = ofono:%s -> mce:%s", key,str,
call_state_repr(self->state));
}
#if 0
else {
mce_log(LL_DEBUG, "* %s = %s", key, "...");
}
#endif
EXIT:
return;
}
/** Update oFono voice call object from array of dict entries
*
* @param self oFono voice call object
*/
static void
ofono_vcall_update_N(ofono_vcall_t *self, DBusMessageIter *iter)
{
DBusMessageIter arr2, dict;
// <arg name="properties" type="a{sv}"/>
self->probed = true;
if( !mce_dbus_iter_get_array(iter, &arr2) )
goto EXIT;
while( !mce_dbus_iter_at_end(&arr2) ) {
if( !mce_dbus_iter_get_entry(&arr2, &dict) )
goto EXIT;
ofono_vcall_update_1(self, &dict);
}
EXIT:
return;
}
/* ========================================================================= *
* MANAGE VOICE CALL OBJECTS
* ========================================================================= */
/** Lookup table for tracked voice call objects */
static GHashTable *vcalls_lut = 0;
/** Lookup a voice call objects by name
*
* @param name D-Bus object path
*
* @return object pointer, or NULL if not found
*/
static ofono_vcall_t *
vcalls_get_call(const char *name)
{
ofono_vcall_t *self = 0;
if( !vcalls_lut )
goto EXIT;
self = g_hash_table_lookup(vcalls_lut, name);
EXIT:
return self;
}
/** Lookup or create a voice call objects by name
*
* @param name D-Bus object path
*
* @return object pointer, or NULL on errors
*/
static ofono_vcall_t *
vcalls_add_call(const char *name)
{
ofono_vcall_t *self = 0;
if( !vcalls_lut )
goto EXIT;
if( !(self = g_hash_table_lookup(vcalls_lut, name)) ) {
self = ofono_vcall_create(name);
g_hash_table_replace(vcalls_lut, g_strdup(name), self);
}
EXIT:
return self;
}
/** Remove a voice call objects by name
*
* @param name D-Bus object path
*/
static void
vcalls_rem_call(const char *name)
{
if( !vcalls_lut )
goto EXIT;
g_hash_table_remove(vcalls_lut, name);
EXIT:
return;
}
/** Remove all tracked voice call objects
*
* @param name D-Bus object path
*/
static void
vcalls_rem_calls(void)
{
if( vcalls_lut )
g_hash_table_remove_all(vcalls_lut);
}
/** Initialize voice call object look up table */
static void
vcalls_init(void)
{
if( !vcalls_lut )
vcalls_lut = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, ofono_vcall_delete_cb);
}
/** Delete voice call object look up table */
static void
vcalls_quit(void)
{
if( vcalls_lut )
g_hash_table_unref(vcalls_lut), vcalls_lut = 0;
}
/* ========================================================================= *
* MODEM OBJECTS
* ========================================================================= */
/** oFono modem tracking data
*/
typedef struct
{
/** D-Bus object path for the modem */
char *name;
/** Flag for: Properties for this modem have been processed */
bool probed;
/** Flag for: The Emergency call property for the modem is set */
bool emergency;
/** Flag for: org.ofono.VoiceCallManager inteface is available */
bool vcalls_iface;
/** Flag for: async dbus query to get vcalls for this modem is made */
bool vcalls_probed;
} ofono_modem_t;
/** Create oFono modem tracking object
*
* @param name D-Bus object path
*
* @return object pointer
*/
static ofono_modem_t *
ofono_modem_create(const char *path)
{
ofono_modem_t *self = calloc(1, sizeof *self);
self->name = g_strdup(path);
self->probed = false;
self->emergency = false;
self->vcalls_iface = false;
self->vcalls_probed = false;
mce_log(LL_DEBUG, "modem=%s", self->name);
return self;
}
/** Delete oFono modem tracking object
*
* @param self object pointer, or NULL
*/
static void
ofono_modem_delete(ofono_modem_t *self)
{
if( self ) {
mce_log(LL_DEBUG, "modem=%s", self->name);
g_free(self->name);
free(self);
}
}
/** Type agnostic delete callback function for oFono modem tracking objects
*
* @param self object pointer, or NULL
*/
static void
ofono_modem_delete_cb(gpointer self)
{
ofono_modem_delete(self);
}
/** Update oFono modem tracking object from key + variant data
*
* @param self object pointer
* @param iter dbus message iterator pointing to key string + variant data
*/
static void
ofono_modem_update_1(ofono_modem_t *self, DBusMessageIter *iter)
{
const char *key = 0;
DBusMessageIter var;
if( !mce_dbus_iter_get_string(iter, &key) )
goto EXIT;
if( !mce_dbus_iter_get_variant(iter, &var) )
goto EXIT;
if( !strcmp(key, "Emergency") ) {
if( !mce_dbus_iter_get_bool(&var, &self->emergency) )
goto EXIT;
mce_log(LL_DEBUG, "* %s = %s", key,
self->emergency ? "true" : "false");
}
else if( !strcmp(key, "Interfaces") ) {
DBusMessageIter arr;
if( !mce_dbus_iter_get_array(&var, &arr) )
goto EXIT;
bool vcalls_iface = false;
while( !mce_dbus_iter_at_end(&arr) ) {
const char *iface = 0;
if( !mce_dbus_iter_get_string(&arr, &iface) )
goto EXIT;
if( strcmp(iface, OFONO_VCALLMANAGER_INTERFACE) )
continue;
vcalls_iface = true;
break;
}
if( self->vcalls_iface != vcalls_iface ) {
self->vcalls_iface = vcalls_iface;
self->vcalls_probed = false;
mce_log(LL_NOTICE, "%s interface %savailable",
OFONO_VCALLMANAGER_INTERFACE,
self->vcalls_iface ? "" : "not ");
}
}
#if 0
else {
mce_log(LL_DEBUG, "* %s = %s", key, "...");
}
#endif
EXIT:
return;
}
/** Update oFono modem tracking object from array of dict entries
*
* @param self object pointer
* @param iter dbus message iterator pointing to array of dict entries
*/
static void
ofono_modem_update_N(ofono_modem_t *self, DBusMessageIter *iter)
{
DBusMessageIter arr2, dict;
self->probed = true;
// <arg name="properties" type="a{sv}"/>
if( !mce_dbus_iter_get_array(iter, &arr2) )
goto EXIT;
while( !mce_dbus_iter_at_end(&arr2) ) {
if( !mce_dbus_iter_get_entry(&arr2, &dict) )
goto EXIT;
ofono_modem_update_1(self, &dict);
}
EXIT:
return;
}
/** Get voice calls for a modem
*
* If org.ofono.VoiceCallManager D-Bus interface is available for use,
* enumerate voice call objects for the modem to get initial properties
* of the calls.
*
* @param self object pointer
*/
static void
ofono_modem_get_vcalls(ofono_modem_t *self)
{
/* Interface available? */
if( !self->vcalls_iface )
goto EXIT;
/* Already done? */
if( self->vcalls_probed )
goto EXIT;
/* Mark as done */
self->vcalls_probed = true;
/* Start async D-Bus query */
xofono_get_vcalls(self->name);
EXIT:
return;
}
/* ========================================================================= *
* MODEMS
* ========================================================================= */
/** Lookup table for tracked oFono modem objects */
static GHashTable *modems_lut = 0;
/** Lookup modem object by name
*
* @param name D-Bus object path
*
* @return object pointer, or NULL
*/
static ofono_modem_t *
modems_get_modem(const char *name)
{
ofono_modem_t *self = 0;
if( !modems_lut )
goto EXIT;
self = g_hash_table_lookup(modems_lut, name);
EXIT:
return self;
}
/** Lookup existing / insert new modem object by name
*
* @param name D-Bus object path
*
* @return object pointer, or NULL
*/
static ofono_modem_t *
modems_add_modem(const char *name)
{
ofono_modem_t *self = 0;
if( !modems_lut )
goto EXIT;
if( !(self = g_hash_table_lookup(modems_lut, name)) ) {
self = ofono_modem_create(name);
g_hash_table_replace(modems_lut, g_strdup(name), self);
}
EXIT:
return self;
}
/** Remove modem object by name
*
* @param name D-Bus object path
*/
static void
modems_rem_modem(const char *name)
{
if( !modems_lut )
goto EXIT;
g_hash_table_remove(modems_lut, name);
EXIT:
return;
}
/** Remove all tracked modem objects
*/
static void
modems_rem_all_modems(void)
{
if( modems_lut )
g_hash_table_remove_all(modems_lut);
}
/** Initialize lookup table for oFono modem tracking objects
*/
static void
modems_init(void)
{
if( !modems_lut )
modems_lut = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, ofono_modem_delete_cb);
}
/** Delete lookup table for oFono modem tracking objects
*/
static void
modems_quit(void)
{
if( modems_lut )
g_hash_table_unref(modems_lut), modems_lut = 0;
}
/* ========================================================================= *
* OFONO DBUS GLUE
* ========================================================================= */
/** Handle reply to voice calls query
*
* @param pc pending call object
* @param aptr (not used)
*/
static void
xofono_get_vcalls_cb(DBusPendingCall *pc, void *aptr)
{
(void) aptr;
DBusMessage *rsp = 0;
DBusError err = DBUS_ERROR_INIT;
int cnt = 0;
if( !(rsp = dbus_pending_call_steal_reply(pc)) ) {
mce_log(LL_ERR, "%s: no reply",
OFONO_VCALLMANAGER_REQ_GET_CALLS);
goto EXIT;
}
if( dbus_set_error_from_message(&err, rsp) ) {
mce_log(LL_ERR, "%s: %s", err.name, err.message);
goto EXIT;
}
// <arg name="calls_with_properties" type="a(oa{sv})" direction="out"/>
DBusMessageIter body, arr1, mod;
dbus_message_iter_init(rsp, &body);
if( !mce_dbus_iter_get_array(&body, &arr1) )
goto EXIT;
while( !mce_dbus_iter_at_end(&arr1) ) {
const char *name = 0;
if( !mce_dbus_iter_get_struct(&arr1, &mod) )
goto EXIT;
if( !mce_dbus_iter_get_object(&mod, &name) )
goto EXIT;
ofono_vcall_t *vcall = vcalls_add_call(name);
if( !vcall )
continue;
ofono_vcall_update_N(vcall, &mod);
++cnt;
}
call_state_rethink_schedule();
EXIT:
mce_log(LL_DEBUG, "added %d calls", cnt);
if( rsp ) dbus_message_unref(rsp);
dbus_error_free(&err);
return;
}
/** Get voice calls associated with a modem
*
* Populate voice call lookup table with the reply data
*
* @param modem D-Bus object path
*/
static void
xofono_get_vcalls(const char *modem)
{
dbus_send_ex(OFONO_SERVICE,
modem,
OFONO_VCALLMANAGER_INTERFACE,
OFONO_VCALLMANAGER_REQ_GET_CALLS,
xofono_get_vcalls_cb,
0,0,0,
DBUS_TYPE_INVALID);
}
/** Handle voice call changed signal
*
* Update voice call lookup table with the content
*
* @param msg property changed signal
*/
static gboolean
xofono_vcall_changed_cb(DBusMessage *const msg)
{
(void)msg;
DBusMessageIter body;
dbus_message_iter_init(msg, &body);
const char *name = dbus_message_get_path(msg);
if( !name )
goto EXIT;
ofono_vcall_t *vcall = vcalls_get_call(name);
if( !vcall )
goto EXIT;
ofono_vcall_update_1(vcall, &body);
call_state_rethink_schedule();
EXIT:
return TRUE;
}
/** Handle voice call added signal
*
* Update voice call lookup table with the content
*
* @param msg call added signal
*/
static gboolean
xofono_vcall_added_cb(DBusMessage *const msg)
{
(void)msg;
DBusMessageIter body;
dbus_message_iter_init(msg, &body);
const char *name = 0;
if( !mce_dbus_iter_get_object(&body, &name) )
goto EXIT;
ofono_vcall_t *vcall = vcalls_add_call(name);
if( vcall )
ofono_vcall_update_N(vcall, &body);
call_state_rethink_schedule();
EXIT:
return TRUE;
}
/** Handle voice call removed signal
*
* Update voice call lookup table with the content
*
* @param msg call removed signal
*/
static gboolean
xofono_vcall_removed_cb(DBusMessage *const msg)
{
(void)msg;
DBusMessageIter body;
dbus_message_iter_init(msg, &body);
const char *name = 0;
if( !mce_dbus_iter_get_object(&body, &name) )
goto EXIT;
vcalls_rem_call(name);
call_state_rethink_schedule();
EXIT:
return TRUE;
}
/** Handle reply to xofono_get_modems()
*
* @param pc pending call object
* @param aptr (not used)
*/
static void
xofono_get_modems_cb(DBusPendingCall *pc, void *aptr)
{
(void)aptr;
mce_log(LL_DEBUG, "%s.%s %s", OFONO_MANAGER_INTERFACE,
OFONO_MANAGER_REQ_GET_MODEMS, "reply");
DBusMessage *rsp = 0;
DBusError err = DBUS_ERROR_INIT;
int cnt = 0;
if( !(rsp = dbus_pending_call_steal_reply(pc)) )
goto EXIT;
if( dbus_set_error_from_message(&err, rsp) ) {
mce_log(LL_ERR, "%s: %s", err.name, err.message);
goto EXIT;
}
// <arg name="modems" type="a(oa{sv})" direction="out"/>
DBusMessageIter body, arr1, mod;
dbus_message_iter_init(rsp, &body);
if( !mce_dbus_iter_get_array(&body, &arr1) )
goto EXIT;
while( !mce_dbus_iter_at_end(&arr1) ) {
const char *name = 0;
if( !mce_dbus_iter_get_struct(&arr1, &mod) )
goto EXIT;
if( !mce_dbus_iter_get_object(&mod, &name) )
goto EXIT;
ofono_modem_t *modem = modems_add_modem(name);
if( !modem )
continue;
ofono_modem_update_N(modem, &mod);
ofono_modem_get_vcalls(modem);
++cnt;
}
call_state_rethink_schedule();
EXIT:
mce_log(LL_DEBUG, "added %d modems", cnt);
if( rsp ) dbus_message_unref(rsp);
dbus_error_free(&err);
}
/** Get list of modems [async]
*
* Populate modem lookup table with the reply data
*/
static void
xofono_get_modems(void)
{
bool res = dbus_send(OFONO_SERVICE,
OFONO_MANAGER_OBJECT,
OFONO_MANAGER_INTERFACE,
OFONO_MANAGER_REQ_GET_MODEMS,