From: brianjjones Date: Thu, 17 Apr 2014 20:57:21 +0000 (-0700) Subject: Pairing and selection issues patch X-Git-Tag: submit/tizen/20140417.223221^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;p=profile%2Fivi%2Fwrt-plugins-ivi-bt.git Pairing and selection issues patch Change-Id: Ia8fe57159437f508969bc8f0e244ce0426364b58 Signed-off-by: brianjjones --- diff --git a/packaging/wrt-plugins-tizen-bt.changes b/packaging/wrt-plugins-tizen-bt.changes index 6f5d700..bfc015a 100644 --- a/packaging/wrt-plugins-tizen-bt.changes +++ b/packaging/wrt-plugins-tizen-bt.changes @@ -1,3 +1,6 @@ +* Thu Apr 17 2014 brianjjones accepted/tizen/ivi/release/20140404.171137@00e4dd0 +- Pairing and selection issues patch + * Thu Mar 27 2014 brianjjones submit/tizen/20140321.171938@a09aa36 - Updated this component to use Bluez 5 API calls. This fixes TIVI-2936 - Initial commit for Bluetooth plugin for HTML5 UI diff --git a/src/BluetoothAdapter.cpp b/src/BluetoothAdapter.cpp index 72c4e45..35b14ae 100644 --- a/src/BluetoothAdapter.cpp +++ b/src/BluetoothAdapter.cpp @@ -441,11 +441,13 @@ void BluetoothAdapter::removeConnReq(std::string &remoteAddress) { mConnReqMap.erase(remoteAddress); + LoggerE("removeConnReq for address: %s", remoteAddress.c_str()); if(mRegisteredUUID.size() == 0 && mConnReqMap.size() == 0 && mConnectedSocket.size() == 0) { - if(bt_socket_unset_connection_state_changed_cb() != BT_ERROR_NONE) + int result=bt_socket_unset_connection_state_changed_cb(); + if(result != BT_ERROR_NONE) { - LoggerW("Unsetting connection event callback failed"); + LoggerW("Unsetting connection event callback failed with error: %d", result); } } } @@ -1048,7 +1050,7 @@ void BluetoothAdapter::createBonding(std::string &address, MultiCallbackUserData char* devicePath = NULL; - for (int i = 0; i < mFoundDevices.size(); i++) + for (size_t i = 0; i < mFoundDevices.size(); ++i) { if (mFoundDevices[i]->getAddress() == address) { @@ -1059,16 +1061,22 @@ void BluetoothAdapter::createBonding(std::string &address, MultiCallbackUserData } if (!devicePath) + { devicePath = getDeviceFromAddress(address); + if(!devicePath) + { + LoggerE("Device currently unavailable"); + NotFoundException *error = new NotFoundException("Device currently unavailable. Try again."); + BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error); + mCreateBondingAddress.clear(); + mUserDataList[CREATE_BONDING].reset(); + return; + } + } if(mEnabled == true) { // if(setupAgent(AGENT_PATH)) { - if (!devicePath) - { - LoggerE("devicePath was null, setting to empty string"); - devicePath = ""; - } if (devicePath != NULL) { @@ -1210,7 +1218,6 @@ void BluetoothAdapter::connectToServiceByUUID(std::string &remoteAddress, std::s void BluetoothAdapter::returnKnownDevices(Common::MultiCallbackUserDataPtr userData) { - char *result; bool done = false; GError * error = nullptr; @@ -1285,6 +1292,21 @@ void BluetoothAdapter::returnKnownDevices(Common::MultiCallbackUserDataPtr userD } g_variant_iter_free(iter); + if(knownDevices.size() > 0) + { + int num = knownDevices.size(); + JSObjectRef devices[num]; + for(int i = 0; i < num; ++i) + { + JSObjectRef deviceObj = JSBluetoothDevice::createJSObject(userData->getContext(), knownDevices[i]); + devices[i] = deviceObj; + } + + userData->invokeCallback("success", JSObjectMakeArray(userData->getContext(), num, devices, NULL)); + } + else + userData->invokeCallback("success", JSObjectMakeArray(userData->getContext(), 0, NULL, NULL) ); + } void BluetoothAdapter::returnDevice(std::string &address, Common::MultiCallbackUserDataPtr userData) @@ -1481,7 +1503,7 @@ bool BluetoothAdapter::isBtTechnologyPowered() gchar* BluetoothAdapter::getDefaultAdapter() const { - char *result; + char *result=nullptr; bool done = false; GError * error = nullptr; @@ -1611,7 +1633,6 @@ gchar* BluetoothAdapter::getDeviceFromAddress(std::string &address) const result = objPath?strdup(objPath):NULL; done = true; - LoggerD("getDeviceFromAddress found : " << result); } g_free(addr); @@ -1706,7 +1727,7 @@ void BluetoothAdapter::handleSignal(GDBusConnection *connection, while(g_variant_iter_next(iter, "{sa{sv}}",&interface, &iter2)) { - if(!strcmp(interface, "org.bluez.Adapter1")) + if(!strcmp(interface, BLUEZ_ADAPTER_IFACE)) { gchar * adapterPath = ctx->getDefaultAdapter(); free(ctx->mAdapterPath); @@ -1719,7 +1740,6 @@ void BluetoothAdapter::handleSignal(GDBusConnection *connection, ctx); } } - else if(!strcmp(interface, "org.bluez.Device1")) { bt_adapter_device_discovery_info_s discoveryInfo; @@ -1728,7 +1748,7 @@ void BluetoothAdapter::handleSignal(GDBusConnection *connection, discoveryInfo.service_uuid = NULL; discoveryInfo.service_count = 0; - const char *key; + char *key; GVariant *value; while(g_variant_iter_next(iter2, "{sv}", &key, &value)) @@ -1762,17 +1782,20 @@ void BluetoothAdapter::handleSignal(GDBusConnection *connection, else if(!strcmp(key, "UUIDs")) { - GVariantIter *iter; - const char *uuid = NULL; - g_variant_get(value, "as", &iter); - discoveryInfo.service_count = g_variant_iter_n_children(iter); + GVariantIter *iter3; + char *uuid = NULL; + g_variant_get(value, "as", &iter3); + discoveryInfo.service_count = g_variant_iter_n_children(iter3); discoveryInfo.service_uuid = (char**)malloc(discoveryInfo.service_count*sizeof(char*)); char **uuids = discoveryInfo.service_uuid; // make a copy of ptr, since we will modify the pointer - while(g_variant_iter_next(iter, "s", &uuid)) + while(g_variant_iter_next(iter3, "s", &uuid)) { *uuids++ = uuid?strdup(uuid):NULL; } + g_variant_iter_free(iter3); } + g_variant_unref(value); + g_free(key); } if(!discoveryInfo.remote_address) @@ -1787,7 +1810,7 @@ void BluetoothAdapter::handleSignal(GDBusConnection *connection, discoveryInfo.remote_name = strdup(""); } - LoggerD("Found BT device: " << discoveryInfo.remote_address << " ... " << (discoveryInfo.remote_name?discoveryInfo.remote_name:"")); + LoggerE("Found BT device: " << discoveryInfo.remote_address << " ... " << (discoveryInfo.remote_name?discoveryInfo.remote_name:"")); if(ctx->mUserDataList[DISCOVER_DEVICES] != NULL) { @@ -1822,122 +1845,155 @@ void BluetoothAdapter::handleSignal(GDBusConnection *connection, ctx->freeDiscoveryInfo(&discoveryInfo); } + g_free(interface); } + g_variant_iter_free(iter2); } + g_free(objPath); + g_variant_iter_free(iter); } - else if(!strcmp(signal_name, "AdapterRemoved")) + else if(!strcmp(signal_name, "InterfacesRemoved")) { - const char *adapter = NULL; - g_variant_get(parameters, "(o)", &adapter); - if(adapter) + char *obj_path = nullptr; + GVariantIter *iter; + g_variant_get(parameters, "(oas)", &obj_path, &iter); + + if(obj_path) { - LoggerD("Adapter removed: " << adapter); + char *iface = nullptr; + + while(g_variant_iter_next(iter, "s", &iface)) + { + if(!strcmp(iface, BLUEZ_DEVICE_IFACE)) + { + LoggerE("Interface removed: " << iface); + } + + g_free(iface); + } + g_variant_iter_free(iter); } + g_free(obj_path); } } - else if(!strcmp(interface_name, BLUEZ_ADAPTER_IFACE)) + else if(!strcmp(signal_name, "PropertiesChanged")) { - if(!strcmp(signal_name, "PropertyChanged")) + char *objPath = NULL; + GVariantIter *iter, *iter2; + + g_variant_get(parameters, "(sa{sv}as)", &objPath, &iter, &iter2); + + if(objPath) { - const char *name; - GVariant *var; - g_variant_get(parameters, "(sv)", &name, &var); - LoggerD("\tname=" << name); - if(!strcmp(name, "Name")) - { - const char *_name = g_variant_get_string(var, NULL); - ctx->onNameChanged(_name); - } - else if(!strcmp(name, "Powered")) - { - bool powered = g_variant_get_boolean(var); - ctx->onPoweredChanged(powered); - } - else if(!strcmp(name, "Discoverable")) - { - bool visible = g_variant_get_boolean(var); - ctx->onVisibilityChanged(visible); - } - else if(!strcmp(name, "Discovering")) + GVariant* var; + char *prop = NULL; + + while(g_variant_iter_next(iter, "{sv}", &prop, &var)) { - bool discovering = g_variant_get_boolean(var); - if(discovering) // discovery started + if(!strcmp(prop, "Name")) { - MultiCallbackUserDataPtr callback = static_cast(ctx->mUserDataList[DISCOVER_DEVICES]); - if(callback) - { - callback->invokeCallback("onstarted"); - } + const char *_name = g_variant_get_string(var, NULL); + ctx->onNameChanged(_name); + } + else if(!strcmp(prop, "Powered")) + { + bool powered = g_variant_get_boolean(var); + ctx->onPoweredChanged(powered); + } + else if(!strcmp(prop, "Discoverable")) + { + bool visible = g_variant_get_boolean(var); + ctx->onVisibilityChanged(visible); } - else // discovery completed + else if(!strcmp(prop, "Discovering")) { - LoggerD("Discovery completed"); - if(ctx->mUserDataList[DISCOVER_DEVICES] != NULL) + bool discovering = g_variant_get_boolean(var); + if(discovering) // discovery started { - MultiCallbackUserDataPtr callback = - static_cast(ctx->mUserDataList[DISCOVER_DEVICES]); - + MultiCallbackUserDataPtr callback = static_cast(ctx->mUserDataList[DISCOVER_DEVICES]); if(callback) { - if(ctx->mDisappearedDevices.size() > 0) + callback->invokeCallback("onstarted"); + } + } + else // discovery completed + { + LoggerE("Discovery completed"); + if(ctx->mUserDataList[DISCOVER_DEVICES] != NULL) + { + MultiCallbackUserDataPtr callback = + static_cast(ctx->mUserDataList[DISCOVER_DEVICES]); + + if(callback) { - LoggerD("There are disappeared devices"); - for(auto iter = ctx->mDisappearedDevices.begin(); - iter != ctx->mDisappearedDevices.end(); iter++) + if(ctx->mDisappearedDevices.size() > 0) { + LoggerD("There are disappeared devices"); + for(auto iter = ctx->mDisappearedDevices.begin(); + iter != ctx->mDisappearedDevices.end(); iter++) + { - callback->invokeCallback("ondevicedisappeared", - JSUtil::toJSValueRef(callback->getContext(), *iter)); + callback->invokeCallback("ondevicedisappeared", + JSUtil::toJSValueRef(callback->getContext(), *iter)); + } } - } - if(ctx->mFoundDevices.size() > 0) // There are found devices - { - LoggerD("There are found devices"); - int num = ctx->mFoundDevices.size(); - JSObjectRef devices[num]; - for(int i = 0; i < num; i++) + if(ctx->mFoundDevices.size() > 0) // There are found devices { - JSObjectRef deviceObj = JSBluetoothDevice::createJSObject(callback->getContext(), ctx->mFoundDevices[i]); - devices[i] = deviceObj; - } + LoggerD("There are found devices"); + int num = ctx->mFoundDevices.size(); + JSObjectRef devices[num]; + for(int i = 0; i < num; i++) + { + JSObjectRef deviceObj = JSBluetoothDevice::createJSObject(callback->getContext(), ctx->mFoundDevices[i]); + devices[i] = deviceObj; + } - ctx->mUserDataList[DISCOVER_DEVICES].reset(); + ctx->mUserDataList[DISCOVER_DEVICES].reset(); - callback->invokeCallback( - "onfinished", - JSObjectMakeArray(callback->getContext(), num, devices, NULL) ); - } - else // There is no found device - { - LoggerD("There is no found device"); - ctx->mUserDataList[DISCOVER_DEVICES].reset(); + callback->invokeCallback( + "onfinished", + JSObjectMakeArray(callback->getContext(), num, devices, NULL) ); + } + else // There is no found device + { + LoggerD("There is no found device"); + ctx->mUserDataList[DISCOVER_DEVICES].reset(); - callback->invokeCallback( - "onfinished", - JSObjectMakeArray(callback->getContext(), 0, NULL, NULL) ); + callback->invokeCallback( + "onfinished", + JSObjectMakeArray(callback->getContext(), 0, NULL, NULL) ); + } } - } - Utils::removeSignalListener(G_BUS_TYPE_SYSTEM, BLUEZ_SERVICE, BLUEZ_ADAPTER_IFACE, object_path, "DeviceFound"); - - GError *err = NULL; - g_dbus_connection_call_sync( g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL), - BLUEZ_SERVICE, - ctx->mAdapterPath, - BLUEZ_ADAPTER_IFACE, - "StopDiscovery", - NULL, - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &err); - if(err) - g_error_free(err); + GError *err = NULL; + g_dbus_connection_call_sync( g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL), + BLUEZ_SERVICE, + ctx->mAdapterPath, + BLUEZ_ADAPTER_IFACE, + "StopDiscovery", + NULL, + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &err); + if(err) + g_error_free(err); + } } } } + g_variant_iter_free(iter); + g_variant_iter_free(iter2); + } + g_free(objPath); + } + else if(!strcmp(interface_name, BLUEZ_ADAPTER_IFACE)) + { + if(!strcmp(signal_name, "PropertyChanged")) + { + LoggerE("PropertyChanged not working!!"); } } /* @@ -2251,6 +2307,7 @@ bool BluetoothAdapter::isDevicePaired(const char *device) if(err || !reply) { + LoggerE("isDevicePaired return an error: %s, device: %s", err->message, device); if(err) g_error_free(err); return false; @@ -2282,7 +2339,7 @@ bool BluetoothAdapter::getDeviceInfoByAddress(bt_device_info_s *deviceInfo, cons if(!mAdapterPath) return false; - std::string addressStr = std::string(address); + std::string addressStr(address); char* device = getDeviceFromAddress(addressStr); if(!device) @@ -2343,7 +2400,6 @@ bool BluetoothAdapter::getDeviceInfo(bt_device_info_s *deviceInfo, const char *d GVariant *value; while(g_variant_iter_next(iter, "{sv}", &key, &value)) { - //LoggerD("KEY: " << key); if(!strcmp(key, "Name")) { const char *name = g_variant_get_string(value, NULL); @@ -2431,14 +2487,13 @@ void BluetoothAdapter::freeDiscoveryInfo(bt_adapter_device_discovery_info_s *dis bool BluetoothAdapter::removeDevice(const char *address) { - if(!address) return false; if(!mAdapterPath) return false; - std::string addressStr = std::string(address); + std::string addressStr(address); char* device = getDeviceFromAddress(addressStr); if(!device) @@ -2472,7 +2527,20 @@ bool BluetoothAdapter::removeDevice(const char *address) } } - LoggerD("removed device : " << device); + for(auto iter=mFoundDevices.begin(); iter!=mFoundDevices.end();) + { + BluetoothDeviceSharedPtr foundDevice = *iter; + + if(!strcmp(foundDevice->getAddress().c_str(), address)) + { + iter=mFoundDevices.erase(iter); + mDisappearedDevices.push_back(address); + } + else + ++iter; + } + + LoggerE(" removed device : " << device); return success; } diff --git a/src/BluetoothDevice.cpp b/src/BluetoothDevice.cpp index 830c13f..7f978bd 100644 --- a/src/BluetoothDevice.cpp +++ b/src/BluetoothDevice.cpp @@ -99,7 +99,7 @@ JSValueRef BluetoothDevice::getDeviceClass(JSContextRef context) gchar* BluetoothDevice::getDefaultAdapter() const { - char *result; + char *result=nullptr; bool done = false; GError * error = nullptr;