summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-01-18 23:15:12 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-01-18 23:15:12 +0000
commitd71d1b8aac88cc66455016e38ebdc1f79c19f36b (patch)
tree909754a10a60b172a34aa3bddf2e99aaabffee90 /daemon
parentaa79fbd0ea4a4b97e174d6835be895ead383d885 (diff)
Add skeleton for database interface
Diffstat (limited to 'daemon')
-rw-r--r--daemon/Makefile.am3
-rw-r--r--daemon/database.c99
-rw-r--r--daemon/database.h25
-rw-r--r--daemon/main.c60
-rw-r--r--daemon/manager.c25
-rw-r--r--daemon/system.h24
6 files changed, 203 insertions, 33 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 0ab5e02d..4d1f59ea 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -9,7 +9,8 @@ endif
noinst_PROGRAMS = bluetoothd
-bluetoothd_SOURCES = main.c manager.h manager.c
+bluetoothd_SOURCES = main.c system.h \
+ manager.h manager.c database.h database.c
bluetoothd_LDADD = $(glib_ldadd) @DBUS_LIBS@ @BLUEZ_LIBS@ \
$(top_builddir)/sdpd/libsdpserver.a \
diff --git a/daemon/database.c b/daemon/database.c
new file mode 100644
index 00000000..39d8c21c
--- /dev/null
+++ b/daemon/database.c
@@ -0,0 +1,99 @@
+/*
+ *
+ * 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
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <dbus/dbus.h>
+
+#include "dbus-helper.h"
+#include "logging.h"
+
+#include "system.h"
+#include "database.h"
+
+#define DATABASE_INTERFACE "org.bluez.Database"
+
+static DBusConnection *connection = NULL;
+
+static DBusHandlerResult add_service_record(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ dbus_message_append_args(reply, DBUS_TYPE_INVALID);
+
+ return dbus_connection_send_and_unref(conn, reply);
+}
+
+static DBusHandlerResult remove_service_record(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ dbus_message_append_args(reply, DBUS_TYPE_INVALID);
+
+ return dbus_connection_send_and_unref(conn, reply);
+}
+
+static DBusMethodVTable database_table[] = {
+ { "AddServiceRecord", add_service_record,
+ DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_UINT32_AS_STRING },
+ { "RemoveServiceRecord", remove_service_record,
+ DBUS_TYPE_UINT32_AS_STRING, DBUS_TYPE_INVALID_AS_STRING },
+ { }
+};
+
+int database_init(DBusConnection *conn)
+{
+ connection = dbus_connection_ref(conn);
+
+ info("Starting database interface");
+
+ if (dbus_connection_register_interface(connection, SYSTEM_PATH,
+ DATABASE_INTERFACE, database_table, NULL) == FALSE) {
+ error("Database interface registration failed");
+ dbus_connection_unref(connection);
+ return -1;
+ }
+
+ return 0;
+}
+
+void database_exit(void)
+{
+ info("Stopping database interface");
+
+ dbus_connection_unref(connection);
+
+ connection = NULL;
+}
diff --git a/daemon/database.h b/daemon/database.h
new file mode 100644
index 00000000..1acdd3fb
--- /dev/null
+++ b/daemon/database.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 database_init(DBusConnection *conn);
+void database_exit(void);
diff --git a/daemon/main.c b/daemon/main.c
index 43aafaa7..3064a6a6 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -35,6 +35,8 @@
#include <dbus/dbus.h>
+#include "dbus-helper.h"
+
#include "glib-ectomy.h"
#include "dbus.h"
#include "notify.h"
@@ -42,7 +44,9 @@
#include "sdpd.h"
+#include "system.h"
#include "manager.h"
+#include "database.h"
static GMainLoop *main_loop = NULL;
@@ -65,6 +69,46 @@ static void config_notify(int action, const char *name, void *data)
}
}
+static int setup_dbus(void)
+{
+ system_bus = init_dbus("org.bluez", NULL, NULL);
+ if (!system_bus)
+ return -1;
+
+ if (dbus_connection_create_object_path(system_bus,
+ SYSTEM_PATH, NULL, NULL) == FALSE) {
+ error("System path registration failed");
+ dbus_connection_unref(system_bus);
+ return -1;
+ }
+
+ if (manager_init(system_bus) < 0) {
+ dbus_connection_destroy_object_path(system_bus, SYSTEM_PATH);
+ dbus_connection_unref(system_bus);
+ return -1;
+ }
+
+ if (database_init(system_bus) < 0) {
+ manager_exit();
+ dbus_connection_destroy_object_path(system_bus, SYSTEM_PATH);
+ dbus_connection_unref(system_bus);
+ return -1;
+ }
+
+ return 0;
+}
+
+static void cleanup_dbus(void)
+{
+ database_exit();
+
+ manager_exit();
+
+ dbus_connection_destroy_object_path(system_bus, SYSTEM_PATH);
+
+ dbus_connection_unref(system_bus);
+}
+
static void sig_term(int sig)
{
g_main_loop_quit(main_loop);
@@ -158,21 +202,13 @@ int main(int argc, char *argv[])
notify_add(CONFIGDIR, config_notify, NULL);
- system_bus = init_dbus("org.bluez", NULL, NULL);
- if (!system_bus) {
- g_main_loop_unref(main_loop);
- exit(1);
- }
-
- if (manager_init(system_bus) < 0) {
- dbus_connection_unref(system_bus);
+ if (setup_dbus() < 0) {
g_main_loop_unref(main_loop);
exit(1);
}
if (start_sdp_server(0, SDP_SERVER_COMPAT) < 0) {
- manager_exit();
- dbus_connection_unref(system_bus);
+ cleanup_dbus();
g_main_loop_unref(main_loop);
exit(1);
}
@@ -181,9 +217,7 @@ int main(int argc, char *argv[])
stop_sdp_server();
- manager_exit();
-
- dbus_connection_unref(system_bus);
+ cleanup_dbus();
notify_remove(CONFIGDIR);
diff --git a/daemon/manager.c b/daemon/manager.c
index 718c2b2e..7dbb7417 100644
--- a/daemon/manager.c
+++ b/daemon/manager.c
@@ -27,17 +27,14 @@
#include <dbus/dbus.h>
-#include "logging.h"
-#include "dbus.h"
-
#include "dbus-helper.h"
+#include "logging.h"
+#include "system.h"
#include "manager.h"
#define MANAGER_INTERFACE "org.bluez.Manager"
-#define MANAGER_PATH "/org/bluez"
-
static DBusConnection *connection = NULL;
static DBusHandlerResult list_adapters(DBusConnection *conn,
@@ -60,7 +57,7 @@ static DBusHandlerResult list_adapters(DBusConnection *conn,
dbus_message_iter_close_container(&iter, &array);
- return send_message_and_unref(conn, reply);
+ return dbus_connection_send_and_unref(conn, reply);
}
static DBusHandlerResult find_adapter(DBusConnection *conn,
@@ -76,7 +73,7 @@ static DBusHandlerResult find_adapter(DBusConnection *conn,
dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr,
DBUS_TYPE_INVALID);
- return send_message_and_unref(conn, reply);
+ return dbus_connection_send_and_unref(conn, reply);
}
static DBusHandlerResult default_adapter(DBusConnection *conn,
@@ -92,7 +89,7 @@ static DBusHandlerResult default_adapter(DBusConnection *conn,
dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr,
DBUS_TYPE_INVALID);
- return send_message_and_unref(conn, reply);
+ return dbus_connection_send_and_unref(conn, reply);
}
static DBusMethodVTable manager_table[] = {
@@ -111,17 +108,9 @@ int manager_init(DBusConnection *conn)
info("Starting manager interface");
- if (dbus_connection_create_object_path(connection,
- MANAGER_PATH, NULL, NULL) == FALSE) {
- error("Manager path registration failed");
- dbus_connection_unref(connection);
- return -1;
- }
-
- if (dbus_connection_register_interface(connection, MANAGER_PATH,
+ if (dbus_connection_register_interface(connection, SYSTEM_PATH,
MANAGER_INTERFACE, manager_table, NULL) == FALSE) {
error("Manager interface registration failed");
- dbus_connection_destroy_object_path(connection, MANAGER_PATH);
dbus_connection_unref(connection);
return -1;
}
@@ -133,8 +122,6 @@ void manager_exit(void)
{
info("Stopping manager interface");
- dbus_connection_destroy_object_path(connection, MANAGER_PATH);
-
dbus_connection_unref(connection);
connection = NULL;
diff --git a/daemon/system.h b/daemon/system.h
new file mode 100644
index 00000000..910ca3c1
--- /dev/null
+++ b/daemon/system.h
@@ -0,0 +1,24 @@
+/*
+ *
+ * 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
+ *
+ */
+
+#define SYSTEM_PATH "/org/bluez"