From cf647a95213c209ab7214f1c1c16f1771c4bb229 Mon Sep 17 00:00:00 2001 From: Raquel Medina Date: Thu, 17 Sep 2020 14:30:56 +0200 Subject: create persistence binding entry for default adapter Add logic to create an entry for 'default_adapter' in the persistence database. This will enable having the stored value available between power up/power down cycles. Bug-AGL: SPEC-3577 Signed-off-by: Raquel Medina Change-Id: I158dcc1d37ccaf8dfe5d53e262f0619ad780c26a --- binding/bluetooth-api.c | 6 +++++- binding/bluetooth-conf.c | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c index c731c34..86883e0 100644 --- a/binding/bluetooth-api.c +++ b/binding/bluetooth-api.c @@ -726,8 +726,12 @@ static int init(afb_api_t api) } id->default_adapter = get_default_adapter(id->api); - if (!id->default_adapter) + if (!id->default_adapter) { id->default_adapter = g_strdup(BLUEZ_DEFAULT_ADAPTER); + ret = set_default_adapter(api, BLUEZ_DEFAULT_ADAPTER); + if (ret) + AFB_WARNING("Request to save default adapter to persistent storage failed "); + } args = json_object_new_object(); json_object_object_add(args , "technology", json_object_new_string("bluetooth")); diff --git a/binding/bluetooth-conf.c b/binding/bluetooth-conf.c index 2f6f475..ff888d6 100644 --- a/binding/bluetooth-conf.c +++ b/binding/bluetooth-conf.c @@ -66,7 +66,14 @@ int set_default_adapter(afb_api_t api, const char *adapter) json_object_object_add(query, "value", json_object_new_string(adapter)); ret = afb_api_call_sync(api, "persistence", "update", query, &response, NULL, NULL); + if (ret < 0) { + ret = afb_api_call_sync(api, "persistence", "insert", query, &response, NULL, NULL); + if (ret < 0) + goto out; + } + json_object_put(response); +out: return ret; } -- cgit 1.2.3-korg