summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-06-16 13:55:48 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-06-16 13:55:48 +0000
commit9fd6757e19e57f085b2ebf72b1078edbd4b7285e (patch)
tree4673930bae048eedbb75f36d6e5da715b622793a
parent5542ce34cfb07a75eebd5659fb66d1fe2394faa6 (diff)
Add skeleton for local D-Bus server
-rw-r--r--hcid/Makefile.am1
-rw-r--r--hcid/main.c5
-rw-r--r--hcid/server.c100
-rw-r--r--hcid/server.h25
4 files changed, 131 insertions, 0 deletions
diff --git a/hcid/Makefile.am b/hcid/Makefile.am
index b690d4a0..d1ade7d9 100644
--- a/hcid/Makefile.am
+++ b/hcid/Makefile.am
@@ -15,6 +15,7 @@ noinst_LIBRARIES = libhciserver.a
libhciserver_a_SOURCES = hcid.h security.c device.c \
storage.c parser.h parser.y lexer.l kword.c kword.h \
+ server.h server.c \
dbus-hci.h dbus-hci.c dbus-common.c dbus-common.h \
dbus-error.c dbus-error.h dbus-manager.c dbus-manager.h \
dbus-database.c dbus-database.h dbus-security.c dbus-security.h \
diff --git a/hcid/main.c b/hcid/main.c
index 850f1086..42cfab89 100644
--- a/hcid/main.c
+++ b/hcid/main.c
@@ -50,6 +50,7 @@
#include "hcid.h"
#include "sdpd.h"
+#include "server.h"
#include "dbus-common.h"
#include "dbus-service.h"
#include "dbus-database.h"
@@ -870,6 +871,8 @@ int main(int argc, char *argv[])
notify_init();
+ init_local_server();
+
init_services(CONFIGDIR);
/* Start event processor */
@@ -884,6 +887,8 @@ int main(int argc, char *argv[])
notify_close();
+ shutdown_local_server();
+
cleanup_sdp_session();
g_main_loop_unref(event_loop);
diff --git a/hcid/server.c b/hcid/server.c
new file mode 100644
index 00000000..702002c7
--- /dev/null
+++ b/hcid/server.c
@@ -0,0 +1,100 @@
+/*
+ *
+ * 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.h>
+
+#include "logging.h"
+#include "server.h"
+
+static DBusHandlerResult message_handler(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static void unregister_handler(DBusConnection *conn, void *data)
+{
+ debug("Unregister local connection %p", conn);
+}
+
+static void handle_connection(DBusServer *server, DBusConnection *conn, void *data)
+{
+ DBusObjectPathVTable vtable = { &unregister_handler, &message_handler,
+ NULL, NULL, NULL, NULL};
+
+ debug("New local connection %p", conn);
+
+ //dbus_connection_add_filter(conn, filter_function, NULL, NULL);
+
+ dbus_connection_register_fallback(conn, "/org/bluez", &vtable, NULL);
+
+ dbus_connection_ref(conn);
+
+ //dbus_connection_setup_with_g_main(conn, NULL);
+}
+
+static DBusServer *server = NULL;
+
+void init_local_server(void)
+{
+ DBusError err;
+ char *address;
+
+ dbus_error_init(&err);
+
+ server = dbus_server_listen("unix:tmpdir=/var/run", &err);
+ if (server == NULL) {
+ error("Can't create local D-Bus server");
+ dbus_error_free(&err);
+ return;
+ }
+
+ address = dbus_server_get_address(server);
+
+ info("Created local server at %s", address);
+
+ dbus_free(address);
+
+ //dbus_server_setup_with_g_main(server, NULL);
+
+ dbus_server_set_new_connection_function(server, handle_connection,
+ NULL, NULL);
+}
+
+void shutdown_local_server(void)
+{
+ if (server == NULL)
+ return;
+
+ info("Shutting down local server");
+
+ dbus_server_disconnect(server);
+
+ dbus_server_unref(server);
+
+ server = NULL;
+}
diff --git a/hcid/server.h b/hcid/server.h
new file mode 100644
index 00000000..ad5674c6
--- /dev/null
+++ b/hcid/server.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
+ *
+ */
+
+void init_local_server(void);
+void shutdown_local_server(void);