diff mbox series

[v2,2/7] gatt: Store local GATT database

Message ID 20220520041701.2572197-2-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Commit f66673878a9f3745c9cb3cfaa85b5b8f99a929d6
Headers show
Series [v2,1/7] settings: Add btd_settings_gatt_db_{store,load} | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/checkpatch success Checkpatch PASS
tedd_an/gitlint success Gitlint PASS

Commit Message

Luiz Augusto von Dentz May 20, 2022, 4:16 a.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This enables storing the local (adapter) GATT database which later will
be used by btmon to decode GATT handles.
---
 src/gatt-database.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/src/gatt-database.c b/src/gatt-database.c
index d32f616a9..cf651b5f5 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -38,6 +38,8 @@ 
 #include "dbus-common.h"
 #include "profile.h"
 #include "service.h"
+#include "textfile.h"
+#include "settings.h"
 
 #define GATT_MANAGER_IFACE	"org.bluez.GattManager1"
 #define GATT_PROFILE_IFACE	"org.bluez.GattProfile1"
@@ -1528,6 +1530,17 @@  static void send_service_changed(struct btd_gatt_database *database,
 		error("Failed to notify Service Changed");
 }
 
+static void database_store(struct btd_gatt_database *database)
+{
+	char filename[PATH_MAX];
+
+	create_filename(filename, PATH_MAX, "/%s/attributes",
+				btd_adapter_get_storage_dir(database->adapter));
+	create_file(filename, 0600);
+
+	btd_settings_gatt_db_store(database->db, filename);
+}
+
 static void gatt_db_service_added(struct gatt_db_attribute *attrib,
 								void *user_data)
 {
@@ -1538,6 +1551,8 @@  static void gatt_db_service_added(struct gatt_db_attribute *attrib,
 	database_add_record(database, attrib);
 
 	send_service_changed(database, attrib);
+
+	database_store(database);
 }
 
 static bool ccc_match_service(const void *data, const void *match_data)