From b1cde69a66270076ff5afb86250b29dd4fa53256 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 10 Sep 2012 15:32:22 +0300 Subject: [PATCH] core: Move profile code into profile.{c,h} --- Makefile.am | 1 + audio/manager.c | 1 + profiles/deviceinfo/manager.c | 1 + profiles/gatt/manager.c | 1 + profiles/health/hdp_manager.c | 1 + profiles/input/hog_manager.c | 1 + profiles/input/manager.c | 1 + profiles/network/manager.c | 1 + profiles/proximity/manager.c | 1 + profiles/sap/manager.c | 1 + profiles/thermometer/manager.c | 1 + profiles/time/manager.c | 1 + src/adapter.c | 1 + src/device.c | 42 +-------------------- src/device.h | 31 ---------------- src/profile.c | 68 ++++++++++++++++++++++++++++++++++ src/profile.h | 50 +++++++++++++++++++++++++ 17 files changed, 133 insertions(+), 71 deletions(-) create mode 100644 src/profile.c create mode 100644 src/profile.h diff --git a/Makefile.am b/Makefile.am index 4977a0597..53b347ca2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -294,6 +294,7 @@ src_bluetoothd_SOURCES = $(gdbus_sources) $(builtin_sources) \ src/error.h src/error.c \ src/manager.h src/manager.c \ src/adapter.h src/adapter.c \ + src/profile.h src/profile.c \ src/device.h src/device.c src/attio.h \ src/dbus-common.c src/dbus-common.h \ src/event.h src/event.c \ diff --git a/audio/manager.c b/audio/manager.c index 5c819570e..99fcaf89b 100644 --- a/audio/manager.c +++ b/audio/manager.c @@ -53,6 +53,7 @@ #include "../src/adapter.h" #include "../src/manager.h" #include "../src/device.h" +#include "../src/profile.h" #include "log.h" #include "device.h" diff --git a/profiles/deviceinfo/manager.c b/profiles/deviceinfo/manager.c index 914ec4060..982135e94 100644 --- a/profiles/deviceinfo/manager.c +++ b/profiles/deviceinfo/manager.c @@ -27,6 +27,7 @@ #include "adapter.h" #include "device.h" +#include "profile.h" #include "att.h" #include "gattrib.h" #include "gatt.h" diff --git a/profiles/gatt/manager.c b/profiles/gatt/manager.c index 9c5ea14b4..6a520b3fa 100644 --- a/profiles/gatt/manager.c +++ b/profiles/gatt/manager.c @@ -27,6 +27,7 @@ #include "adapter.h" #include "device.h" +#include "profile.h" #include "att.h" #include "gattrib.h" #include "gatt.h" diff --git a/profiles/health/hdp_manager.c b/profiles/health/hdp_manager.c index 416286ee6..1f899dc98 100644 --- a/profiles/health/hdp_manager.c +++ b/profiles/health/hdp_manager.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include diff --git a/profiles/input/hog_manager.c b/profiles/input/hog_manager.c index 6d971fa01..827264025 100644 --- a/profiles/input/hog_manager.c +++ b/profiles/input/hog_manager.c @@ -32,6 +32,7 @@ #include "log.h" #include "../src/adapter.h" #include "../src/device.h" +#include "../src/profile.h" #include "plugin.h" #include "hcid.h" diff --git a/profiles/input/manager.c b/profiles/input/manager.c index 58c369441..3b494f5fd 100644 --- a/profiles/input/manager.c +++ b/profiles/input/manager.c @@ -36,6 +36,7 @@ #include "log.h" #include "../src/adapter.h" #include "../src/device.h" +#include "../src/profile.h" #include "device.h" #include "hog_device.h" diff --git a/profiles/network/manager.c b/profiles/network/manager.c index ac36406e9..9ab3a8b7b 100644 --- a/profiles/network/manager.c +++ b/profiles/network/manager.c @@ -39,6 +39,7 @@ #include "adapter.h" #include "device.h" +#include "profile.h" #include "manager.h" #include "common.h" #include "connection.h" diff --git a/profiles/proximity/manager.c b/profiles/proximity/manager.c index 7fa00b472..39c2bfe66 100644 --- a/profiles/proximity/manager.c +++ b/profiles/proximity/manager.c @@ -34,6 +34,7 @@ #include "adapter.h" #include "device.h" +#include "profile.h" #include "att.h" #include "gattrib.h" #include "gatt.h" diff --git a/profiles/sap/manager.c b/profiles/sap/manager.c index b563d7b0d..ecf672eeb 100644 --- a/profiles/sap/manager.c +++ b/profiles/sap/manager.c @@ -27,6 +27,7 @@ #include "log.h" #include "adapter.h" #include "device.h" +#include "profile.h" #include "manager.h" #include "server.h" diff --git a/profiles/thermometer/manager.c b/profiles/thermometer/manager.c index 9bbba67b6..4a894cf00 100644 --- a/profiles/thermometer/manager.c +++ b/profiles/thermometer/manager.c @@ -27,6 +27,7 @@ #include "adapter.h" #include "device.h" +#include "profile.h" #include "att.h" #include "gattrib.h" #include "gatt.h" diff --git a/profiles/time/manager.c b/profiles/time/manager.c index c29951c35..8dab12f0e 100644 --- a/profiles/time/manager.c +++ b/profiles/time/manager.c @@ -31,6 +31,7 @@ #include "manager.h" #include "adapter.h" #include "device.h" +#include "profile.h" #include "server.h" struct btd_profile time_profile = { diff --git a/src/adapter.c b/src/adapter.c index 4b675e802..1c13b2d09 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -51,6 +51,7 @@ #include "adapter.h" #include "manager.h" #include "device.h" +#include "profile.h" #include "dbus-common.h" #include "error.h" #include "glib-helper.h" diff --git a/src/device.c b/src/device.c index 02ef35e82..49021e4a4 100644 --- a/src/device.c +++ b/src/device.c @@ -53,6 +53,7 @@ #include "gattrib.h" #include "attio.h" #include "device.h" +#include "profile.h" #include "dbus-common.h" #include "error.h" #include "glib-helper.h" @@ -171,8 +172,6 @@ struct btd_device { guint cleanup_id; }; -static GSList *profiles = NULL; - static uint16_t uuid_list[] = { L2CAP_UUID, PNP_INFO_SVCLASS_ID, @@ -1294,7 +1293,7 @@ void device_probe_profiles(struct btd_device *device, GSList *uuids) DBG("Probing profiles for device %s", addr); - for (l = profiles; l != NULL; l = g_slist_next(l)) { + for (l = btd_get_profiles(); l != NULL; l = g_slist_next(l)) { struct btd_profile *profile = l->data; GSList *probe_uuids; int err; @@ -3226,40 +3225,3 @@ void device_set_pnpid(struct btd_device *device, uint8_t vendor_id_src, device_set_version(device, product_ver); } -void btd_profile_foreach(void (*func)(struct btd_profile *p, void *data), - void *data) -{ - GSList *l, *next; - - for (l = profiles; l != NULL; l = next) { - struct btd_profile *profile = l->data; - - next = g_slist_next(l); - - func(profile, data); - } -} - -int btd_profile_register(struct btd_profile *profile) -{ - profiles = g_slist_append(profiles, profile); - return 0; -} - -void btd_profile_unregister(struct btd_profile *profile) -{ - profiles = g_slist_remove(profiles, profile); -} - -void btd_profile_connected(struct btd_profile *profile, - struct btd_device *device, int err) -{ - if (err == 0) - device->conns = g_slist_append(device->conns, profile); -} - -void btd_profile_disconnected(struct btd_profile *profile, - struct btd_device *device) -{ - device->conns = g_slist_remove(device->conns, profile); -} diff --git a/src/device.h b/src/device.h index f1d95c6d5..9426ef867 100644 --- a/src/device.h +++ b/src/device.h @@ -34,37 +34,6 @@ typedef enum { AUTH_TYPE_NOTIFY_PINCODE, } auth_type_t; -#define BTD_UUIDS(args...) ((const char *[]) { args, NULL } ) - -struct btd_profile { - const char *name; - - const char *local_uuid; - const char **remote_uuids; - - bool auto_connect; - - int (*device_probe) (struct btd_device *device, GSList *uuids); - void (*device_remove) (struct btd_device *device); - - void (*connect) (struct btd_device *device); - void (*disconnect) (struct btd_device *device); - - int (*adapter_probe) (struct btd_adapter *adapter); - void (*adapter_remove) (struct btd_adapter *adapter); -}; - -void btd_profile_foreach(void (*func)(struct btd_profile *p, void *data), - void *data); - -int btd_profile_register(struct btd_profile *profile); -void btd_profile_unregister(struct btd_profile *profile); - -void btd_profile_connected(struct btd_profile *profile, - struct btd_device *device, int err); -void btd_profile_disconnected(struct btd_profile *profile, - struct btd_device *device); - struct btd_device *device_create(DBusConnection *conn, struct btd_adapter *adapter, const char *address, uint8_t bdaddr_type); diff --git a/src/profile.c b/src/profile.c new file mode 100644 index 000000000..71861f520 --- /dev/null +++ b/src/profile.c @@ -0,0 +1,68 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * + * 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 +#endif + +#include +#include + +#include +#include + +#include "adapter.h" +#include "device.h" +#include "profile.h" + +static GSList *profiles = NULL; + +void btd_profile_foreach(void (*func)(struct btd_profile *p, void *data), + void *data) +{ + GSList *l, *next; + + for (l = profiles; l != NULL; l = next) { + struct btd_profile *profile = l->data; + + next = g_slist_next(l); + + func(profile, data); + } +} + +int btd_profile_register(struct btd_profile *profile) +{ + profiles = g_slist_append(profiles, profile); + return 0; +} + +void btd_profile_unregister(struct btd_profile *profile) +{ + profiles = g_slist_remove(profiles, profile); +} + +GSList *btd_get_profiles(void) +{ + return profiles; +} diff --git a/src/profile.h b/src/profile.h new file mode 100644 index 000000000..9088c322d --- /dev/null +++ b/src/profile.h @@ -0,0 +1,50 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * + * 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 BTD_UUIDS(args...) ((const char *[]) { args, NULL } ) + +struct btd_profile { + const char *name; + + const char *local_uuid; + const char **remote_uuids; + + bool auto_connect; + + int (*device_probe) (struct btd_device *device, GSList *uuids); + void (*device_remove) (struct btd_device *device); + + void (*connect) (struct btd_device *device); + void (*disconnect) (struct btd_device *device); + + int (*adapter_probe) (struct btd_adapter *adapter); + void (*adapter_remove) (struct btd_adapter *adapter); +}; + +void btd_profile_foreach(void (*func)(struct btd_profile *p, void *data), + void *data); + +int btd_profile_register(struct btd_profile *profile); +void btd_profile_unregister(struct btd_profile *profile); + +GSList *btd_get_profiles(void); -- 2.47.3