| 1 |
/* |
| 2 |
* Copyright (C) 2019 Purism SPC |
| 3 |
* Copyright (C) 2020 Arnaud Ferraris <[email protected]> |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 6 |
*/ |
| 7 |
|
| 8 |
#define G_LOG_DOMAIN "callaudiod" |
| 9 |
|
| 10 |
#include "callaudiod.h" |
| 11 |
#include "cad-manager.h" |
| 12 |
#include "cad-pulse.h" |
| 13 |
#include "config.h" |
| 14 |
|
| 15 |
#include <glib.h> |
| 16 |
#include <glib-unix.h> |
| 17 |
|
| 18 |
static GMainLoop *main_loop = NULL; |
| 19 |
|
| 20 |
static gboolean quit_cb(gpointer user_data) |
| 21 |
{ |
| 22 |
g_info("Caught signal, shutting down..."); |
| 23 |
|
| 24 |
if (main_loop) |
| 25 |
g_idle_add((GSourceFunc)g_main_loop_quit, main_loop); |
| 26 |
else |
| 27 |
exit(0); |
| 28 |
|
| 29 |
return FALSE; |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
static void bus_acquired_cb(GDBusConnection *connection, const gchar *name, |
| 34 |
gpointer user_data) |
| 35 |
{ |
| 36 |
CadManager *manager = cad_manager_get_default(); |
| 37 |
|
| 38 |
g_debug("Bus acquired, creating manager..."); |
| 39 |
|
| 40 |
g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(manager), |
| 41 |
connection, CALLAUDIO_DBUS_PATH, NULL); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
static void name_acquired_cb(GDBusConnection *connection, const gchar *name, |
| 46 |
gpointer user_data) |
| 47 |
{ |
| 48 |
g_debug("Service name '%s' was acquired", name); |
| 49 |
} |
| 50 |
|
| 51 |
static void name_lost_cb(GDBusConnection *connection, const gchar *name, |
| 52 |
gpointer user_data) |
| 53 |
{ |
| 54 |
if (!name) { |
| 55 |
g_warning("Could not get the session bus. Make sure " |
| 56 |
"the message bus daemon is running!"); |
| 57 |
} else { |
| 58 |
if (connection) |
| 59 |
g_warning("Could not acquire the '%s' service name", name); |
| 60 |
else |
| 61 |
g_debug("DBus connection close"); |
| 62 |
} |
| 63 |
|
| 64 |
g_main_loop_quit(main_loop); |
| 65 |
} |
| 66 |
|
| 67 |
int main(int argc, char **argv) |
| 68 |
{ |
| 69 |
g_unix_signal_add(SIGTERM, quit_cb, NULL); |
| 70 |
g_unix_signal_add(SIGINT, quit_cb, NULL); |
| 71 |
|
| 72 |
main_loop = g_main_loop_new(NULL, FALSE); |
| 73 |
|
| 74 |
// Initialize the PulseAudio backend |
| 75 |
cad_pulse_get_default(); |
| 76 |
|
| 77 |
g_bus_own_name(CALLAUDIO_DBUS_TYPE, CALLAUDIO_DBUS_NAME, |
| 78 |
G_BUS_NAME_OWNER_FLAGS_NONE, |
| 79 |
bus_acquired_cb, name_acquired_cb, name_lost_cb, |
| 80 |
NULL, NULL); |
| 81 |
|
| 82 |
g_main_loop_run(main_loop); |
| 83 |
g_main_loop_unref(main_loop); |
| 84 |
|
| 85 |
return 0; |
| 86 |
} |