All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Frédéric Danis" <frederic.danis@linux.intel.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2 04/15] device: Load profiles from storage
Date: Thu, 13 Dec 2012 21:39:19 +0100	[thread overview]
Message-ID: <1355431170-12897-4-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1355431170-12897-1-git-send-email-frederic.danis@linux.intel.com>

Add device_get_uuids() to retrieve UUIDs list.
It will allow to call device_probe_profiles() from
load_devices() of adapter.c after device creation.

Remove write_device_profiles from storage.[ch].
---
 src/device.c  |   89 ++++++++++++++++++++++++++++++---------------------------
 src/device.h  |    1 +
 src/storage.c |   18 ------------
 src/storage.h |    2 --
 4 files changed, 48 insertions(+), 62 deletions(-)

diff --git a/src/device.c b/src/device.c
index e07e7b8..42a7c65 100644
--- a/src/device.c
+++ b/src/device.c
@@ -216,6 +216,7 @@ static gboolean store_device_info_cb(gpointer user_data)
 	char device_addr[18];
 	char *str;
 	char class[9];
+	gchar **uuids = NULL;
 	gsize length = 0;
 
 	device->store_id = 0;
@@ -279,6 +280,19 @@ static gboolean store_device_info_cb(gpointer user_data)
 	g_key_file_set_boolean(key_file, "General", "Blocked",
 							device->blocked);
 
+	if (device->uuids) {
+		GSList *l;
+		int i;
+
+		uuids = g_new0(gchar *, g_slist_length(device->uuids) + 1);
+		for (i = 0, l = device->uuids; l; l = g_slist_next(l), i++)
+			uuids[i] = l->data;
+		g_key_file_set_string_list(key_file, "General", "Profiles",
+						(const gchar **)uuids, i);
+	} else {
+		g_key_file_remove_key(key_file, "General", "Profiles", NULL);
+	}
+
 	if (device->vendor_src) {
 		g_key_file_set_integer(key_file, "DeviceID", "Source",
 					device->vendor_src);
@@ -299,6 +313,7 @@ static gboolean store_device_info_cb(gpointer user_data)
 	g_free(str);
 
 	g_key_file_free(key_file);
+	g_free(uuids);
 
 	return FALSE;
 }
@@ -1740,6 +1755,7 @@ static void load_info(struct btd_device *device, const gchar *local,
 	char *str;
 	gboolean store_needed = FALSE;
 	gboolean blocked;
+	gchar **uuids;
 	int source, vendor, product, version;
 	char **techno, **t;
 	gboolean bredr = FALSE;
@@ -1819,6 +1835,27 @@ next:
 	if (blocked)
 		device_block(device, FALSE);
 
+	/* Load device profile list */
+	uuids = g_key_file_get_string_list(key_file, "General", "Profiles",
+						NULL, NULL);
+	if (uuids) {
+		gchar **uuid;
+
+		for (uuid = uuids; *uuid; uuid++) {
+			GSList *match;
+
+			match = g_slist_find_custom(device->uuids, *uuid,
+							bt_uuid_strcmp);
+			if (match)
+				continue;
+
+			device->uuids = g_slist_insert_sorted(device->uuids,
+								g_strdup(*uuid),
+								bt_uuid_strcmp);
+		}
+		g_strfreev(uuids);
+	}
+
 	/* Load device id */
 	source = g_key_file_get_integer(key_file, "DeviceID", "Source", NULL);
 	if (source) {
@@ -2124,6 +2161,11 @@ static gboolean record_has_uuid(const sdp_record_t *rec,
 	return FALSE;
 }
 
+GSList *device_get_uuids(struct btd_device *device)
+{
+	return device->uuids;
+}
+
 static GSList *device_match_profile(struct btd_device *device,
 					struct btd_profile *profile,
 					GSList *uuids)
@@ -2263,35 +2305,16 @@ add_uuids:
 static void device_remove_profiles(struct btd_device *device, GSList *uuids)
 {
 	char srcaddr[18], dstaddr[18];
-	sdp_list_t *records;
 	GSList *l, *next;
 
 	ba2str(adapter_get_address(device->adapter), srcaddr);
 	ba2str(&device->bdaddr, dstaddr);
 
-	records = read_records(adapter_get_address(device->adapter),
-							&device->bdaddr);
-
 	DBG("Removing profiles for %s", dstaddr);
 
-	for (l = uuids; l != NULL; l = g_slist_next(l)) {
-		sdp_record_t *rec;
-
-		device->uuids = g_slist_remove(device->uuids, l->data);
-
-		rec = find_record_in_list(records, l->data);
-		if (!rec)
-			continue;
-
-		delete_record(srcaddr, dstaddr, device->bdaddr_type,
-							rec->handle);
-
-		records = sdp_list_remove(records, rec);
-		sdp_record_free(rec);
-	}
-
-	if (records)
-		sdp_list_free(records, (sdp_free_func_t) sdp_record_free);
+	g_slist_free(device->uuids);
+	device->uuids = NULL;
+	store_device_info(device);
 
 	for (l = device->profiles; l != NULL; l = next) {
 		struct btd_profile *profile = l->data;
@@ -2460,24 +2483,6 @@ static void update_gatt_services(struct browse_req *req, GSList *current,
 	g_slist_free(left);
 }
 
-static void store_profiles(struct btd_device *device)
-{
-	struct btd_adapter *adapter = device->adapter;
-	char *str;
-
-	if (!device->uuids) {
-		write_device_profiles(adapter_get_address(adapter),
-					&device->bdaddr, device->bdaddr_type,
-					"");
-		return;
-	}
-
-	str = bt_list2string(device->uuids);
-	write_device_profiles(adapter_get_address(adapter), &device->bdaddr,
-						device->bdaddr_type, str);
-	g_free(str);
-}
-
 GSList *device_services_from_record(struct btd_device *device, GSList *profiles)
 {
 	GSList *l, *prim_list = NULL;
@@ -2567,7 +2572,7 @@ send_reply:
 	device_svc_resolved(device, err);
 
 	if (!device->temporary)
-		store_profiles(device);
+		store_device_info(device);
 
 	browse_request_free(req);
 }
@@ -3820,7 +3825,7 @@ void btd_device_add_uuid(struct btd_device *device, const char *uuid)
 	g_free(new_uuid);
 	g_slist_free(uuid_list);
 
-	store_profiles(device);
+	store_device_info(device);
 	uuids_changed(device);
 }
 
diff --git a/src/device.h b/src/device.h
index a207a4f..9102e60 100644
--- a/src/device.h
+++ b/src/device.h
@@ -42,6 +42,7 @@ uint16_t btd_device_get_version(struct btd_device *device);
 void device_remove(struct btd_device *device, gboolean remove_stored);
 gint device_address_cmp(struct btd_device *device, const gchar *address);
 gint device_bdaddr_cmp(struct btd_device *device, bdaddr_t *bdaddr);
+GSList *device_get_uuids(struct btd_device *device);
 void device_probe_profiles(struct btd_device *device, GSList *profiles);
 const sdp_record_t *btd_device_get_record(struct btd_device *device,
 						const char *uuid);
diff --git a/src/storage.c b/src/storage.c
index 0b9ed2d..74b19c0 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -245,24 +245,6 @@ ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin)
 	return len;
 }
 
-int write_device_profiles(const bdaddr_t *src, const bdaddr_t *dst,
-					uint8_t dst_type, const char *profiles)
-{
-	char filename[PATH_MAX + 1], key[20];
-
-	if (!profiles)
-		return -EINVAL;
-
-	create_filename(filename, PATH_MAX, src, "profiles");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	ba2str(dst, key);
-	sprintf(&key[17], "#%hhu", dst_type);
-
-	return textfile_put(filename, key, profiles);
-}
-
 int delete_entry(const bdaddr_t *src, const char *storage, const bdaddr_t *dst,
 							uint8_t dst_type)
 {
diff --git a/src/storage.h b/src/storage.h
index cb9d836..2e2889d 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -35,8 +35,6 @@ int read_remote_appearance(const bdaddr_t *local, const bdaddr_t *peer,
 int write_lastused_info(const bdaddr_t *local, const bdaddr_t *peer,
 					uint8_t peer_type, struct tm *tm);
 ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin);
-int write_device_profiles(const bdaddr_t *src, const bdaddr_t *dst,
-				uint8_t dst_type, const char *profiles);
 int delete_entry(const bdaddr_t *src, const char *storage, const bdaddr_t *dst,
 							uint8_t dst_type);
 int store_record(const gchar *src, const gchar *dst, uint8_t dst_type,
-- 
1.7.9.5


  parent reply	other threads:[~2012-12-13 20:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-13 20:39 [PATCH v2 01/15] device: Retrieve device technology from storage Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 02/15] device: Add device_create_from_storage() function Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 03/15] adapter: Convert device profiles list Frédéric Danis
2012-12-13 20:39 ` Frédéric Danis [this message]
2012-12-13 20:39 ` [PATCH v2 05/15] adapter: Probe profiles after device creation Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 06/15] device: Delete storage device recursively Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 07/15] doc: Update Settings-storage for SDP records Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 08/15] adapter: Convert device sdp file Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 09/15] device: Remove stored SDP records on device removal Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 10/15] device: Load primary attributes from storage Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 11/15] device: Store SDP records in new storage Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 12/15] adapter: Convert device primaries list Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 13/15] adapter: Remove create_stored_device_from_primaries Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 14/15] device: Update btd_device_get_record to use new storage Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 15/15] input: Use new storage architecture Frédéric Danis
2012-12-14  8:31 ` [PATCH v2 01/15] device: Retrieve device technology from storage Johan Hedberg

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=1355431170-12897-4-git-send-email-frederic.danis@linux.intel.com \
    --to=frederic.danis@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.