summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-01-19 02:21:55 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-01-19 02:21:55 +0000
commita6dcaafcc9ac9d791991fff9964bc3e48e6b9a8a (patch)
tree09371601e0d2e266d523f16dbf64ca962d18ae50 /daemon
parent32443320a01544f9a26d09b47cbaee7ca5f30ede (diff)
Add skeleton for service framework
Diffstat (limited to 'daemon')
-rw-r--r--daemon/Makefile.am3
-rw-r--r--daemon/main.c32
-rw-r--r--daemon/manager.c54
-rw-r--r--daemon/service.c78
-rw-r--r--daemon/service.h25
5 files changed, 170 insertions, 22 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 4d1f59ea..317c431f 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -10,7 +10,8 @@ endif
noinst_PROGRAMS = bluetoothd
bluetoothd_SOURCES = main.c system.h \
- manager.h manager.c database.h database.c
+ manager.h manager.c database.h database.c \
+ service.h service.c
bluetoothd_LDADD = $(glib_ldadd) @DBUS_LIBS@ @BLUEZ_LIBS@ \
$(top_builddir)/sdpd/libsdpserver.a \
diff --git a/daemon/main.c b/daemon/main.c
index 3064a6a6..6c4bc963 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -47,28 +47,12 @@
#include "system.h"
#include "manager.h"
#include "database.h"
+#include "service.h"
static GMainLoop *main_loop = NULL;
static DBusConnection *system_bus = NULL;
-static void config_notify(int action, const char *name, void *data)
-{
- switch (action) {
- case NOTIFY_CREATE:
- debug("File %s/%s created", CONFIGDIR, name);
- break;
-
- case NOTIFY_DELETE:
- debug("File %s/%s deleted", CONFIGDIR, name);
- break;
-
- case NOTIFY_MODIFY:
- debug("File %s/%s modified", CONFIGDIR, name);
- break;
- }
-}
-
static int setup_dbus(void)
{
system_bus = init_dbus("org.bluez", NULL, NULL);
@@ -95,11 +79,21 @@ static int setup_dbus(void)
return -1;
}
+ if (service_init(system_bus) < 0) {
+ database_exit();
+ 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)
{
+ service_exit();
+
database_exit();
manager_exit();
@@ -200,8 +194,6 @@ int main(int argc, char *argv[])
notify_init();
- notify_add(CONFIGDIR, config_notify, NULL);
-
if (setup_dbus() < 0) {
g_main_loop_unref(main_loop);
exit(1);
@@ -219,8 +211,6 @@ int main(int argc, char *argv[])
cleanup_dbus();
- notify_remove(CONFIGDIR);
-
notify_close();
g_main_loop_unref(main_loop);
diff --git a/daemon/manager.c b/daemon/manager.c
index 16447e59..29a4947e 100644
--- a/daemon/manager.c
+++ b/daemon/manager.c
@@ -92,6 +92,54 @@ static DBusHandlerResult default_adapter(DBusConnection *conn,
return dbus_connection_send_and_unref(conn, reply);
}
+static DBusHandlerResult list_services(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter, array;
+ DBusMessage *reply;
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_STRING_AS_STRING, &array);
+
+ dbus_message_iter_close_container(&iter, &array);
+
+ return dbus_connection_send_and_unref(conn, reply);
+}
+
+static DBusHandlerResult find_service(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 activate_service(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 manager_table[] = {
{ "ListAdapters", list_adapters,
DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_STRING_ARRAY_AS_STRING },
@@ -99,6 +147,12 @@ static DBusMethodVTable manager_table[] = {
DBUS_TYPE_STRING_AS_STRING, DBUS_TYPE_STRING_AS_STRING },
{ "DefaultAdapter", default_adapter,
DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_STRING_AS_STRING },
+ { "ListServices", list_services,
+ DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_STRING_ARRAY_AS_STRING },
+ { "FindService", find_service,
+ DBUS_TYPE_STRING_AS_STRING, DBUS_TYPE_STRING_AS_STRING },
+ { "ActivateService", activate_service,
+ DBUS_TYPE_STRING_AS_STRING, DBUS_TYPE_STRING_AS_STRING },
{ }
};
diff --git a/daemon/service.c b/daemon/service.c
new file mode 100644
index 00000000..95b5e1ed
--- /dev/null
+++ b/daemon/service.c
@@ -0,0 +1,78 @@
+/*
+ *
+ * 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 "notify.h"
+
+#include "system.h"
+#include "service.h"
+
+#define SERVICE_INTERFACE "org.bluez.Service"
+
+static DBusConnection *connection = NULL;
+
+static void config_notify(int action, const char *name, void *data)
+{
+ switch (action) {
+ case NOTIFY_CREATE:
+ debug("File %s/%s created", CONFIGDIR, name);
+ break;
+
+ case NOTIFY_DELETE:
+ debug("File %s/%s deleted", CONFIGDIR, name);
+ break;
+
+ case NOTIFY_MODIFY:
+ debug("File %s/%s modified", CONFIGDIR, name);
+ break;
+ }
+}
+
+int service_init(DBusConnection *conn)
+{
+ connection = dbus_connection_ref(conn);
+
+ info("Starting service framework");
+
+ notify_add(CONFIGDIR, config_notify, NULL);
+
+ return 0;
+}
+
+void service_exit(void)
+{
+ info("Stopping service framework");
+
+ notify_remove(CONFIGDIR);
+
+ dbus_connection_unref(connection);
+
+ connection = NULL;
+}
diff --git a/daemon/service.h b/daemon/service.h
new file mode 100644
index 00000000..65e5ab84
--- /dev/null
+++ b/daemon/service.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 service_init(DBusConnection *conn);
+void service_exit(void);