summaryrefslogtreecommitdiff
path: root/src/components/connection_handler
diff options
context:
space:
mode:
authorAndrey Oleynik (GitHub) <aoleynik@luxoft.com>2017-11-29 18:33:59 +0200
committerAndriy Byzhynar <AByzhynar@luxoft.com>2018-01-18 12:03:51 +0200
commitee1d2d7677a7d94da43cc8b1e047bdd816e5fd83 (patch)
treee1b956cd3c472f792117735a20935587e75cfb79 /src/components/connection_handler
parent11bef60123b62bbe0f8f624bb24a5f0cf74980aa (diff)
downloadsdl_core-ee1d2d7677a7d94da43cc8b1e047bdd816e5fd83.tar.gz
Changes iAP2 Bluetooth to USB switching flow
These changes update switching flow so now instead of automatic switching start in case of same UUID is detected SDL will wait for external signal from the system to start this flow. Also due to UUID is reliable only while device remains connected (at least on certain systems) SDL now uses Bluetooth MAC and USB serial to manage devices and UUID is used only for detection of devices able to switch their transports. Currently only iAP2 Bluetooth to USB support is implemented.
Diffstat (limited to 'src/components/connection_handler')
-rw-r--r--src/components/connection_handler/include/connection_handler/connection_handler_impl.h7
-rw-r--r--src/components/connection_handler/src/connection_handler_impl.cc28
2 files changed, 30 insertions, 5 deletions
diff --git a/src/components/connection_handler/include/connection_handler/connection_handler_impl.h b/src/components/connection_handler/include/connection_handler/connection_handler_impl.h
index 4c0c7b2985..a4d228f0fe 100644
--- a/src/components/connection_handler/include/connection_handler/connection_handler_impl.h
+++ b/src/components/connection_handler/include/connection_handler/connection_handler_impl.h
@@ -140,9 +140,12 @@ class ConnectionHandlerImpl
/**
* @brief OnDeviceSwitchingStart notifies listeners on device transport
* switching start
- * @param device_uid the id of the device which has to be switched.
+ * @param device_uid_from the id of the device which has to switch its
+ * transport
+ * @param device_uid_to the id of the device on new transport
*/
- void OnDeviceSwitchingStart(const std::string& device_uid) FINAL;
+ void OnDeviceSwitchingStart(const std::string& device_uid_from,
+ const std::string& device_uid_to) FINAL;
/**
* @brief OnDeviceSwitchingFinish notifies listeners on device transport
diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc
index 67a54678cc..9f68d5ce31 100644
--- a/src/components/connection_handler/src/connection_handler_impl.cc
+++ b/src/components/connection_handler/src/connection_handler_impl.cc
@@ -198,12 +198,34 @@ void ConnectionHandlerImpl::OnDeviceSwitchingFinish(
}
}
+namespace {
+struct DeviceFinder {
+ explicit DeviceFinder(const std::string& device_uid)
+ : device_uid_(device_uid) {}
+ bool operator()(const DeviceMap::value_type& device) {
+ return device_uid_ == device.second.mac_address();
+ }
+private:
+ const std::string& device_uid_;
+};
+} // namespace
+
void ConnectionHandlerImpl::OnDeviceSwitchingStart(
- const std::string& device_uid) {
+ const std::string& device_uid_from, const std::string& device_uid_to) {
+ auto device_from = std::find_if(
+ device_list_.begin(), device_list_.end(),
+ DeviceFinder(encryption::MakeHash(device_uid_from)));
+
+ auto device_to = std::find_if(
+ device_list_.begin(), device_list_.end(),
+ DeviceFinder(encryption::MakeHash(device_uid_to)));
+
+ DCHECK_OR_RETURN_VOID(device_list_.end() != device_from);
+ DCHECK_OR_RETURN_VOID(device_list_.end() != device_to);
sync_primitives::AutoReadLock read_lock(connection_handler_observer_lock_);
if (connection_handler_observer_) {
- connection_handler_observer_->OnDeviceSwitchingStart(
- encryption::MakeHash(device_uid));
+ connection_handler_observer_->OnDeviceSwitchingStart(device_from->second,
+ device_to->second);
}
}