diff options
-rw-r--r-- | audio/Makefile.am | 6 | ||||
-rw-r--r-- | audio/headset.c | 108 | ||||
-rw-r--r-- | audio/headset.h | 25 | ||||
-rw-r--r-- | audio/main.c | 62 |
4 files changed, 96 insertions, 105 deletions
diff --git a/audio/Makefile.am b/audio/Makefile.am index cbb27956..fe5931b1 100644 --- a/audio/Makefile.am +++ b/audio/Makefile.am @@ -10,10 +10,10 @@ servicedir = $(libdir)/bluetooth service_PROGRAMS = bluetoothd-service-audio -bluetoothd_service_audio_SOURCES = manager.h manager.c headset.c +bluetoothd_service_audio_SOURCES = main.c manager.h manager.c headset.c bluetoothd_service_audio_LDADD = $(top_builddir)/common/libhelper.a \ - @SBC_LIBS@ @GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@ + @GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@ endif if ALSA @@ -23,7 +23,7 @@ alsa_LTLIBRARIES = libasound_module_pcm_bluetooth.la libasound_module_ctl_blueto libasound_module_pcm_bluetooth_la_SOURCES = pcm_bluetooth.c libasound_module_pcm_bluetooth_la_LDFLAGS = -module -avoid-version -export-dynamic -libasound_module_pcm_bluetooth_la_LIBADD = @ALSA_LIBS@ +libasound_module_pcm_bluetooth_la_LIBADD = @SBC_LIBS@ @ALSA_LIBS@ libasound_module_ctl_bluetooth_la_SOURCES = ctl_bluetooth.c libasound_module_ctl_bluetooth_la_LDFLAGS = -module -avoid-version -export-dynamic diff --git a/audio/headset.c b/audio/headset.c index fcff8174..9e303782 100644 --- a/audio/headset.c +++ b/audio/headset.c @@ -1963,78 +1963,11 @@ void audio_manager_free(struct manager *manager) g_free(manager); } -static void sig_term(int sig) -{ - g_main_loop_quit(main_loop); -} +static struct manager *manager = NULL; -int main(int argc, char *argv[]) +int headset_init(DBusConnection *conn) { - uint8_t opt_channel = 12; - char *opt_bda = NULL; - char *opt_input = NULL; - char *opt_output = NULL; - gboolean register_svc = FALSE; - bdaddr_t bda; - struct headset *hs; - struct manager *manager; - struct sigaction sa; - int opt; - - while ((opt = getopt(argc, argv, "c:o:i:ds")) != EOF) { - switch (opt) { - case 'c': - opt_channel = strtol(optarg, NULL, 0); - break; - - case 'i': - opt_input = optarg; - break; - - case 'o': - opt_output = optarg; - break; - - case 'd': - enable_debug(); - break; - - case 's': - register_svc = TRUE; - break; - - default: - printf("Usage: %s -c local_channel [-d] [-o output] [-i input] [bdaddr]\n", argv[0]); - exit(1); - } - } - - if (optind < argc && argv[optind]) - opt_bda = argv[optind]; - - start_logging("audio", "Bluetooth audio service daemon"); - - memset(&sa, 0, sizeof(sa)); - sa.sa_flags = SA_NOCLDSTOP; - sa.sa_handler = sig_term; - sigaction(SIGTERM, &sa, NULL); - sigaction(SIGINT, &sa, NULL); - - sa.sa_handler = SIG_IGN; - sigaction(SIGCHLD, &sa, NULL); - sigaction(SIGPIPE, &sa, NULL); - - main_loop = g_main_loop_new(NULL, FALSE); - - connection = init_dbus(NULL, NULL, NULL); - if (!connection) { - error("Connection to system bus failed"); - g_main_loop_unref(main_loop); - exit(1); - } - - if (register_svc) - register_external_service(connection, "audio", "Audio service", ""); + connection = dbus_connection_ref(conn); manager = audio_manager_new(connection); if (!manager) { @@ -2044,40 +1977,15 @@ int main(int argc, char *argv[]) exit(1); } - audio_manager_create_headset_server(manager, opt_channel); - - if (opt_bda) { - str2ba(opt_bda, &bda); - hs = audio_headset_new(connection, &bda); - if (!hs) { - error("Connection setup failed"); - dbus_connection_unref(connection); - g_main_loop_unref(main_loop); - exit(1); - } - - if (opt_output) - audio_headset_open_output(hs, opt_output); - if (opt_input) - audio_headset_open_input(hs, opt_input); + audio_manager_create_headset_server(manager, 12); - audio_manager_add_headset(manager, hs); - /* connect */ - hs_connect(hs, NULL); - } - - g_main_loop_run(main_loop); + return 0; +} +void headset_exit(void) +{ audio_manager_free(manager); manager = NULL; dbus_connection_unref(connection); - - g_main_loop_unref(main_loop); - - info("Exit"); - - stop_logging(); - - return 0; } diff --git a/audio/headset.h b/audio/headset.h new file mode 100644 index 00000000..a87be7e3 --- /dev/null +++ b/audio/headset.h @@ -0,0 +1,25 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org> + * + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +int headset_init(DBusConnection *conn); +void headset_exit(void); diff --git a/audio/main.c b/audio/main.c index 2f3a1fa0..08194d82 100644 --- a/audio/main.c +++ b/audio/main.c @@ -25,16 +25,74 @@ #include <config.h> #endif -#include <stdio.h> -#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <signal.h> + +#include <glib.h> + +#include <dbus/dbus.h> + +#include "dbus.h" +#include "logging.h" #include "manager.h" +#include "headset.h" + +static GMainLoop *main_loop = NULL; + +static void sig_term(int sig) +{ + g_main_loop_quit(main_loop); +} int main(int argc, char *argv[]) { + DBusConnection *conn; + struct sigaction sa; + + start_logging("audio", "Bluetooth Audio daemon"); + + memset(&sa, 0, sizeof(sa)); + sa.sa_flags = SA_NOCLDSTOP; + sa.sa_handler = sig_term; + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGINT, &sa, NULL); + + sa.sa_handler = SIG_IGN; + sigaction(SIGCHLD, &sa, NULL); + sigaction(SIGPIPE, &sa, NULL); + + enable_debug(); + + main_loop = g_main_loop_new(NULL, FALSE); + + conn = dbus_bus_system_setup_with_main_loop(NULL, NULL, NULL); + if (!conn) { + g_main_loop_unref(main_loop); + exit(1); + } + audio_init(); + headset_init(conn); + + if (argc > 1 && !strcmp(argv[1], "-s")) + register_external_service(conn, "audio", "Audio service", ""); + + g_main_loop_run(main_loop); + + headset_exit(); + audio_exit(); + dbus_connection_unref(conn); + + g_main_loop_unref(main_loop); + + info("Exit"); + + stop_logging(); + return 0; } |