From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 08/15] android/scpp: Strip dependencies from scan plugin
Date: Thu, 26 Jun 2014 17:46:41 +0300 [thread overview]
Message-ID: <1403794008-18585-8-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1403794008-18585-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This strip any dependecy from scan plugin so the code can be reused
by HoG implementation.
---
android/Android.mk | 1 +
android/Makefile.am | 1 +
android/scpp.c | 168 ++++++++++++++++++++-----------------------
android/{health.h => scpp.h} | 15 ++--
4 files changed, 89 insertions(+), 96 deletions(-)
copy android/{health.h => scpp.h} (65%)
diff --git a/android/Android.mk b/android/Android.mk
index 7485c0f..fdc352a 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -36,6 +36,7 @@ LOCAL_SRC_FILES := \
bluez/android/main.c \
bluez/android/bluetooth.c \
bluez/android/dis.c \
+ bluez/android/scpp.c \
bluez/android/hog.c \
bluez/android/hidhost.c \
bluez/android/socket.c \
diff --git a/android/Makefile.am b/android/Makefile.am
index 0349f38..ffcb199 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -39,6 +39,7 @@ android_bluetoothd_SOURCES = android/main.c \
android/bluetooth.h android/bluetooth.c \
android/hidhost.h android/hidhost.c \
android/dis.h android/dis.c \
+ android/scpp.h android/scpp.c \
android/hog.h android/hog.c \
android/ipc-common.h \
android/ipc.h android/ipc.c \
diff --git a/android/scpp.c b/android/scpp.c
index 3eece9d..c73a015 100644
--- a/android/scpp.c
+++ b/android/scpp.c
@@ -29,18 +29,18 @@
#include <stdbool.h>
#include <errno.h>
-#include "lib/uuid.h"
+#include <glib.h>
+
#include "src/log.h"
-#include "src/plugin.h"
-#include "src/adapter.h"
-#include "src/device.h"
-#include "src/profile.h"
-#include "src/service.h"
+
+#include "lib/uuid.h"
#include "src/shared/util.h"
+
#include "attrib/att.h"
#include "attrib/gattrib.h"
#include "attrib/gatt.h"
-#include "src/attio.h"
+
+#include "android/scpp.h"
#define SCAN_INTERVAL_WIN_UUID 0x2A4F
#define SCAN_REFRESH_UUID 0x2A31
@@ -49,11 +49,10 @@
#define SCAN_WINDOW 0x0030
#define SERVER_REQUIRES_REFRESH 0x00
-struct scan {
- struct btd_device *device;
+struct bt_scpp {
+ int ref_count;
GAttrib *attrib;
- struct att_range range;
- guint attioid;
+ struct gatt_primary *primary;
uint16_t interval;
uint16_t window;
uint16_t iwhandle;
@@ -61,6 +60,50 @@ struct scan {
guint refresh_cb_id;
};
+static void scpp_free(struct bt_scpp *scan)
+{
+ if (scan->attrib)
+ g_attrib_unref(scan->attrib);
+
+ g_free(scan->primary);
+ g_free(scan);
+}
+
+struct bt_scpp *bt_scpp_new(void *primary)
+{
+ struct bt_scpp *scan;
+
+ scan = g_try_new0(struct bt_scpp, 1);
+ if (!scan)
+ return NULL;
+
+ if (primary)
+ scan->primary = g_memdup(primary, sizeof(*scan->primary));
+
+ return bt_scpp_ref(scan);
+}
+
+struct bt_scpp *bt_scpp_ref(struct bt_scpp *scan)
+{
+ if (!scan)
+ return NULL;
+
+ __sync_fetch_and_add(&scan->ref_count, 1);
+
+ return scan;
+}
+
+void bt_scpp_unref(struct bt_scpp *scan)
+{
+ if (!scan)
+ return;
+
+ if (__sync_sub_and_fetch(&scan->ref_count, 1))
+ return;
+
+ scpp_free(scan);
+}
+
static void write_scan_params(GAttrib *attrib, uint16_t handle)
{
uint8_t value[4];
@@ -74,7 +117,7 @@ static void write_scan_params(GAttrib *attrib, uint16_t handle)
static void refresh_value_cb(const uint8_t *pdu, uint16_t len,
gpointer user_data)
{
- struct scan *scan = user_data;
+ struct bt_scpp *scan = user_data;
DBG("Server requires refresh: %d", pdu[3]);
@@ -85,7 +128,7 @@ static void refresh_value_cb(const uint8_t *pdu, uint16_t len,
static void ccc_written_cb(guint8 status, const guint8 *pdu,
guint16 plen, gpointer user_data)
{
- struct scan *scan = user_data;
+ struct bt_scpp *scan = user_data;
if (status != 0) {
error("Write Scan Refresh CCC failed: %s",
@@ -103,7 +146,7 @@ static void ccc_written_cb(guint8 status, const guint8 *pdu,
static void discover_descriptor_cb(uint8_t status, GSList *descs,
void *user_data)
{
- struct scan *scan = user_data;
+ struct bt_scpp *scan = user_data;
struct gatt_desc *desc;
uint8_t value[2];
@@ -123,7 +166,7 @@ static void discover_descriptor_cb(uint8_t status, GSList *descs,
static void refresh_discovered_cb(uint8_t status, GSList *chars,
void *user_data)
{
- struct scan *scan = user_data;
+ struct bt_scpp *scan = user_data;
struct gatt_char *chr;
uint16_t start, end;
bt_uuid_t uuid;
@@ -143,7 +186,7 @@ static void refresh_discovered_cb(uint8_t status, GSList *chars,
DBG("Scan Refresh handle: 0x%04x", chr->value_handle);
start = chr->value_handle + 1;
- end = scan->range.end;
+ end = scan->primary->range.end;
if (start > end)
return;
@@ -158,7 +201,7 @@ static void refresh_discovered_cb(uint8_t status, GSList *chars,
static void iwin_discovered_cb(uint8_t status, GSList *chars, void *user_data)
{
- struct scan *scan = user_data;
+ struct bt_scpp *scan = user_data;
struct gatt_char *chr;
if (status) {
@@ -175,98 +218,39 @@ static void iwin_discovered_cb(uint8_t status, GSList *chars, void *user_data)
write_scan_params(scan->attrib, scan->iwhandle);
}
-static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
+bool bt_scpp_attach(struct bt_scpp *scan, void *attrib)
{
- struct scan *scan = user_data;
bt_uuid_t iwin_uuid, refresh_uuid;
+ if (!scan || scan->attrib || !scan->primary)
+ return false;
+
scan->attrib = g_attrib_ref(attrib);
if (scan->iwhandle) {
write_scan_params(scan->attrib, scan->iwhandle);
- return;
+ return true;
}
bt_uuid16_create(&iwin_uuid, SCAN_INTERVAL_WIN_UUID);
bt_uuid16_create(&refresh_uuid, SCAN_REFRESH_UUID);
- gatt_discover_char(scan->attrib, scan->range.start, scan->range.end,
- &iwin_uuid, iwin_discovered_cb, scan);
+ gatt_discover_char(scan->attrib, scan->primary->range.start,
+ scan->primary->range.end, &iwin_uuid,
+ iwin_discovered_cb, scan);
- gatt_discover_char(scan->attrib, scan->range.start, scan->range.end,
- &refresh_uuid, refresh_discovered_cb, scan);
-}
-
-static void attio_disconnected_cb(gpointer user_data)
-{
- struct scan *scan = user_data;
+ gatt_discover_char(scan->attrib, scan->primary->range.start,
+ scan->primary->range.end, &refresh_uuid,
+ refresh_discovered_cb, scan);
- g_attrib_unref(scan->attrib);
- scan->attrib = NULL;
+ return true;
}
-static int scan_register(struct btd_service *service, struct gatt_primary *prim)
+void bt_scpp_detach(struct bt_scpp *scan)
{
- struct btd_device *device = btd_service_get_device(service);
- struct scan *scan;
-
- scan = g_new0(struct scan, 1);
- scan->device = btd_device_ref(device);
- scan->range = prim->range;
- scan->attioid = btd_device_add_attio_callback(device,
- attio_connected_cb,
- attio_disconnected_cb,
- scan);
-
- btd_service_set_user_data(service, scan);
-
- return 0;
-}
-
-static void scan_param_remove(struct btd_service *service)
-{
- struct scan *scan = btd_service_get_user_data(service);
-
- if (scan->attrib != NULL && scan->refresh_cb_id > 0)
- g_attrib_unregister(scan->attrib, scan->refresh_cb_id);
+ if (!scan || !scan->attrib)
+ return;
- btd_device_remove_attio_callback(scan->device, scan->attioid);
- btd_device_unref(scan->device);
g_attrib_unref(scan->attrib);
- g_free(scan);
-}
-
-static int scan_param_probe(struct btd_service *service)
-{
- struct btd_device *device = btd_service_get_device(service);
- struct gatt_primary *prim;
-
- DBG("Probing Scan Parameters");
-
- prim = btd_device_get_primary(device, SCAN_PARAMETERS_UUID);
- if (!prim)
- return -EINVAL;
-
- return scan_register(service, prim);
-}
-
-static struct btd_profile scan_profile = {
- .name = "Scan Parameters Client Driver",
- .remote_uuid = SCAN_PARAMETERS_UUID,
- .device_probe = scan_param_probe,
- .device_remove = scan_param_remove,
-};
-
-static int scan_param_init(void)
-{
- return btd_profile_register(&scan_profile);
-}
-
-static void scan_param_exit(void)
-{
- btd_profile_unregister(&scan_profile);
+ scan->attrib = NULL;
}
-
-BLUETOOTH_PLUGIN_DEFINE(scanparam, VERSION,
- BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
- scan_param_init, scan_param_exit)
diff --git a/android/health.h b/android/scpp.h
similarity index 65%
copy from android/health.h
copy to android/scpp.h
index 0b32fd3..f374cee 100644
--- a/android/health.h
+++ b/android/scpp.h
@@ -5,12 +5,12 @@
* Copyright (C) 2014 Intel Corporation. All rights reserved.
*
*
- * This library is free software; you can redistribute it and/or
+ * This library is free software; you can rescpptribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful,
+ * This library is scpptributed 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
* Lesser General Public License for more details.
@@ -21,5 +21,12 @@
*
*/
-bool bt_health_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode);
-void bt_health_unregister(void);
+struct bt_scpp;
+
+struct bt_scpp *bt_scpp_new(void *primary);
+
+struct bt_scpp *bt_scpp_ref(struct bt_scpp *scan);
+void bt_scpp_unref(struct bt_scpp *scan);
+
+bool bt_scpp_attach(struct bt_scpp *scan, void *gatt);
+void bt_scpp_detach(struct bt_scpp *scan);
--
1.9.3
next prev parent reply other threads:[~2014-06-26 14:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-26 14:46 [PATCH BlueZ v2 01/15] android/dis: Add copy to Device Info implementation Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 02/15] android/dis: Strip dependencies from deviceinfo plugin Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 03/15] android/dis: Add bt_dis_set_notification Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 04/15] android/dis: Only cache the handle not all the characteristics Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 05/15] android/hog: Add support for reading device details via DIS Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 06/15] lib/uuid: Add define for Scan Parameter UUID Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 07/15] android/scpp: Add copy to Scan Parameter Profile implementation Luiz Augusto von Dentz
2014-06-26 14:46 ` Luiz Augusto von Dentz [this message]
2014-06-26 14:46 ` [PATCH BlueZ v2 09/15] android/scpp: Add bt_scpp_set_interval and bt_scpp_set_window Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 10/15] android/scpp: Check for cached handles on attach Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 11/15] android/hog: Add support for Scan Parameter Service Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 12/15] android: Add initial implementation of Battery Service client Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 13/15] lib/uuid: Add define for Battery UUID Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 14/15] android/hog: Add support for Battery Service Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 15/15] android/hog: Add support for multiple instaces Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1403794008-18585-8-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).