summaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
authorLi, Xiaoming <lixm.fnst@cn.fujitsu.com>2020-09-26 09:58:21 -0700
committerLi, Xiaoming <lixm.fnst@cn.fujitsu.com>2020-09-26 10:10:09 -0700
commit8ba3e0d2ffe62c2c94844d8b536c1d49e12e35dd (patch)
treeac871f7bc9008ad4258f6c72878e4c8e331944bf /binding
parentcf647a95213c209ab7214f1c1c16f1771c4bb229 (diff)
Improve default_adapter verb performance
If not provide a new adapter or if new adapter is the same one with default, reply with existing defalut adapter. At the same time, clean some unnecessary code, following up the change of https://gerrit.automotivelinux.org/gerrit/c/apps/agl-service-bluetooth/+/25292 Bug-AGL: SPEC-3577 Change-Id: If3cbf8d1fb36a144f321db1056c38fd335ef9a28 Signed-off-by: Li, Xiaoming <lixm.fnst@cn.fujitsu.com>
Diffstat (limited to 'binding')
-rw-r--r--binding/bluetooth-api.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c
index 86883e0..876f546 100644
--- a/binding/bluetooth-api.c
+++ b/binding/bluetooth-api.c
@@ -1006,29 +1006,28 @@ static void bluetooth_adapter(afb_req_t request)
static void bluetooth_default_adapter(afb_req_t request)
{
- struct bluetooth_state *ns = bluetooth_get_userdata(request);
const char *adapter = afb_req_value(request, "adapter");
json_object *jresp = json_object_new_object();
+ afb_api_t api = afb_req_get_api(request);
+ const char *adapter_default = get_default_adapter(api);
int rc;
- if (!ns || !adapter ) {
- afb_req_fail(request, "failed",
- "No default adapter");
- return;
+ if (adapter) {
+ if (adapter_default && g_strcmp0(adapter_default, adapter)) {
+ rc = set_default_adapter(api, adapter);
+ if (rc) {
+ AFB_DEBUG("Request to save default adapter to persistent storage failed ");
+ afb_req_fail(request, "failed", "Update default adapter failed");
+ return;
+ }
+ }
+ json_object_object_add(jresp, "adapter", json_object_new_string(adapter));
+ } else if (adapter_default) {
+ json_object_object_add(jresp, "adapter", json_object_new_string(adapter_default));
+ } else {
+ afb_req_fail(request, "failed", "No default adapter");
+ return;
}
-
- call_work_lock(ns);
- rc = set_default_adapter(afb_req_get_api(request), adapter);
-
- if (ns->adapter)
- g_free(ns->adapter);
- ns->adapter = g_strdup(adapter);
-
- json_object_object_add(jresp, "adapter", json_object_new_string(ns->adapter));
- call_work_unlock(ns);
- if (rc)
- AFB_DEBUG("Request to save default adapter to persistent storage failed ");
-
afb_req_success(request, jresp, "Bluetooth - default adapter");
}