diff options
Diffstat (limited to 'src/components')
39 files changed, 335 insertions, 237 deletions
diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index a612c263ca..8ee5ff64f6 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -419,26 +419,25 @@ class PolicyHandler : public PolicyHandlerInterface, * @brief Get cloud app policy information, all fields that aren't set for a * given app will be filled with empty strings * @param policy_app_id Unique application id + * @param enabled Whether or not the app is enabled * @param endpoint Filled with the endpoint used to connect to the cloud * application * @param certificate Filled with the certificate used to for creating a - * secure - * connection to the cloud application + * secure connection to the cloud application * @param auth_token Filled with the token used for authentication when * reconnecting to the cloud app * @param cloud_transport_type Filled with the transport type used by the * cloud application (ex. "WSS") - * @param cloud_transport_type Filled with the hybrid app preference for the + * @param hybrid_app_preference Filled with the hybrid app preference for the * cloud application set by the user - * @return true if the cloud app is enabled, false otherwise */ - const bool GetCloudAppParameters( - const std::string& policy_app_id, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const OVERRIDE; + void GetCloudAppParameters(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const OVERRIDE; /** * @brief Callback for when a SetCloudAppProperties message is received from a diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_request.cc index ca5a46e3dc..0beb7631c7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_request.cc @@ -18,6 +18,7 @@ SetCloudAppPropertiesRequest::SetCloudAppPropertiesRequest( policy_handler) {} SetCloudAppPropertiesRequest::~SetCloudAppPropertiesRequest() {} + void SetCloudAppPropertiesRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); ApplicationSharedPtr app = application_manager_.application(connection_key()); @@ -69,6 +70,7 @@ void SetCloudAppPropertiesRequest::Run() { } policy_handler_.OnSetCloudAppProperties(cloud_app_properties); + SendResponse(true, mobile_apis::Result::SUCCESS); } diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 80b25dc814..02bf5b49fe 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -964,7 +964,7 @@ void ApplicationImpl::CleanupFiles() { application_manager_.get_settings().app_storage_folder(); directory_name += "/" + folder_name(); - if (file_system::DirectoryExists(directory_name)) { + if (file_system::DirectoryExists(directory_name) && !folder_name().empty()) { std::vector<std::string> files = file_system::ListFiles(directory_name); AppFilesMap::const_iterator app_files_it; diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 1c8be1deab..edbeaf888e 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -807,6 +807,7 @@ void ApplicationManagerImpl::OnHMIStartedCooperation() { } void ApplicationManagerImpl::CollectCloudAppInformation() { + LOG4CXX_AUTO_TRACE(logger_); std::vector<std::string> cloud_app_id_vector; GetPolicyHandler().GetEnabledCloudApps(cloud_app_id_vector); std::vector<std::string>::iterator it = cloud_app_id_vector.begin(); @@ -816,8 +817,10 @@ void ApplicationManagerImpl::CollectCloudAppInformation() { std::string auth_token = ""; std::string cloud_transport_type = ""; std::string hybrid_app_preference = ""; + bool enabled = true; for (; it != end; ++it) { GetPolicyHandler().GetCloudAppParameters(*it, + enabled, endpoint, certificate, auth_token, @@ -842,7 +845,7 @@ void ApplicationManagerImpl::CreatePendingApplication( std::string auth_token = ""; std::string cloud_transport_type = ""; std::string hybrid_app_preference_str = ""; - + bool enabled = true; std::string name = device_info.name(); auto it = pending_device_map_.find(name); if (it == pending_device_map_.end()) { @@ -878,7 +881,14 @@ void ApplicationManagerImpl::CreatePendingApplication( return; } + const std::string app_icon_dir(settings_.app_icons_folder()); + const std::string full_icon_path(app_icon_dir + "/" + policy_app_id); + if (file_system::FileExists(full_icon_path)) { + application->set_app_icon_path(full_icon_path); + } + GetPolicyHandler().GetCloudAppParameters(policy_app_id, + enabled, endpoint, certificate, auth_token, @@ -3546,6 +3556,7 @@ void ApplicationManagerImpl::OnPTUFinished(const bool ptu_result) { if (!ptu_result) { return; } + CollectCloudAppInformation(); auto on_app_policy_updated = [](plugin_manager::RPCPlugin& plugin) { plugin.OnPolicyEvent(plugin_manager::kApplicationPolicyUpdated); }; diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 8c6de5482c..c603659353 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1852,36 +1852,41 @@ void PolicyHandler::GetEnabledCloudApps( policy_manager_->GetEnabledCloudApps(enabled_apps); } -const bool PolicyHandler::GetCloudAppParameters( +void PolicyHandler::GetCloudAppParameters( const std::string& policy_app_id, + bool& enabled, std::string& endpoint, std::string& certificate, std::string& auth_token, std::string& cloud_transport_type, std::string& hybrid_app_preference) const { - POLICY_LIB_CHECK(false); - return policy_manager_->GetCloudAppParameters(policy_app_id, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference); + POLICY_LIB_CHECK_VOID(); + policy_manager_->GetCloudAppParameters(policy_app_id, + enabled, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); } const bool PolicyHandler::CheckCloudAppEnabled( const std::string& policy_app_id) const { POLICY_LIB_CHECK(false); + bool enabled = false; std::string endpoint; std::string auth_token; std::string certificate; std::string cloud_transport_type; std::string hybrid_app_preference; - return policy_manager_->GetCloudAppParameters(policy_app_id, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference); + policy_manager_->GetCloudAppParameters(policy_app_id, + enabled, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); + return enabled; } void PolicyHandler::OnSetCloudAppProperties( @@ -1901,6 +1906,9 @@ void PolicyHandler::OnSetCloudAppProperties( return; } std::string policy_app_id(msg_params[strings::app_id].asString()); + + policy_manager_->InitCloudApp(policy_app_id); + if (msg_params.keyExists(strings::enabled)) { policy_manager_->SetCloudAppEnabled(policy_app_id, msg_params[strings::enabled].asBool()); diff --git a/src/components/application_manager/src/state_controller_impl.cc b/src/components/application_manager/src/state_controller_impl.cc index 3d44709657..5e912ca3be 100644 --- a/src/components/application_manager/src/state_controller_impl.cc +++ b/src/components/application_manager/src/state_controller_impl.cc @@ -475,7 +475,9 @@ mobile_apis::HMILevel::eType StateControllerImpl::GetAvailableHmiLevel( return result; } - const bool is_active_app_exist = (bool)app_mngr_.active_application(); + ApplicationConstSharedPtr active_app = app_mngr_.active_application(); + const bool is_active_app_exist = + (active_app.use_count() != 0) && active_app->app_id() != app->app_id(); if (is_audio_app) { if (does_audio_app_with_same_type_exist) { result = app_mngr_.GetDefaultHmiLevel(app); diff --git a/src/components/config_profile/src/profile.cc b/src/components/config_profile/src/profile.cc index c10f81a869..38afdbf35b 100644 --- a/src/components/config_profile/src/profile.cc +++ b/src/components/config_profile/src/profile.cc @@ -81,7 +81,7 @@ const char* kMediaManagerSection = "MEDIA MANAGER"; const char* kGlobalPropertiesSection = "GLOBAL PROPERTIES"; const char* kVrCommandsSection = "VR COMMANDS"; const char* kTransportManagerSection = "TransportManager"; -const char* kCloudAppTransportSection = "Cloud App Connections"; +const char* kCloudAppTransportSection = "CloudAppConnections"; const char* kApplicationManagerSection = "ApplicationManager"; const char* kFilesystemRestrictionsSection = "FILESYSTEM RESTRICTIONS"; const char* kIAPSection = "IAP"; diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index 0d6aabcae4..fdfdb6b48f 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -270,7 +270,6 @@ void ConnectionHandlerImpl::OnConnectionPending( LOG4CXX_DEBUG(logger_, "Add Pending Connection #" << connection_id << " to the list."); - // todo maybe create a seperate "pending_connection_list" sync_primitives::AutoWriteLock lock(connection_list_lock_); if (connection_list_.find(connection_id) == connection_list_.end()) { Connection* connection = diff --git a/src/components/include/application_manager/policies/policy_handler_interface.h b/src/components/include/application_manager/policies/policy_handler_interface.h index ddeb1da8f7..8c8a12ced3 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -459,7 +459,8 @@ class PolicyHandlerInterface { * @brief Get cloud app policy information, all fields that aren't set for a * given app will be filled with empty strings * @param policy_app_id Unique application id - * @param endpoint Filled the endpoint used to connect to the cloud + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud * application * @param certificate Filled with the certificate used to for creating a * secure connection to the cloud application @@ -467,12 +468,12 @@ class PolicyHandlerInterface { * reconnecting to the cloud app * @param cloud_transport_type Filled with the transport type used by the * cloud application (ex. "WSS") - * @param cloud_transport_type Filled with the hybrid app preference for the + * @param hybrid_app_preference Filled with the hybrid app preference for the * cloud application set by the user - * @return true if the cloud app is enabled, false otherwise */ - virtual const bool GetCloudAppParameters( + virtual void GetCloudAppParameters( const std::string& policy_app_id, + bool& enabled, std::string& endpoint, std::string& certificate, std::string& auth_token, diff --git a/src/components/include/policy/policy_external/policy/policy_manager.h b/src/components/include/policy/policy_external/policy/policy_manager.h index b0fac8eae9..92c0305279 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -534,7 +534,8 @@ class PolicyManager : public usage_statistics::StatisticsManager { * @brief Get cloud app policy information, all fields that aren't set for a * given app will be filled with empty strings * @param policy_app_id Unique application id - * @param endpoint Filled the endpoint used to connect to the cloud + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud * application * @param certificate Filled with the certificate used to for creating a * secure connection to the cloud application @@ -542,12 +543,12 @@ class PolicyManager : public usage_statistics::StatisticsManager { * reconnecting to the cloud app * @param cloud_transport_type Filled with the transport type used by the * cloud application (ex. "WSS") - * @param cloud_transport_type Filled with the hybrid app preference for the + * @param hybrid_app_preference Filled with the hybrid app preference for the * cloud application set by the user - * @return true if the cloud app is enabled, false otherwise */ - virtual const bool GetCloudAppParameters( + virtual void GetCloudAppParameters( const std::string& policy_app_id, + bool& enabled, std::string& endpoint, std::string& certificate, std::string& auth_token, @@ -555,6 +556,12 @@ class PolicyManager : public usage_statistics::StatisticsManager { std::string& hybrid_app_preference) const = 0; /** + * @ brief Initialize new cloud app in the policy table + * @ param policy_app_id Application ID + */ + virtual void InitCloudApp(const std::string& policy_app_id) = 0; + + /** * @brief Enable or disable a cloud application in the HMI * @param enabled Cloud app enabled state */ diff --git a/src/components/include/policy/policy_regular/policy/policy_manager.h b/src/components/include/policy/policy_regular/policy/policy_manager.h index 1f0f520077..b2d48585f4 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -514,7 +514,8 @@ class PolicyManager : public usage_statistics::StatisticsManager { * @brief Get cloud app policy information, all fields that aren't set for a * given app will be filled with empty strings * @param policy_app_id Unique application id - * @param endpoint Filled the endpoint used to connect to the cloud + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud * application * @param certificate Filled with the certificate used to for creating a * secure connection to the cloud application @@ -522,12 +523,12 @@ class PolicyManager : public usage_statistics::StatisticsManager { * reconnecting to the cloud app * @param cloud_transport_type Filled with the transport type used by the * cloud application (ex. "WSS") - * @param cloud_transport_type Filled with the hybrid app preference for the + * @param hybrid_app_preference Filled with the hybrid app preference for the * cloud application set by the user - * @return true if the cloud app is enabled, false otherwise */ - virtual const bool GetCloudAppParameters( + virtual void GetCloudAppParameters( const std::string& policy_app_id, + bool& enabled, std::string& endpoint, std::string& certificate, std::string& auth_token, @@ -535,6 +536,13 @@ class PolicyManager : public usage_statistics::StatisticsManager { std::string& hybrid_app_preference) const = 0; /** + * @ brief Initialize new cloud app in the policy table + * @ param policy_app_id Application ID + */ + + virtual void InitCloudApp(const std::string& policy_app_id) = 0; + + /** * @brief Enable or disable a cloud application in the HMI * @param enabled Cloud app enabled state */ diff --git a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h index cea36082c8..02a0d73086 100644 --- a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h +++ b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h @@ -217,13 +217,14 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { void(std::vector<std::string>& enabled_apps)); MOCK_CONST_METHOD1(CheckCloudAppEnabled, const bool(const std::string& policy_app_id)); - MOCK_CONST_METHOD6(GetCloudAppParameters, - const bool(const std::string& policy_app_id, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference)); + MOCK_CONST_METHOD7(GetCloudAppParameters, + void(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); MOCK_METHOD1(OnSetCloudAppProperties, void(const smart_objects::SmartObject& message)); diff --git a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h index 03e0882129..da2b4cc2a1 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h @@ -78,13 +78,15 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_CONST_METHOD0(GetVehicleInfo, const VehicleInfo()); MOCK_CONST_METHOD1(GetEnabledCloudApps, void(std::vector<std::string>& enabled_apps)); - MOCK_CONST_METHOD6(GetCloudAppParameters, - const bool(const std::string& policy_app_id, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference)); + MOCK_CONST_METHOD7(GetCloudAppParameters, + void(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD1(InitCloudApp, void(const std::string& policy_app_id)); MOCK_METHOD2(SetCloudAppEnabled, void(const std::string& policy_app_id, const bool enabled)); MOCK_METHOD2(SetAppAuthToken, diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h index 70dab8e99a..72dcb147e3 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h @@ -186,13 +186,15 @@ class MockPolicyManager : public PolicyManager { MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); MOCK_CONST_METHOD1(GetEnabledCloudApps, void(std::vector<std::string>& enabled_apps)); - MOCK_CONST_METHOD6(GetCloudAppParameters, - const bool(const std::string& policy_app_id, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference)); + MOCK_CONST_METHOD7(GetCloudAppParameters, + void(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD1(InitCloudApp, void(const std::string& policy_app_id)); MOCK_METHOD2(SetCloudAppEnabled, void(const std::string& policy_app_id, const bool enabled)); MOCK_METHOD2(SetAppAuthToken, diff --git a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h index 7ac94d278d..24fe9b2393 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h @@ -65,13 +65,15 @@ class MockCacheManagerInterface : public CacheManagerInterface { MOCK_CONST_METHOD0(GetVehicleInfo, const VehicleInfo()); MOCK_CONST_METHOD1(GetEnabledCloudApps, void(std::vector<std::string>& enabled_apps)); - MOCK_CONST_METHOD6(GetCloudAppParameters, - const bool(const std::string& policy_app_id, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference)); + MOCK_CONST_METHOD7(GetCloudAppParameters, + void(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD1(InitCloudApp, void(const std::string& policy_app_id)); MOCK_METHOD2(SetCloudAppEnabled, void(const std::string& policy_app_id, const bool enabled)); MOCK_METHOD2(SetAppAuthToken, diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h index 7441701a34..a5ce488e1a 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h @@ -183,13 +183,15 @@ class MockPolicyManager : public PolicyManager { MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); MOCK_CONST_METHOD1(GetEnabledCloudApps, void(std::vector<std::string>& enabled_apps)); - MOCK_CONST_METHOD6(GetCloudAppParameters, - const bool(const std::string& policy_app_id, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference)); + MOCK_CONST_METHOD7(GetCloudAppParameters, + void(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD1(InitCloudApp, void(const std::string& policy_app_id)); MOCK_METHOD2(SetCloudAppEnabled, void(const std::string& policy_app_id, const bool enabled)); MOCK_METHOD2(SetAppAuthToken, diff --git a/src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h b/src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h index c993f245b9..3864c3f6f9 100644 --- a/src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h +++ b/src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h @@ -35,6 +35,7 @@ #include "gmock/gmock.h" #include "transport_manager/transport_adapter/transport_adapter.h" +#include "transport_manager/transport_adapter/device.h" namespace test { namespace components { @@ -69,7 +70,6 @@ class MockTransportAdapter MOCK_CONST_METHOD1(GetConnectionStatus, ::transport_manager::ConnectionStatus( const ::transport_manager::DeviceUID& device_handle)); - MOCK_METHOD0(ConnectionStatusUpdated, void()); MOCK_METHOD2(RunAppOnDevice, void(const std::string&, const std::string&)); MOCK_CONST_METHOD0(IsClientOriginatedConnectSupported, bool()); MOCK_METHOD0( diff --git a/src/components/include/transport_manager/transport_adapter/transport_adapter.h b/src/components/include/transport_manager/transport_adapter/transport_adapter.h index 303f677720..2b3efd3624 100644 --- a/src/components/include/transport_manager/transport_adapter/transport_adapter.h +++ b/src/components/include/transport_manager/transport_adapter/transport_adapter.h @@ -71,21 +71,6 @@ enum DeviceType { UNKNOWN }; -enum HybridAppPreference { // todo find correct place for this enum defintion. - MOBILE, - CLOUD, - BOTH -}; - -struct CloudAppProperties { - std::string endpoint; - std::string certificate; - bool enabled; - std::string auth_token; - DeviceType cloud_transport_type; - HybridAppPreference hybrid_app_preference; -}; - typedef std::map<DeviceType, std::string> DeviceTypes; /** @@ -105,12 +90,6 @@ typedef std::list<TransportAdapterListener*> TransportAdapterListenerList; typedef std::map<std::string, std::string> TransportConfig; /** - * @brief Type definition of container indexed by app id that contains - * connection information for all cloud apps. - */ -typedef std::map<std::string, CloudAppProperties> CloudAppTransportConfig; - -/** * @brief TransportConfig keys */ extern const char* tc_enabled; @@ -227,8 +206,6 @@ class TransportAdapter { virtual ConnectionStatus GetConnectionStatus( const DeviceUID& device_handle) const = 0; - virtual void ConnectionStatusUpdated() = 0; - /** * @brief RunAppOnDevice allows to run specific application on the certain *device. diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index 1707f65bad..714399bce6 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -547,9 +547,9 @@ <enum name="HybridAppPreference" since="5.1"> <description>Enumeration for the user's preference of which app type to use when both are available</description> - <element name = "MOBILE" /> - <element name = "CLOUD" /> - <element name = "BOTH" /> + <element name="MOBILE" /> + <element name="CLOUD" /> + <element name="BOTH" /> </enum> <enum name="ButtonName" since="1.0"> diff --git a/src/components/policy/policy_external/include/policy/cache_manager.h b/src/components/policy/policy_external/include/policy/cache_manager.h index 7660eb2df9..3344b149e4 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -170,7 +170,8 @@ class CacheManager : public CacheManagerInterface { * @brief Get cloud app policy information, all fields that aren't set for a * given app will be filled with empty strings * @param policy_app_id Unique application id - * @param endpoint Filled the endpoint used to connect to the cloud + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud * application * @param certificate Filled with the certificate used to for creating a * secure connection to the cloud application @@ -178,17 +179,24 @@ class CacheManager : public CacheManagerInterface { * reconnecting to the cloud app * @param cloud_transport_type Filled with the transport type used by the * cloud application (ex. "WSS") - * @param cloud_transport_type Filled with the hybrid app preference for the + * @param hybrid_app_preference Filled with the hybrid app preference for the * cloud application set by the user - * @return true if the cloud app is enabled, false otherwise */ - virtual const bool GetCloudAppParameters( - const std::string& policy_app_id, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const; + virtual void GetCloudAppParameters(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const; + + /** + * Initializes a new cloud application with default policies + * Then adds cloud specific policies + * @param app_id application id + * @return true if success + */ + virtual void InitCloudApp(const std::string& policy_app_id); /** * @brief Enable or disable a cloud application in the HMI diff --git a/src/components/policy/policy_external/include/policy/cache_manager_interface.h b/src/components/policy/policy_external/include/policy/cache_manager_interface.h index 79d6f4e731..6a172e6f4b 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_external/include/policy/cache_manager_interface.h @@ -177,7 +177,8 @@ class CacheManagerInterface { * @brief Get cloud app policy information, all fields that aren't set for a * given app will be filled with empty strings * @param policy_app_id Unique application id - * @param endpoint Filled the endpoint used to connect to the cloud + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud * application * @param certificate Filled with the certificate used to for creating a * secure connection to the cloud application @@ -185,12 +186,12 @@ class CacheManagerInterface { * reconnecting to the cloud app * @param cloud_transport_type Filled with the transport type used by the * cloud application (ex. "WSS") - * @param cloud_transport_type Filled with the hybrid app preference for the + * @param hybrid_app_preference Filled with the hybrid app preference for the * cloud application set by the user - * @return true if the cloud app is enabled, false otherwise */ - virtual const bool GetCloudAppParameters( + virtual void GetCloudAppParameters( const std::string& policy_app_id, + bool& enabled, std::string& endpoint, std::string& certificate, std::string& auth_token, @@ -198,6 +199,14 @@ class CacheManagerInterface { std::string& hybrid_app_preference) const = 0; /** + * Initializes a new cloud application with default policies + * Then adds cloud specific policies + * @param app_id application id + * @return true if success + */ + virtual void InitCloudApp(const std::string& policy_app_id) = 0; + + /** * @brief Enable or disable a cloud application in the HMI * @param enabled Cloud app enabled state */ diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h index 778892df13..399c95170d 100644 --- a/src/components/policy/policy_external/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h @@ -582,7 +582,8 @@ class PolicyManagerImpl : public PolicyManager { * @brief Get cloud app policy information, all fields that aren't set for a * given app will be filled with empty strings * @param policy_app_id Unique application id - * @param endpoint Filled the endpoint used to connect to the cloud + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud * application * @param certificate Filled with the certificate used to for creating a * secure connection to the cloud application @@ -590,17 +591,22 @@ class PolicyManagerImpl : public PolicyManager { * reconnecting to the cloud app * @param cloud_transport_type Filled with the transport type used by the * cloud application (ex. "WSS") - * @param cloud_transport_type Filled with the hybrid app preference for the + * @param hybrid_app_preference Filled with the hybrid app preference for the * cloud application set by the user - * @return true if the cloud app is enabled, false otherwise */ - const bool GetCloudAppParameters( - const std::string& policy_app_id, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const OVERRIDE; + void GetCloudAppParameters(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const OVERRIDE; + + /** + * @ brief Initialize new cloud app in the policy table + * @ param policy_app_id Application ID + */ + void InitCloudApp(const std::string& policy_app_id) OVERRIDE; /** * @brief Enable or disable a cloud application in the HMI diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index 116b315755..8cec6ef91c 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -1403,8 +1403,9 @@ void CacheManager::GetEnabledCloudApps( } } -const bool CacheManager::GetCloudAppParameters( +void CacheManager::GetCloudAppParameters( const std::string& policy_app_id, + bool& enabled, std::string& endpoint, std::string& certificate, std::string& auth_token, @@ -1418,21 +1419,39 @@ const bool CacheManager::GetCloudAppParameters( auto app_policy = (*policy_iter).second; endpoint = app_policy.endpoint.is_initialized() ? *app_policy.endpoint : std::string(); - certificate = app_policy.certificate.is_initialized() - ? *app_policy.certificate - : std::string(); auth_token = app_policy.auth_token.is_initialized() ? *app_policy.auth_token : std::string(); cloud_transport_type = app_policy.cloud_transport_type.is_initialized() ? *app_policy.cloud_transport_type : std::string(); + certificate = app_policy.certificate.is_initialized() + ? *app_policy.certificate + : std::string(); hybrid_app_preference = app_policy.hybrid_app_preference.is_initialized() ? EnumToJsonString(*app_policy.hybrid_app_preference) : std::string(); - return app_policy.enabled.is_initialized() && *app_policy.enabled; + enabled = app_policy.enabled.is_initialized() && *app_policy.enabled; } - return false; +} + +void CacheManager::InitCloudApp(const std::string& policy_app_id) { + CACHE_MANAGER_CHECK_VOID(); + sync_primitives::AutoLock auto_lock(cache_lock_); + + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::const_iterator default_iter = + policies.find(kDefaultId); + policy_table::ApplicationPolicies::const_iterator app_iter = + policies.find(policy_app_id); + if (default_iter != policies.end()) { + if (app_iter == policies.end()) { + policies[policy_app_id] = policies[kDefaultId]; + } + } + // Add cloud app specific policies + Backup(); } void CacheManager::SetCloudAppEnabled(const std::string& policy_app_id, diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index 31cc212254..0844edd8eb 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -730,19 +730,25 @@ void PolicyManagerImpl::GetEnabledCloudApps( cache_->GetEnabledCloudApps(enabled_apps); } -const bool PolicyManagerImpl::GetCloudAppParameters( +void PolicyManagerImpl::GetCloudAppParameters( const std::string& policy_app_id, + bool& enabled, std::string& endpoint, std::string& certificate, std::string& auth_token, std::string& cloud_transport_type, std::string& hybrid_app_preference) const { - return cache_->GetCloudAppParameters(policy_app_id, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference); + cache_->GetCloudAppParameters(policy_app_id, + enabled, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); +} + +void PolicyManagerImpl::InitCloudApp(const std::string& policy_app_id) { + cache_->InitCloudApp(policy_app_id); } void PolicyManagerImpl::SetCloudAppEnabled(const std::string& policy_app_id, diff --git a/src/components/policy/policy_regular/include/policy/cache_manager.h b/src/components/policy/policy_regular/include/policy/cache_manager.h index 39f9cc73cd..8c8f0c55c6 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -158,7 +158,8 @@ class CacheManager : public CacheManagerInterface { * @brief Get cloud app policy information, all fields that aren't set for a * given app will be filled with empty strings * @param policy_app_id Unique application id - * @param endpoint Filled the endpoint used to connect to the cloud + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud * application * @param certificate Filled with the certificate used to for creating a * secure connection to the cloud application @@ -166,17 +167,24 @@ class CacheManager : public CacheManagerInterface { * reconnecting to the cloud app * @param cloud_transport_type Filled with the transport type used by the * cloud application (ex. "WSS") - * @param cloud_transport_type Filled with the hybrid app preference for the + * @param hybrid_app_preference Filled with the hybrid app preference for the * cloud application set by the user - * @return true if the cloud app is enabled, false otherwise */ - virtual const bool GetCloudAppParameters( - const std::string& policy_app_id, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const; + virtual void GetCloudAppParameters(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const; + + /** + * Initializes a new cloud application with default policies + * Then adds cloud specific policies + * @param app_id application id + * @return true if success + */ + virtual void InitCloudApp(const std::string& policy_app_id); /** * @brief Enable or disable a cloud application in the HMI diff --git a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h index 3b2b10d0bc..50b546ecc5 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h @@ -163,7 +163,8 @@ class CacheManagerInterface { * @brief Get cloud app policy information, all fields that aren't set for a * given app will be filled with empty strings * @param policy_app_id Unique application id - * @param endpoint Filled the endpoint used to connect to the cloud + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud * application * @param certificate Filled with the certificate used to for creating a * secure connection to the cloud application @@ -171,12 +172,12 @@ class CacheManagerInterface { * reconnecting to the cloud app * @param cloud_transport_type Filled with the transport type used by the * cloud application (ex. "WSS") - * @param cloud_transport_type Filled with the hybrid app preference for the + * @param hybrid_app_preference Filled with the hybrid app preference for the * cloud application set by the user - * @return true if the cloud app is enabled, false otherwise */ - virtual const bool GetCloudAppParameters( + virtual void GetCloudAppParameters( const std::string& policy_app_id, + bool& enabled, std::string& endpoint, std::string& certificate, std::string& auth_token, @@ -184,6 +185,14 @@ class CacheManagerInterface { std::string& hybrid_app_preference) const = 0; /** + * Initializes a new cloud application with default policies + * Then adds cloud specific policies + * @param app_id application id + * @return true if success + */ + virtual void InitCloudApp(const std::string& policy_app_id) = 0; + + /** * @brief Enable or disable a cloud application in the HMI * @param enabled Cloud app enabled state */ diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h index 311ced31d2..20a37717a7 100644 --- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h @@ -576,7 +576,8 @@ class PolicyManagerImpl : public PolicyManager { * @brief Get cloud app policy information, all fields that aren't set for a * given app will be filled with empty strings * @param policy_app_id Unique application id - * @param endpoint Filled the endpoint used to connect to the cloud + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud * application * @param certificate Filled with the certificate used to for creating a * secure connection to the cloud application @@ -584,17 +585,23 @@ class PolicyManagerImpl : public PolicyManager { * reconnecting to the cloud app * @param cloud_transport_type Filled with the transport type used by the * cloud application (ex. "WSS") - * @param cloud_transport_type Filled with the hybrid app preference for the + * @param hybrid_app_preference Filled with the hybrid app preference for the * cloud application set by the user - * @return true if the cloud app is enabled, false otherwise */ - const bool GetCloudAppParameters( - const std::string& policy_app_id, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const OVERRIDE; + void GetCloudAppParameters(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const OVERRIDE; + + /** + * @ brief Initialize new cloud app in the policy table + * @ param policy_app_id Application ID + */ + + void InitCloudApp(const std::string& policy_app_id) OVERRIDE; /** * @brief Enable or disable a cloud application in the HMI diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 9292c389b9..ca61a338f1 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -696,8 +696,9 @@ void CacheManager::GetEnabledCloudApps( } } -const bool CacheManager::GetCloudAppParameters( +void CacheManager::GetCloudAppParameters( const std::string& policy_app_id, + bool& enabled, std::string& endpoint, std::string& certificate, std::string& auth_token, @@ -723,9 +724,29 @@ const bool CacheManager::GetCloudAppParameters( app_policy.hybrid_app_preference.is_initialized() ? EnumToJsonString(*app_policy.hybrid_app_preference) : std::string(); - return app_policy.enabled.is_initialized() && *app_policy.enabled; + enabled = app_policy.enabled.is_initialized() && *app_policy.enabled; } - return false; +} + +void CacheManager::InitCloudApp(const std::string& policy_app_id) { + CACHE_MANAGER_CHECK_VOID(); + sync_primitives::AutoLock auto_lock(cache_lock_); + + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::const_iterator default_iter = + policies.find(kDefaultId); + policy_table::ApplicationPolicies::const_iterator app_iter = + policies.find(policy_app_id); + + if (default_iter != policies.end()) { + if (app_iter == policies.end()) { + policies[policy_app_id] = policies[kDefaultId]; + } + } + // Add cloud app specific policies + + Backup(); } void CacheManager::SetCloudAppEnabled(const std::string& policy_app_id, diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc index 5aa29fc896..9b2392a015 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -549,19 +549,25 @@ void PolicyManagerImpl::GetEnabledCloudApps( cache_->GetEnabledCloudApps(enabled_apps); } -const bool PolicyManagerImpl::GetCloudAppParameters( +void PolicyManagerImpl::GetCloudAppParameters( const std::string& policy_app_id, + bool& enabled, std::string& endpoint, std::string& certificate, std::string& auth_token, std::string& cloud_transport_type, std::string& hybrid_app_preference) const { - return cache_->GetCloudAppParameters(policy_app_id, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference); + cache_->GetCloudAppParameters(policy_app_id, + enabled, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); +} + +void PolicyManagerImpl::InitCloudApp(const std::string& policy_app_id) { + cache_->InitCloudApp(policy_app_id); } void PolicyManagerImpl::SetCloudAppEnabled(const std::string& policy_app_id, diff --git a/src/components/transport_manager/include/transport_manager/cloud/cloud_device.h b/src/components/transport_manager/include/transport_manager/cloud/cloud_device.h index 8eac8c6f75..47a82e7921 100644 --- a/src/components/transport_manager/include/transport_manager/cloud/cloud_device.h +++ b/src/components/transport_manager/include/transport_manager/cloud/cloud_device.h @@ -47,9 +47,9 @@ class CloudDevice : public Device { public: CloudDevice(std::string& host, std::string& port, std::string& name); - virtual const std::string& GetHost(); + virtual const std::string& GetHost() const; - virtual const std::string& GetPort(); + virtual const std::string& GetPort() const; protected: virtual bool IsSameAs(const Device* other_device) const; diff --git a/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_transport_adapter.h b/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_transport_adapter.h index 546ab71fbd..d52e4b307d 100644 --- a/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_transport_adapter.h +++ b/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_transport_adapter.h @@ -58,18 +58,6 @@ class CloudWebsocketTransportAdapter : public TransportAdapterImpl { */ virtual ~CloudWebsocketTransportAdapter(); - /** - * @brief Notification that transport's configuration is updated - * - * @param new_config The new configuration of the transport - */ - void CloudTransportConfigUpdated(const CloudAppTransportConfig& new_config); - - /** - * @brief Returns the transport's configuration information - */ - CloudAppTransportConfig GetCloudTransportConfiguration() const; - protected: /** * @brief Return type of device. @@ -93,14 +81,6 @@ class CloudWebsocketTransportAdapter : public TransportAdapterImpl { void CreateDevice(const std::string& uid) OVERRIDE; private: - /** - * @brief Keeps transport specific configuration - * - * Cloud websocket transport uses following information: - * - "enabled": whether the transport is currently enabled or not. Value can - * be "true" or "false". - */ - CloudAppTransportConfig transport_config_; }; } // namespace transport_adapter diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h index f1f64ae53a..b30f1e35b2 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h @@ -159,7 +159,11 @@ class TransportAdapterImpl : public TransportAdapter, ConnectionStatus GetConnectionStatus( const DeviceUID& device_handle) const OVERRIDE; - void ConnectionStatusUpdated() OVERRIDE; + /** + * @brief Notifies the application manager that a cloud connection status has + * updated and should trigger an UpdateAppList RPC to the HMI + */ + void ConnectionStatusUpdated(DeviceSptr device, ConnectionStatus status); /** * @brief Disconnect from specified session. diff --git a/src/components/transport_manager/src/cloud/cloud_device.cc b/src/components/transport_manager/src/cloud/cloud_device.cc index 770962be47..184fcc10cc 100644 --- a/src/components/transport_manager/src/cloud/cloud_device.cc +++ b/src/components/transport_manager/src/cloud/cloud_device.cc @@ -46,21 +46,28 @@ CloudDevice::CloudDevice(std::string& host, bool CloudDevice::IsSameAs(const Device* other) const { LOG4CXX_TRACE(logger_, "enter. device: " << other); - bool result = false; - return result; + + const CloudDevice* other_cloud_device = + dynamic_cast<const CloudDevice*>(other); + + if (host_ != other_cloud_device->GetHost()) { + return false; + } + if (port_ != other_cloud_device->GetPort()) { + return false; + } + return true; } -// todo implement getApplicationList -// to be populated by policies ApplicationList CloudDevice::GetApplicationList() const { return ApplicationList{0}; } -const std::string& CloudDevice::GetHost() { +const std::string& CloudDevice::GetHost() const { return host_; } -const std::string& CloudDevice::GetPort() { +const std::string& CloudDevice::GetPort() const { return port_; } diff --git a/src/components/transport_manager/src/cloud/cloud_websocket_transport_adapter.cc b/src/components/transport_manager/src/cloud/cloud_websocket_transport_adapter.cc index 1ef62c6368..5093e6c2af 100644 --- a/src/components/transport_manager/src/cloud/cloud_websocket_transport_adapter.cc +++ b/src/components/transport_manager/src/cloud/cloud_websocket_transport_adapter.cc @@ -53,23 +53,13 @@ CloudWebsocketTransportAdapter::CloudWebsocketTransportAdapter( CloudWebsocketTransportAdapter::~CloudWebsocketTransportAdapter() {} -void CloudWebsocketTransportAdapter::CloudTransportConfigUpdated( - const CloudAppTransportConfig& new_config) {} - -CloudAppTransportConfig -CloudWebsocketTransportAdapter::GetCloudTransportConfiguration() const { - return transport_config_; -} - DeviceType CloudWebsocketTransportAdapter::GetDeviceType() const { return CLOUD_WEBSOCKET; } -void CloudWebsocketTransportAdapter::Store() const { -} // todo decide if this is needed +void CloudWebsocketTransportAdapter::Store() const {} -bool CloudWebsocketTransportAdapter::Restore() { // todo decide if resumption - // is needed +bool CloudWebsocketTransportAdapter::Restore() { return true; } @@ -115,7 +105,6 @@ void CloudWebsocketTransportAdapter::CreateDevice(const std::string& uid) { "Creating Cloud Device For Host: " << host << " and Port: " << port); - // todo get nickname from policies to name device auto cloud_device = std::make_shared<CloudDevice>(host, port, device_id); DeviceVector devices{cloud_device}; diff --git a/src/components/transport_manager/src/cloud/websocket_client_connection.cc b/src/components/transport_manager/src/cloud/websocket_client_connection.cc index f487a9a16a..ec372369c6 100644 --- a/src/components/transport_manager/src/cloud/websocket_client_connection.cc +++ b/src/components/transport_manager/src/cloud/websocket_client_connection.cc @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2017, Ford Motor Company + * Copyright (c) 2018, Livio * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/components/transport_manager/src/transport_adapter/transport_adapter_impl.cc b/src/components/transport_manager/src/transport_adapter/transport_adapter_impl.cc index e25e21a95f..13474c03ab 100644 --- a/src/components/transport_manager/src/transport_adapter/transport_adapter_impl.cc +++ b/src/components/transport_manager/src/transport_adapter/transport_adapter_impl.cc @@ -254,13 +254,11 @@ TransportAdapter::Error TransportAdapterImpl::ConnectDevice( // Update retry count if (device->retry_count() >= get_settings().cloud_app_max_retry_attempts()) { - device->set_connection_status(ConnectionStatus::PENDING); device->reset_retry_count(); - ConnectionStatusUpdated(); + ConnectionStatusUpdated(device, ConnectionStatus::PENDING); return err; } else if (device->connection_status() == ConnectionStatus::PENDING) { - device->set_connection_status(ConnectionStatus::RETRY); - ConnectionStatusUpdated(); + ConnectionStatusUpdated(device, ConnectionStatus::RETRY); } device->next_retry(); @@ -275,8 +273,7 @@ TransportAdapter::Error TransportAdapterImpl::ConnectDevice( retry_timer->Start(get_settings().cloud_app_retry_timeout(), timer::kSingleShot); } else if (OK == err) { - device->set_connection_status(ConnectionStatus::CONNECTED); - ConnectionStatusUpdated(); + ConnectionStatusUpdated(device, ConnectionStatus::CONNECTED); } LOG4CXX_TRACE(logger_, "exit with error: " << err); return err; @@ -330,7 +327,9 @@ ConnectionStatus TransportAdapterImpl::GetConnectionStatus( : device->connection_status(); } -void TransportAdapterImpl::ConnectionStatusUpdated() { +void TransportAdapterImpl::ConnectionStatusUpdated(DeviceSptr device, + ConnectionStatus status) { + device->set_connection_status(status); for (TransportAdapterListenerList::iterator it = listeners_.begin(); it != listeners_.end(); ++it) { @@ -368,8 +367,7 @@ TransportAdapter::Error TransportAdapterImpl::DisconnectDevice( Error error = OK; DeviceSptr device = FindDevice(device_id); - device->set_connection_status(ConnectionStatus::CLOSING); - ConnectionStatusUpdated(); + ConnectionStatusUpdated(device, ConnectionStatus::CLOSING); std::vector<ConnectionInfo> to_disconnect; connections_lock_.AcquireForReading(); diff --git a/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_controller.h b/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_controller.h index 1de5eac702..f64009317f 100644 --- a/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_controller.h +++ b/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_controller.h @@ -44,7 +44,7 @@ using namespace ::transport_manager::transport_adapter; class MockTransportAdapterController : public TransportAdapterController { public: - MOCK_METHOD1(AddDevice, DeviceSptr(DeviceSptr device)); + MOCK_METHOD1(AddDevice, DeviceSptr(std::string device)); MOCK_METHOD1(SearchDeviceDone, void(DeviceVector device)); MOCK_METHOD1(ApplicationListUpdated, ApplicationListUpdated(const DeviceUID& device_handle)); diff --git a/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_impl.h b/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_impl.h index e18d1bc53b..3a1422cee1 100644 --- a/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_impl.h +++ b/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_impl.h @@ -36,6 +36,8 @@ #include "gmock/gmock.h" #include "transport_manager/transport_manager_settings.h" #include "transport_manager/transport_adapter/transport_adapter_impl.h" +#include "transport_manager/transport_adapter/device.h" +#include "transport_manager/common.h" using ::transport_manager::transport_adapter::TransportAdapterImpl; using ::transport_manager::transport_adapter::DeviceScanner; @@ -75,7 +77,9 @@ class MockTransportAdapterImpl : public TransportAdapterImpl { MOCK_CONST_METHOD1(FindDevice, transport_manager::transport_adapter::DeviceSptr( const DeviceUID& device_id)); - MOCK_METHOD0(ConnectionStatusUpdated, void()); + MOCK_METHOD2(ConnectionStatusUpdated, + void(transport_manager::transport_adapter::DeviceSptr device, + ::transport_manager::ConnectionStatus status)); MOCK_CONST_METHOD0(GetDeviceType, ::transport_manager::transport_adapter::DeviceType()); MOCK_METHOD0(RetryConnection, void()); diff --git a/src/components/transport_manager/test/transport_adapter_test.cc b/src/components/transport_manager/test/transport_adapter_test.cc index b917c60187..72cf0ba76e 100644 --- a/src/components/transport_manager/test/transport_adapter_test.cc +++ b/src/components/transport_manager/test/transport_adapter_test.cc @@ -359,7 +359,6 @@ TEST_F(TransportAdapterTest, ConnectDevice_DeviceAdded) { EXPECT_CALL(*serverMock, CreateConnection(uniq_id, app_handle)) .WillOnce(Return(TransportAdapter::OK)); EXPECT_CALL(transport_adapter, FindDevice(uniq_id)).WillOnce(Return(mockdev)); - EXPECT_CALL(transport_adapter, ConnectionStatusUpdated()); TransportAdapter::Error res = transport_adapter.ConnectDevice(uniq_id); EXPECT_EQ(TransportAdapter::OK, res); EXPECT_EQ(ConnectionStatus::CONNECTED, mockdev->connection_status()); @@ -372,7 +371,6 @@ TEST_F(TransportAdapterTest, ConnectDevice_DeviceAdded_ConnectFailedRetry) { MockTransportAdapterImpl transport_adapter( NULL, server_mock, NULL, last_state_, transport_manager_settings); SetDefaultExpectations(transport_adapter); - // transport_adapter.SetDeviceType(DeviceType::CLOUD_WEBSOCKET); EXPECT_CALL(*server_mock, Init()).WillOnce(Return(TransportAdapter::OK)); EXPECT_CALL(transport_adapter, Restore()).WillOnce(Return(true)); @@ -396,7 +394,6 @@ TEST_F(TransportAdapterTest, ConnectDevice_DeviceAdded_ConnectFailedRetry) { EXPECT_CALL(transport_adapter, FindDevice(uniq_id)).WillOnce(Return(mockdev)); EXPECT_CALL(transport_adapter, GetDeviceType()) .WillOnce(Return(DeviceType::CLOUD_WEBSOCKET)); - EXPECT_CALL(transport_adapter, ConnectionStatusUpdated()); EXPECT_CALL(transport_manager_settings, cloud_app_max_retry_attempts()) .WillOnce(Return(0)); TransportAdapter::Error res = transport_adapter.ConnectDevice(uniq_id); @@ -432,7 +429,6 @@ TEST_F(TransportAdapterTest, ConnectDevice_DeviceAddedTwice) { EXPECT_CALL(*serverMock, CreateConnection(uniq_id, app_handle)) .WillOnce(Return(TransportAdapter::OK)); EXPECT_CALL(transport_adapter, FindDevice(uniq_id)).WillOnce(Return(mockdev)); - EXPECT_CALL(transport_adapter, ConnectionStatusUpdated()); TransportAdapter::Error res = transport_adapter.ConnectDevice(uniq_id); EXPECT_EQ(TransportAdapter::OK, res); EXPECT_EQ(ConnectionStatus::CONNECTED, mockdev->connection_status()); @@ -444,7 +440,6 @@ TEST_F(TransportAdapterTest, ConnectDevice_DeviceAddedTwice) { EXPECT_CALL(*serverMock, IsInitialised()).WillOnce(Return(true)); EXPECT_CALL(*serverMock, CreateConnection(uniq_id, app_handle)).Times(0); EXPECT_CALL(transport_adapter, FindDevice(uniq_id)).WillOnce(Return(mockdev)); - EXPECT_CALL(transport_adapter, ConnectionStatusUpdated()); TransportAdapter::Error newres = transport_adapter.ConnectDevice(uniq_id); EXPECT_EQ(TransportAdapter::OK, newres); EXPECT_EQ(ConnectionStatus::CONNECTED, mockdev->connection_status()); @@ -509,7 +504,7 @@ TEST_F(TransportAdapterTest, DisconnectDevice_DeviceAddedConnectionCreated) { .WillOnce(Return(TransportAdapter::OK)); EXPECT_CALL(transport_adapter, FindDevice(uniq_id)) .WillRepeatedly(Return(mockdev)); - EXPECT_CALL(transport_adapter, ConnectionStatusUpdated()); + // EXPECT_CALL(transport_adapter, ConnectionStatusUpdated(_, _)); TransportAdapter::Error res = transport_adapter.ConnectDevice(uniq_id); EXPECT_EQ(TransportAdapter::OK, res); EXPECT_EQ(ConnectionStatus::CONNECTED, mockdev->connection_status()); @@ -520,7 +515,7 @@ TEST_F(TransportAdapterTest, DisconnectDevice_DeviceAddedConnectionCreated) { EXPECT_CALL(*mock_connection, Disconnect()) .WillOnce(Return(TransportAdapter::OK)); - EXPECT_CALL(transport_adapter, ConnectionStatusUpdated()); + // EXPECT_CALL(transport_adapter, ConnectionStatusUpdated(_, _)); TransportAdapter::Error new_res = transport_adapter.DisconnectDevice(uniq_id); EXPECT_EQ(TransportAdapter::OK, new_res); EXPECT_EQ(ConnectionStatus::CLOSING, mockdev->connection_status()); @@ -556,7 +551,6 @@ TEST_F(TransportAdapterTest, DeviceDisconnected) { EXPECT_CALL(*serverMock, IsInitialised()).WillOnce(Return(true)); EXPECT_CALL(*serverMock, CreateConnection(uniq_id, app_handle)) .WillOnce(Return(TransportAdapter::OK)); - EXPECT_CALL(transport_adapter, ConnectionStatusUpdated()); TransportAdapter::Error res = transport_adapter.ConnectDevice(uniq_id); EXPECT_EQ(TransportAdapter::OK, res); EXPECT_EQ(ConnectionStatus::CONNECTED, mockdev->connection_status()); |