_bt_convert_address_to_string(&device_addr,
(bluetooth_device_address_t *)(param->param_data));
client_s = (bt_gatt_client_s *)_bt_gatt_get_client(device_addr);
- if (client_s && !client_s->services_discovered) {
- if (_bt_gatt_client_update_services(client_s) != BT_ERROR_NONE)
- BT_ERR("_bt_gatt_client_update_services failed");
- else
- client_s->services_discovered = true;
- }
- if (client_s)
+ if (client_s) {
client_s->connected = true;
+ _bt_gatt_client_update_services(client_s);
+ }
if (event_index >= 0)
cb = bt_event_slot_container[event_index].callback;
if (cb)
int ret;
int i;
+ if (!client_s->connected) {
+ BT_INFO("Not connected");
+ return BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED;
+ }
+
+ if (client_s->services_discovered) {
+ BT_INFO("Already discovered");
+ return BT_ERROR_ALREADY_DONE;
+ }
+
_bt_convert_address_to_hex(&addr_hex, client_s->remote_address);
ret = bluetooth_gatt_get_primary_services(&addr_hex, &prim_svc);
return ret;
}
- g_slist_free_full(client_s->services, __bt_gatt_free_service);
+ if (client_s->services)
+ g_slist_free_full(client_s->services, __bt_gatt_free_service);
client_s->services = NULL;
if (prim_svc.count == 0) {
return BT_ERROR_NONE;
}
+ client_s->services_discovered = true;
for (i = 0; i < prim_svc.count; i++) {
- if (!_bt_gatt_client_add_service(client, prim_svc.handle[i]))
+ if (!_bt_gatt_client_add_service(client, prim_svc.handle[i])) {
BT_ERR("_bt_gatt_client_add_service is failed [%s]",
prim_svc.handle[i]);
+ client_s->services_discovered = false;
+ }
}
g_strfreev(prim_svc.handle);
return ret;
}
- *client = (bt_gatt_client_h)client_s;
- gatt_client_list = g_slist_append(gatt_client_list, client_s);
-
if (bt_device_is_profile_connected(remote_address, BT_PROFILE_GATT,
&connected) != BT_ERROR_NONE)
BT_ERR("bt_device_is_profile_connected is failed");
else
client_s->connected = connected;
- if (_bt_gatt_client_update_services(*client) == BT_ERROR_NONE)
- client_s->services_discovered = true;
+ ret = _bt_gatt_client_update_services(client_s);
+ if (ret != BT_ERROR_NONE) {
+ BT_INFO("_bt_gatt_client_update_services returns 0x%X. "
+ "It could be updated when service is available.", ret);
+ ret = BT_ERROR_NONE;
+ }
+
+ *client = (bt_gatt_client_h)client_s;
+ gatt_client_list = g_slist_append(gatt_client_list, client_s);
BT_INFO("GATT Client Handle is created");