Debian Codegraph @

src/cbd-daemon.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2025 The Cbd Developers
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * Author: Guido Günther <[email protected]>
7 */
8
9 #define G_LOG_DOMAIN "cbd-daemon"
10
11 #include "cbd-config.h"
12
13 #include "cbd-daemon.h"
14 #include "cbd-manager.h"
15
16 #include <glib-unix.h>
17 #include <gio/gio.h>
18
19 /**
20 * CbdDaemon:
21 *
22 * The daemon object
23 */
24
25
26 struct _CbdDaemon {
27 GApplication parent;
28
29 CbdManager *manager;
30 CbdChannelManager *channel_manager;
31 };
32 G_DEFINE_TYPE (CbdDaemon, cbd_daemon, G_TYPE_APPLICATION)
33
34
35 static gboolean
36 on_shutdown_signal (gpointer data)
37 {
38 CbdDaemon *self = CBD_DAEMON (data);
39
40 g_debug ("Exiting gracefully.");
41
42 g_application_release (G_APPLICATION (self));
43
44 return FALSE;
45 }
46
47
48 static gboolean
49 cbd_daemon_dbus_register (GApplication *application,
50 GDBusConnection *connection,
51 const gchar *object_path,
52 GError **error)
53 {
54 CbdDaemon *self = CBD_DAEMON (application);
55 gboolean success;
56 g_autoptr (GError) err = NULL;
57
58 success = G_APPLICATION_CLASS (cbd_daemon_parent_class)->dbus_register (application,
59 connection,
60 object_path,
61 error);
62 if (!success)
63 return success;
64
65 g_debug ("Registered on bus, exporting manager");
66 self->manager = cbd_manager_new ();
67
68 success = g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->manager),
69 connection,
70 object_path,
71 error);
72 return success;
73 }
74
75
76 static void
77 cbd_daemon_dbus_unregister (GApplication *application,
78 GDBusConnection *connection,
79 const gchar *object_path)
80 {
81 CbdDaemon *self = CBD_DAEMON (application);
82
83 g_clear_object (&self->manager);
84
85 G_APPLICATION_CLASS (cbd_daemon_parent_class)->dbus_unregister (application,
86 connection,
87 object_path);
88 }
89
90
91 static void
92 cbd_daemon_activate (GApplication *application)
93 {
94 g_application_hold (application);
95 }
96
97
98 static void
99 cbd_daemon_dispose (GObject *object)
100 {
101 G_OBJECT_CLASS (cbd_daemon_parent_class)->dispose (object);
102 }
103
104
105 static void
106 cbd_daemon_class_init (CbdDaemonClass *klass)
107 {
108 GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
109 GObjectClass *object_class = G_OBJECT_CLASS (klass);
110
111 object_class->dispose = cbd_daemon_dispose;
112
113 application_class->activate = cbd_daemon_activate;
114 application_class->dbus_register = cbd_daemon_dbus_register;
115 application_class->dbus_unregister = cbd_daemon_dbus_unregister;
116 }
117
118
119 static void
120 cbd_daemon_init (CbdDaemon *self)
121 {
122 self->channel_manager = cbd_channel_manager_new (NULL);
123
124 g_application_set_version (G_APPLICATION (self), CBD_VERSION);
125
126 g_unix_signal_add (SIGTERM, on_shutdown_signal, self);
127 g_unix_signal_add (SIGINT, on_shutdown_signal, self);
128 }
129
130
131 CbdDaemon *
132 cbd_daemon_new (void)
133 {
134 return g_object_new (CBD_TYPE_DAEMON,
135 "flags", G_APPLICATION_DEFAULT_FLAGS,
136 "application-id", CBD_APP_ID,
137 NULL);
138 }