diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2008-06-03 12:38:51 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2008-06-03 12:38:51 +0000 |
commit | d2a60bd49635c5fabd3df4f406ae67fbad535d30 (patch) | |
tree | a55a280b7c3ed49b88266e6c8bfe7d7cf2f9e4dd | |
parent | f52b310f85b0a3f8dbbed8307aca48100e9e5ccb (diff) |
Remove bluetoothd prototype that never got finished
-rw-r--r-- | daemon/Makefile.am | 15 | ||||
-rw-r--r-- | daemon/adapter.c | 117 | ||||
-rw-r--r-- | daemon/adapter.h | 25 | ||||
-rw-r--r-- | daemon/database.c | 230 | ||||
-rw-r--r-- | daemon/database.h | 25 | ||||
-rw-r--r-- | daemon/main.c | 228 | ||||
-rw-r--r-- | daemon/manager.c | 102 | ||||
-rw-r--r-- | daemon/manager.h | 25 | ||||
-rw-r--r-- | daemon/service.c | 308 | ||||
-rw-r--r-- | daemon/service.h | 25 | ||||
-rw-r--r-- | daemon/system.h | 26 |
11 files changed, 2 insertions, 1124 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am index e2a16be2..22430657 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -1,5 +1,5 @@ -noinst_PROGRAMS = bluetoothd passkey-agent auth-agent +noinst_PROGRAMS = passkey-agent auth-agent if CONFIGFILES dbusdir = $(sysconfdir)/dbus-1/system.d @@ -7,15 +7,6 @@ dbusdir = $(sysconfdir)/dbus-1/system.d dbus_DATA = bluetooth.conf endif -bluetoothd_SOURCES = main.c system.h \ - manager.h manager.c database.h database.c \ - adapter.h adapter.c service.h service.c - -bluetoothd_LDADD = \ - $(top_builddir)/common/libhelper.a \ - $(top_builddir)/sdpd/libsdpserver.a \ - @GDBUS_LIBS@ @GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@ - passkey_agent_SOURCES = passkey-agent.c passkey_agent_LDADD = @DBUS_LIBS@ @@ -24,9 +15,7 @@ auth_agent_SOURCES = auth-agent.c auth_agent_LDADD = @DBUS_LIBS@ -AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@ @GDBUS_CFLAGS@ - -INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/sdpd +AM_CFLAGS = @DBUS_CFLAGS@ EXTRA_DIST = bluetooth.conf test-manager test-database diff --git a/daemon/adapter.c b/daemon/adapter.c deleted file mode 100644 index 2c5e608e..00000000 --- a/daemon/adapter.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * 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 - -#include <dbus/dbus.h> -#include <gdbus.h> - -#include "logging.h" - -#include "system.h" -#include "adapter.h" - -#define ADAPTER_INTERFACE "org.bluez.Adapter" - -static DBusConnection *connection = NULL; - -DBusHandlerResult manager_list_adapters(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - DBusMessageIter iter, array; - const char path[] = "/org/bluez/hci0", *ptr = path; - - 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_append_basic(&array, DBUS_TYPE_STRING, &ptr); - - dbus_message_iter_close_container(&iter, &array); - - return dbus_connection_send_and_unref(conn, reply); -} - -DBusHandlerResult manager_find_adapter(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - const char *pattern; - const char path[] = "/org/bluez/hci0", *ptr = path; - - dbus_message_get_args(msg, NULL, - DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID); - - debug("Searching adapter with pattern \"%s\"", pattern); - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, - DBUS_TYPE_INVALID); - - return dbus_connection_send_and_unref(conn, reply); -} - -DBusHandlerResult manager_default_adapter(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - const char path[] = "/org/bluez/hci0", *ptr = path; - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, - DBUS_TYPE_INVALID); - - return dbus_connection_send_and_unref(conn, reply); -} - -int adapter_init(DBusConnection *conn) -{ - connection = dbus_connection_ref(conn); - - info("Starting adapter framework"); - - return 0; -} - -void adapter_exit(void) -{ - info("Stopping adapter framework"); - - dbus_connection_unref(connection); - - connection = NULL; -} diff --git a/daemon/adapter.h b/daemon/adapter.h deleted file mode 100644 index b57f42fd..00000000 --- a/daemon/adapter.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * 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 - * - */ - -int adapter_init(DBusConnection *conn); -void adapter_exit(void); diff --git a/daemon/database.c b/daemon/database.c deleted file mode 100644 index be6ca28c..00000000 --- a/daemon/database.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * 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 - -#include <stdlib.h> -#include <string.h> - -#include <bluetooth/bluetooth.h> -#include <bluetooth/sdp.h> -#include <bluetooth/sdp_lib.h> - -#include <glib.h> -#include <dbus/dbus.h> -#include <gdbus.h> - -#include "sdp-xml.h" -#include "logging.h" - -#include "sdpd.h" - -#include "system.h" -#include "database.h" - -#define DATABASE_INTERFACE "org.bluez.Database" - -static DBusConnection *connection = NULL; - -static GSList *records = NULL; - -struct record_data { - uint32_t handle; - char *sender; - guint listener_id; -}; - -static struct record_data *find_record(uint32_t handle, const char *sender) -{ - GSList *list; - - for (list = records; list; list = list->next) { - struct record_data *data = list->data; - if (handle == data->handle && !strcmp(sender, data->sender)) - return data; - } - - return NULL; -} - -static void exit_callback(void *user_data) -{ - struct record_data *user_record = user_data; - - records = g_slist_remove(records, user_record); - - remove_record_from_server(user_record->handle); - - free(user_record); -} - -static DBusHandlerResult add_service_record(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - DBusMessageIter iter, array; - dbus_uint32_t handle = 0x12345; - const uint8_t *record; - int i, len = -1; - - dbus_message_iter_init(msg, &iter); - dbus_message_iter_recurse(&iter, &array); - - dbus_message_iter_get_fixed_array(&array, &record, &len); - if (len < 0) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - for (i = 0; i < len; i++) - debug("0x%02x", record[i]); - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - dbus_message_append_args(reply, DBUS_TYPE_UINT32, &handle, - DBUS_TYPE_INVALID); - - return dbus_connection_send_and_unref(conn, reply); -} - -static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - const char *sender, *record; - struct record_data *user_record; - sdp_record_t *sdp_record; - - dbus_message_get_args(msg, NULL, - DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID); - - user_record = malloc(sizeof(*user_record)); - if (!user_record) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - sdp_record = sdp_xml_parse_record(record, strlen(record)); - if (!sdp_record) { - error("Parsing of XML service record failed"); - free(user_record); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - if (add_record_to_server(BDADDR_ANY, sdp_record) < 0) { - error("Failed to register service record"); - free(user_record); - sdp_record_free(sdp_record); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - sender = dbus_message_get_sender(msg); - - user_record->handle = sdp_record->handle; - user_record->sender = strdup(sender); - - records = g_slist_append(records, user_record); - - user_record->listener_id = g_dbus_add_disconnect_watch(conn, sender, - exit_callback, - user_record, NULL); - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - dbus_message_append_args(reply, DBUS_TYPE_UINT32, &user_record->handle, - DBUS_TYPE_INVALID); - - return dbus_connection_send_and_unref(conn, reply); -} - -static DBusHandlerResult remove_service_record(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - dbus_uint32_t handle; - const char *sender; - struct record_data *user_record; - - dbus_message_get_args(msg, NULL, - DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID); - - sender = dbus_message_get_sender(msg); - - user_record = find_record(handle, sender); - if (!user_record) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - g_dbus_remove_watch(conn, user_record->listener_id); - - remove_record_from_server(handle); - - free(user_record); - - 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_BYTE_ARRAY_AS_STRING, DBUS_TYPE_UINT32_AS_STRING }, - { "AddServiceRecordFromXML", add_service_record_from_xml, - DBUS_TYPE_STRING_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, 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_unregister_interface(connection, - SYSTEM_PATH, DATABASE_INTERFACE); - - dbus_connection_unref(connection); - - connection = NULL; -} diff --git a/daemon/database.h b/daemon/database.h deleted file mode 100644 index db93b526..00000000 --- a/daemon/database.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * 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 - * - */ - -int database_init(DBusConnection *conn); -void database_exit(void); diff --git a/daemon/main.c b/daemon/main.c deleted file mode 100644 index a1b58ada..00000000 --- a/daemon/main.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * 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 - -#include <stdio.h> -#include <errno.h> -#include <unistd.h> -#include <stdlib.h> -#include <signal.h> -#include <getopt.h> -#include <sys/stat.h> - -#include <glib.h> -#include <dbus/dbus.h> -#include <gdbus.h> - -#include "logging.h" - -#include "sdpd.h" - -#include "system.h" -#include "manager.h" -#include "database.h" -#include "adapter.h" -#include "service.h" - -static GMainLoop *main_loop = NULL; - -static DBusConnection *system_bus = NULL; - -static int setup_dbus(void) -{ - system_bus = g_dbus_setup_bus(DBUS_BUS_SYSTEM, "org.bluez", 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; - } - - if (adapter_init(system_bus) < 0) { - database_exit(); - manager_exit(); - dbus_connection_destroy_object_path(system_bus, SYSTEM_PATH); - dbus_connection_unref(system_bus); - return -1; - } - - if (service_init(system_bus) < 0) { - adapter_exit(); - 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(); - - adapter_exit(); - - 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); -} - -static void sig_hup(int sig) -{ -} - -static void sig_debug(int sig) -{ - toggle_debug(); -} - -static void usage(void) -{ - printf("bluetoothd - Bluetooth daemon ver %s\n\n", VERSION); - - printf("Usage:\n\tbluetoothd [options]\n\n"); - - printf("Options:\n" - "\t--help Display help\n" - "\t--debug Enable debug information\n" - "\t--nodaemon Run daemon in foreground\n"); -} - -static struct option main_options[] = { - { "nodaemon", 0, 0, 'n' }, - { "debug", 0, 0, 'd' }, - { "help", 0, 0, 'h' }, - { 0, 0, 0, 0} -}; - -int main(int argc, char *argv[]) -{ - struct sigaction sa; - int opt, debug = 0, daemonize = 1; - - while ((opt = getopt_long(argc, argv, "ndh", main_options, NULL)) != -1) { - switch (opt) { - case 'n': - daemonize = 0; - break; - - case 'd': - debug = 1; - break; - - case 'h': - usage(); - exit(0); - - default: - usage(); - exit(1); - } - } - - if (daemonize && daemon(0, 0)) { - error("Daemon startup failed: %s (%d)", strerror(errno), errno); - exit(1); - } - - umask(0077); - - start_logging("bluetoothd", "Bluetooth daemon ver %s", VERSION); - - 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_hup; - sigaction(SIGHUP, &sa, NULL); - - sa.sa_handler = sig_debug; - sigaction(SIGUSR2, &sa, NULL); - - sa.sa_handler = SIG_IGN; - sigaction(SIGCHLD, &sa, NULL); - sigaction(SIGPIPE, &sa, NULL); - - if (debug) { - info("Enabling debug information"); - enable_debug(); - } - - main_loop = g_main_loop_new(NULL, FALSE); - - if (setup_dbus() < 0) { - g_main_loop_unref(main_loop); - exit(1); - } - - if (start_sdp_server(0, NULL, SDP_SERVER_COMPAT) < 0) { - cleanup_dbus(); - g_main_loop_unref(main_loop); - exit(1); - } - - g_main_loop_run(main_loop); - - stop_sdp_server(); - - cleanup_dbus(); - - g_main_loop_unref(main_loop); - - info("Exit"); - - stop_logging(); - - return 0; -} diff --git a/daemon/manager.c b/daemon/manager.c deleted file mode 100644 index 92e34dd5..00000000 --- a/daemon/manager.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * 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 - -#include <dbus/dbus.h> -#include <gdbus.h> - -#include "logging.h" - -#include "system.h" -#include "adapter.h" -#include "service.h" -#include "manager.h" - -#define MANAGER_INTERFACE "org.bluez.Manager" - -static DBusConnection *connection = NULL; - -extern DBusHandlerResult manager_list_adapters(DBusConnection *conn, - DBusMessage *msg, void *data); - -extern DBusHandlerResult manager_find_adapter(DBusConnection *conn, - DBusMessage *msg, void *data); - -extern DBusHandlerResult manager_default_adapter(DBusConnection *conn, - DBusMessage *msg, void *data); - -extern DBusHandlerResult manager_list_services(DBusConnection *conn, - DBusMessage *msg, void *data); - -extern DBusHandlerResult manager_find_service(DBusConnection *conn, - DBusMessage *msg, void *data); - -extern DBusHandlerResult manager_activate_service(DBusConnection *conn, - DBusMessage *msg, void *data); - -static DBusMethodVTable manager_table[] = { - { "ListAdapters", manager_list_adapters, - DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_STRING_ARRAY_AS_STRING }, - { "FindAdapter", manager_find_adapter, - DBUS_TYPE_STRING_AS_STRING, DBUS_TYPE_STRING_AS_STRING }, - { "DefaultAdapter", manager_default_adapter, - DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_STRING_AS_STRING }, - { "ListServices", manager_list_services, - DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_STRING_ARRAY_AS_STRING }, - { "FindService", manager_find_service, - DBUS_TYPE_STRING_AS_STRING, DBUS_TYPE_STRING_AS_STRING }, - { "ActivateService", manager_activate_service, - DBUS_TYPE_STRING_AS_STRING, DBUS_TYPE_STRING_AS_STRING }, - { } -}; - -int manager_init(DBusConnection *conn) -{ - connection = dbus_connection_ref(conn); - - info("Starting manager interface"); - - if (dbus_connection_register_interface(connection, SYSTEM_PATH, - MANAGER_INTERFACE, manager_table, NULL, NULL) == FALSE) { - error("Manager interface registration failed"); - dbus_connection_unref(connection); - return -1; - } - - return 0; -} - -void manager_exit(void) -{ - info("Stopping manager interface"); - - dbus_connection_unregister_interface(connection, - SYSTEM_PATH, MANAGER_INTERFACE); - - dbus_connection_unref(connection); - - connection = NULL; -} diff --git a/daemon/manager.h b/daemon/manager.h deleted file mode 100644 index 422a84d7..00000000 --- a/daemon/manager.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * 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 - * - */ - -int manager_init(DBusConnection *conn); -void manager_exit(void); diff --git a/daemon/service.c b/daemon/service.c deleted file mode 100644 index 7668d653..00000000 --- a/daemon/service.c +++ /dev/null @@ -1,308 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * 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 - -#include <stdlib.h> -#include <string.h> -#include <signal.h> - -#include <glib.h> -#include <dbus/dbus.h> -#include <gdbus.h> - -#include "logging.h" - -#include "system.h" -#include "service.h" - -#define SERVICE_INTERFACE "org.bluez.Service" - -static DBusConnection *connection = NULL; - -static char *test_conn_name = NULL; -static GPid test_service_pid = 0; -static guint test_watch_id = -1; - -DBusHandlerResult manager_list_services(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - DBusMessageIter iter, array; - const char path[] = "/org/bluez/service", *ptr = path; - - 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_append_basic(&array, DBUS_TYPE_STRING, &ptr); - - dbus_message_iter_close_container(&iter, &array); - - return dbus_connection_send_and_unref(conn, reply); -} - -DBusHandlerResult manager_find_service(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - const char *pattern; - const char path[] = "/org/bluez/service", *ptr = path; - - dbus_message_get_args(msg, NULL, - DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID); - - debug("Searching service with pattern \"%s\"", pattern); - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, - DBUS_TYPE_INVALID); - - return dbus_connection_send_and_unref(conn, reply); -} - -DBusHandlerResult manager_activate_service(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - const char *pattern; - - dbus_message_get_args(msg, NULL, - DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID); - - debug("Activating service with pattern \"%s\"", pattern); - - reply = dbus_message_new_error(msg, ERROR_INTERFACE ".NotFound", - "Service does not exists"); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - return dbus_connection_send_and_unref(conn, reply); -} - -static DBusHandlerResult service_get_identifier(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - const char name[] = "service", *ptr = name; - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, - DBUS_TYPE_INVALID); - - return dbus_connection_send_and_unref(conn, reply); -} - -static DBusHandlerResult service_get_name(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - const char name[] = "Demo service", *ptr = name; - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, - DBUS_TYPE_INVALID); - - return dbus_connection_send_and_unref(conn, reply); -} - -static DBusHandlerResult service_get_description(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - const char text[] = "Demo service for testing", *ptr = text; - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - dbus_message_append_args(reply, DBUS_TYPE_STRING, &ptr, - DBUS_TYPE_INVALID); - - return dbus_connection_send_and_unref(conn, reply); -} - -static void service_died(GPid pid, gint status, gpointer data) -{ - debug("Child with PID %d died with status %d", pid, status); - - g_spawn_close_pid(pid); - test_service_pid = 0; -} - -static DBusHandlerResult service_start(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - GPid pid; - char *argv[2]; - - debug("Starting service"); - - if (test_conn_name) { - reply = dbus_message_new_error(msg, ERROR_INTERFACE ".AlreadyRunning", - "Service is already running"); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - } else { - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - test_conn_name = strdup("org.bluez.service"); - if (!test_conn_name) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - dbus_message_append_args(reply, DBUS_TYPE_INVALID); - - argv[0] = SERVICEDIR "bluetoothd-service-echo"; - argv[1] = NULL; - - g_spawn_async(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL); - - test_watch_id = g_child_watch_add(pid, service_died, NULL); - - debug("New process with PID %d executed", pid); - - test_service_pid = pid; - } - - return dbus_connection_send_and_unref(conn, reply); -} - -static DBusHandlerResult service_stop(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - - debug("Stopping service"); - - if (test_conn_name) { - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - free(test_conn_name); - test_conn_name = NULL; - - kill(test_service_pid, SIGTERM); - test_service_pid = 0; - - dbus_message_append_args(reply, DBUS_TYPE_INVALID); - } else { - reply = dbus_message_new_error(msg, ERROR_INTERFACE ".NotRunning", - "Service is not running"); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - } - - return dbus_connection_send_and_unref(conn, reply); -} - -static DBusHandlerResult service_is_running(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - dbus_bool_t running; - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - running = test_conn_name ? TRUE : FALSE; - - dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &running, - DBUS_TYPE_INVALID); - - return dbus_connection_send_and_unref(conn, reply); -} - -static DBusMethodVTable service_table[] = { - { "GetIdentifier", service_get_identifier, - DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_STRING_AS_STRING }, - { "GetName", service_get_name, - DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_STRING_AS_STRING }, - { "GetDescription", service_get_description, - DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_STRING_AS_STRING }, - { "Start", service_start, - DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_INVALID_AS_STRING }, - { "Stop", service_stop, - DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_INVALID_AS_STRING }, - { "IsRunning", service_is_running, - DBUS_TYPE_INVALID_AS_STRING, DBUS_TYPE_BOOLEAN_AS_STRING }, - { } -}; - -int service_init(DBusConnection *conn) -{ - connection = dbus_connection_ref(conn); - - info("Starting service framework"); - - if (dbus_connection_create_object_path(connection, - "/org/bluez/service", NULL, NULL) == FALSE) { - error("Service path registration failed"); - dbus_connection_unref(connection); - return -1; - } - - if (dbus_connection_register_interface(connection, "/org/bluez/service", - SERVICE_INTERFACE, service_table, NULL, NULL) == FALSE) { - error("Service interface registration failed"); - dbus_connection_destroy_object_path(connection, "/org/bluez/service"); - dbus_connection_unref(connection); - return -1; - } - - return 0; -} - -void service_exit(void) -{ - info("Stopping service framework"); - - dbus_connection_unregister_interface(connection, - "/org/bluez/service", SERVICE_INTERFACE); - - dbus_connection_destroy_object_path(connection, "/org/bluez/service"); - - dbus_connection_unref(connection); - - connection = NULL; -} diff --git a/daemon/service.h b/daemon/service.h deleted file mode 100644 index 6de12ced..00000000 --- a/daemon/service.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * 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 - * - */ - -int service_init(DBusConnection *conn); -void service_exit(void); diff --git a/daemon/system.h b/daemon/system.h deleted file mode 100644 index 247fe0e3..00000000 --- a/daemon/system.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * 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 - * - */ - -#define ERROR_INTERFACE "org.bluez.Error" - -#define SYSTEM_PATH "/org/bluez" |