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
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details:
*
* Copyright (C) 2024 Guido Günther <agx@sigxcpu.org>n
*/
#include <ModemManager.h>
#define _LIBMM_INSIDE_MM
#include <libmm-glib.h>
#include "mm-iface-modem.h"
#include "mm-iface-modem-cell-broadcast.h"
#include "mm-cbm-list.h"
#include "mm-log-object.h"
#include "mm-error-helpers.h"
#include "mm-modem-helpers.h"
#define SUPPORT_CHECKED_TAG "cell-broadcast-support-checked-tag"
#define SUPPORTED_TAG "cell-broadcast-supported-tag"
static GQuark support_checked_quark;
static GQuark supported_quark;
G_DEFINE_INTERFACE (MMIfaceModemCellBroadcast, mm_iface_modem_cell_broadcast, MM_TYPE_IFACE_MODEM)
/*****************************************************************************/
void
mm_iface_modem_cell_broadcast_bind_simple_status (MMIfaceModemCellBroadcast *self,
MMSimpleStatus *status)
{
}
/*****************************************************************************/
typedef struct {
MmGdbusModemCellBroadcast *skeleton;
GDBusMethodInvocation *invocation;
MMIfaceModemCellBroadcast *self;
GArray *channels;
} HandleSetChannelsCellBroadcastContext;
static void
handle_set_channels_context_free (HandleSetChannelsCellBroadcastContext *ctx)
{
g_object_unref (ctx->skeleton);
g_object_unref (ctx->invocation);
g_object_unref (ctx->self);
g_array_unref (ctx->channels);
g_slice_free (HandleSetChannelsCellBroadcastContext, ctx);
}
static void
set_channels_ready (MMIfaceModemCellBroadcast *self,
GAsyncResult *res,
HandleSetChannelsCellBroadcastContext *ctx)
{
GError *error = NULL;
if (!MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->set_channels_finish (self, res, &error))
mm_dbus_method_invocation_take_error (ctx->invocation, error);
else {
mm_gdbus_modem_cell_broadcast_set_channels (ctx->skeleton,
mm_common_cell_broadcast_channels_garray_to_variant (ctx->channels));
mm_gdbus_modem_cell_broadcast_complete_set_channels (ctx->skeleton, ctx->invocation);
}
handle_set_channels_context_free (ctx);
}
static void
handle_set_channels_auth_ready (MMIfaceAuth *_self,
GAsyncResult *res,
HandleSetChannelsCellBroadcastContext *ctx)
{
MMIfaceModemCellBroadcast *self = MM_IFACE_MODEM_CELL_BROADCAST (_self);
GError *error = NULL;
if (!mm_iface_auth_authorize_finish (_self, res, &error)) {
mm_dbus_method_invocation_take_error (ctx->invocation, error);
handle_set_channels_context_free (ctx);
return;
}
/* Validate channels (either number or range) */
if (!mm_validate_cbs_channels (ctx->channels, &error)) {
mm_dbus_method_invocation_return_gerror (ctx->invocation, error);
handle_set_channels_context_free (ctx);
return;
}
/* Check if plugin implements it */
if (!MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->set_channels ||
!MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->set_channels_finish) {
mm_dbus_method_invocation_return_error_literal (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
"Cannot set channels: not implemented");
handle_set_channels_context_free (ctx);
return;
}
/* Request to change channels */
mm_obj_info (self, "processing user request to set channels...");
MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->set_channels (ctx->self,
ctx->channels,
(GAsyncReadyCallback)set_channels_ready,
ctx);
}
static gboolean
handle_set_channels (MmGdbusModemCellBroadcast *skeleton,
GDBusMethodInvocation *invocation,
GVariant *channels,
MMIfaceModemCellBroadcast *self)
{
HandleSetChannelsCellBroadcastContext *ctx;
ctx = g_slice_new0 (HandleSetChannelsCellBroadcastContext);
ctx->skeleton = g_object_ref (skeleton);
ctx->invocation = g_object_ref (invocation);
ctx->self = g_object_ref (self);
ctx->channels = mm_common_cell_broadcast_channels_variant_to_garray (channels);
mm_iface_auth_authorize (MM_IFACE_AUTH (self),
invocation,
MM_AUTHORIZATION_DEVICE_CONTROL,
(GAsyncReadyCallback)handle_set_channels_auth_ready,
ctx);
return TRUE;
}
/*****************************************************************************/
typedef struct {
MmGdbusModemCellBroadcast *skeleton;
GDBusMethodInvocation *invocation;
MMIfaceModemCellBroadcast *self;
gchar *path;
} HandleDeleteContext;
static void
handle_delete_context_free (HandleDeleteContext *ctx)
{
g_object_unref (ctx->skeleton);
g_object_unref (ctx->invocation);
g_object_unref (ctx->self);
g_free (ctx->path);
g_slice_free (HandleDeleteContext, ctx);
}
static void
handle_delete_ready (MMCbmList *list,
GAsyncResult *res,
HandleDeleteContext *ctx)
{
GError *error = NULL;
if (!mm_cbm_list_delete_cbm_finish (list, res, &error)) {
mm_obj_warn (ctx->self, "failed deleting CBM message '%s': %s", ctx->path, error->message);
mm_dbus_method_invocation_take_error (ctx->invocation, error);
} else {
mm_obj_info (ctx->self, "deleted CBM message '%s'", ctx->path);
mm_gdbus_modem_cell_broadcast_complete_delete (ctx->skeleton, ctx->invocation);
}
handle_delete_context_free (ctx);
}
static void
handle_delete_auth_ready (MMIfaceAuth *_self,
GAsyncResult *res,
HandleDeleteContext *ctx)
{
MMIfaceModemCellBroadcast *self = MM_IFACE_MODEM_CELL_BROADCAST (_self);
g_autoptr(MMCbmList) list = NULL;
GError *error = NULL;
if (!mm_iface_auth_authorize_finish (_self, res, &error)) {
mm_dbus_method_invocation_take_error (ctx->invocation, error);
handle_delete_context_free (ctx);
return;
}
/* We do allow deleting CBMs while enabling or disabling, it doesn't
* interfere with the state transition logic to do so. The main reason to allow
* this is that during modem enabling we're emitting "Added" signals before we
* reach the enabled state, and so users listening to the signal may want to
* delete the CBM message as soon as it's read. */
if (mm_iface_modem_abort_invocation_if_state_not_reached (MM_IFACE_MODEM (self),
ctx->invocation,
MM_MODEM_STATE_DISABLING)) {
handle_delete_context_free (ctx);
return;
}
g_object_get (self,
MM_IFACE_MODEM_CELL_BROADCAST_CBM_LIST, &list,
NULL);
if (!list) {
mm_dbus_method_invocation_return_error_literal (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE,
"Cannot delete CBM: missing CBM list");
handle_delete_context_free (ctx);
return;
}
mm_obj_info (self, "processing user request to delete CBM message '%s'...", ctx->path);
mm_cbm_list_delete_cbm (list,
ctx->path,
(GAsyncReadyCallback)handle_delete_ready,
ctx);
}
static gboolean
handle_delete (MmGdbusModemCellBroadcast *skeleton,
GDBusMethodInvocation *invocation,
const gchar *path,
MMIfaceModemCellBroadcast *self)
{
HandleDeleteContext *ctx;
ctx = g_slice_new0 (HandleDeleteContext);
ctx->skeleton = g_object_ref (skeleton);
ctx->invocation = g_object_ref (invocation);
ctx->self = g_object_ref (self);
ctx->path = g_strdup (path);
mm_iface_auth_authorize (MM_IFACE_AUTH (self),
invocation,
MM_AUTHORIZATION_CELL_BROADCAST,
(GAsyncReadyCallback)handle_delete_auth_ready,
ctx);
return TRUE;
}
/*****************************************************************************/
static gboolean
handle_list (MmGdbusModemCellBroadcast *skeleton,
GDBusMethodInvocation *invocation,
MMIfaceModemCellBroadcast *self)
{
g_auto(GStrv) paths = NULL;
g_autoptr(MMCbmList) list = NULL;
if (mm_iface_modem_abort_invocation_if_state_not_reached (MM_IFACE_MODEM (self),
invocation,
MM_MODEM_STATE_ENABLED))
return TRUE;
g_object_get (self,
MM_IFACE_MODEM_CELL_BROADCAST_CBM_LIST, &list,
NULL);
if (!list) {
mm_dbus_method_invocation_return_error_literal (invocation, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE,
"Cannot list CBM: missing CBM list");
return TRUE;
}
mm_obj_info (self, "processing user request to list CBM messages...");
paths = mm_cbm_list_get_paths (list);
mm_gdbus_modem_cell_broadcast_complete_list (skeleton,
invocation,
(const gchar *const *)paths);
mm_obj_info (self, "reported %u CBM messages available", paths ? g_strv_length (paths) : 0);
return TRUE;
}
/*****************************************************************************/
typedef struct _InitializationContext InitializationContext;
static void interface_initialization_step (GTask *task);
typedef enum {
INITIALIZATION_STEP_FIRST,
INITIALIZATION_STEP_CHECK_SUPPORT,
INITIALIZATION_STEP_FAIL_IF_UNSUPPORTED,
INITIALIZATION_STEP_LAST
} InitializationStep;
struct _InitializationContext {
MmGdbusModemCellBroadcast *skeleton;
InitializationStep step;
};
static void
initialization_context_free (InitializationContext *ctx)
{
g_object_unref (ctx->skeleton);
g_free (ctx);
}
gboolean
mm_iface_modem_cell_broadcast_initialize_finish (MMIfaceModemCellBroadcast *self,
GAsyncResult *res,
GError **error)
{
return g_task_propagate_boolean (G_TASK (res), error);
}
static void
check_support_ready (MMIfaceModemCellBroadcast *self,
GAsyncResult *res,
GTask *task)
{
InitializationContext *ctx;
GError *error = NULL;
if (!MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->check_support_finish (self,
res,
&error)) {
if (error) {
/* This error shouldn't be treated as critical */
mm_obj_dbg (self, "cell broadcast support check failed: %s", error->message);
g_error_free (error);
}
} else {
/* CellBroadcast is supported! */
g_object_set_qdata (G_OBJECT (self),
supported_quark,
GUINT_TO_POINTER (TRUE));
}
/* Go on to next step */
ctx = g_task_get_task_data (task);
ctx->step++;
interface_initialization_step (task);
}
static void
interface_initialization_step (GTask *task)
{
MMIfaceModemCellBroadcast *self;
InitializationContext *ctx;
/* Don't run new steps if we're cancelled */
if (g_task_return_error_if_cancelled (task)) {
g_object_unref (task);
return;
}
self = g_task_get_source_object (task);
ctx = g_task_get_task_data (task);
switch (ctx->step) {
case INITIALIZATION_STEP_FIRST:
/* Setup quarks if we didn't do it before */
if (G_UNLIKELY (!support_checked_quark))
support_checked_quark = (g_quark_from_static_string (
SUPPORT_CHECKED_TAG));
if (G_UNLIKELY (!supported_quark))
supported_quark = (g_quark_from_static_string (
SUPPORTED_TAG));
ctx->step++;
/* fall through */
case INITIALIZATION_STEP_CHECK_SUPPORT:
if (!GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (self),
support_checked_quark))) {
/* Set the checked flag so that we don't run it again */
g_object_set_qdata (G_OBJECT (self),
support_checked_quark,
GUINT_TO_POINTER (TRUE));
/* Initially, assume we don't support it */
g_object_set_qdata (G_OBJECT (self),
supported_quark,
GUINT_TO_POINTER (FALSE));
if (MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->check_support &&
MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->check_support_finish) {
MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->check_support (
self,
(GAsyncReadyCallback)check_support_ready,
task);
return;
}
/* If there is no implementation to check support, assume we DON'T
* support it. */
}
ctx->step++;
/* fall through */
case INITIALIZATION_STEP_FAIL_IF_UNSUPPORTED:
if (!GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (self),
supported_quark))) {
g_task_return_new_error (task,
MM_CORE_ERROR,
MM_CORE_ERROR_UNSUPPORTED,
"CellBroadcast not supported");
g_object_unref (task);
return;
}
ctx->step++;
/* fall through */
case INITIALIZATION_STEP_LAST:
/* We are done without errors! */
/* Handle method invocations */
g_signal_connect (ctx->skeleton,
"handle-set-channels",
G_CALLBACK (handle_set_channels),
self);
g_signal_connect (ctx->skeleton,
"handle-delete",
G_CALLBACK (handle_delete),
self);
g_signal_connect (ctx->skeleton,
"handle-list",
G_CALLBACK (handle_list),
self);
/* Finally, export the new interface */
mm_gdbus_object_skeleton_set_modem_cell_broadcast (MM_GDBUS_OBJECT_SKELETON (self),
MM_GDBUS_MODEM_CELL_BROADCAST (ctx->skeleton));
g_task_return_boolean (task, TRUE);
g_object_unref (task);
return;
default:
break;
}
g_assert_not_reached ();
}
void
mm_iface_modem_cell_broadcast_initialize (MMIfaceModemCellBroadcast *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
InitializationContext *ctx;
MmGdbusModemCellBroadcast *skeleton = NULL;
GTask *task;
/* Did we already create it? */
g_object_get (self,
MM_IFACE_MODEM_CELL_BROADCAST_DBUS_SKELETON, &skeleton,
NULL);
if (!skeleton) {
skeleton = mm_gdbus_modem_cell_broadcast_skeleton_new ();
g_object_set (self,
MM_IFACE_MODEM_CELL_BROADCAST_DBUS_SKELETON, skeleton,
NULL);
}
/* Perform async initialization here */
ctx = g_new0 (InitializationContext, 1);
ctx->step = INITIALIZATION_STEP_FIRST;
ctx->skeleton = skeleton;
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_task_data (task, ctx, (GDestroyNotify)initialization_context_free);
interface_initialization_step (task);
}
void
mm_iface_modem_cell_broadcast_shutdown (MMIfaceModemCellBroadcast *self)
{
/* Unexport DBus interface and remove the skeleton */
mm_gdbus_object_skeleton_set_modem_cell_broadcast (MM_GDBUS_OBJECT_SKELETON (self), NULL);
g_object_set (self,
MM_IFACE_MODEM_CELL_BROADCAST_DBUS_SKELETON, NULL,
NULL);
}
/*****************************************************************************/
static void
update_message_list (MmGdbusModemCellBroadcast *skeleton,
MMCbmList *list)
{
gchar **paths;
paths = mm_cbm_list_get_paths (list);
mm_gdbus_modem_cell_broadcast_set_cell_broadcasts (skeleton, (const gchar *const *)paths);
g_strfreev (paths);
g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (skeleton));
}
static void
cbm_added (MMCbmList *list,
const gchar *cbm_path,
gboolean received,
MmGdbusModemCellBroadcast *skeleton)
{
update_message_list (skeleton, list);
mm_gdbus_modem_cell_broadcast_emit_added (skeleton, cbm_path);
}
static void
cbm_deleted (MMCbmList *list,
const gchar *cbm_path,
MmGdbusModemCellBroadcast *skeleton)
{
update_message_list (skeleton, list);
mm_gdbus_modem_cell_broadcast_emit_deleted (skeleton, cbm_path);
}
/*****************************************************************************/
typedef struct _EnablingContext EnablingContext;
static void interface_enabling_step (GTask *task);
typedef enum {
ENABLING_STEP_FIRST,
ENABLING_STEP_SETUP_UNSOLICITED_EVENTS,
ENABLING_STEP_ENABLE_UNSOLICITED_EVENTS,
ENABLING_STEP_GET_CHANNELS,
ENABLING_STEP_LAST
} EnablingStep;
struct _EnablingContext {
EnablingStep step;
MmGdbusModemCellBroadcast *skeleton;
};
static void
enabling_context_free (EnablingContext *ctx)
{
if (ctx->skeleton)
g_object_unref (ctx->skeleton);
g_free (ctx);
}
gboolean
mm_iface_modem_cell_broadcast_enable_finish (MMIfaceModemCellBroadcast *self,
GAsyncResult *res,
GError **error)
{
return g_task_propagate_boolean (G_TASK (res), error);
}
static void
setup_unsolicited_events_ready (MMIfaceModemCellBroadcast *self,
GAsyncResult *res,
GTask *task)
{
EnablingContext *ctx;
GError *error = NULL;
MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->setup_unsolicited_events_finish (self, res, &error);
if (error) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
/* Go on to next step */
ctx = g_task_get_task_data (task);
ctx->step++;
interface_enabling_step (task);
}
static void
enable_unsolicited_events_ready (MMIfaceModemCellBroadcast *self,
GAsyncResult *res,
GTask *task)
{
EnablingContext *ctx;
GError *error = NULL;
/* Not critical! */
if (!MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->enable_unsolicited_events_finish (self, res, &error)) {
mm_obj_dbg (self, "Can't enable unsolicited events: %s", error->message);
g_error_free (error);
}
/* Go on with next step */
ctx = g_task_get_task_data (task);
ctx->step++;
interface_enabling_step (task);
}
static void
load_channels_ready (MMIfaceModemCellBroadcast *self,
GAsyncResult *res,
GTask *task)
{
EnablingContext *ctx;
g_autoptr (GError) error = NULL;
g_autoptr (GArray) channels = NULL;
ctx = g_task_get_task_data (task);
channels = MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->load_channels_finish (self, res, &error);
if (channels) {
mm_gdbus_modem_cell_broadcast_set_channels (
ctx->skeleton,
mm_common_cell_broadcast_channels_garray_to_variant (channels));
} else {
/* Not critical! */
mm_obj_warn (self, "Couldn't load current channel list: %s", error->message);
}
/* Go on with next step */
ctx->step++;
interface_enabling_step (task);
}
static void
interface_enabling_step (GTask *task)
{
MMIfaceModemCellBroadcast *self;
EnablingContext *ctx;
/* Don't run new steps if we're cancelled */
if (g_task_return_error_if_cancelled (task)) {
g_object_unref (task);
return;
}
self = g_task_get_source_object (task);
ctx = g_task_get_task_data (task);
switch (ctx->step) {
case ENABLING_STEP_FIRST: {
g_autoptr (MMCbmList) list = NULL;
list = mm_cbm_list_new (MM_BASE_MODEM (self), G_OBJECT (self));
g_object_set (self,
MM_IFACE_MODEM_CELL_BROADCAST_CBM_LIST, list,
NULL);
/* Connect to list's signals */
g_signal_connect (list,
MM_CBM_ADDED,
G_CALLBACK (cbm_added),
ctx->skeleton);
g_signal_connect (list,
MM_CBM_DELETED,
G_CALLBACK (cbm_deleted),
ctx->skeleton);
ctx->step++;
} /* fall through */
case ENABLING_STEP_SETUP_UNSOLICITED_EVENTS:
/* Allow setting up unsolicited events */
if (MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->setup_unsolicited_events &&
MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->setup_unsolicited_events_finish) {
MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->setup_unsolicited_events (
self,
(GAsyncReadyCallback)setup_unsolicited_events_ready,
task);
return;
}
ctx->step++;
/* fall through */
case ENABLING_STEP_ENABLE_UNSOLICITED_EVENTS:
/* Allow enabling unsolicited events */
if (MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->enable_unsolicited_events &&
MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->enable_unsolicited_events_finish) {
MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->enable_unsolicited_events (
self,
(GAsyncReadyCallback)enable_unsolicited_events_ready,
task);
return;
}
ctx->step++;
/* fall through */
case ENABLING_STEP_GET_CHANNELS:
/* Read current channel list */
if (MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->load_channels &&
MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->load_channels_finish) {
MM_IFACE_MODEM_CELL_BROADCAST_GET_IFACE (self)->load_channels (
self,
(GAsyncReadyCallback)load_channels_ready,
task);
return;
}
ctx->step++;
/* fall through */
case ENABLING_STEP_LAST:
/* We are done without errors! */
g_task_return_boolean (task, TRUE);
g_object_unref (task);
return;
default:
break;
}
g_assert_not_reached ();
}
void
mm_iface_modem_cell_broadcast_enable (MMIfaceModemCellBroadcast *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
EnablingContext *ctx;
GTask *task;
ctx = g_new0 (EnablingContext, 1);
ctx->step = ENABLING_STEP_FIRST;
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_task_data (task, ctx, (GDestroyNotify)enabling_context_free);
g_object_get (self,
MM_IFACE_MODEM_CELL_BROADCAST_DBUS_SKELETON, &ctx->skeleton,
NULL);
if (!ctx->skeleton) {
g_task_return_new_error (task,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Can't get interface skeleton");
g_object_unref (task);
return;
}
interface_enabling_step (task);
}
/*****************************************************************************/
gboolean
mm_iface_modem_cell_broadcast_take_part (MMIfaceModemCellBroadcast *self,
GObject *bind_to,
MMCbmPart *cbm_part,
MMCbmState state,
GError **error)
{
g_autoptr(MMCbmList) list = NULL;
gboolean added = FALSE;
g_object_get (self,
MM_IFACE_MODEM_CELL_BROADCAST_CBM_LIST, &list,
NULL);
if (list) {
added = mm_cbm_list_take_part (list, bind_to, cbm_part, state, error);
if (!added)
g_prefix_error (error, "couldn't take part in CBM list: ");
}
/* If part wasn't taken, we need to free the part ourselves */
if (!added)
mm_cbm_part_free (cbm_part);
return added;
}
/*****************************************************************************/
static void
mm_iface_modem_cell_broadcast_default_init (MMIfaceModemCellBroadcastInterface *iface)
{
static gsize initialized = 0;
if (!g_once_init_enter (&initialized))
return;
/* Properties */
g_object_interface_install_property (
iface,
g_param_spec_object (MM_IFACE_MODEM_CELL_BROADCAST_DBUS_SKELETON,
"CellBroadcast DBus skeleton",
"DBus skeleton for the CellBroadcast interface",
MM_GDBUS_TYPE_MODEM_CELL_BROADCAST_SKELETON,
G_PARAM_READWRITE));
g_object_interface_install_property (
iface,
g_param_spec_object (MM_IFACE_MODEM_CELL_BROADCAST_CBM_LIST,
"CBM list",
"List of CBM objects managed in the interface",
MM_TYPE_CBM_LIST,
G_PARAM_READWRITE));
g_once_init_leave (&initialized, 1);
}
|