bluez/audio/main.c

94 lines
2.1 KiB
C
Raw Normal View History

/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
2007-10-24 01:17:47 +08:00
* Copyright (C) 2006-2007 Nokia Corporation
2008-02-02 11:37:05 +08:00
* Copyright (C) 2004-2008 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
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
2008-03-28 07:07:19 +08:00
#include <errno.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
2007-04-09 07:13:18 +08:00
#include <glib.h>
#include <dbus/dbus.h>
2007-04-09 07:13:18 +08:00
2008-03-28 07:07:19 +08:00
#include "plugin.h"
2007-04-09 07:13:18 +08:00
#include "logging.h"
#include "unix.h"
2007-08-27 20:05:10 +08:00
#include "device.h"
2007-03-10 06:32:47 +08:00
#include "manager.h"
2007-04-09 07:13:18 +08:00
2008-09-05 02:58:54 +08:00
static DBusConnection *connection = NULL;
static GKeyFile *load_config_file(const char *file)
2007-05-31 20:51:49 +08:00
{
GError *err = NULL;
GKeyFile *keyfile;
2007-05-31 20:51:49 +08:00
keyfile = g_key_file_new();
if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
error("Parsing %s failed: %s", file, err->message);
g_error_free(err);
g_key_file_free(keyfile);
return NULL;
2007-10-25 04:02:53 +08:00
}
return keyfile;
2007-05-31 20:51:49 +08:00
}
2008-03-28 07:07:19 +08:00
static int audio_init(void)
{
GKeyFile *config;
2007-04-09 07:13:18 +08:00
2008-09-05 02:58:54 +08:00
connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
if (connection == NULL)
2008-03-28 07:07:19 +08:00
return -EIO;
2007-04-09 07:13:18 +08:00
config = load_config_file(CONFIGDIR "/audio.conf");
2007-05-31 20:51:49 +08:00
if (unix_init() < 0) {
error("Unable to setup unix socket");
2008-03-28 07:07:19 +08:00
return -EIO;
}
2008-09-05 02:58:54 +08:00
if (audio_manager_init(connection, config) < 0) {
dbus_connection_unref(connection);
2008-03-28 07:07:19 +08:00
return -EIO;
2007-04-12 22:26:55 +08:00
}
2008-03-28 07:07:19 +08:00
return 0;
}
2007-04-09 07:13:18 +08:00
2008-03-28 07:07:19 +08:00
static void audio_exit(void)
{
audio_manager_exit();
2007-04-12 22:26:55 +08:00
unix_exit();
2008-09-05 02:58:54 +08:00
dbus_connection_unref(connection);
}
2008-03-28 07:07:19 +08:00
BLUETOOTH_PLUGIN_DEFINE("audio", audio_init, audio_exit)