Return-Path: MIME-Version: 1.0 In-Reply-To: <1426180319-16509-3-git-send-email-jamuraa@chromium.org> References: <1426180319-16509-1-git-send-email-jamuraa@chromium.org> <1426180319-16509-3-git-send-email-jamuraa@chromium.org> Date: Thu, 12 Mar 2015 12:42:11 -0700 Message-ID: Subject: Re: [BlueZ 02/12] core: advertising: add LEAdvertisingManager stubs From: Arman Uguray To: Michael Janssen Cc: BlueZ development Content-Type: text/plain; charset=UTF-8 Sender: linux-bluetooth-owner@vger.kernel.org List-ID: Hi Michael, > On Thu, Mar 12, 2015 at 10:11 AM, Michael Janssen wrote: > Introducing src/advertising-manager which will implement the > org.bluez.LEAdvertisingManager1 D-Bus interface defined in > doc/advertising-api.txt. Each LE-capable controller gets > an instance of the interface. > --- > Makefile.am | 1 + > src/adapter.c | 19 ++++++++ > src/advertising-manager.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++ > src/advertising-manager.h | 25 ++++++++++ > 4 files changed, 165 insertions(+) > create mode 100644 src/advertising-manager.c > create mode 100644 src/advertising-manager.h > > diff --git a/Makefile.am b/Makefile.am > index d0da411..38f9420 100644 > --- a/Makefile.am > +++ b/Makefile.am > @@ -175,6 +175,7 @@ src_bluetoothd_SOURCES = $(builtin_sources) \ > src/uinput.h \ > src/plugin.h src/plugin.c \ > src/storage.h src/storage.c \ > + src/advertising-manager.h src/advertising-manager.c \ > src/agent.h src/agent.c \ > src/error.h src/error.c \ > src/adapter.h src/adapter.c \ > diff --git a/src/adapter.c b/src/adapter.c > index 329e9b4..d4401ec 100644 > --- a/src/adapter.c > +++ b/src/adapter.c > @@ -74,6 +74,7 @@ > #include "attrib/gatt.h" > #include "attrib-server.h" > #include "gatt-database.h" > +#include "advertising-manager.h" > #include "eir.h" > > #define ADAPTER_INTERFACE "org.bluez.Adapter1" > @@ -210,6 +211,7 @@ struct btd_adapter { > sdp_list_t *services; /* Services associated to adapter */ > > struct btd_gatt_database *database; > + struct btd_advertising_manager *adv_manager; > > gboolean initialized; > > @@ -4607,6 +4609,9 @@ static void adapter_remove(struct btd_adapter *adapter) > btd_gatt_database_destroy(adapter->database); > adapter->database = NULL; > > + btd_advertising_manager_destroy(adapter->adv_manager); > + adapter->adv_manager = NULL; > + > g_slist_free(adapter->pin_callbacks); > adapter->pin_callbacks = NULL; > > @@ -6679,6 +6684,20 @@ static int adapter_register(struct btd_adapter *adapter) > return -EINVAL; > } > > + /* Don't start advertising managers on non-LE controllers. */ > + if (adapter->supported_settings && MGMT_SETTING_LE) { Did you mean to do a bitwise-& here? > + adapter->adv_manager = btd_advertising_manager_new(adapter); > + if (!adapter->adv_manager) { > + error("Failed to register LEAdvertisingManager1 " > + "interface for adapter"); > + btd_gatt_database_destroy(adapter->database); > + adapter->database = NULL; > + return -EINVAL; > + } > + } else { > + error("Not starting LEAdvertisingManager, LE not supported"); > + } > + > db = btd_gatt_database_get_db(adapter->database); > adapter->db_id = gatt_db_register(db, services_modified, > services_modified, > diff --git a/src/advertising-manager.c b/src/advertising-manager.c > new file mode 100644 > index 0000000..754b6ff > --- /dev/null > +++ b/src/advertising-manager.c > @@ -0,0 +1,120 @@ > +/* > + * > + * BlueZ - Bluetooth protocol stack for Linux > + * > + * Copyright (C) 2015 Google Inc. > + * > + * > + * 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. > + * > + */ > + > +#include "advertising-manager.h" > + > +#include > +#include > + > +#include "adapter.h" > +#include "dbus-common.h" > +#include "log.h" > +#include "src/shared/util.h" > + > +#define LE_ADVERTISING_MGR_IFACE "org.bluez.LEAdvertisingManager1" > + > +struct btd_advertising_manager { > + struct btd_adapter *adapter; > +}; > + > +static DBusMessage *register_advertisement(DBusConnection *conn, > + DBusMessage *msg, > + void *user_data) > +{ > + DBG("RegisterAdvertisement"); > + > + /* TODO */ > + return NULL; > +} > + > +static DBusMessage *unregister_advertisement(DBusConnection *conn, > + DBusMessage *msg, > + void *user_data) > +{ > + DBG("UnregisterAdvertisement"); > + > + /* TODO */ > + return NULL; > +} > + > +static const GDBusMethodTable methods[] = { > + { GDBUS_EXPERIMENTAL_ASYNC_METHOD("RegisterAdvertisement", > + GDBUS_ARGS({ "advertisement", "o"}, nit: I would pick a consistent style for static initializers and spacing, i.e either {a, b} or { a, b } (not sure what the recommended style is for BlueZ), you seem to have a mix of everything here. > + { "options", "a{sv}" }), > + NULL, register_advertisement) }, > + { GDBUS_EXPERIMENTAL_ASYNC_METHOD("UnregisterAdvertisement", > + GDBUS_ARGS({"service", "o"}), > + NULL, > + unregister_advertisement) }, > + { } > +}; > + > +static struct btd_advertising_manager * > +advertising_manager_create(struct btd_adapter *adapter) > +{ > + struct btd_advertising_manager *manager; > + > + manager = new0(struct btd_advertising_manager, 1); > + if (!manager) > + return NULL; > + > + manager->adapter = adapter; > + > + if (!g_dbus_register_interface(btd_get_dbus_connection(), > + adapter_get_path(adapter), > + LE_ADVERTISING_MGR_IFACE, > + methods, NULL, NULL, adapter, The user_data should be |manager| here instead of |adapter|, no? > + NULL)) { > + error("Failed to register " LE_ADVERTISING_MGR_IFACE); > + free(manager); > + return NULL; > + } > + > + return manager; > +} > + > +struct btd_advertising_manager * > +btd_advertising_manager_new(struct btd_adapter *adapter) > +{ > + struct btd_advertising_manager *manager; > + > + if (!adapter) > + return NULL; > + > + manager = advertising_manager_create(adapter); > + if (!manager) > + return NULL; > + > + DBG("LE Advertising Manager created for adapter: %s", > + adapter_get_path(adapter)); > + > + return manager; > +} > + > +void btd_advertising_manager_destroy(struct btd_advertising_manager *manager) > +{ > + if (!manager) > + return; > + > + g_dbus_unregister_interface(btd_get_dbus_connection(), > + adapter_get_path(manager->adapter), > + LE_ADVERTISING_MGR_IFACE); > + > + free(manager); You can also pass "free" as the destroy function to g_dbus_register_interface above, if you pass "manager" as the user data. > +} > diff --git a/src/advertising-manager.h b/src/advertising-manager.h > new file mode 100644 > index 0000000..4046013 > --- /dev/null > +++ b/src/advertising-manager.h > @@ -0,0 +1,25 @@ > +/* > + * > + * BlueZ - Bluetooth protocol stack for Linux > + * > + * Copyright (C) 2015 Google Inc. > + * > + * > + * 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. > + * > + */ > + > +struct btd_adapter; > +struct btd_advertising_manager; > + > +struct btd_advertising_manager *btd_advertising_manager_new( > + struct btd_adapter *adapter); > +void btd_advertising_manager_destroy(struct btd_advertising_manager *manager); > -- > 2.2.0.rc0.207.ga3a616c > > -- > To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html Thanks, Arman