Debian Codegraph @

libcellbroadcast/lcb-main.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2025 The Phosh.mobi e.V.
3 *
4 * SPDX-License-Identifier: LGPL-2.1+
5 */
6
7 #include "lcb-dbus.h"
8 #include "lcb-main.h"
9 #include "lcb-names.h"
10
11 static LcbDBusCbd *_proxy = NULL;
12 static GCancellable *_cancellable = NULL;
13
14
15 /**
16 * lcb_init:
17 * @error: Error information
18 *
19 * Initialize libcellbroadcast.
20 * This must be called before any other of libcellbroadcast's functions.
21 *
22 * Returns: %TRUE if successful, or %FALSE on error.
23 */
24 gboolean
25 lcb_init (GError **error)
26 {
27 static gsize init = FALSE;
28
29 if (g_once_init_enter (&init)) {
30 _cancellable = g_cancellable_new ();
31 _proxy = lcb_dbus_cbd_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
32 G_DBUS_PROXY_FLAGS_NONE,
33 CB_DBUS_NAME,
34 CB_DBUS_PATH,
35 _cancellable,
36 error);
37 g_once_init_leave (&init, TRUE);
38 }
39
40 return !!_proxy;
41 }
42
43
44 /**
45 * lcb_uninit:
46 *
47 * Uninitialize the library when no longer used. Usually called
48 * on program shutdown.
49 */
50 void
51 lcb_uninit (void)
52 {
53 g_cancellable_cancel (_cancellable);
54 g_clear_object (&_cancellable);
55 g_clear_object (&_proxy);
56 }
57
58 /**
59 * lcb_is_innited:
60 *
61 * Whether libcellbroadcast is initialized.
62 *
63 * Returns: %TRUE, if library is initialized, %FALSE otherwise.
64 */
65 gboolean
66 lcb_is_initted (void)
67 {
68 return !!_proxy;
69 }
70
71 /**
72 * lcb_get_proxy:
73 *
74 * This can be used to access the lower level API e.g. to listen to
75 * property changes. The object is not owned by the caller. Don't
76 * unref it after use.
77 *
78 * Returns: (transfer none): The DBus proxy.
79 */
80 LcbDBusCbd *
81 lcb_get_proxy (void)
82 {
83 g_return_val_if_fail (LCB_DBUS_IS_CBD (_proxy), NULL);
84
85 return _proxy;
86 }