From 6b45e3a52be38ed3f3b0ff333ea803aef7e76b7b Mon Sep 17 00:00:00 2001 From: jacobkeeler Date: Thu, 1 Nov 2018 16:08:28 -0400 Subject: Add cloud app parameters to regular policies --- .../application_manager/policies/policy_handler.h | 23 +++++++ .../application_manager/smart_object_keys.h | 4 ++ .../src/policies/policy_handler.cc | 63 ++++++++++++++++++ .../application_manager/src/smart_object_keys.cc | 4 ++ .../policies/policy_handler_interface.h | 39 +++++++++++ .../policy/policy_regular/policy/policy_manager.h | 51 +++++++++++++++ .../policies/mock_policy_handler_interface.h | 10 +++ .../policy_regular/policy/mock_cache_manager.h | 17 +++++ .../policy_regular/policy/mock_policy_manager.h | 17 +++++ .../policy_regular/include/policy/cache_manager.h | 51 +++++++++++++++ .../include/policy/cache_manager_interface.h | 51 +++++++++++++++ .../include/policy/policy_manager_impl.h | 52 +++++++++++++++ .../include/policy/policy_table/enums.h | 6 ++ .../include/policy/policy_table/types.h | 6 ++ .../policy/policy_regular/src/cache_manager.cc | 75 ++++++++++++++++++++++ .../policy_regular/src/policy_manager_impl.cc | 32 ++++++++- .../policy_regular/src/policy_table/enums.cc | 35 +++++++++- .../policy_regular/src/policy_table/types.cc | 65 ++++++++++++++++++- .../policy/policy_regular/src/sql_pt_queries.cc | 43 ++++++++++--- .../policy_regular/src/sql_pt_representation.cc | 43 ++++++++++++- .../test/sql_pt_representation_test.cc | 4 +- 21 files changed, 675 insertions(+), 16 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 c8f3bcf888..3af03bf28b 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 @@ -398,6 +398,29 @@ class PolicyHandler : public PolicyHandlerInterface, custom_str::CustomString GetAppName( const std::string& policy_app_id) OVERRIDE; + /** + * @brief Checks if a given application is an enabled cloud application + * @param policy_app_id Unique application id + * @return true, if the application is an enabled cloud application, + * otherwise - false + */ + const bool CheckCloudAppEnabled( + const std::string& policy_app_id) const OVERRIDE; + + /**plzfix + * @brief Checks if certain request type is allowed for application + * @param policy_app_id Unique application id + * @return true, if allowed, otherwise - false + */ + const bool GetCloudAppParameters(const std::string& policy_app_id, + std::string& endpoint, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const OVERRIDE; + + void OnSetCloudAppProperties( + const smart_objects::SmartObject& message) OVERRIDE; + virtual void OnUpdateHMIAppType( std::map app_hmi_types) OVERRIDE; diff --git a/src/components/application_manager/include/application_manager/smart_object_keys.h b/src/components/application_manager/include/application_manager/smart_object_keys.h index 6e32853a3d..e8d05c14db 100644 --- a/src/components/application_manager/include/application_manager/smart_object_keys.h +++ b/src/components/application_manager/include/application_manager/smart_object_keys.h @@ -188,6 +188,10 @@ extern const char* green; extern const char* blue; extern const char* display_layout; extern const char* icon_resumed; +extern const char* enabled; +extern const char* cloud_app_auth_token; +extern const char* cloud_transport_type; +extern const char* hybrid_app_preference; // PutFile extern const char* sync_file_name; diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 1b64c5d7b4..c73e35768e 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1845,6 +1845,69 @@ bool PolicyHandler::CheckSystemAction( return false; } +const bool PolicyHandler::GetCloudAppParameters( + const std::string& policy_app_id, + std::string& endpoint, + 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, + auth_token, + cloud_transport_type, + hybrid_app_preference); +} + +const bool PolicyHandler::CheckCloudAppEnabled(const std::string& policy_app_id) const { + POLICY_LIB_CHECK(false); + std::string endpoint; + std::string auth_token; + std::string cloud_transport_type; + std::string hybrid_app_preference; + return policy_manager_->GetCloudAppParameters(policy_app_id, + endpoint, + auth_token, + cloud_transport_type, + hybrid_app_preference); +} + +void PolicyHandler::OnSetCloudAppProperties( + const smart_objects::SmartObject& message) { + POLICY_LIB_CHECK_VOID(); + if (!message.keyExists(strings::msg_params)) { + LOG4CXX_ERROR( + logger_, + "Message does not contain mandatory section " << strings::msg_params); + return; + } + const smart_objects::SmartObject& msg_params = message[strings::msg_params]; + if (!msg_params.keyExists(strings::app_id)) { + LOG4CXX_ERROR( + logger_, + "Message does not contain mandatory parameter " << strings::app_id); + return; + } + std::string policy_app_id(msg_params[strings::app_id].asString()); + if (msg_params.keyExists(strings::enabled)) { + policy_manager_->SetCloudAppEnabled(policy_app_id, + msg_params[strings::enabled].asBool()); + } + if (msg_params.keyExists(strings::cloud_app_auth_token)) { + policy_manager_->SetAppAuthToken(policy_app_id, + msg_params[strings::cloud_app_auth_token].asString()); + } + if (msg_params.keyExists(strings::cloud_transport_type)) { + policy_manager_->SetAppCloudTransportType( + policy_app_id, msg_params[strings::cloud_transport_type].asString()); + } + if (msg_params.keyExists(strings::hybrid_app_preference)) { + //const std::string hybrid_app_preference = EnumConversionHelper::EnumToString(msg_params[strings::hybrid_app_preference]); + //policy_manager_->SetHybridAppPreference( + // policy_app_id, hybrid_app_preference); + } +} + uint32_t PolicyHandler::HeartBeatTimeout(const std::string& app_id) const { POLICY_LIB_CHECK(0); return policy_manager_->HeartBeatTimeout(app_id); diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc index ff9ebb6208..8e53929451 100644 --- a/src/components/application_manager/src/smart_object_keys.cc +++ b/src/components/application_manager/src/smart_object_keys.cc @@ -155,6 +155,10 @@ const char* green = "green"; const char* blue = "blue"; const char* display_layout = "displayLayout"; const char* icon_resumed = "iconResumed"; +const char* enabled = "enabled"; +const char* cloud_app_auth_token = "cloudAppAuthToken"; +const char* cloud_transport_type = "cloudTransportType"; +const char* hybrid_app_preference = "hybridAppPreference"; // PutFile const char* sync_file_name = "syncFileName"; 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 ee9274ead7..69433e6118 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -437,6 +437,45 @@ class PolicyHandlerInterface { * @return Structure with vehicle information */ virtual const VehicleInfo GetVehicleInfo() const = 0; + + /** + * @brief Checks if a given application is an enabled cloud application + * @param policy_app_id Unique application id + * @return true if the application is an enabled cloud application, + * false otherwise + */ + virtual const bool CheckCloudAppEnabled( + const std::string& policy_app_id) const = 0; + + /** + * @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 + * 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 + * 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& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const = 0; + + /** + * @brief Callback for when a SetCloudAppProperties message is received from a + * mobile app + * @param message The SetCloudAppProperties message + */ + virtual void OnSetCloudAppProperties( + const smart_objects::SmartObject& message) = 0; + #ifdef EXTERNAL_PROPRIETARY_MODE /** * @brief Gets meta information 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 ee0bae7118..9c67e239b7 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -502,6 +502,57 @@ class PolicyManager : public usage_statistics::StatisticsManager { */ virtual const VehicleInfo GetVehicleInfo() const = 0; + /** + * @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 + * 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 + * 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& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const = 0; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + virtual void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) = 0; + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + virtual void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) = 0; + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + virtual void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type) = 0; + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + virtual void SetHybridAppPreference(const std::string& policy_app_id, + const std::string& hybrid_app_preference) = 0; + /** * @brief OnAppRegisteredOnMobile allows to handle event when application were * succesfully registered on mobile device. 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 cb47147074..bd56d78128 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 @@ -213,6 +213,16 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { GetAppRequestTypes, const std::vector(const std::string& policy_app_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); + MOCK_CONST_METHOD1(CheckCloudAppEnabled, + const bool(const std::string& policy_app_id)); + MOCK_CONST_METHOD5(GetCloudAppParameters, + const bool(const std::string& policy_app_id, + std::string& endpoint, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD1(OnSetCloudAppProperties, + void(const smart_objects::SmartObject& message)); #ifdef EXTERNAL_PROPRIETARY_MODE MOCK_CONST_METHOD0(GetMetaInfo, const policy::MetaInfo()); 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 440000dbff..745bcd2db5 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 @@ -63,6 +63,23 @@ class MockCacheManagerInterface : public CacheManagerInterface { MOCK_METHOD0(TimeoutResponse, int()); MOCK_METHOD1(SecondsBetweenRetries, bool(std::vector& seconds)); MOCK_CONST_METHOD0(GetVehicleInfo, const VehicleInfo()); + MOCK_CONST_METHOD5(GetCloudAppParameters, + const bool(const std::string& policy_app_id, + std::string& endpoint, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD2(SetCloudAppEnabled, + void(const std::string& policy_app_id, const bool enabled)); + MOCK_METHOD2(SetAppAuthToken, + void(const std::string& policy_app_id, + const std::string& auth_token)); + MOCK_METHOD2(SetAppCloudTransportType, + void(const std::string& policy_app_id, + const std::string& cloud_transport_type)); + MOCK_METHOD2(SetHybridAppPreference, + void(const std::string& policy_app_id, + const std::string& hybrid_app_preference)); MOCK_METHOD1(SetVINValue, bool(const std::string& value)); MOCK_METHOD2(GetUserFriendlyMsg, std::vector( 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 0e06e9c1a3..8867c3de80 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 @@ -181,6 +181,23 @@ class MockPolicyManager : public PolicyManager { GetAppRequestTypes, const std::vector(const std::string policy_app_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); + MOCK_CONST_METHOD5(GetCloudAppParameters, + const bool(const std::string& policy_app_id, + std::string& endpoint, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD2(SetCloudAppEnabled, + void(const std::string& policy_app_id, const bool enabled)); + MOCK_METHOD2(SetAppAuthToken, + void(const std::string& policy_app_id, + const std::string& auth_token)); + MOCK_METHOD2(SetAppCloudTransportType, + void(const std::string& policy_app_id, + const std::string& cloud_transport_type)); + MOCK_METHOD2(SetHybridAppPreference, + void(const std::string& policy_app_id, + const std::string& hybrid_app_preference)); MOCK_CONST_METHOD0(GetMetaInfo, const policy::MetaInfo()); MOCK_CONST_METHOD0(RetrieveCertificate, std::string()); MOCK_CONST_METHOD0(HasCertificate, bool()); 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 48e00f7049..119a0c0519 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -146,6 +146,57 @@ class CacheManager : public CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const; + /** + * @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 + * 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 + * 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& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + virtual void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled); + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + virtual void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token); + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + virtual void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type); + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + virtual void SetHybridAppPreference(const std::string& policy_app_id, + const std::string& hybrid_app_preference); + /** * @brief Allows to update 'vin' field in module_meta table. * 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 10a6ea7f89..9408809f1e 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 @@ -151,6 +151,57 @@ class CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const = 0; + /** + * @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 + * 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 + * 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& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const = 0; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + virtual void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) = 0; + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + virtual void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) = 0; + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + virtual void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type) = 0; + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + virtual void SetHybridAppPreference(const std::string& policy_app_id, + const std::string& hybrid_app_preference) = 0; + /** * @brief Allows to update 'vin' field in module_meta table. * 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 51d4ee88aa..e1221b613f 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 @@ -564,6 +564,58 @@ class PolicyManagerImpl : public PolicyManager { */ const VehicleInfo GetVehicleInfo() const OVERRIDE; + /** + * @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 + * 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 + * 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& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const OVERRIDE; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) OVERRIDE; + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) OVERRIDE; + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type) OVERRIDE; + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) OVERRIDE; + /** * @brief OnAppRegisteredOnMobile allows to handle event when application were * succesfully registered on mobile device. diff --git a/src/components/policy/policy_regular/include/policy/policy_table/enums.h b/src/components/policy/policy_regular/include/policy/policy_table/enums.h index 1f10db9f6f..3cdca195bf 100644 --- a/src/components/policy/policy_regular/include/policy/policy_table/enums.h +++ b/src/components/policy/policy_regular/include/policy/policy_table/enums.h @@ -167,6 +167,12 @@ bool IsValidEnum(ModuleType val); const char* EnumToJsonString(ModuleType val); bool EnumFromJsonString(const std::string& literal, ModuleType* result); +enum HybridAppPreference { HAP_MOBILE, HAP_CLOUD, HAP_BOTH }; +bool IsValidEnum(HybridAppPreference val); +const char* EnumToJsonString(HybridAppPreference val); +bool EnumFromJsonString(const std::string& literal, + HybridAppPreference* result); + /** * @brief Enumeration FunctionID. * diff --git a/src/components/policy/policy_regular/include/policy/policy_table/types.h b/src/components/policy/policy_regular/include/policy/policy_table/types.h index e201251745..58f07492c4 100644 --- a/src/components/policy/policy_regular/include/policy/policy_table/types.h +++ b/src/components/policy/policy_regular/include/policy/policy_table/types.h @@ -144,6 +144,12 @@ struct ApplicationParams : PolicyBase { Optional > heart_beat_timeout_ms; Optional > certificate; mutable Optional moduleType; + // Cloud application params + Optional > hybrid_app_preference; + Optional > endpoint; + Optional enabled; + Optional > auth_token; + Optional > cloud_transport_type; public: ApplicationParams(); diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index bd95fc8e7c..68e70c107d 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -682,6 +682,81 @@ const policy::VehicleInfo CacheManager::GetVehicleInfo() const { return vehicle_info; } +const bool CacheManager::GetCloudAppParameters( + const std::string& policy_app_id, + std::string& endpoint, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const { + const policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::const_iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + auto app_policy = (*policy_iter).second; + endpoint = app_policy.endpoint.is_initialized() ? *app_policy.endpoint + : 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(); + 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; + } + return false; +} + +void CacheManager::SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) { + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + *(*policy_iter).second.enabled = enabled; + } +} + +void CacheManager::SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) { + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + *(*policy_iter).second.auth_token = auth_token; + } +} + +void CacheManager::SetAppCloudTransportType( + const std::string& policy_app_id, const std::string& cloud_transport_type) { + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + *(*policy_iter).second.cloud_transport_type = cloud_transport_type; + } +} + +void CacheManager::SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) { + policy_table::HybridAppPreference value; + bool valid = EnumFromJsonString(hybrid_app_preference, &value); + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter && valid) { + *(*policy_iter).second.hybrid_app_preference = value; + } +} + std::vector CacheManager::GetUserFriendlyMsg( const std::vector& msg_codes, const std::string& language) { LOG4CXX_AUTO_TRACE(logger_); 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 4985035629..9317708216 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -217,7 +217,7 @@ void FilterInvalidApplicationParameters( } app_params.AppHMIType->swap(valid_app_hmi_types); - // Filter RquestTypes array + // Filter RequestTypes array policy_table::RequestTypes valid_request_types; const policy_table::RequestTypes& request_types = *(app_params.RequestType); for (const auto& request_type : request_types) { @@ -544,6 +544,36 @@ const VehicleInfo PolicyManagerImpl::GetVehicleInfo() const { return cache_->GetVehicleInfo(); } +const bool PolicyManagerImpl::GetCloudAppParameters( + const std::string& policy_app_id, + std::string& endpoint, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const { + return cache_->GetCloudAppParameters(policy_app_id, endpoint, auth_token, cloud_transport_type, hybrid_app_preference); +} + +void PolicyManagerImpl::SetCloudAppEnabled( + const std::string& policy_app_id, const bool enabled) { + cache_->SetCloudAppEnabled(policy_app_id, enabled); +} + +void PolicyManagerImpl::SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) { + cache_->SetAppAuthToken(policy_app_id, auth_token); +} + +void PolicyManagerImpl::SetAppCloudTransportType( + const std::string& policy_app_id, const std::string& cloud_transport_type) { + cache_->SetAppCloudTransportType(policy_app_id, cloud_transport_type); +} + +void PolicyManagerImpl::SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) { + cache_->SetHybridAppPreference(policy_app_id, hybrid_app_preference); +} + void PolicyManagerImpl::CheckPermissions(const PTString& device_id, const PTString& app_id, const PTString& hmi_level, diff --git a/src/components/policy/policy_regular/src/policy_table/enums.cc b/src/components/policy/policy_regular/src/policy_table/enums.cc index 428e18d0bd..4102db51b3 100644 --- a/src/components/policy/policy_regular/src/policy_table/enums.cc +++ b/src/components/policy/policy_regular/src/policy_table/enums.cc @@ -1,5 +1,5 @@ -// This file is generated, do not edit #include "policy/policy_table/enums.h" +#include namespace rpc { namespace policy_table_interface_base { @@ -662,6 +662,7 @@ bool IsValidEnum(ModuleType val) { return false; } } + const char* EnumToJsonString(ModuleType val) { switch (val) { case MT_CLIMATE: @@ -709,6 +710,38 @@ bool EnumFromJsonString(const std::string& literal, ModuleType* result) { return false; } +bool IsValidEnum(HybridAppPreference val) { + return strlen(EnumToJsonString(val)) > 0; +} + +const char* EnumToJsonString(HybridAppPreference val) { + switch (val) { + case HAP_MOBILE: + return "MOBILE"; + case HAP_CLOUD: + return "CLOUD"; + case HAP_BOTH: + return "BOTH"; + default: + return ""; + } +} + +bool EnumFromJsonString(const std::string& literal, + HybridAppPreference* result) { + if ("MOBILE" == literal) { + *result = HAP_MOBILE; + return true; + } else if ("CLOUD" == literal) { + *result = HAP_CLOUD; + return true; + } else if ("BOTH" == literal) { + *result = HAP_BOTH; + return true; + } + return false; +} + bool IsValidEnum(FunctionID val) { switch (val) { case RegisterAppInterfaceID: diff --git a/src/components/policy/policy_regular/src/policy_table/types.cc b/src/components/policy/policy_regular/src/policy_table/types.cc index 851ed1bd18..88564df050 100644 --- a/src/components/policy/policy_regular/src/policy_table/types.cc +++ b/src/components/policy/policy_regular/src/policy_table/types.cc @@ -168,7 +168,13 @@ ApplicationParams::ApplicationParams(const Json::Value* value__) , memory_kb(impl::ValueMember(value__, "memory_kb"), 0) , heart_beat_timeout_ms(impl::ValueMember(value__, "heart_beat_timeout_ms")) , certificate(impl::ValueMember(value__, "certificate"), "not_specified") - , moduleType(impl::ValueMember(value__, "moduleType")) {} + , moduleType(impl::ValueMember(value__, "moduleType")) + , hybrid_app_preference(impl::ValueMember(value__, "hybrid_app_preference")) + , endpoint(impl::ValueMember(value__, "endpoint")) + , enabled(impl::ValueMember(value__, "enabled")) + , auth_token(impl::ValueMember(value__, "auth_token")) + , cloud_transport_type(impl::ValueMember(value__, "cloud_transport_type")) { +} Json::Value ApplicationParams::ToJsonValue() const { Json::Value result__(PolicyBase::ToJsonValue()); @@ -180,7 +186,14 @@ Json::Value ApplicationParams::ToJsonValue() const { impl::WriteJsonField("memory_kb", memory_kb, &result__); impl::WriteJsonField( "heart_beat_timeout_ms", heart_beat_timeout_ms, &result__); + impl::WriteJsonField("certificate", certificate, &result__); impl::WriteJsonField("moduleType", moduleType, &result__); + impl::WriteJsonField( + "hybrid_app_preference", hybrid_app_preference, &result__); + impl::WriteJsonField("endpoint", endpoint, &result__); + impl::WriteJsonField("enabled", enabled, &result__); + impl::WriteJsonField("auth_token", auth_token, &result__); + impl::WriteJsonField("cloud_transport_type", cloud_transport_type, &result__); return result__; } @@ -212,6 +225,21 @@ bool ApplicationParams::is_valid() const { if (!moduleType.is_valid()) { return false; } + if (!endpoint.is_valid()) { + return false; + } + if (!enabled.is_valid()) { + return false; + } + if (!auth_token.is_valid()) { + return false; + } + if (!cloud_transport_type.is_valid()) { + return false; + } + if (!hybrid_app_preference.is_valid()) { + return false; + } return Validate(); } @@ -250,6 +278,21 @@ bool ApplicationParams::struct_empty() const { if (moduleType.is_initialized()) { return false; } + if (endpoint.is_initialized()) { + return false; + } + if (enabled.is_initialized()) { + return false; + } + if (auth_token.is_initialized()) { + return false; + } + if (cloud_transport_type.is_initialized()) { + return false; + } + if (hybrid_app_preference.is_initialized()) { + return false; + } return true; } @@ -288,6 +331,22 @@ void ApplicationParams::ReportErrors(rpc::ValidationReport* report__) const { if (!moduleType.is_valid()) { moduleType.ReportErrors(&report__->ReportSubobject("moduleType")); } + if (!endpoint.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("endpoint")); + } + if (!enabled.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("enabled")); + } + if (!auth_token.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("auth_token")); + } + if (!cloud_transport_type.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("cloud_transport_type")); + } + if (!hybrid_app_preference.is_valid()) { + moduleType.ReportErrors( + &report__->ReportSubobject("hybrid_app_preference")); + } } void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) { @@ -300,6 +359,10 @@ void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) { heart_beat_timeout_ms.SetPolicyTableType(pt_type); certificate.SetPolicyTableType(pt_type); moduleType.SetPolicyTableType(pt_type); + endpoint.SetPolicyTableType(pt_type); + enabled.SetPolicyTableType(pt_type); + cloud_transport_type.SetPolicyTableType(pt_type); + hybrid_app_preference.SetPolicyTableType(pt_type); } // RpcParameters methods diff --git a/src/components/policy/policy_regular/src/sql_pt_queries.cc b/src/components/policy/policy_regular/src/sql_pt_queries.cc index f5ccffce3b..ef6c7f2a03 100644 --- a/src/components/policy/policy_regular/src/sql_pt_queries.cc +++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc @@ -84,6 +84,9 @@ const std::string kCreateSchema = "CREATE TABLE IF NOT EXISTS `hmi_level`( " " `value` VARCHAR(45) PRIMARY KEY NOT NULL " "); " + "CREATE TABLE IF NOT EXISTS `hybrid_app_preference`( " + " `value` VARCHAR(45) PRIMARY KEY NOT NULL " + "); " "CREATE TABLE IF NOT EXISTS `notifications_by_priority`( " " `priority_value` VARCHAR(45) PRIMARY KEY NOT NULL, " " `value` INTEGER NOT NULL, " @@ -133,7 +136,12 @@ const std::string kCreateSchema = " `is_predata` BOOLEAN, " " `memory_kb` INTEGER NOT NULL, " " `heart_beat_timeout_ms` INTEGER NOT NULL, " - " `certificate` VARCHAR(45), " + " `certificate` VARCHAR(65535), " + " `hybrid_app_preference_value` VARCHAR(255), " + " `endpoint` VARCHAR(255), " + " `enabled` BOOLEAN, " + " `auth_token` VARCHAR(65535), " + " `cloud_transport_type` VARCHAR(255), " " `remote_control_denied` BOOLEAN NOT NULL DEFAULT 0, " " CONSTRAINT `fk_application_hmi_level1` " " FOREIGN KEY(`default_hmi`) " @@ -141,11 +149,17 @@ const std::string kCreateSchema = " CONSTRAINT `fk_application_priorities1` " " FOREIGN KEY(`priority_value`) " " REFERENCES `priority`(`value`) " + " CONSTRAINT `fk_application_hybrid_app_preference1` " + " FOREIGN KEY(`hybrid_app_preference_value`) " + " REFERENCES `hybrid_app_preference`(`value`) " "); " "CREATE INDEX IF NOT EXISTS `application.fk_application_hmi_level1_idx` " " ON `application`(`default_hmi`); " "CREATE INDEX IF NOT EXISTS `application.fk_application_priorities1_idx` " " ON `application`(`priority_value`); " + "CREATE INDEX IF NOT EXISTS " + "`application.fk_application_hybrid_app_preference1` " + " ON `application`(`hybrid_app_preference_value`); " "CREATE TABLE IF NOT EXISTS `app_group`( " " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, " " `functional_group_id` INTEGER NOT NULL, " @@ -391,6 +405,9 @@ const std::string kInsertInitData = "INSERT OR IGNORE INTO `hmi_level`(`value`) VALUES ('LIMITED'); " "INSERT OR IGNORE INTO `hmi_level`(`value`) VALUES ('BACKGROUND'); " "INSERT OR IGNORE INTO `hmi_level`(`value`) VALUES ('NONE'); " + "INSERT OR IGNORE INTO `hybrid_app_preference`(`value`) VALUES ('MOBILE'); " + "INSERT OR IGNORE INTO `hybrid_app_preference`(`value`) VALUES ('CLOUD'); " + "INSERT OR IGNORE INTO `hybrid_app_preference`(`value`) VALUES ('BOTH'); " "INSERT OR IGNORE INTO `version` (`number`) VALUES('0'); " "INSERT OR IGNORE INTO `_internal_data` (`db_version_hash`) VALUES(0); " ""; @@ -491,6 +508,7 @@ const std::string kDropSchema = "`notifications_by_priority.fk_notifications_by_priority_priority1_idx`; " "DROP TABLE IF EXISTS `notifications_by_priority`; " "DROP TABLE IF EXISTS `hmi_level`; " + "DROP TABLE IF EXISTS `hybrid_app_preference`; " "DROP TABLE IF EXISTS `priority`; " "DROP TABLE IF EXISTS `functional_group`; " "DROP TABLE IF EXISTS `module_config`; " @@ -578,8 +596,10 @@ const std::string kInsertRpcWithParameter = const std::string kInsertApplication = "INSERT OR IGNORE INTO `application` (`id`, `priority_value`, " - "`is_revoked`, `memory_kb`," - " `heart_beat_timeout_ms`, `certificate`) VALUES (?,?,?,?,?,?)"; + "`is_revoked`, `memory_kb`, `heart_beat_timeout_ms`, `certificate`, " + "`hybrid_app_preference_value`, `endpoint`, `enabled`, `auth_token`, " + "`cloud_transport_type`) VALUES " + "(?,?,?,?,?,?,?,?,?,?,?)"; const std::string kInsertAppGroup = "INSERT INTO `app_group` (`application_id`, `functional_group_id`)" @@ -688,7 +708,8 @@ const std::string kSelectUserMsgsVersion = const std::string kSelectAppPolicies = "SELECT `id`, `priority_value`, `memory_kb`, " - " `heart_beat_timeout_ms`, `certificate` FROM `application`"; + " `heart_beat_timeout_ms`, `certificate`, `hybrid_app_preference_value`, " + " `endpoint`, `enabled`, `cloud_transport_type` FROM `application`"; const std::string kCollectFriendlyMsg = "SELECT * FROM `message`"; @@ -785,15 +806,19 @@ const std::string kDeleteAppGroupByApplicationId = const std::string kInsertApplicationFull = "INSERT OR IGNORE INTO `application` (`id`, `keep_context`, `steal_focus`, " - " `default_hmi`, `priority_value`, `is_revoked`, `is_default`, " - "`is_predata`, " - " `memory_kb`, `heart_beat_timeout_ms`, `certificate`) " - " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + " `default_hmi`, `priority_value`, `is_revoked`, `is_default`, " + " `is_predata`, `memory_kb`, `heart_beat_timeout_ms`, " + " `certificate`, `hybrid_app_preference_value`, `endpoint`, `enabled`, " + " `auth_token`, `cloud_transport_type`) " + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; const std::string kSelectApplicationFull = "SELECT `keep_context`, `steal_focus`, `default_hmi`, `priority_value`, " " `is_revoked`, `is_default`, `is_predata`, `memory_kb`," - " `heart_beat_timeout_ms`, `certificate` FROM `application` WHERE `id` = " + " `heart_beat_timeout_ms`, `certificate`, `hybrid_app_preference_value`, " + " `endpoint`, `enabled`, `auth_token`, `cloud_transport_type` " + "FROM `application` " + "WHERE `id` = " "?"; const std::string kSelectDBVersion = diff --git a/src/components/policy/policy_regular/src/sql_pt_representation.cc b/src/components/policy/policy_regular/src/sql_pt_representation.cc index 75f8be74eb..9282caf535 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -716,12 +716,24 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection( params.priority = priority; *params.memory_kb = query.GetInteger(2); - *params.heart_beat_timeout_ms = query.GetUInteger(3); - if (!query.IsNull(3)) { + if (!query.IsNull(4)) { *params.certificate = query.GetString(4); } + // Read cloud app properties + policy_table::HybridAppPreference hap; + bool valid = policy_table::EnumFromJsonString(query.GetString(5), &hap); + if (valid) { + *params.hybrid_app_preference = hap; + } + *params.endpoint = query.GetString(6); + if (!query.IsNull(7)) { + *params.enabled = query.GetBoolean(7); + } + *params.auth_token = query.GetString(8); + *params.cloud_transport_type = query.GetString(9); + const auto& gather_app_id = ((*policies).apps[app_id].is_string()) ? (*policies).apps[app_id].get_string() : app_id; @@ -984,6 +996,22 @@ bool SQLPTRepresentation::SaveSpecificAppPolicy( app.second.certificate.is_initialized() ? app_query.Bind(5, *app.second.certificate) : app_query.Bind(5); + app.second.hybrid_app_preference.is_initialized() + ? app_query.Bind(6, + std::string(policy_table::EnumToJsonString( + *app.second.hybrid_app_preference))) + : app_query.Bind(6); + app.second.endpoint.is_initialized() ? app_query.Bind(7, *app.second.endpoint) + : app_query.Bind(7); + app.second.enabled.is_initialized() ? app_query.Bind(8, *app.second.enabled) + : app_query.Bind(8); + app.second.auth_token.is_initialized() + ? app_query.Bind(9, *app.second.auth_token) + : app_query.Bind(9); + app.second.cloud_transport_type.is_initialized() + ? app_query.Bind(10, *app.second.cloud_transport_type) + : app_query.Bind(10); + if (!app_query.Exec() || !app_query.Reset()) { LOG4CXX_WARN(logger_, "Incorrect insert into application."); return false; @@ -2084,6 +2112,17 @@ bool SQLPTRepresentation::CopyApplication(const std::string& source, query.Bind(9, source_app.GetInteger(8)); source_app.IsNull(9) ? query.Bind(10) : query.Bind(10, source_app.GetString(9)); + source_app.IsNull(10) ? query.Bind(11) + : query.Bind(11, source_app.GetString(10)); + source_app.IsNull(11) ? query.Bind(12) + : query.Bind(12, source_app.GetString(11)); + source_app.IsNull(12) ? query.Bind(13) + : query.Bind(13, source_app.GetBoolean(12)); + source_app.IsNull(13) ? query.Bind(14) + : query.Bind(14, source_app.GetString(13)); + source_app.IsNull(14) ? query.Bind(15) + : query.Bind(15, source_app.GetString(14)); + if (!query.Exec()) { LOG4CXX_WARN(logger_, "Failed inserting into application."); return false; diff --git a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc index 7d192515dc..030dc374dd 100644 --- a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc +++ b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc @@ -426,8 +426,8 @@ TEST_F(SQLPTRepresentationTest, ASSERT_TRUE(reps->RefreshDB()); // Check PT structure destroyed and tables number is 0 - // There are 29 tables in the database, now. - const int32_t total_tables_number = 29; + // There are 30 tables in the database, now. + const int32_t total_tables_number = 30; ASSERT_EQ(total_tables_number, dbms->FetchOneInt(query_select)); const char* query_select_count_of_iap_buffer_full = "SELECT `count_of_iap_buffer_full` FROM `usage_and_error_count`"; -- cgit v1.2.1 From 9018590ff13671993ea10479cc4d9fe2fbbe7d9a Mon Sep 17 00:00:00 2001 From: jacobkeeler Date: Fri, 2 Nov 2018 14:20:45 -0400 Subject: Add cloud app parameters to external policies --- .../policy/policy_external/policy/policy_manager.h | 52 +++++++++++++++ .../policy_external/policy/mock_cache_manager.h | 17 +++++ .../policy_external/policy/mock_policy_manager.h | 17 +++++ .../policy_external/include/policy/cache_manager.h | 51 +++++++++++++++ .../include/policy/cache_manager_interface.h | 52 +++++++++++++++ .../include/policy/policy_manager_impl.h | 52 +++++++++++++++ .../include/policy/policy_table/enums.h | 10 +++ .../include/policy/policy_table/types.h | 7 ++ .../include/policy/policy_table_interface_ext.xml | 15 ++++- .../policy/policy_external/src/cache_manager.cc | 75 ++++++++++++++++++++++ .../policy_external/src/policy_manager_impl.cc | 34 ++++++++++ .../policy_external/src/policy_table/enums.cc | 33 ++++++++++ .../policy_external/src/policy_table/types.cc | 75 +++++++++++++++++++++- .../policy_external/src/sql_pt_ext_queries.cc | 10 ++- .../src/sql_pt_ext_representation.cc | 34 ++++++++++ .../policy/policy_external/src/sql_pt_queries.cc | 42 +++++++++--- .../policy_external/src/sql_pt_representation.cc | 47 ++++++++++++++ .../test/sql_pt_representation_test.cc | 4 +- 18 files changed, 612 insertions(+), 15 deletions(-) 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 57f6d2f802..2ea8ef08f1 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -521,6 +521,58 @@ class PolicyManager : public usage_statistics::StatisticsManager { * @return vehicle information */ virtual const VehicleInfo GetVehicleInfo() const = 0; + + /** + * @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 + * 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 + * 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& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const = 0; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + virtual void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) = 0; + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + virtual void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) = 0; + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + virtual void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type) = 0; + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + virtual void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) = 0; /** * @brief Gets meta information 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 a4d50d7cc2..ecbd8c6cd6 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 @@ -76,6 +76,23 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_METHOD1(SecondsBetweenRetries, bool(std::vector& seconds)); MOCK_CONST_METHOD1(IsDeviceConsentCached, bool(const std::string& device_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const VehicleInfo()); + MOCK_CONST_METHOD5(GetCloudAppParameters, + const bool(const std::string& policy_app_id, + std::string& endpoint, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD2(SetCloudAppEnabled, + void(const std::string& policy_app_id, const bool enabled)); + MOCK_METHOD2(SetAppAuthToken, + void(const std::string& policy_app_id, + const std::string& auth_token)); + MOCK_METHOD2(SetAppCloudTransportType, + void(const std::string& policy_app_id, + const std::string& cloud_transport_type)); + MOCK_METHOD2(SetHybridAppPreference, + void(const std::string& policy_app_id, + const std::string& hybrid_app_preference)); MOCK_CONST_METHOD1(GetDeviceConsent, DeviceConsent(const std::string& device_id)); MOCK_METHOD2(SetDeviceConsent, 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 aeabf8fdcb..f58ed10934 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 @@ -184,6 +184,23 @@ class MockPolicyManager : public PolicyManager { GetAppRequestTypes, const std::vector(const std::string policy_app_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); + MOCK_CONST_METHOD5(GetCloudAppParameters, + const bool(const std::string& policy_app_id, + std::string& endpoint, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD2(SetCloudAppEnabled, + void(const std::string& policy_app_id, const bool enabled)); + MOCK_METHOD2(SetAppAuthToken, + void(const std::string& policy_app_id, + const std::string& auth_token)); + MOCK_METHOD2(SetAppCloudTransportType, + void(const std::string& policy_app_id, + const std::string& cloud_transport_type)); + MOCK_METHOD2(SetHybridAppPreference, + void(const std::string& policy_app_id, + const std::string& hybrid_app_preference)); MOCK_CONST_METHOD0(GetMetaInfo, const policy::MetaInfo()); MOCK_CONST_METHOD0(RetrieveCertificate, std::string()); MOCK_CONST_METHOD0(HasCertificate, bool()); 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 d30e7cea24..d6eeb0457b 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -158,6 +158,57 @@ class CacheManager : public CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const; + /** + * @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 + * 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 + * 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& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + virtual void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled); + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + virtual void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token); + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + virtual void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type); + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + virtual void SetHybridAppPreference(const std::string& policy_app_id, + const std::string& hybrid_app_preference); + /** * @brief Allows to update 'vin' field in module_meta table. * 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 bb9ce14c7f..0c094d2edb 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 @@ -165,6 +165,58 @@ class CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const = 0; + /** + * @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 + * 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 + * 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& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const = 0; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + virtual void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) = 0; + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + virtual void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) = 0; + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + virtual void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type) = 0; + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + virtual void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) = 0; + /** * @brief Allows to update 'vin' field in module_meta table. * 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 3837dda1fa..f9648f803c 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 @@ -569,6 +569,58 @@ class PolicyManagerImpl : public PolicyManager { * @return vehicle information */ const VehicleInfo GetVehicleInfo() const OVERRIDE; + + /** + * @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 + * 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 + * 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& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const OVERRIDE; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) OVERRIDE; + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) OVERRIDE; + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type) OVERRIDE; + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) OVERRIDE; /** * @brief OnAppRegisteredOnMobile allows to handle event when application were diff --git a/src/components/policy/policy_external/include/policy/policy_table/enums.h b/src/components/policy/policy_external/include/policy/policy_table/enums.h index 34864c5602..f5b85f0a4d 100644 --- a/src/components/policy/policy_external/include/policy/policy_table/enums.h +++ b/src/components/policy/policy_external/include/policy/policy_table/enums.h @@ -181,6 +181,16 @@ bool IsValidEnum(ModuleType val); const char* EnumToJsonString(ModuleType val); bool EnumFromJsonString(const std::string& literal, ModuleType* result); +enum HybridAppPreference { + HAP_MOBILE, + HAP_CLOUD, + HAP_BOTH +}; +bool IsValidEnum(HybridAppPreference val); +const char* EnumToJsonString(HybridAppPreference val); +bool EnumFromJsonString(const std::string& literal, + HybridAppPreference* result); + /** * @brief Enumeration FunctionID. * diff --git a/src/components/policy/policy_external/include/policy/policy_table/types.h b/src/components/policy/policy_external/include/policy/policy_table/types.h index 68e29a97ee..f37531eb63 100644 --- a/src/components/policy/policy_external/include/policy/policy_table/types.h +++ b/src/components/policy/policy_external/include/policy/policy_table/types.h @@ -177,6 +177,13 @@ struct ApplicationParams : PolicyBase { Optional > memory_kb; Optional > heart_beat_timeout_ms; mutable Optional moduleType; + Optional > certificate; + // Cloud application params + Optional > hybrid_app_preference; + Optional > endpoint; + Optional enabled; + Optional > auth_token; + Optional > cloud_transport_type; public: ApplicationParams(); diff --git a/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml b/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml index 26af165506..f5f0a7dedc 100644 --- a/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml +++ b/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml @@ -70,6 +70,12 @@ + + + + + + @@ -92,8 +98,15 @@ - + + + + + policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::const_iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + auto app_policy = (*policy_iter).second; + endpoint = app_policy.endpoint.is_initialized() ? *app_policy.endpoint + : 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(); + 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; + } + return false; +} + +void CacheManager::SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) { + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + *(*policy_iter).second.enabled = enabled; + } +} + +void CacheManager::SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) { + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + *(*policy_iter).second.auth_token = auth_token; + } +} + +void CacheManager::SetAppCloudTransportType( + const std::string& policy_app_id, const std::string& cloud_transport_type) { + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + *(*policy_iter).second.cloud_transport_type = cloud_transport_type; + } +} + +void CacheManager::SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) { + policy_table::HybridAppPreference value; + bool valid = EnumFromJsonString(hybrid_app_preference, &value); + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter && valid) { + *(*policy_iter).second.hybrid_app_preference = value; + } +} + std::vector CacheManager::GetUserFriendlyMsg( const std::vector& msg_codes, const std::string& language, 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 a603f122e2..e7538fa1b0 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -725,6 +725,40 @@ const VehicleInfo PolicyManagerImpl::GetVehicleInfo() const { return cache_->GetVehicleInfo(); } +const bool PolicyManagerImpl::GetCloudAppParameters( + const std::string& policy_app_id, + std::string& endpoint, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const { + return cache_->GetCloudAppParameters(policy_app_id, + endpoint, + auth_token, + cloud_transport_type, + hybrid_app_preference); +} + +void PolicyManagerImpl::SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) { + cache_->SetCloudAppEnabled(policy_app_id, enabled); +} + +void PolicyManagerImpl::SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) { + cache_->SetAppAuthToken(policy_app_id, auth_token); +} + +void PolicyManagerImpl::SetAppCloudTransportType( + const std::string& policy_app_id, const std::string& cloud_transport_type) { + cache_->SetAppCloudTransportType(policy_app_id, cloud_transport_type); +} + +void PolicyManagerImpl::SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) { + cache_->SetHybridAppPreference(policy_app_id, hybrid_app_preference); +} + void PolicyManagerImpl::CheckPermissions(const PTString& app_id, const PTString& hmi_level, const PTString& rpc, diff --git a/src/components/policy/policy_external/src/policy_table/enums.cc b/src/components/policy/policy_external/src/policy_table/enums.cc index 27db505e3f..d8e73670b2 100644 --- a/src/components/policy/policy_external/src/policy_table/enums.cc +++ b/src/components/policy/policy_external/src/policy_table/enums.cc @@ -1,4 +1,5 @@ #include "policy/policy_table/enums.h" +#include namespace rpc { namespace policy_table_interface_base { @@ -840,6 +841,38 @@ bool EnumFromJsonString(const std::string& literal, ModuleType* result) { } } +bool IsValidEnum(HybridAppPreference val) { + return strlen(EnumToJsonString(val)) > 0; +} + +const char* EnumToJsonString(HybridAppPreference val) { + switch (val) { + case HAP_MOBILE: + return "MOBILE"; + case HAP_CLOUD: + return "CLOUD"; + case HAP_BOTH: + return "BOTH"; + default: + return ""; + } +} + +bool EnumFromJsonString(const std::string& literal, + HybridAppPreference* result) { + if ("MOBILE" == literal) { + *result = HAP_MOBILE; + return true; + } else if ("CLOUD" == literal) { + *result = HAP_CLOUD; + return true; + } else if ("BOTH" == literal) { + *result = HAP_BOTH; + return true; + } + return false; +} + bool EnumFromJsonString(const std::string& literal, FunctionID* result) { if ("RegisterAppInterface" == literal) { *result = RegisterAppInterfaceID; diff --git a/src/components/policy/policy_external/src/policy_table/types.cc b/src/components/policy/policy_external/src/policy_table/types.cc index 5922a020e6..4867eef281 100644 --- a/src/components/policy/policy_external/src/policy_table/types.cc +++ b/src/components/policy/policy_external/src/policy_table/types.cc @@ -241,7 +241,13 @@ ApplicationParams::ApplicationParams(const Json::Value* value__) , RequestSubType(impl::ValueMember(value__, "RequestSubType")) , memory_kb(impl::ValueMember(value__, "memory_kb"), 0) , heart_beat_timeout_ms(impl::ValueMember(value__, "heart_beat_timeout_ms")) - , moduleType(impl::ValueMember(value__, "moduleType")) {} + , moduleType(impl::ValueMember(value__, "moduleType")) + , certificate(impl::ValueMember(value__, "certificate"), "not_specified") + , hybrid_app_preference(impl::ValueMember(value__, "hybrid_app_preference")) + , endpoint(impl::ValueMember(value__, "endpoint")) + , enabled(impl::ValueMember(value__, "enabled")) + , auth_token(impl::ValueMember(value__, "auth_token")) + , cloud_transport_type(impl::ValueMember(value__, "cloud_transport_type")) {} Json::Value ApplicationParams::ToJsonValue() const { Json::Value result__(PolicyBase::ToJsonValue()); @@ -253,6 +259,13 @@ Json::Value ApplicationParams::ToJsonValue() const { impl::WriteJsonField( "heart_beat_timeout_ms", heart_beat_timeout_ms, &result__); impl::WriteJsonField("moduleType", moduleType, &result__); + impl::WriteJsonField("certificate", certificate, &result__); + impl::WriteJsonField( + "hybrid_app_preference", hybrid_app_preference, &result__); + impl::WriteJsonField("endpoint", endpoint, &result__); + impl::WriteJsonField("enabled", enabled, &result__); + impl::WriteJsonField("auth_token", auth_token, &result__); + impl::WriteJsonField("cloud_transport_type", cloud_transport_type, &result__); return result__; } @@ -277,6 +290,24 @@ bool ApplicationParams::is_valid() const { if (!moduleType.is_valid()) { return false; } + if (!certificate.is_valid()) { + return false; + } + if (!endpoint.is_valid()) { + return false; + } + if (!enabled.is_valid()) { + return false; + } + if (!auth_token.is_valid()) { + return false; + } + if (!cloud_transport_type.is_valid()) { + return false; + } + if (!hybrid_app_preference.is_valid()) { + return false; + } return Validate(); } @@ -309,6 +340,24 @@ bool ApplicationParams::struct_empty() const { if (moduleType.is_initialized()) { return false; } + if (certificate.is_initialized()) { + return false; + } + if (endpoint.is_initialized()) { + return false; + } + if (enabled.is_initialized()) { + return false; + } + if (auth_token.is_initialized()) { + return false; + } + if (cloud_transport_type.is_initialized()) { + return false; + } + if (hybrid_app_preference.is_initialized()) { + return false; + } return true; } @@ -357,6 +406,25 @@ void ApplicationParams::ReportErrors(rpc::ValidationReport* report__) const { if (!moduleType.is_valid()) { moduleType.ReportErrors(&report__->ReportSubobject("moduleType")); } + if (!certificate.is_valid()) { + certificate.ReportErrors(&report__->ReportSubobject("certificate")); + } + if (!endpoint.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("endpoint")); + } + if (!enabled.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("enabled")); + } + if (!auth_token.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("auth_token")); + } + if (!cloud_transport_type.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("cloud_transport_type")); + } + if (!hybrid_app_preference.is_valid()) { + moduleType.ReportErrors( + &report__->ReportSubobject("hybrid_app_preference")); + } } void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) { @@ -367,6 +435,11 @@ void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) { memory_kb.SetPolicyTableType(pt_type); heart_beat_timeout_ms.SetPolicyTableType(pt_type); moduleType.SetPolicyTableType(pt_type); + certificate.SetPolicyTableType(pt_type); + endpoint.SetPolicyTableType(pt_type); + enabled.SetPolicyTableType(pt_type); + cloud_transport_type.SetPolicyTableType(pt_type); + hybrid_app_preference.SetPolicyTableType(pt_type); } // RpcParameters methods diff --git a/src/components/policy/policy_external/src/sql_pt_ext_queries.cc b/src/components/policy/policy_external/src/sql_pt_ext_queries.cc index afb1180692..f7e1acb59a 100644 --- a/src/components/policy/policy_external/src/sql_pt_ext_queries.cc +++ b/src/components/policy/policy_external/src/sql_pt_ext_queries.cc @@ -205,7 +205,10 @@ const std::string kUpdateGroupPermissions = const std::string kInsertApplication = "INSERT OR IGNORE INTO `application`(`id`, `keep_context`, `steal_focus`, " " `default_hmi`, `priority_value`, `is_revoked`, `memory_kb`, " - " `heart_beat_timeout_ms`) VALUES( ?, ?, ?, ?, ?, ?, ?, ?) "; + " `heart_beat_timeout_ms`, `certificate`, `hybrid_app_preference_value`, " + " `endpoint`, `enabled`, `auth_token`, " + " `cloud_transport_type`) VALUES " + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; const std::string kCollectFriendlyMsg = "SELECT * FROM `message`"; @@ -232,8 +235,9 @@ const std::string kSelectPreconsentedGroupsId = const std::string kSelectAppPolicies = "SELECT `id`, `priority_value`, `default_hmi`, `keep_context`, " - "`steal_focus`, " - " `memory_kb`, `heart_beat_timeout_ms` FROM `application`"; + " `steal_focus`, `memory_kb`, `heart_beat_timeout_ms`, `certificate`, " + " `hybrid_app_preference_value`, `endpoint`, `enabled`, " + " `cloud_transport_type` FROM `application`"; const std::string kSelectFunctionalGroupNames = "SELECT `id`, `user_consent_prompt`, `name`" diff --git a/src/components/policy/policy_external/src/sql_pt_ext_representation.cc b/src/components/policy/policy_external/src/sql_pt_ext_representation.cc index a43b22a3b8..6a40e6d135 100644 --- a/src/components/policy/policy_external/src/sql_pt_ext_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_ext_representation.cc @@ -752,6 +752,24 @@ bool SQLPTExtRepresentation::SaveSpecificAppPolicy( app_query.Bind(5, app.second.is_null()); app_query.Bind(6, *app.second.memory_kb); app_query.Bind(7, static_cast(*app.second.heart_beat_timeout_ms)); + app.second.certificate.is_initialized() + ? app_query.Bind(8, *app.second.certificate) + : app_query.Bind(8); + app.second.hybrid_app_preference.is_initialized() + ? app_query.Bind(9, + std::string(policy_table::EnumToJsonString( + *app.second.hybrid_app_preference))) + : app_query.Bind(9); + app.second.endpoint.is_initialized() ? app_query.Bind(10, *app.second.endpoint) + : app_query.Bind(10); + app.second.enabled.is_initialized() ? app_query.Bind(11, *app.second.enabled) + : app_query.Bind(11); + app.second.auth_token.is_initialized() + ? app_query.Bind(12, *app.second.auth_token) + : app_query.Bind(12); + app.second.cloud_transport_type.is_initialized() + ? app_query.Bind(13, *app.second.cloud_transport_type) + : app_query.Bind(13); if (!app_query.Exec() || !app_query.Reset()) { LOG4CXX_WARN(logger_, "Incorrect insert into application."); @@ -873,6 +891,22 @@ bool SQLPTExtRepresentation::GatherApplicationPoliciesSection( params.steal_focus = query.GetBoolean(4); *params.memory_kb = query.GetInteger(5); *params.heart_beat_timeout_ms = query.GetUInteger(6); + if (!query.IsNull(7)) { + *params.certificate = query.GetString(7); + } + + // Read cloud app properties + policy_table::HybridAppPreference hap; + bool valid = policy_table::EnumFromJsonString(query.GetString(8), &hap); + if (valid) { + *params.hybrid_app_preference = hap; + } + *params.endpoint = query.GetString(9); + if (!query.IsNull(10)) { + *params.enabled = query.GetBoolean(10); + } + *params.auth_token = query.GetString(11); + *params.cloud_transport_type = query.GetString(12); const auto& gather_app_id = ((*policies).apps[app_id].is_string()) ? (*policies).apps[app_id].get_string() diff --git a/src/components/policy/policy_external/src/sql_pt_queries.cc b/src/components/policy/policy_external/src/sql_pt_queries.cc index 97d75731ea..8c4227963a 100644 --- a/src/components/policy/policy_external/src/sql_pt_queries.cc +++ b/src/components/policy/policy_external/src/sql_pt_queries.cc @@ -98,6 +98,9 @@ const std::string kCreateSchema = "CREATE TABLE IF NOT EXISTS `hmi_level`( " " `value` VARCHAR(45) PRIMARY KEY NOT NULL " "); " + "CREATE TABLE IF NOT EXISTS `hybrid_app_preference`( " + " `value` VARCHAR(45) PRIMARY KEY NOT NULL " + "); " "CREATE TABLE IF NOT EXISTS `notifications_by_priority`( " " `priority_value` VARCHAR(45) PRIMARY KEY NOT NULL, " " `value` INTEGER NOT NULL, " @@ -147,6 +150,12 @@ const std::string kCreateSchema = " `is_predata` BOOLEAN, " " `memory_kb` INTEGER NOT NULL, " " `heart_beat_timeout_ms` INTEGER NOT NULL, " + " `certificate` VARCHAR(65535), " + " `hybrid_app_preference_value` VARCHAR(255), " + " `endpoint` VARCHAR(255), " + " `enabled` BOOLEAN, " + " `auth_token` VARCHAR(65535), " + " `cloud_transport_type` VARCHAR(255), " " `remote_control_denied` BOOLEAN NOT NULL DEFAULT 0, " " CONSTRAINT `fk_application_hmi_level1` " " FOREIGN KEY(`default_hmi`) " @@ -154,11 +163,17 @@ const std::string kCreateSchema = " CONSTRAINT `fk_application_priorities1` " " FOREIGN KEY(`priority_value`) " " REFERENCES `priority`(`value`) " + " CONSTRAINT `fk_application_hybrid_app_preference1` " + " FOREIGN KEY(`hybrid_app_preference_value`) " + " REFERENCES `hybrid_app_preference`(`value`) " "); " "CREATE INDEX IF NOT EXISTS `application.fk_application_hmi_level1_idx` " " ON `application`(`default_hmi`); " "CREATE INDEX IF NOT EXISTS `application.fk_application_priorities1_idx` " " ON `application`(`priority_value`); " + "CREATE INDEX IF NOT EXISTS " + "`application.fk_application_hybrid_app_preference1` " + " ON `application`(`hybrid_app_preference_value`); " "CREATE TABLE IF NOT EXISTS `app_group`( " " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, " " `functional_group_id` INTEGER NOT NULL, " @@ -430,6 +445,9 @@ const std::string kInsertInitData = "INSERT OR IGNORE INTO `hmi_level`(`value`) VALUES ('LIMITED'); " "INSERT OR IGNORE INTO `hmi_level`(`value`) VALUES ('BACKGROUND'); " "INSERT OR IGNORE INTO `hmi_level`(`value`) VALUES ('NONE'); " + "INSERT OR IGNORE INTO `hybrid_app_preference`(`value`) VALUES ('MOBILE'); " + "INSERT OR IGNORE INTO `hybrid_app_preference`(`value`) VALUES ('CLOUD'); " + "INSERT OR IGNORE INTO `hybrid_app_preference`(`value`) VALUES ('BOTH'); " "INSERT OR IGNORE INTO `version` (`number`) VALUES('0'); " "INSERT OR IGNORE INTO `_internal_data` (`db_version_hash`) VALUES(0); " ""; @@ -532,6 +550,7 @@ const std::string kDropSchema = "`notifications_by_priority.fk_notifications_by_priority_priority1_idx`; " "DROP TABLE IF EXISTS `notifications_by_priority`; " "DROP TABLE IF EXISTS `hmi_level`; " + "DROP TABLE IF EXISTS `hybrid_app_preference`; " "DROP TABLE IF EXISTS `priority`; " "DROP TABLE IF EXISTS `functional_group`; " "DROP TABLE IF EXISTS `module_config`; " @@ -628,8 +647,10 @@ const std::string kInsertRpcWithParameter = const std::string kInsertApplication = "INSERT OR IGNORE INTO `application` (`id`, `priority_value`, " - "`is_revoked`, `memory_kb`," - " `heart_beat_timeout_ms`) VALUES (?,?,?,?,?)"; + "`is_revoked`, `memory_kb`, `heart_beat_timeout_ms`, `certificate`, " + "`hybrid_app_preference_value`, `endpoint`, `enabled`, `auth_token`, " + "`cloud_transport_type`) VALUES " + "(?,?,?,?,?,?,?,?,?,?,?)"; const std::string kInsertAppGroup = "INSERT INTO `app_group` (`application_id`, `functional_group_id`)" @@ -752,7 +773,8 @@ const std::string kSelectUserMsgsVersion = const std::string kSelectAppPolicies = "SELECT `id`, `priority_value`, `memory_kb`, " - " `heart_beat_timeout_ms` FROM `application`"; + " `heart_beat_timeout_ms`, `certificate`, `hybrid_app_preference_value`, " + " `endpoint`, `enabled`, `cloud_transport_type` FROM `application`"; const std::string kCollectFriendlyMsg = "SELECT * FROM `message`"; @@ -849,15 +871,19 @@ const std::string kDeleteAppGroupByApplicationId = const std::string kInsertApplicationFull = "INSERT OR IGNORE INTO `application` (`id`, `keep_context`, `steal_focus`, " - " `default_hmi`, `priority_value`, `is_revoked`, `is_default`, " - "`is_predata`, " - " `memory_kb`, `heart_beat_timeout_ms`) " - " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + " `default_hmi`, `priority_value`, `is_revoked`, `is_default`, " + " `is_predata`, `memory_kb`, `heart_beat_timeout_ms`, " + " `certificate`, `hybrid_app_preference_value`, `endpoint`, `enabled`, " + " `auth_token`, `cloud_transport_type`) " + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; const std::string kSelectApplicationFull = "SELECT `keep_context`, `steal_focus`, `default_hmi`, `priority_value`, " " `is_revoked`, `is_default`, `is_predata`, `memory_kb`," - " `heart_beat_timeout_ms` FROM `application` WHERE `id` = ?"; + " `heart_beat_timeout_ms`, `certificate`, `hybrid_app_preference_value`, " + " `endpoint`, `enabled`, `auth_token`, `cloud_transport_type` " + "FROM `application` " + "WHERE `id` = ?"; const std::string kSelectDBVersion = "SELECT `db_version_hash` from `_internal_data`"; diff --git a/src/components/policy/policy_external/src/sql_pt_representation.cc b/src/components/policy/policy_external/src/sql_pt_representation.cc index c8b367c8ec..b794d4c3a6 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -761,6 +761,23 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection( *params.memory_kb = query.GetInteger(2); *params.heart_beat_timeout_ms = query.GetUInteger(3); + if (!query.IsNull(4)) { + *params.certificate = query.GetString(4); + } + + // Read cloud app properties + policy_table::HybridAppPreference hap; + bool valid = policy_table::EnumFromJsonString(query.GetString(5), &hap); + if (valid) { + *params.hybrid_app_preference = hap; + } + *params.endpoint = query.GetString(6); + if (!query.IsNull(7)) { + *params.enabled = query.GetBoolean(7); + } + *params.auth_token = query.GetString(8); + *params.cloud_transport_type = query.GetString(9); + const auto& gather_app_id = ((*policies).apps[app_id].is_string()) ? (*policies).apps[app_id].get_string() : app_id; @@ -1035,6 +1052,24 @@ bool SQLPTRepresentation::SaveSpecificAppPolicy( app_query.Bind(2, app.second.is_null()); app_query.Bind(3, *app.second.memory_kb); app_query.Bind(4, static_cast(*app.second.heart_beat_timeout_ms)); + app.second.certificate.is_initialized() + ? app_query.Bind(5, *app.second.certificate) + : app_query.Bind(5); + app.second.hybrid_app_preference.is_initialized() + ? app_query.Bind(6, + std::string(policy_table::EnumToJsonString( + *app.second.hybrid_app_preference))) + : app_query.Bind(6); + app.second.endpoint.is_initialized() ? app_query.Bind(7, *app.second.endpoint) + : app_query.Bind(7); + app.second.enabled.is_initialized() ? app_query.Bind(8, *app.second.enabled) + : app_query.Bind(8); + app.second.auth_token.is_initialized() + ? app_query.Bind(9, *app.second.auth_token) + : app_query.Bind(9); + app.second.cloud_transport_type.is_initialized() + ? app_query.Bind(10, *app.second.cloud_transport_type) + : app_query.Bind(10); if (!app_query.Exec() || !app_query.Reset()) { LOG4CXX_WARN(logger_, "Incorrect insert into application."); @@ -2125,6 +2160,18 @@ bool SQLPTRepresentation::CopyApplication(const std::string& source, : query.Bind(7, source_app.GetBoolean(6)); query.Bind(8, source_app.GetInteger(7)); query.Bind(9, source_app.GetInteger(8)); + source_app.IsNull(9) ? query.Bind(10) + : query.Bind(10, source_app.GetString(9)); + source_app.IsNull(10) ? query.Bind(11) + : query.Bind(11, source_app.GetString(10)); + source_app.IsNull(11) ? query.Bind(12) + : query.Bind(12, source_app.GetString(11)); + source_app.IsNull(12) ? query.Bind(13) + : query.Bind(13, source_app.GetBoolean(12)); + source_app.IsNull(13) ? query.Bind(14) + : query.Bind(14, source_app.GetString(13)); + source_app.IsNull(14) ? query.Bind(15) + : query.Bind(15, source_app.GetString(14)); if (!query.Exec()) { LOG4CXX_WARN(logger_, "Failed inserting into application."); diff --git a/src/components/policy/policy_external/test/sql_pt_representation_test.cc b/src/components/policy/policy_external/test/sql_pt_representation_test.cc index b0f340b0f2..fddc5e631e 100644 --- a/src/components/policy/policy_external/test/sql_pt_representation_test.cc +++ b/src/components/policy/policy_external/test/sql_pt_representation_test.cc @@ -406,8 +406,8 @@ TEST_F(SQLPTRepresentationTest, query.Prepare(query_select); query.Next(); - // 33 - is current total tables number created by schema - const int policy_tables_number = 33; + // 34 - is current total tables number created by schema + const int policy_tables_number = 34; ASSERT_EQ(policy_tables_number, query.GetInteger(0)); const std::string query_select_count_of_iap_buffer_full = -- cgit v1.2.1 From 32b6a07f53e87bc71466656155e8896eb747b277 Mon Sep 17 00:00:00 2001 From: jacobkeeler Date: Mon, 5 Nov 2018 17:56:55 -0500 Subject: Fix style, add certificate, and add GetEnabledCloudApps --- .../application_manager/policies/policy_handler.h | 44 +++++++++++++++++----- .../src/policies/policy_handler.cc | 36 ++++++++++++------ .../policies/policy_handler_interface.h | 15 +++++++- .../policy/policy_external/policy/policy_manager.h | 13 ++++++- .../policy/policy_regular/policy/policy_manager.h | 15 +++++++- .../policies/mock_policy_handler_interface.h | 5 ++- .../policy_external/policy/mock_cache_manager.h | 5 ++- .../policy_external/policy/mock_policy_manager.h | 5 ++- .../policy_regular/policy/mock_cache_manager.h | 15 +++++--- .../policy_regular/policy/mock_policy_manager.h | 5 ++- .../policy_external/include/policy/cache_manager.h | 11 ++++++ .../include/policy/cache_manager_interface.h | 11 ++++++ .../include/policy/policy_manager_impl.h | 12 +++++- .../include/policy/policy_table/enums.h | 6 +-- .../policy/policy_external/src/cache_manager.cc | 18 +++++++++ .../policy_external/src/policy_manager_impl.cc | 7 ++++ .../policy_external/src/policy_table/types.cc | 3 +- .../src/sql_pt_ext_representation.cc | 5 ++- .../policy_regular/include/policy/cache_manager.h | 11 ++++++ .../include/policy/cache_manager_interface.h | 16 +++++++- .../include/policy/policy_manager_impl.h | 11 +++++- .../policy/policy_regular/src/cache_manager.cc | 18 +++++++++ .../policy_regular/src/policy_manager_impl.cc | 15 ++++++-- 23 files changed, 251 insertions(+), 51 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 3af03bf28b..648e856456 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 @@ -398,6 +398,13 @@ class PolicyHandler : public PolicyHandlerInterface, custom_str::CustomString GetAppName( const std::string& policy_app_id) OVERRIDE; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled cloud + * application + */ + void GetEnabledCloudApps(std::vector& enabled_apps) const OVERRIDE; + /** * @brief Checks if a given application is an enabled cloud application * @param policy_app_id Unique application id @@ -407,17 +414,36 @@ class PolicyHandler : public PolicyHandlerInterface, const bool CheckCloudAppEnabled( const std::string& policy_app_id) const OVERRIDE; - /**plzfix - * @brief Checks if certain request type is allowed for application + /** + * @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 - * @return true, if allowed, otherwise - false - */ - const bool GetCloudAppParameters(const std::string& policy_app_id, - std::string& endpoint, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const OVERRIDE; + * @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 + * @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 + * 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; + /** + * @brief Callback for when a SetCloudAppProperties message is received from a + * mobile app + * @param message The SetCloudAppProperties message + */ void OnSetCloudAppProperties( const smart_objects::SmartObject& message) OVERRIDE; diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index c73e35768e..cc62d9f6f8 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1845,28 +1845,39 @@ bool PolicyHandler::CheckSystemAction( return false; } +void PolicyHandler::GetEnabledCloudApps( + std::vector& enabled_apps) const { + POLICY_LIB_CHECK_VOID(); + policy_manager_->GetEnabledCloudApps(enabled_apps); +} + const bool PolicyHandler::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 { POLICY_LIB_CHECK(false); return policy_manager_->GetCloudAppParameters(policy_app_id, endpoint, + certificate, auth_token, cloud_transport_type, hybrid_app_preference); } -const bool PolicyHandler::CheckCloudAppEnabled(const std::string& policy_app_id) const { +const bool PolicyHandler::CheckCloudAppEnabled( + const std::string& policy_app_id) const { POLICY_LIB_CHECK(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); @@ -1876,34 +1887,35 @@ void PolicyHandler::OnSetCloudAppProperties( const smart_objects::SmartObject& message) { POLICY_LIB_CHECK_VOID(); if (!message.keyExists(strings::msg_params)) { - LOG4CXX_ERROR( - logger_, - "Message does not contain mandatory section " << strings::msg_params); + LOG4CXX_ERROR(logger_, + "Message does not contain mandatory section " + << strings::msg_params); return; } const smart_objects::SmartObject& msg_params = message[strings::msg_params]; if (!msg_params.keyExists(strings::app_id)) { - LOG4CXX_ERROR( - logger_, - "Message does not contain mandatory parameter " << strings::app_id); + LOG4CXX_ERROR(logger_, + "Message does not contain mandatory parameter " + << strings::app_id); return; } std::string policy_app_id(msg_params[strings::app_id].asString()); if (msg_params.keyExists(strings::enabled)) { policy_manager_->SetCloudAppEnabled(policy_app_id, - msg_params[strings::enabled].asBool()); + msg_params[strings::enabled].asBool()); } if (msg_params.keyExists(strings::cloud_app_auth_token)) { - policy_manager_->SetAppAuthToken(policy_app_id, - msg_params[strings::cloud_app_auth_token].asString()); + policy_manager_->SetAppAuthToken( + policy_app_id, msg_params[strings::cloud_app_auth_token].asString()); } if (msg_params.keyExists(strings::cloud_transport_type)) { policy_manager_->SetAppCloudTransportType( policy_app_id, msg_params[strings::cloud_transport_type].asString()); } if (msg_params.keyExists(strings::hybrid_app_preference)) { - //const std::string hybrid_app_preference = EnumConversionHelper::EnumToString(msg_params[strings::hybrid_app_preference]); - //policy_manager_->SetHybridAppPreference( + // const std::string hybrid_app_preference = + // EnumConversionHelper::EnumToString(msg_params[strings::hybrid_app_preference]); + // policy_manager_->SetHybridAppPreference( // policy_app_id, hybrid_app_preference); } } 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 69433e6118..ddeb1da8f7 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -437,7 +437,15 @@ class PolicyHandlerInterface { * @return Structure with vehicle information */ virtual const VehicleInfo GetVehicleInfo() const = 0; - + + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const = 0; + /** * @brief Checks if a given application is an enabled cloud application * @param policy_app_id Unique application id @@ -453,6 +461,8 @@ class PolicyHandlerInterface { * @param policy_app_id Unique application id * @param endpoint Filled 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 * @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 @@ -464,6 +474,7 @@ class PolicyHandlerInterface { 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 = 0; @@ -475,7 +486,7 @@ class PolicyHandlerInterface { */ virtual void OnSetCloudAppProperties( const smart_objects::SmartObject& message) = 0; - + #ifdef EXTERNAL_PROPRIETARY_MODE /** * @brief Gets meta information 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 2ea8ef08f1..b0fac8eae9 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -521,13 +521,23 @@ class PolicyManager : public usage_statistics::StatisticsManager { * @return vehicle information */ virtual const VehicleInfo GetVehicleInfo() const = 0; - + + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const = 0; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -539,6 +549,7 @@ class PolicyManager : public usage_statistics::StatisticsManager { 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 = 0; 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 9c67e239b7..4a82c8620b 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -502,12 +502,22 @@ class PolicyManager : public usage_statistics::StatisticsManager { */ virtual const VehicleInfo GetVehicleInfo() const = 0; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const = 0; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -550,8 +560,9 @@ class PolicyManager : public usage_statistics::StatisticsManager { * should be used * @param hybrid_app_preference Hybrid app user preference */ - virtual void SetHybridAppPreference(const std::string& policy_app_id, - const std::string& hybrid_app_preference) = 0; + virtual void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) = 0; /** * @brief OnAppRegisteredOnMobile allows to handle event when application were 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 bd56d78128..cea36082c8 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 @@ -213,11 +213,14 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { GetAppRequestTypes, const std::vector(const std::string& policy_app_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector& enabled_apps)); MOCK_CONST_METHOD1(CheckCloudAppEnabled, const bool(const std::string& policy_app_id)); - MOCK_CONST_METHOD5(GetCloudAppParameters, + 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)); 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 ecbd8c6cd6..03e0882129 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 @@ -76,9 +76,12 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_METHOD1(SecondsBetweenRetries, bool(std::vector& seconds)); MOCK_CONST_METHOD1(IsDeviceConsentCached, bool(const std::string& device_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const VehicleInfo()); - MOCK_CONST_METHOD5(GetCloudAppParameters, + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector& 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)); 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 f58ed10934..70dab8e99a 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 @@ -184,9 +184,12 @@ class MockPolicyManager : public PolicyManager { GetAppRequestTypes, const std::vector(const std::string policy_app_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); - MOCK_CONST_METHOD5(GetCloudAppParameters, + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector& 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)); 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 745bcd2db5..7ac94d278d 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 @@ -63,12 +63,15 @@ class MockCacheManagerInterface : public CacheManagerInterface { MOCK_METHOD0(TimeoutResponse, int()); MOCK_METHOD1(SecondsBetweenRetries, bool(std::vector& seconds)); MOCK_CONST_METHOD0(GetVehicleInfo, const VehicleInfo()); - MOCK_CONST_METHOD5(GetCloudAppParameters, - const bool(const std::string& policy_app_id, - std::string& endpoint, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference)); + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector& 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_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 8867c3de80..7441701a34 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 @@ -181,9 +181,12 @@ class MockPolicyManager : public PolicyManager { GetAppRequestTypes, const std::vector(const std::string policy_app_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); - MOCK_CONST_METHOD5(GetCloudAppParameters, + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector& 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)); 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 d6eeb0457b..7660eb2df9 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -158,12 +158,22 @@ class CacheManager : public CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -175,6 +185,7 @@ class CacheManager : public CacheManagerInterface { 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; 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 0c094d2edb..75948e760a 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 @@ -165,12 +165,22 @@ class CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const = 0; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled cloud + * application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const = 0; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -182,6 +192,7 @@ class CacheManagerInterface { 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 = 0; 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 f9648f803c..3bdf75f19e 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 @@ -570,12 +570,21 @@ class PolicyManagerImpl : public PolicyManager { */ const VehicleInfo GetVehicleInfo() const OVERRIDE; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + void GetEnabledCloudApps(std::vector& enabled_apps) const OVERRIDE; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -587,6 +596,7 @@ class PolicyManagerImpl : public PolicyManager { 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; @@ -597,7 +607,7 @@ class PolicyManagerImpl : public PolicyManager { */ void SetCloudAppEnabled(const std::string& policy_app_id, const bool enabled) OVERRIDE; - + /** * @brief Set an app's auth token * @param auth_token Cloud app authentication token diff --git a/src/components/policy/policy_external/include/policy/policy_table/enums.h b/src/components/policy/policy_external/include/policy/policy_table/enums.h index f5b85f0a4d..c2148de3b6 100644 --- a/src/components/policy/policy_external/include/policy/policy_table/enums.h +++ b/src/components/policy/policy_external/include/policy/policy_table/enums.h @@ -181,11 +181,7 @@ bool IsValidEnum(ModuleType val); const char* EnumToJsonString(ModuleType val); bool EnumFromJsonString(const std::string& literal, ModuleType* result); -enum HybridAppPreference { - HAP_MOBILE, - HAP_CLOUD, - HAP_BOTH -}; +enum HybridAppPreference { HAP_MOBILE, HAP_CLOUD, HAP_BOTH }; bool IsValidEnum(HybridAppPreference val); const char* EnumToJsonString(HybridAppPreference val); bool EnumFromJsonString(const std::string& literal, diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index d6d5f6daa5..116b315755 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -1389,9 +1389,24 @@ const policy::VehicleInfo CacheManager::GetVehicleInfo() const { return vehicle_info; } +void CacheManager::GetEnabledCloudApps( + std::vector& enabled_apps) const { + const policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + for (policy_table::ApplicationPolicies::const_iterator it = policies.begin(); + it != policies.end(); + ++it) { + auto app_policy = (*it).second; + if (app_policy.enabled.is_initialized() && *app_policy.enabled) { + enabled_apps.push_back((*it).first); + } + } +} + const bool CacheManager::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 { @@ -1403,6 +1418,9 @@ 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() 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 e7538fa1b0..31cc212254 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -725,14 +725,21 @@ const VehicleInfo PolicyManagerImpl::GetVehicleInfo() const { return cache_->GetVehicleInfo(); } +void PolicyManagerImpl::GetEnabledCloudApps( + std::vector& enabled_apps) const { + cache_->GetEnabledCloudApps(enabled_apps); +} + const bool PolicyManagerImpl::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 { return cache_->GetCloudAppParameters(policy_app_id, endpoint, + certificate, auth_token, cloud_transport_type, hybrid_app_preference); diff --git a/src/components/policy/policy_external/src/policy_table/types.cc b/src/components/policy/policy_external/src/policy_table/types.cc index 4867eef281..977448dacd 100644 --- a/src/components/policy/policy_external/src/policy_table/types.cc +++ b/src/components/policy/policy_external/src/policy_table/types.cc @@ -247,7 +247,8 @@ ApplicationParams::ApplicationParams(const Json::Value* value__) , endpoint(impl::ValueMember(value__, "endpoint")) , enabled(impl::ValueMember(value__, "enabled")) , auth_token(impl::ValueMember(value__, "auth_token")) - , cloud_transport_type(impl::ValueMember(value__, "cloud_transport_type")) {} + , cloud_transport_type(impl::ValueMember(value__, "cloud_transport_type")) { +} Json::Value ApplicationParams::ToJsonValue() const { Json::Value result__(PolicyBase::ToJsonValue()); diff --git a/src/components/policy/policy_external/src/sql_pt_ext_representation.cc b/src/components/policy/policy_external/src/sql_pt_ext_representation.cc index 6a40e6d135..43961815d6 100644 --- a/src/components/policy/policy_external/src/sql_pt_ext_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_ext_representation.cc @@ -760,8 +760,9 @@ bool SQLPTExtRepresentation::SaveSpecificAppPolicy( std::string(policy_table::EnumToJsonString( *app.second.hybrid_app_preference))) : app_query.Bind(9); - app.second.endpoint.is_initialized() ? app_query.Bind(10, *app.second.endpoint) - : app_query.Bind(10); + app.second.endpoint.is_initialized() + ? app_query.Bind(10, *app.second.endpoint) + : app_query.Bind(10); app.second.enabled.is_initialized() ? app_query.Bind(11, *app.second.enabled) : app_query.Bind(11); app.second.auth_token.is_initialized() 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 119a0c0519..39f9cc73cd 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -146,12 +146,22 @@ class CacheManager : public CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -163,6 +173,7 @@ class CacheManager : public CacheManagerInterface { 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; 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 9408809f1e..3b2b10d0bc 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 @@ -151,12 +151,22 @@ class CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const = 0; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const = 0; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -168,6 +178,7 @@ class CacheManagerInterface { 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 = 0; @@ -199,8 +210,9 @@ class CacheManagerInterface { * should be used * @param hybrid_app_preference Hybrid app user preference */ - virtual void SetHybridAppPreference(const std::string& policy_app_id, - const std::string& hybrid_app_preference) = 0; + virtual void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) = 0; /** * @brief Allows to update 'vin' field in module_meta table. 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 e1221b613f..9ee6b416fa 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 @@ -564,12 +564,21 @@ class PolicyManagerImpl : public PolicyManager { */ const VehicleInfo GetVehicleInfo() const OVERRIDE; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled cloud + * application + */ + void GetEnabledCloudApps(std::vector& enabled_apps) const OVERRIDE; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -591,7 +600,7 @@ class PolicyManagerImpl : public PolicyManager { */ void SetCloudAppEnabled(const std::string& policy_app_id, const bool enabled) OVERRIDE; - + /** * @brief Set an app's auth token * @param auth_token Cloud app authentication token diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 68e70c107d..9292c389b9 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -682,9 +682,24 @@ const policy::VehicleInfo CacheManager::GetVehicleInfo() const { return vehicle_info; } +void CacheManager::GetEnabledCloudApps( + std::vector& enabled_apps) const { + const policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + for (policy_table::ApplicationPolicies::const_iterator it = policies.begin(); + it != policies.end(); + ++it) { + auto app_policy = (*it).second; + if (app_policy.enabled.is_initialized() && *app_policy.enabled) { + enabled_apps.push_back((*it).first); + } + } +} + const bool CacheManager::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 { @@ -701,6 +716,9 @@ const bool CacheManager::GetCloudAppParameters( 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) 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 9317708216..f4ffb56027 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -544,17 +544,26 @@ const VehicleInfo PolicyManagerImpl::GetVehicleInfo() const { return cache_->GetVehicleInfo(); } +void PolicyManagerImpl::GetEnabledCloudApps( + std::vector& enabled_apps) const { + cache_->GetEnabledCloudApps(enabled_apps); +} + const bool PolicyManagerImpl::GetCloudAppParameters( const std::string& policy_app_id, std::string& endpoint, std::string& auth_token, std::string& cloud_transport_type, std::string& hybrid_app_preference) const { - return cache_->GetCloudAppParameters(policy_app_id, endpoint, auth_token, cloud_transport_type, hybrid_app_preference); + return cache_->GetCloudAppParameters(policy_app_id, + endpoint, + auth_token, + cloud_transport_type, + hybrid_app_preference); } -void PolicyManagerImpl::SetCloudAppEnabled( - const std::string& policy_app_id, const bool enabled) { +void PolicyManagerImpl::SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) { cache_->SetCloudAppEnabled(policy_app_id, enabled); } -- cgit v1.2.1 From 802830a4a50a3f7317478218470e1ab3c07c1322 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Wed, 7 Nov 2018 14:04:17 -0500 Subject: Add Cloud Info to Application Class --- .../include/application_manager/application.h | 20 +++++++++++ .../include/application_manager/application_impl.h | 27 +++++++++++++++ .../application_manager/application_manager_impl.h | 2 ++ .../application_manager/src/application_impl.cc | 40 ++++++++++++++++++++++ .../src/application_manager_impl.cc | 20 +++++++++++ .../connection_handler/connection_handler_impl.h | 2 ++ .../src/connection_handler_impl.cc | 4 +++ .../connection_handler/connection_handler.h | 2 ++ .../policy/policy_regular/policy/policy_manager.h | 1 + .../include/transport_manager/transport_manager.h | 2 ++ .../include/policy/policy_manager_impl.h | 1 + .../policy_regular/src/policy_manager_impl.cc | 2 ++ .../transport_manager/transport_manager_impl.h | 2 ++ .../src/transport_manager_impl.cc | 4 +++ 14 files changed, 129 insertions(+) diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index ad7570955e..700c0e5d2c 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -946,6 +946,26 @@ class Application : public virtual InitialApplicationData, */ virtual const std::list& Extensions() const = 0; + virtual std::string cloud_app_endpoint() = 0; + + virtual std::string cloud_app_authtoken() = 0; + + virtual std::string cloud_app_transport_type() = 0; + + virtual std::string hybrid_app_preference() = 0; + + virtual std::string cloud_app_certificate() = 0; + + virtual void set_cloud_app_endpoint(const std::string& endpoint) = 0; + + virtual void set_cloud_app_auth_token(const std::string& auth_token) = 0; + + virtual void set_cloud_app_transport_type(const std::string& transport_type) = 0; + + virtual void set_hybrid_app_preference(const std::string& hybrid_app_preference) = 0; + + virtual void set_cloud_app_certificate(const std::string& certificate) = 0; + protected: mutable sync_primitives::Lock hmi_states_lock_; diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index 8dc3b2da20..0c365fc752 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -409,6 +409,26 @@ class ApplicationImpl : public virtual Application, void SwapMobileMessageQueue(MobileMessageQueue& mobile_messages) OVERRIDE; + std::string cloud_app_endpoint() OVERRIDE; + + std::string cloud_app_authtoken() OVERRIDE; + + std::string cloud_app_transport_type() OVERRIDE; + + std::string hybrid_app_preference() OVERRIDE; + + std::string cloud_app_certificate() OVERRIDE; + + void set_cloud_app_endpoint(const std::string& endpoint) OVERRIDE; + + void set_cloud_app_auth_token(const std::string& auth_token) OVERRIDE; + + void set_cloud_app_transport_type(const std::string& transport_type) OVERRIDE; + + void set_hybrid_app_preference(const std::string& hybrid_app_preference) OVERRIDE; + + void set_cloud_app_certificate(const std::string& certificate) OVERRIDE; + protected: /** * @brief Clean up application folder. Persistent files will stay @@ -513,6 +533,13 @@ class ApplicationImpl : public virtual Application, std::list extensions_; + // Cloud app properties + std::string endpoint_; + std::string auth_token_; + std::string cloud_transport_type_; + std::string hybrid_app_preference_; + std::string certificate_; + /** * @brief Defines number per time in seconds limits */ diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 6c111dbbb3..23d7fc4892 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -360,6 +360,8 @@ class ApplicationManagerImpl void ConnectToDevice(const std::string& device_mac) OVERRIDE; void OnHMIStartedCooperation() OVERRIDE; + void CollectCloudAppInformation(); + /* * @brief Returns unique correlation ID for HMI request * diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 8a611195c7..65f2a36fa8 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -1163,6 +1163,46 @@ const std::list& ApplicationImpl::Extensions() const { return extensions_; } +std::string ApplicationImpl::cloud_app_endpoint() { + return endpoint_; +} + +std::string ApplicationImpl::cloud_app_authtoken() { + return auth_token_; +} + +std::string ApplicationImpl::cloud_app_transport_type() { + return cloud_transport_type_; +} + +std::string ApplicationImpl::hybrid_app_preference() { + return hybrid_app_preference_; +} + +std::string ApplicationImpl::cloud_app_certificate() { + return certificate_; +} + +void ApplicationImpl::set_cloud_app_endpoint(const std::string& endpoint) { + endpoint_ = endpoint; +} + +void ApplicationImpl::set_cloud_app_auth_token(const std::string& auth_token) { + auth_token_ = auth_token; +} + +void ApplicationImpl::set_cloud_app_transport_type(const std::string& transport_type) { + cloud_transport_type_ = transport_type; +} + +void ApplicationImpl::set_hybrid_app_preference(const std::string& hybrid_app_preference) { + hybrid_app_preference_ = hybrid_app_preference; +} + +void ApplicationImpl::set_cloud_app_certificate(const std::string& certificate) { + certificate_ = certificate; +} + void ApplicationImpl::PushMobileMessage( smart_objects::SmartObjectSPtr mobile_message) { sync_primitives::AutoLock lock(mobile_message_lock_); diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 24f27af2e2..4a0bb63bae 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -779,6 +779,26 @@ void ApplicationManagerImpl::OnHMIStartedCooperation() { *this)); rpc_service_->ManageHMICommand(mixing_audio_supported_request); resume_controller().ResetLaunchTime(); + + CollectCloudAppInformation(); +} + +void ApplicationManagerImpl::CollectCloudAppInformation() { + std::vector cloud_app_id_vector; + GetPolicyHandler().GetEnabledCloudApps(cloud_app_id_vector); + std::vector::iterator it = cloud_app_id_vector.begin(); + std::vector::iterator end = cloud_app_id_vector.end(); + std::string endpoint = ""; + std::string certificate = ""; + std::string auth_token = ""; + std::string cloud_transport_type = ""; + std::string hybrid_app_preference = ""; + for (; it!=end; ++it) { + GetPolicyHandler().GetCloudAppParameters(*it, endpoint, certificate, auth_token, + cloud_transport_type, hybrid_app_preference); + + connection_handler().AddCloudAppDevice(*it, endpoint, cloud_transport_type); + } } uint32_t ApplicationManagerImpl::GetNextHMICorrelationID() { 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 1ab70ce702..5984f74c34 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 @@ -120,6 +120,8 @@ class ConnectionHandlerImpl void ConnectToAllDevices() OVERRIDE; + void AddCloudAppDevice(const std::string& policy_app_id, const std::string& endpoint, const std::string& cloud_transport_type) OVERRIDE; + void StartTransportManager() OVERRIDE; void OnDeviceListUpdated( diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index 478127c42a..399dbf90d7 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -1267,6 +1267,10 @@ void ConnectionHandlerImpl::ConnectToAllDevices() { } } +void ConnectionHandlerImpl::AddCloudAppDevice(const std::string& policy_app_id, const std::string& endpoint, const std::string& cloud_transport_type) { + transport_manager_.AddCloudDevice(endpoint, cloud_transport_type); +} + void ConnectionHandlerImpl::StartTransportManager() { LOG4CXX_AUTO_TRACE(logger_); transport_manager_.Visibility(true); diff --git a/src/components/include/connection_handler/connection_handler.h b/src/components/include/connection_handler/connection_handler.h index a50760b547..21c10dc3db 100644 --- a/src/components/include/connection_handler/connection_handler.h +++ b/src/components/include/connection_handler/connection_handler.h @@ -93,6 +93,8 @@ class ConnectionHandler { virtual void ConnectToAllDevices() = 0; + virtual void AddCloudAppDevice(const std::string& policy_app_id, const std::string& endpoint, const std::string& cloud_transport_type) = 0; + /** * @brief Close the connection revoked by Policy * @param connection_key pair of connection and session id 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 4a82c8620b..1f0f520077 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -529,6 +529,7 @@ class PolicyManager : public usage_statistics::StatisticsManager { 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 = 0; diff --git a/src/components/include/transport_manager/transport_manager.h b/src/components/include/transport_manager/transport_manager.h index 0847886c46..f67923daef 100644 --- a/src/components/include/transport_manager/transport_manager.h +++ b/src/components/include/transport_manager/transport_manager.h @@ -75,6 +75,8 @@ class TransportManager { **/ virtual int SearchDevices() = 0; + virtual void AddCloudDevice(const std::string& endpoint, const std::string& cloud_transport_type) = 0; + /** * @brief Connect to all applications discovered on device. * 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 9ee6b416fa..aee2584ec2 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 @@ -590,6 +590,7 @@ class PolicyManagerImpl : public PolicyManager { 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; 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 f4ffb56027..5aa29fc896 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -552,11 +552,13 @@ void PolicyManagerImpl::GetEnabledCloudApps( const bool PolicyManagerImpl::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 { return cache_->GetCloudAppParameters(policy_app_id, endpoint, + certificate, auth_token, cloud_transport_type, hybrid_app_preference); diff --git a/src/components/transport_manager/include/transport_manager/transport_manager_impl.h b/src/components/transport_manager/include/transport_manager/transport_manager_impl.h index c1df49f91b..e2ce07ad18 100644 --- a/src/components/transport_manager/include/transport_manager/transport_manager_impl.h +++ b/src/components/transport_manager/include/transport_manager/transport_manager_impl.h @@ -140,6 +140,8 @@ class TransportManagerImpl **/ int SearchDevices() OVERRIDE; + void AddCloudDevice(const std::string& endpoint, const std::string& cloud_transport_type) OVERRIDE; + /** * @brief Connect to all applications discovered on device. * diff --git a/src/components/transport_manager/src/transport_manager_impl.cc b/src/components/transport_manager/src/transport_manager_impl.cc index 2b0296debb..63fa4b451d 100644 --- a/src/components/transport_manager/src/transport_manager_impl.cc +++ b/src/components/transport_manager/src/transport_manager_impl.cc @@ -129,6 +129,10 @@ void TransportManagerImpl::ReconnectionTimeout() { device_to_reconnect_); } +void TransportManagerImpl::AddCloudDevice(const std::string& endpoint, const std::string& cloud_transport_type) { + return; +} + int TransportManagerImpl::ConnectDevice(const DeviceHandle device_handle) { LOG4CXX_TRACE(logger_, "enter. DeviceHandle: " << &device_handle); if (!this->is_initialized_) { -- cgit v1.2.1 From 9d3c712daf5f5b0a461288bcd23f63a2ef883c65 Mon Sep 17 00:00:00 2001 From: jacobkeeler Date: Mon, 5 Nov 2018 17:56:55 -0500 Subject: Fix style, add certificate, and add GetEnabledCloudApps --- .../application_manager/policies/policy_handler.h | 45 +++++++++++++++++----- .../src/policies/policy_handler.cc | 36 +++++++++++------ .../policies/policy_handler_interface.h | 15 +++++++- .../policy/policy_external/policy/policy_manager.h | 13 ++++++- .../policy/policy_regular/policy/policy_manager.h | 16 +++++++- .../policies/mock_policy_handler_interface.h | 5 ++- .../policy_external/policy/mock_cache_manager.h | 5 ++- .../policy_external/policy/mock_policy_manager.h | 5 ++- .../policy_regular/policy/mock_cache_manager.h | 15 +++++--- .../policy_regular/policy/mock_policy_manager.h | 5 ++- .../policy_external/include/policy/cache_manager.h | 11 ++++++ .../include/policy/cache_manager_interface.h | 11 ++++++ .../include/policy/policy_manager_impl.h | 15 +++++++- .../include/policy/policy_table/enums.h | 6 +-- .../policy/policy_external/src/cache_manager.cc | 18 +++++++++ .../policy_external/src/policy_manager_impl.cc | 7 ++++ .../policy_external/src/policy_table/types.cc | 3 +- .../src/sql_pt_ext_representation.cc | 5 ++- .../policy_regular/include/policy/cache_manager.h | 11 ++++++ .../include/policy/cache_manager_interface.h | 16 +++++++- .../include/policy/policy_manager_impl.h | 13 ++++++- .../policy/policy_regular/src/cache_manager.cc | 18 +++++++++ .../policy_regular/src/policy_manager_impl.cc | 17 ++++++-- 23 files changed, 259 insertions(+), 52 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 3af03bf28b..a612c263ca 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 @@ -398,6 +398,14 @@ class PolicyHandler : public PolicyHandlerInterface, custom_str::CustomString GetAppName( const std::string& policy_app_id) OVERRIDE; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + void GetEnabledCloudApps( + std::vector& enabled_apps) const OVERRIDE; + /** * @brief Checks if a given application is an enabled cloud application * @param policy_app_id Unique application id @@ -407,17 +415,36 @@ class PolicyHandler : public PolicyHandlerInterface, const bool CheckCloudAppEnabled( const std::string& policy_app_id) const OVERRIDE; - /**plzfix - * @brief Checks if certain request type is allowed for application + /** + * @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 - * @return true, if allowed, otherwise - false - */ - const bool GetCloudAppParameters(const std::string& policy_app_id, - std::string& endpoint, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const OVERRIDE; + * @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 + * @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 + * 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; + /** + * @brief Callback for when a SetCloudAppProperties message is received from a + * mobile app + * @param message The SetCloudAppProperties message + */ void OnSetCloudAppProperties( const smart_objects::SmartObject& message) OVERRIDE; diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index c73e35768e..cc62d9f6f8 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1845,28 +1845,39 @@ bool PolicyHandler::CheckSystemAction( return false; } +void PolicyHandler::GetEnabledCloudApps( + std::vector& enabled_apps) const { + POLICY_LIB_CHECK_VOID(); + policy_manager_->GetEnabledCloudApps(enabled_apps); +} + const bool PolicyHandler::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 { POLICY_LIB_CHECK(false); return policy_manager_->GetCloudAppParameters(policy_app_id, endpoint, + certificate, auth_token, cloud_transport_type, hybrid_app_preference); } -const bool PolicyHandler::CheckCloudAppEnabled(const std::string& policy_app_id) const { +const bool PolicyHandler::CheckCloudAppEnabled( + const std::string& policy_app_id) const { POLICY_LIB_CHECK(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); @@ -1876,34 +1887,35 @@ void PolicyHandler::OnSetCloudAppProperties( const smart_objects::SmartObject& message) { POLICY_LIB_CHECK_VOID(); if (!message.keyExists(strings::msg_params)) { - LOG4CXX_ERROR( - logger_, - "Message does not contain mandatory section " << strings::msg_params); + LOG4CXX_ERROR(logger_, + "Message does not contain mandatory section " + << strings::msg_params); return; } const smart_objects::SmartObject& msg_params = message[strings::msg_params]; if (!msg_params.keyExists(strings::app_id)) { - LOG4CXX_ERROR( - logger_, - "Message does not contain mandatory parameter " << strings::app_id); + LOG4CXX_ERROR(logger_, + "Message does not contain mandatory parameter " + << strings::app_id); return; } std::string policy_app_id(msg_params[strings::app_id].asString()); if (msg_params.keyExists(strings::enabled)) { policy_manager_->SetCloudAppEnabled(policy_app_id, - msg_params[strings::enabled].asBool()); + msg_params[strings::enabled].asBool()); } if (msg_params.keyExists(strings::cloud_app_auth_token)) { - policy_manager_->SetAppAuthToken(policy_app_id, - msg_params[strings::cloud_app_auth_token].asString()); + policy_manager_->SetAppAuthToken( + policy_app_id, msg_params[strings::cloud_app_auth_token].asString()); } if (msg_params.keyExists(strings::cloud_transport_type)) { policy_manager_->SetAppCloudTransportType( policy_app_id, msg_params[strings::cloud_transport_type].asString()); } if (msg_params.keyExists(strings::hybrid_app_preference)) { - //const std::string hybrid_app_preference = EnumConversionHelper::EnumToString(msg_params[strings::hybrid_app_preference]); - //policy_manager_->SetHybridAppPreference( + // const std::string hybrid_app_preference = + // EnumConversionHelper::EnumToString(msg_params[strings::hybrid_app_preference]); + // policy_manager_->SetHybridAppPreference( // policy_app_id, hybrid_app_preference); } } 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 69433e6118..ddeb1da8f7 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -437,7 +437,15 @@ class PolicyHandlerInterface { * @return Structure with vehicle information */ virtual const VehicleInfo GetVehicleInfo() const = 0; - + + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const = 0; + /** * @brief Checks if a given application is an enabled cloud application * @param policy_app_id Unique application id @@ -453,6 +461,8 @@ class PolicyHandlerInterface { * @param policy_app_id Unique application id * @param endpoint Filled 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 * @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 @@ -464,6 +474,7 @@ class PolicyHandlerInterface { 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 = 0; @@ -475,7 +486,7 @@ class PolicyHandlerInterface { */ virtual void OnSetCloudAppProperties( const smart_objects::SmartObject& message) = 0; - + #ifdef EXTERNAL_PROPRIETARY_MODE /** * @brief Gets meta information 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 2ea8ef08f1..b0fac8eae9 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -521,13 +521,23 @@ class PolicyManager : public usage_statistics::StatisticsManager { * @return vehicle information */ virtual const VehicleInfo GetVehicleInfo() const = 0; - + + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const = 0; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -539,6 +549,7 @@ class PolicyManager : public usage_statistics::StatisticsManager { 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 = 0; 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 9c67e239b7..1f0f520077 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -502,12 +502,22 @@ class PolicyManager : public usage_statistics::StatisticsManager { */ virtual const VehicleInfo GetVehicleInfo() const = 0; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const = 0; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -519,6 +529,7 @@ class PolicyManager : public usage_statistics::StatisticsManager { 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 = 0; @@ -550,8 +561,9 @@ class PolicyManager : public usage_statistics::StatisticsManager { * should be used * @param hybrid_app_preference Hybrid app user preference */ - virtual void SetHybridAppPreference(const std::string& policy_app_id, - const std::string& hybrid_app_preference) = 0; + virtual void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) = 0; /** * @brief OnAppRegisteredOnMobile allows to handle event when application were 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 bd56d78128..cea36082c8 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 @@ -213,11 +213,14 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { GetAppRequestTypes, const std::vector(const std::string& policy_app_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector& enabled_apps)); MOCK_CONST_METHOD1(CheckCloudAppEnabled, const bool(const std::string& policy_app_id)); - MOCK_CONST_METHOD5(GetCloudAppParameters, + 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)); 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 ecbd8c6cd6..03e0882129 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 @@ -76,9 +76,12 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_METHOD1(SecondsBetweenRetries, bool(std::vector& seconds)); MOCK_CONST_METHOD1(IsDeviceConsentCached, bool(const std::string& device_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const VehicleInfo()); - MOCK_CONST_METHOD5(GetCloudAppParameters, + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector& 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)); 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 f58ed10934..70dab8e99a 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 @@ -184,9 +184,12 @@ class MockPolicyManager : public PolicyManager { GetAppRequestTypes, const std::vector(const std::string policy_app_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); - MOCK_CONST_METHOD5(GetCloudAppParameters, + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector& 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)); 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 745bcd2db5..7ac94d278d 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 @@ -63,12 +63,15 @@ class MockCacheManagerInterface : public CacheManagerInterface { MOCK_METHOD0(TimeoutResponse, int()); MOCK_METHOD1(SecondsBetweenRetries, bool(std::vector& seconds)); MOCK_CONST_METHOD0(GetVehicleInfo, const VehicleInfo()); - MOCK_CONST_METHOD5(GetCloudAppParameters, - const bool(const std::string& policy_app_id, - std::string& endpoint, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference)); + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector& 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_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 8867c3de80..7441701a34 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 @@ -181,9 +181,12 @@ class MockPolicyManager : public PolicyManager { GetAppRequestTypes, const std::vector(const std::string policy_app_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); - MOCK_CONST_METHOD5(GetCloudAppParameters, + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector& 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)); 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 d6eeb0457b..7660eb2df9 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -158,12 +158,22 @@ class CacheManager : public CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -175,6 +185,7 @@ class CacheManager : public CacheManagerInterface { 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; 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 0c094d2edb..79d6f4e731 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 @@ -165,12 +165,22 @@ class CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const = 0; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const = 0; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -182,6 +192,7 @@ class CacheManagerInterface { 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 = 0; 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 f9648f803c..778892df13 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 @@ -569,13 +569,23 @@ class PolicyManagerImpl : public PolicyManager { * @return vehicle information */ const VehicleInfo GetVehicleInfo() const OVERRIDE; - + + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + void GetEnabledCloudApps( + std::vector& enabled_apps) const OVERRIDE; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -587,6 +597,7 @@ class PolicyManagerImpl : public PolicyManager { 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; @@ -597,7 +608,7 @@ class PolicyManagerImpl : public PolicyManager { */ void SetCloudAppEnabled(const std::string& policy_app_id, const bool enabled) OVERRIDE; - + /** * @brief Set an app's auth token * @param auth_token Cloud app authentication token diff --git a/src/components/policy/policy_external/include/policy/policy_table/enums.h b/src/components/policy/policy_external/include/policy/policy_table/enums.h index f5b85f0a4d..c2148de3b6 100644 --- a/src/components/policy/policy_external/include/policy/policy_table/enums.h +++ b/src/components/policy/policy_external/include/policy/policy_table/enums.h @@ -181,11 +181,7 @@ bool IsValidEnum(ModuleType val); const char* EnumToJsonString(ModuleType val); bool EnumFromJsonString(const std::string& literal, ModuleType* result); -enum HybridAppPreference { - HAP_MOBILE, - HAP_CLOUD, - HAP_BOTH -}; +enum HybridAppPreference { HAP_MOBILE, HAP_CLOUD, HAP_BOTH }; bool IsValidEnum(HybridAppPreference val); const char* EnumToJsonString(HybridAppPreference val); bool EnumFromJsonString(const std::string& literal, diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index d6d5f6daa5..116b315755 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -1389,9 +1389,24 @@ const policy::VehicleInfo CacheManager::GetVehicleInfo() const { return vehicle_info; } +void CacheManager::GetEnabledCloudApps( + std::vector& enabled_apps) const { + const policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + for (policy_table::ApplicationPolicies::const_iterator it = policies.begin(); + it != policies.end(); + ++it) { + auto app_policy = (*it).second; + if (app_policy.enabled.is_initialized() && *app_policy.enabled) { + enabled_apps.push_back((*it).first); + } + } +} + const bool CacheManager::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 { @@ -1403,6 +1418,9 @@ 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() 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 e7538fa1b0..31cc212254 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -725,14 +725,21 @@ const VehicleInfo PolicyManagerImpl::GetVehicleInfo() const { return cache_->GetVehicleInfo(); } +void PolicyManagerImpl::GetEnabledCloudApps( + std::vector& enabled_apps) const { + cache_->GetEnabledCloudApps(enabled_apps); +} + const bool PolicyManagerImpl::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 { return cache_->GetCloudAppParameters(policy_app_id, endpoint, + certificate, auth_token, cloud_transport_type, hybrid_app_preference); diff --git a/src/components/policy/policy_external/src/policy_table/types.cc b/src/components/policy/policy_external/src/policy_table/types.cc index 4867eef281..977448dacd 100644 --- a/src/components/policy/policy_external/src/policy_table/types.cc +++ b/src/components/policy/policy_external/src/policy_table/types.cc @@ -247,7 +247,8 @@ ApplicationParams::ApplicationParams(const Json::Value* value__) , endpoint(impl::ValueMember(value__, "endpoint")) , enabled(impl::ValueMember(value__, "enabled")) , auth_token(impl::ValueMember(value__, "auth_token")) - , cloud_transport_type(impl::ValueMember(value__, "cloud_transport_type")) {} + , cloud_transport_type(impl::ValueMember(value__, "cloud_transport_type")) { +} Json::Value ApplicationParams::ToJsonValue() const { Json::Value result__(PolicyBase::ToJsonValue()); diff --git a/src/components/policy/policy_external/src/sql_pt_ext_representation.cc b/src/components/policy/policy_external/src/sql_pt_ext_representation.cc index 6a40e6d135..43961815d6 100644 --- a/src/components/policy/policy_external/src/sql_pt_ext_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_ext_representation.cc @@ -760,8 +760,9 @@ bool SQLPTExtRepresentation::SaveSpecificAppPolicy( std::string(policy_table::EnumToJsonString( *app.second.hybrid_app_preference))) : app_query.Bind(9); - app.second.endpoint.is_initialized() ? app_query.Bind(10, *app.second.endpoint) - : app_query.Bind(10); + app.second.endpoint.is_initialized() + ? app_query.Bind(10, *app.second.endpoint) + : app_query.Bind(10); app.second.enabled.is_initialized() ? app_query.Bind(11, *app.second.enabled) : app_query.Bind(11); app.second.auth_token.is_initialized() 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 119a0c0519..39f9cc73cd 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -146,12 +146,22 @@ class CacheManager : public CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -163,6 +173,7 @@ class CacheManager : public CacheManagerInterface { 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; 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 9408809f1e..3b2b10d0bc 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 @@ -151,12 +151,22 @@ class CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const = 0; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector& enabled_apps) const = 0; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -168,6 +178,7 @@ class CacheManagerInterface { 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 = 0; @@ -199,8 +210,9 @@ class CacheManagerInterface { * should be used * @param hybrid_app_preference Hybrid app user preference */ - virtual void SetHybridAppPreference(const std::string& policy_app_id, - const std::string& hybrid_app_preference) = 0; + virtual void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) = 0; /** * @brief Allows to update 'vin' field in module_meta table. 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 e1221b613f..311ced31d2 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 @@ -564,12 +564,22 @@ class PolicyManagerImpl : public PolicyManager { */ const VehicleInfo GetVehicleInfo() const OVERRIDE; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + void GetEnabledCloudApps( + std::vector& enabled_apps) const OVERRIDE; + /** * @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 * application + * @param certificate Filled with the certificate used to for creating a + * 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 @@ -581,6 +591,7 @@ class PolicyManagerImpl : public PolicyManager { 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; @@ -591,7 +602,7 @@ class PolicyManagerImpl : public PolicyManager { */ void SetCloudAppEnabled(const std::string& policy_app_id, const bool enabled) OVERRIDE; - + /** * @brief Set an app's auth token * @param auth_token Cloud app authentication token diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 68e70c107d..9292c389b9 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -682,9 +682,24 @@ const policy::VehicleInfo CacheManager::GetVehicleInfo() const { return vehicle_info; } +void CacheManager::GetEnabledCloudApps( + std::vector& enabled_apps) const { + const policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + for (policy_table::ApplicationPolicies::const_iterator it = policies.begin(); + it != policies.end(); + ++it) { + auto app_policy = (*it).second; + if (app_policy.enabled.is_initialized() && *app_policy.enabled) { + enabled_apps.push_back((*it).first); + } + } +} + const bool CacheManager::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 { @@ -701,6 +716,9 @@ const bool CacheManager::GetCloudAppParameters( 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) 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 9317708216..5aa29fc896 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -544,17 +544,28 @@ const VehicleInfo PolicyManagerImpl::GetVehicleInfo() const { return cache_->GetVehicleInfo(); } +void PolicyManagerImpl::GetEnabledCloudApps( + std::vector& enabled_apps) const { + cache_->GetEnabledCloudApps(enabled_apps); +} + const bool PolicyManagerImpl::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 { - return cache_->GetCloudAppParameters(policy_app_id, endpoint, auth_token, cloud_transport_type, hybrid_app_preference); + return cache_->GetCloudAppParameters(policy_app_id, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); } -void PolicyManagerImpl::SetCloudAppEnabled( - const std::string& policy_app_id, const bool enabled) { +void PolicyManagerImpl::SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) { cache_->SetCloudAppEnabled(policy_app_id, enabled); } -- cgit v1.2.1 From 2e262bb5c5f0d4a8462579024dfe7ef7e64487a9 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Thu, 8 Nov 2018 09:42:04 -0500 Subject: Initial Cloud Transport Component --- CMakeLists.txt | 6 + src/appMain/smartDeviceLink.ini | 6 + .../include/config_profile/profile.h | 12 + src/components/config_profile/src/profile.cc | 33 +++ .../src/connection_handler_impl.cc | 4 +- .../hmi_message_handler/src/websocket_session.cc | 1 + .../transport_adapter/transport_adapter.h | 21 ++ .../transport_manager/transport_manager_settings.h | 10 + .../include/transport_manager/cloud/cloud_device.h | 64 ++++++ .../cloud/cloud_websocket_connection_factory.h | 98 ++++++++ .../cloud/cloud_websocket_transport_adapter.h | 105 +++++++++ .../cloud/websocket_client_connection.h | 180 +++++++++++++++ .../transport_manager/src/cloud/cloud_device.cc | 62 +++++ .../cloud/cloud_websocket_connection_factory.cc | 99 ++++++++ .../src/cloud/cloud_websocket_transport_adapter.cc | 73 ++++++ .../src/cloud/websocket_client_connection.cc | 252 +++++++++++++++++++++ .../src/transport_manager_default.cc | 16 ++ 17 files changed, 1041 insertions(+), 1 deletion(-) create mode 100644 src/components/transport_manager/include/transport_manager/cloud/cloud_device.h create mode 100644 src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_connection_factory.h create mode 100644 src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_transport_adapter.h create mode 100644 src/components/transport_manager/include/transport_manager/cloud/websocket_client_connection.h create mode 100644 src/components/transport_manager/src/cloud/cloud_device.cc create mode 100644 src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc create mode 100644 src/components/transport_manager/src/cloud/cloud_websocket_transport_adapter.cc create mode 100644 src/components/transport_manager/src/cloud/websocket_client_connection.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a180b6cf9..f6ee77a143 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ option(EXTENDED_MEDIA_MODE "Turn on and off extended Madia Manager features rela option(BUILD_SHARED_LIBS "Build all libraries as shared (if ON) or static (if OFF)" OFF) option(BUILD_BT_SUPPORT "Bluetooth support" ON) option(BUILD_USB_SUPPORT "libusb support" ON) +option(BUILD_CLOUD_APP_SUPPORT "Cloud App Transport Support" ON) option(BUILD_BACKTRACE_SUPPORT "backtrace support" ON) option(BUILD_TESTS "Possibility to build and run tests" OFF) option(TELEMETRY_MONITOR "Enable profiling time test util" ON) @@ -315,6 +316,11 @@ if (BUILD_BT_SUPPORT) message(STATUS "Bluetooth support enabled") endif() +if (BUILD_CLOUD_APP_SUPPORT) + add_definitions(-DCLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT) + message(STATUS "Cloud app websocket support enabled") +endif() + if (BUILD_BACKTRACE_SUPPORT) add_definitions(-DBACKTRACE_SUPPORT) message(STATUS "Backtrace support enabled") diff --git a/src/appMain/smartDeviceLink.ini b/src/appMain/smartDeviceLink.ini index b0513c076f..ac3e1c983a 100644 --- a/src/appMain/smartDeviceLink.ini +++ b/src/appMain/smartDeviceLink.ini @@ -202,6 +202,12 @@ TCPAdapterPort = 12345 ; If the name is omitted, Core will listen on all network interfaces by binding to INADDR_ANY. TCPAdapterNetworkInterface = +[Cloud App Connections] +; Value in milliseconds for time between retry attempts on a failed websocket connection +CloudAppRetryTimeout = 1000 +; MaxNn number of retry attempts for a cloud websocket connection +CloudAppMaxRetryAttempts = 5 + [ProtocolHandler] ; SDL supported protocol version MaxSupportedProtocolVersion = 5 diff --git a/src/components/config_profile/include/config_profile/profile.h b/src/components/config_profile/include/config_profile/profile.h index 57e925cd43..da087086c2 100644 --- a/src/components/config_profile/include/config_profile/profile.h +++ b/src/components/config_profile/include/config_profile/profile.h @@ -413,6 +413,16 @@ class Profile : public protocol_handler::ProtocolHandlerSettings, const std::string& transport_manager_tcp_adapter_network_interface() const OVERRIDE; + /** + * @brief Returns retry timeout for cloud app connections + */ + uint16_t cloud_app_retry_timeout() const OVERRIDE; + + /** + * @brief Returns maximum retry attempts for cloud app connections + */ + uint16_t cloud_app_max_retry_attempts() const OVERRIDE; + // TransportManageMMESettings interface const std::string& event_mq_name() const OVERRIDE; @@ -960,6 +970,8 @@ class Profile : public protocol_handler::ProtocolHandlerSettings, std::string system_files_path_; uint16_t transport_manager_tcp_adapter_port_; std::string transport_manager_tcp_adapter_network_interface_; + uint16_t cloud_app_retry_timeout_; + uint16_t cloud_app_max_retry_attempts_; std::string tts_delimiter_; uint32_t audio_data_stopped_timeout_; uint32_t video_data_stopped_timeout_; diff --git a/src/components/config_profile/src/profile.cc b/src/components/config_profile/src/profile.cc index 57984324aa..5b4c2e5f93 100644 --- a/src/components/config_profile/src/profile.cc +++ b/src/components/config_profile/src/profile.cc @@ -81,6 +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* kApplicationManagerSection = "ApplicationManager"; const char* kFilesystemRestrictionsSection = "FILESYSTEM RESTRICTIONS"; const char* kIAPSection = "IAP"; @@ -154,6 +155,8 @@ const char* kMaxSupportedProtocolVersionKey = "MaxSupportedProtocolVersion"; const char* kUseLastStateKey = "UseLastState"; const char* kTCPAdapterPortKey = "TCPAdapterPort"; const char* kTCPAdapterNetworkInterfaceKey = "TCPAdapterNetworkInterface"; +const char* kCloudAppRetryTimeoutKey = "CloudAppRetryTimeout"; +const char* kCloudAppMaxRetryAttemptsKey = "CloudAppMaxRetryAttempts"; const char* kServerPortKey = "ServerPort"; const char* kVideoStreamingPortKey = "VideoStreamingPort"; const char* kAudioStreamingPortKey = "AudioStreamingPort"; @@ -318,6 +321,8 @@ const uint32_t kDefaultHubProtocolIndex = 0; const uint32_t kDefaultHeartBeatTimeout = 0; const uint16_t kDefaultMaxSupportedProtocolVersion = 5; const uint16_t kDefautTransportManagerTCPPort = 12345; +const uint16_t kDefaultCloudAppRetryTimeout = 1000; +const uint16_t kDefaultCloudAppMaxRetryAttempts = 5; const uint16_t kDefaultServerPort = 8087; const uint16_t kDefaultVideoStreamingPort = 5050; const uint16_t kDefaultAudioStreamingPort = 5080; @@ -452,6 +457,8 @@ Profile::Profile() , supported_diag_modes_() , system_files_path_(kDefaultSystemFilesPath) , transport_manager_tcp_adapter_port_(kDefautTransportManagerTCPPort) + , cloud_app_retry_timeout_(kDefaultCloudAppRetryTimeout) + , cloud_app_max_retry_attempts_(kDefaultCloudAppMaxRetryAttempts) , tts_delimiter_(kDefaultTtsDelimiter) , audio_data_stopped_timeout_(kDefaultAudioDataStoppedTimeout) , video_data_stopped_timeout_(kDefaultVideoDataStoppedTimeout) @@ -784,6 +791,14 @@ const std::string& Profile::transport_manager_tcp_adapter_network_interface() return transport_manager_tcp_adapter_network_interface_; } +uint16_t Profile::cloud_app_retry_timeout() const { + return cloud_app_retry_timeout_; +} + +uint16_t Profile::cloud_app_max_retry_attempts() const { + return cloud_app_max_retry_attempts_; +} + const std::string& Profile::tts_delimiter() const { return tts_delimiter_; } @@ -1769,6 +1784,24 @@ void Profile::UpdateValues() { kTCPAdapterNetworkInterfaceKey, kTransportManagerSection); + ReadUIntValue(&cloud_app_retry_timeout_, + kDefaultCloudAppRetryTimeout, + kCloudAppTransportSection, + kCloudAppRetryTimeoutKey); + + LOG_UPDATED_VALUE(cloud_app_retry_timeout_, + kCloudAppRetryTimeoutKey, + kCloudAppTransportSection); + + ReadUIntValue(&cloud_app_max_retry_attempts_, + kDefaultCloudAppMaxRetryAttempts, + kCloudAppTransportSection, + kCloudAppMaxRetryAttemptsKey); + + LOG_UPDATED_VALUE(cloud_app_max_retry_attempts_, + kCloudAppMaxRetryAttemptsKey, + kCloudAppTransportSection); + // Event MQ ReadStringValue( &event_mq_name_, kDefaultEventMQ, kTransportManagerSection, kEventMQKey); diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index 399dbf90d7..290b1a650e 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -142,6 +142,8 @@ void ConnectionHandlerImpl::OnDeviceAdded( LOG4CXX_AUTO_TRACE(logger_); auto handle = device_info.device_handle(); + LOG4CXX_DEBUG(logger_, "OnDeviceAdded!!!: " << handle << " " << device_info.name() << " " << device_info.mac_address() << " " << device_info.connection_type()); + Device device(handle, device_info.name(), device_info.mac_address(), @@ -248,7 +250,7 @@ void ConnectionHandlerImpl::OnConnectionEstablished( const transport_manager::DeviceInfo& device_info, const transport_manager::ConnectionUID connection_id) { LOG4CXX_AUTO_TRACE(logger_); - + LOG4CXX_DEBUG(logger_, "OnConnectionEstablished!!!: " << device_info.device_handle() << " " << device_info.name() << " " << device_info.mac_address() << " " << device_info.connection_type()); DeviceMap::iterator it = device_list_.find(device_info.device_handle()); if (device_list_.end() == it) { LOG4CXX_ERROR(logger_, "Unknown device!"); diff --git a/src/components/hmi_message_handler/src/websocket_session.cc b/src/components/hmi_message_handler/src/websocket_session.cc index a148f48661..041a89ef82 100644 --- a/src/components/hmi_message_handler/src/websocket_session.cc +++ b/src/components/hmi_message_handler/src/websocket_session.cc @@ -71,6 +71,7 @@ bool WebsocketSession::IsShuttingDown() { } void WebsocketSession::Recv(boost::system::error_code ec) { + printf("!!!server recv connection accepted\n"); if (shutdown_) { return; } 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 ebbf7dae28..6af29aa7c2 100644 --- a/src/components/include/transport_manager/transport_adapter/transport_adapter.h +++ b/src/components/include/transport_manager/transport_adapter/transport_adapter.h @@ -64,12 +64,28 @@ enum DeviceType { IOS_BT, IOS_USB, TCP, + CLOUD_WEBSOCKET, IOS_USB_HOST_MODE, IOS_USB_DEVICE_MODE, IOS_CARPLAY_WIRELESS, // running on iAP over Carplay wireless transport 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 DeviceTypes; /** @@ -88,6 +104,11 @@ typedef std::list TransportAdapterListenerList; */ typedef std::map TransportConfig; +/** + * @brief Type definition of container indexed by app id that contains connection information for all cloud apps. + */ +typedef std::map CloudAppTransportConfig; + /** * @brief TransportConfig keys */ diff --git a/src/components/include/transport_manager/transport_manager_settings.h b/src/components/include/transport_manager/transport_manager_settings.h index 3912bbe747..d59038e5c6 100644 --- a/src/components/include/transport_manager/transport_manager_settings.h +++ b/src/components/include/transport_manager/transport_manager_settings.h @@ -69,6 +69,16 @@ class TransportManagerSettings : public TransportManagerMMESettings { */ virtual const std::string& transport_manager_tcp_adapter_network_interface() const = 0; + + /** + * @brief Returns retry timeout for cloud app connections + */ + virtual uint16_t cloud_app_retry_timeout() const = 0; + + /** + * @brief Returns maximum retry attempts for cloud app connections + */ + virtual uint16_t cloud_app_max_retry_attempts() const = 0; }; } // namespace transport_manager #endif // SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_SETTINGS_H_ 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 new file mode 100644 index 0000000000..5792ba06a1 --- /dev/null +++ b/src/components/transport_manager/include/transport_manager/cloud/cloud_device.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2018, Livio + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * \file Cloud_device.h + * \brief CloudDevice class header file. + */ + +#ifndef SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_DEVICE_H_ +#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_DEVICE_H_ + +#include "transport_manager/transport_adapter/device.h" + +namespace transport_manager { +namespace transport_adapter { + +class CloudDevice : public Device { + public: + CloudDevice(std::string& host, + std::string& port, + std::string& name); + + protected: + virtual bool IsSameAs(const Device* other_device) const; + + virtual ApplicationList GetApplicationList() const; + + private: + //todo add private varaibles, maybe ip port or other connection information? +}; + +} // namespace transport_adapter +} // namespace transport_manager + +#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_DEVICE_H_ diff --git a/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_connection_factory.h b/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_connection_factory.h new file mode 100644 index 0000000000..ef1754a6e7 --- /dev/null +++ b/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_connection_factory.h @@ -0,0 +1,98 @@ +/* + * \file cloud_websocket_connection_factory.h + * \brief CloudWebsocketConnectionFactory class header file. + * + * Copyright (c) 2018, Livio + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_WEBSOCKET_CONNECTION_FACTORY_H_ +#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_WEBSOCKET_CONNECTION_FACTORY_H_ + +#include "transport_manager/transport_adapter/server_connection_factory.h" + +namespace transport_manager { +namespace transport_adapter { + +class TransportAdapterController; + +/** + * @brief Create connections. + */ +class CloudWebsocketConnectionFactory : public ServerConnectionFactory { + public: + /** + * @brief Constructor. + * + * @param controller Pointer to the device adapter controller. + */ + CloudWebsocketConnectionFactory(TransportAdapterController* controller); + + protected: + /** + * @brief Start cloud websocket connection factory. + */ + virtual TransportAdapter::Error Init(); + + /** + * @brief Create cloud boost websocket connection. + * + * @param device_uid Device unique identifier. + * @param ap_handle Handle of application. + */ + virtual TransportAdapter::Error CreateConnection( + const DeviceUID& device_uid, const ApplicationHandle& app_handle); + + /** + * @brief + */ + virtual void Terminate(); + + /** + * @brief Check for initialization. + * + * @return true - initialized. + * false - not initialized. + */ + virtual bool IsInitialised() const; + + /** + * @brief Destructor. + */ + virtual ~CloudWebsocketConnectionFactory(); + + private: + TransportAdapterController* controller_; +}; + +} // namespace transport_adapter +} // namespace transport_manager + +#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_WEBSOCKET_CONNECTION_FACTORY_H_ 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 new file mode 100644 index 0000000000..ad31bd33b3 --- /dev/null +++ b/src/components/transport_manager/include/transport_manager/cloud/cloud_websocket_transport_adapter.h @@ -0,0 +1,105 @@ +/* + * \file cloud_websocket_transport_adapter.h + * \brief Cloud Websocket Transport Adapterclass header file. + * + * Copyright (c) 2018, Livio + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_WEBSOCKET_TRANSPORT_ADAPTER_H_ +#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_CLOUD_WEBSOCKET_TRANSPORT_ADAPTER_H_ + +#include "transport_manager/transport_adapter/transport_adapter_impl.h" + +namespace transport_manager { +namespace transport_adapter { + +/** + * @brief Cloud transport adapter that uses websockets. + */ +class CloudWebsocketTransportAdapter : public TransportAdapterImpl { + public: + /** + * @brief Constructor. + */ + explicit CloudWebsocketTransportAdapter(resumption::LastState& last_state, const TransportManagerSettings& settings); + + /** + * @brief Destructor. + */ + 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. + * + * @return String with device type. + */ + virtual DeviceType GetDeviceType() const; + + /** + * @brief Store adapter state in last state singleton + */ + virtual void Store() const; + + /** + * @brief Restore adapter state from last state singleton + * + * @return True on success false otherwise + */ + virtual bool Restore(); + + 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 +} // namespace transport_manager + +#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TCP_TCP_TRANSPORT_ADAPTER_H_ diff --git a/src/components/transport_manager/include/transport_manager/cloud/websocket_client_connection.h b/src/components/transport_manager/include/transport_manager/cloud/websocket_client_connection.h new file mode 100644 index 0000000000..38eb663b1c --- /dev/null +++ b/src/components/transport_manager/include/transport_manager/cloud/websocket_client_connection.h @@ -0,0 +1,180 @@ +/* + * \file websocket_client_connection.h + * \brief WebsocketClientConnection class header file. + * + * Copyright (c) 2018, Livio + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_WEBSOCKET_CLIENT_CONNECTION_H_ +#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_CLOUD_WEBSOCKET_CLIENT_CONNECTION_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "transport_manager/transport_adapter/connection.h" +#include "utils/threads/thread.h" +#include "utils/threads/message_loop_thread.h" +#include "utils/message_queue.h" + +using tcp = boost::asio::ip::tcp; // from +namespace ssl = boost::asio::ssl; // from +namespace websocket = boost::beast::websocket; // from +using ::utils::MessageQueue; + +typedef std::queue AsyncQueue; +typedef protocol_handler::RawMessagePtr Message; + +namespace transport_manager { +namespace transport_adapter { + +class TransportAdapterController; + +/** + * @brief Class responsible for communication over bluetooth sockets. + */ +class WebsocketClientConnection : public std::enable_shared_from_this, public Connection { + public: + /** + * @brief Constructor. + * + * @param device_uid Device unique identifier. + * @param app_handle Handle of device. + * @param controller Pointer to the device adapter controller. + */ + WebsocketClientConnection(const DeviceUID& device_uid, + const ApplicationHandle& app_handle, + TransportAdapterController* controller); + + /** + * @brief Destructor. + */ + virtual ~WebsocketClientConnection(); + + /** + * @brief Check if we can start the connection attempt and establish + *connection status. + * + * @param error contains information of any error that occurred during + *connection attempt. + * + * @return result that states whether we successfully connected or not. + */ + TransportAdapter::Error Start(); + + /** + * @brief Send data frame. + * + * @param message Smart pointer to the raw message. + * + * @return Error Information about possible reason of sending data failure. + */ + TransportAdapter::Error SendData(::protocol_handler::RawMessagePtr message); + + /** + * @brief Disconnect the current connection. + * + * @return Error Information about possible reason of Disconnect failure. + */ + TransportAdapter::Error Disconnect(); + + void Shutdown(); + + void Recv(boost::system::error_code ec); + + void OnRead(boost::system::error_code ec, + std::size_t bytes_transferred); + + + private: + + TransportAdapterController* controller_; + boost::asio::io_context ioc_; + tcp::resolver resolver_; + websocket::stream ws_; + boost::beast::flat_buffer buffer_; + std::string host_; + std::string text_; + + + std::atomic_bool shutdown_; + + typedef std::queue FrameQueue; + FrameQueue frames_to_send_; + mutable sync_primitives::Lock frames_to_send_mutex_; + + MessageQueue message_queue_; + + + class LoopThreadDelegate : public threads::ThreadDelegate { + public: + LoopThreadDelegate(MessageQueue* message_queue, + WebsocketClientConnection* handler); + + virtual void threadMain() OVERRIDE; + virtual void exitThreadMain() OVERRIDE; + + void OnWrite(); + + void SetShutdown(); + + private: + void DrainQueue(); + MessageQueue& message_queue_; + WebsocketClientConnection& handler_; + sync_primitives::Lock queue_lock_; + sync_primitives::ConditionalVariable queue_new_items_; + std::atomic_bool write_pending_; + std::atomic_bool shutdown_; + + sync_primitives::Lock write_lock_; + }; + + LoopThreadDelegate* thread_delegate_; + threads::Thread* write_thread_; + std::thread io_service_thread_; + + const DeviceUID device_uid_; + const ApplicationHandle app_handle_; +}; + +} // namespace transport_adapter +} // namespace transport_manager + +#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_BLUETOOTH_BLUETOOTH_SOCKET_CONNECTION_H_ diff --git a/src/components/transport_manager/src/cloud/cloud_device.cc b/src/components/transport_manager/src/cloud/cloud_device.cc new file mode 100644 index 0000000000..ab7f8db69a --- /dev/null +++ b/src/components/transport_manager/src/cloud/cloud_device.cc @@ -0,0 +1,62 @@ +/* + * + * Copyright (c) 2018, Livio + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "transport_manager/cloud/cloud_device.h" + +#include "utils/logger.h" + +namespace transport_manager { +namespace transport_adapter { +CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") + +CloudDevice::CloudDevice(std::string& host, + std::string& port, + std::string& name) + : Device(name, std::string(name+host+port)) {} + + +bool CloudDevice::IsSameAs(const Device* other) const { + LOG4CXX_TRACE(logger_, "enter. device: " << other); + bool result = false; + return result; +} + +//todo implement getApplicationList +//to be populated by policies +ApplicationList CloudDevice::GetApplicationList() const { + return ApplicationList{100}; +} + + +} // namespace transport_adapter +} // namespace transport_manager diff --git a/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc b/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc new file mode 100644 index 0000000000..d566dd9bf8 --- /dev/null +++ b/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc @@ -0,0 +1,99 @@ +/* + * \file cloud_websocket_connection_factory.cc + * \brief CloudWebsocketConnectionFactory class source file. + * + * Copyright (c) 2018, Livio + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "transport_manager/transport_adapter/transport_adapter_controller.h" +#include "transport_manager/cloud/cloud_websocket_connection_factory.h" +#include "transport_manager/cloud/websocket_client_connection.h" +#include "utils/logger.h" + +#include "transport_manager/cloud/cloud_device.h" + +namespace transport_manager { +namespace transport_adapter { + +CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") + +CloudWebsocketConnectionFactory::CloudWebsocketConnectionFactory( + TransportAdapterController* controller) + : controller_(controller) {} + +TransportAdapter::Error CloudWebsocketConnectionFactory::Init() { + DeviceUID device_id = "Cloud"; + ApplicationHandle app_handle = 100; + printf("Calling create connection\n"); + + std::string host("192.168.1.69"); + std::string port("8080"); + + //todo move this device logic to the correct place. + auto cloud_device = std::make_shared( + host,port,device_id); + DeviceVector devices{cloud_device}; + + controller_->SearchDeviceDone(devices); + + + const TransportAdapter::Error err = + this->CreateConnection(std::string(device_id+host+port), app_handle); + LOG4CXX_DEBUG(logger_, err); + return TransportAdapter::OK; +} + +TransportAdapter::Error CloudWebsocketConnectionFactory::CreateConnection( + const DeviceUID& device_uid, const ApplicationHandle& app_handle) { + LOG4CXX_AUTO_TRACE(logger_); + printf("Create connection()\n"); + std::shared_ptr connection = + std::make_shared( + device_uid, app_handle, controller_); + controller_->ConnectionCreated(connection, device_uid, app_handle); + TransportAdapter::Error error = connection->Start(); + if (TransportAdapter::OK != error) { + LOG4CXX_ERROR(logger_, + "Cloud Websocket connection::Start() failed with error: " << error); + } + return error; +} + +void CloudWebsocketConnectionFactory::Terminate() {} + +bool CloudWebsocketConnectionFactory::IsInitialised() const { + return true; +} + +CloudWebsocketConnectionFactory::~CloudWebsocketConnectionFactory() {} + +} // namespace transport_adapter +} // namespace transport_manager 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 new file mode 100644 index 0000000000..29ea6e5b27 --- /dev/null +++ b/src/components/transport_manager/src/cloud/cloud_websocket_transport_adapter.cc @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018, Livio + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "transport_manager/cloud/cloud_websocket_transport_adapter.h" +#include "transport_manager/cloud/cloud_websocket_connection_factory.h" + +namespace transport_manager { +namespace transport_adapter { + +CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") + +CloudWebsocketTransportAdapter::CloudWebsocketTransportAdapter(resumption::LastState& last_state, const TransportManagerSettings& settings) +: TransportAdapterImpl(NULL, new CloudWebsocketConnectionFactory(this), NULL, last_state, settings) { + + /*DeviceUID device_id = "Cloud"; + ApplicationHandle app_handle = 100; + printf("Calling create connection\n"); + const TransportAdapter::Error err = + server_connection_factory_->CreateConnection(device_id, app_handle); + LOG4CXX_DEBUG(logger_, err);*/ +} + +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 + +bool CloudWebsocketTransportAdapter::Restore() { // todo decide if resumption is needed + return true; +} + + + + + +} +} \ No newline at end of file diff --git a/src/components/transport_manager/src/cloud/websocket_client_connection.cc b/src/components/transport_manager/src/cloud/websocket_client_connection.cc new file mode 100644 index 0000000000..96641f5cb2 --- /dev/null +++ b/src/components/transport_manager/src/cloud/websocket_client_connection.cc @@ -0,0 +1,252 @@ +/* + * + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "transport_manager/cloud/websocket_client_connection.h" + +#include "transport_manager/transport_adapter/transport_adapter_controller.h" + +#include "utils/logger.h" + +namespace transport_manager { +namespace transport_adapter { +CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") + +WebsocketClientConnection::WebsocketClientConnection( + const DeviceUID& device_uid, + const ApplicationHandle& app_handle, + TransportAdapterController* controller): controller_(controller) + , resolver_(ioc_) + , ws_(ioc_) + , shutdown_(false) + , thread_delegate_(new LoopThreadDelegate(&message_queue_, this)) + , write_thread_(threads::CreateThread("WS Async Send", thread_delegate_)) + , device_uid_(device_uid) + , app_handle_(app_handle) {} + +WebsocketClientConnection::~WebsocketClientConnection() { + ioc_.stop(); + if(io_service_thread_.joinable()) { + io_service_thread_.join(); + } +} + +TransportAdapter::Error WebsocketClientConnection::Start() { + LOG4CXX_AUTO_TRACE(logger_); + printf("Calling websocket start\n"); + auto const host = "192.168.1.69"; + auto const port = "8080"; + boost::system::error_code ec; + auto const results = resolver_.resolve(host, port, ec); + if (ec) { + std::string str_err = "ErrorMessage1: " + ec.message(); + printf("%s\n", str_err.c_str()); + Shutdown(); + return TransportAdapter::FAIL; + } + boost::asio::connect(ws_.next_layer(), results.begin(), results.end(), ec); + if (ec) { + std::string str_err = "ErrorMessage2: " + ec.message(); + printf("%s\n", str_err.c_str()); + Shutdown(); + return TransportAdapter::FAIL; + } + ws_.handshake(host, "/", ec); + if (ec) { + std::string str_err = "ErrorMessage3: " + ec.message(); + printf("%s\n", str_err.c_str()); + Shutdown(); + return TransportAdapter::FAIL; + } + ws_.binary(true); + write_thread_->start(threads::ThreadOptions()); + controller_->ConnectDone(device_uid_, app_handle_); + + // Start async read + ws_.async_read( + buffer_, + std::bind( + &WebsocketClientConnection::OnRead, + this, + std::placeholders::_1, + std::placeholders::_2)); + + // Start IO Service thread. Allows for async reads without blocking. + io_service_thread_ = std::thread([&](){ ioc_.run(); printf("io_service_thread_ END!!!\n"); + }); + + // Start async write thread + + printf("End of websockets\n"); + + return TransportAdapter::OK; +} + +void WebsocketClientConnection::Recv(boost::system::error_code ec) { + printf("Recv\n"); + if (shutdown_) { + printf("shutdown_\n"); + return; + } + + if (ec) { + std::string str_err = "ErrorMessage: " + ec.message(); + printf("%s\n", str_err.c_str()); + LOG4CXX_ERROR(logger_, str_err); + //shutdown_ = true; + //ioc_.stop(); + //thread_delegate_->SetShutdown(); + //controller_->deleteController(this); + Shutdown(); + return; + } + printf("calling async read\n"); + + ws_.async_read( + buffer_, + std::bind( + &WebsocketClientConnection::OnRead, + this, + std::placeholders::_1, + std::placeholders::_2)); +} + +void WebsocketClientConnection::OnRead(boost::system::error_code ec, + std::size_t bytes_transferred) { + printf("OnRead\n"); + boost::ignore_unused(bytes_transferred); + if (ec) { + std::string str_err = "ErrorMessage: " + ec.message(); + printf("%s\n", str_err.c_str()); + LOG4CXX_ERROR(logger_, str_err); + Shutdown(); + controller_->ConnectionAborted( + device_uid_, app_handle_, CommunicationError()); + + printf("return error\n"); + return; + } + + std::string data_str = boost::beast::buffers_to_string(buffer_.data()); + LOG4CXX_DEBUG(logger_, "Cloud Transport Received: " << data_str); + printf("%s\n", data_str.c_str()); + + ssize_t size = (ssize_t)buffer_.size(); + const uint8_t* data = boost::asio::buffer_cast(boost::beast::buffers_front(buffer_.data())); + + ::protocol_handler::RawMessagePtr frame( + new protocol_handler::RawMessage(0, 0, data, size)); + + controller_->DataReceiveDone(device_uid_, app_handle_, frame); + + buffer_.consume(buffer_.size()); + Recv(ec); +} + +TransportAdapter::Error WebsocketClientConnection::SendData( + ::protocol_handler::RawMessagePtr message) { + LOG4CXX_AUTO_TRACE(logger_); + printf("Send DATA!!!\n"); + sync_primitives::AutoLock auto_lock(frames_to_send_mutex_); + message_queue_.push(message); + printf("Data pushed to queue!!!\n"); + return TransportAdapter::OK; +} + +TransportAdapter::Error WebsocketClientConnection::Disconnect() { + LOG4CXX_AUTO_TRACE(logger_); + Shutdown(); + return TransportAdapter::OK; +} + +void WebsocketClientConnection::Shutdown() { + + shutdown_ = true; + + if (thread_delegate_) { + thread_delegate_->SetShutdown(); + write_thread_->join(); + printf("Joined Thread Delegate!!!\n"); + delete thread_delegate_; + } + if (buffer_.size()) { + buffer_.consume(buffer_.size()); + } + printf("End of shutdown!!!\n"); +} + +WebsocketClientConnection::LoopThreadDelegate::LoopThreadDelegate( + MessageQueue* message_queue, WebsocketClientConnection* handler) + : message_queue_(*message_queue), handler_(*handler), shutdown_(false) {} + +void WebsocketClientConnection::LoopThreadDelegate::threadMain() { + printf("Starting write thread\n"); + while (!message_queue_.IsShuttingDown() && !shutdown_) { + DrainQueue(); + message_queue_.wait(); + } + DrainQueue(); +} + +void WebsocketClientConnection::LoopThreadDelegate::exitThreadMain() { + shutdown_ = true; + if (!message_queue_.IsShuttingDown()) { + message_queue_.Shutdown(); + } +} + +void WebsocketClientConnection::LoopThreadDelegate::DrainQueue() { + while (!message_queue_.empty()) { + Message message_ptr; + message_queue_.pop(message_ptr); + if (!shutdown_) { + printf("Calling Write!!!\n"); + boost::system::error_code ec; + handler_.ws_.write(boost::asio::buffer(message_ptr->data(), message_ptr->data_size())); + if (ec) { + LOG4CXX_ERROR(logger_, "Error writing to websocket"); + handler_.Shutdown(); + handler_.controller_->DataSendFailed(handler_.device_uid_, handler_.app_handle_, message_ptr, DataSendError()); + } + } + } +} + +void WebsocketClientConnection::LoopThreadDelegate::SetShutdown() { + shutdown_ = true; + if (!message_queue_.IsShuttingDown()) { + message_queue_.Shutdown(); + } +} + +} // namespace transport_adapter +} // namespace transport_manager \ No newline at end of file diff --git a/src/components/transport_manager/src/transport_manager_default.cc b/src/components/transport_manager/src/transport_manager_default.cc index 196ad09af4..f78c31c0d5 100644 --- a/src/components/transport_manager/src/transport_manager_default.cc +++ b/src/components/transport_manager/src/transport_manager_default.cc @@ -44,6 +44,10 @@ #include "transport_manager/usb/usb_aoa_adapter.h" #endif // USB_SUPPORT +#if defined(CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT) +#include "transport_manager/cloud/cloud_websocket_transport_adapter.h" +#endif + #if defined(BUILD_TESTS) #include "transport_manager/iap2_emulation/iap2_transport_adapter.h" #endif // BUILD_TEST @@ -101,6 +105,18 @@ int TransportManagerDefault::Init(resumption::LastState& last_state) { ta_usb = NULL; #endif // USB_SUPPORT +#if defined CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT + printf("Creating cloud transport\n"); + transport_adapter::TransportAdapterImpl* ta_cloud = new transport_adapter::CloudWebsocketTransportAdapter(last_state, get_settings()); //Todo add retry connection logic from ini to initializer. +#ifdef TELEMETRY_MONITOR + if (metric_observer_) { + ta_cloud->SetTelemetryObserver(metric_observer_); + } +#endif // TELEMETRY_MONITOR + AddTransportAdapter(ta_cloud); + ta_cloud = NULL; +#endif + #if defined BUILD_TESTS const uint16_t iap2_bt_emu_port = 23456; transport_adapter::IAP2BluetoothEmulationTransportAdapter* -- cgit v1.2.1 From 6441bdcc5fecb267ae1f0aa3bd6647b25822d587 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Fri, 9 Nov 2018 13:18:22 -0500 Subject: Pending cloud connection created via policies on startup --- src/3rd_party/CMakeLists.txt | 6 ++-- .../src/application_manager_impl.cc | 14 +++++++- .../connection_handler/connection_handler_impl.h | 8 +++++ .../src/connection_handler_impl.cc | 40 +++++++++++++++++---- .../hmi_message_handler/src/websocket_session.cc | 1 - .../transport_adapter/transport_adapter.h | 2 ++ .../transport_adapter/transport_adapter_event.h | 3 +- .../transport_manager/transport_manager_listener.h | 8 +++++ .../transport_manager_listener_empty.h | 9 +++++ src/components/interfaces/HMI_API.xml | 1 + .../protocol_handler/protocol_handler_impl.h | 4 +++ .../protocol_handler/src/protocol_handler_impl.cc | 5 +++ src/components/transport_manager/CMakeLists.txt | 6 ++++ .../cloud/cloud_websocket_transport_adapter.h | 2 ++ .../transport_adapter_controller.h | 10 ++++++ .../transport_adapter/transport_adapter_impl.h | 16 ++++++++- .../transport_adapter/transport_adapter_listener.h | 13 +++++++ .../transport_adapter_listener_impl.h | 13 +++++++ .../cloud/cloud_websocket_connection_factory.cc | 4 +-- .../src/cloud/cloud_websocket_transport_adapter.cc | 42 ++++++++++++++++++++++ .../transport_adapter/transport_adapter_impl.cc | 22 +++++++++++- .../transport_adapter_listener_impl.cc | 21 +++++++++++ .../src/transport_manager_impl.cc | 35 ++++++++++++++++++ 23 files changed, 269 insertions(+), 16 deletions(-) diff --git a/src/3rd_party/CMakeLists.txt b/src/3rd_party/CMakeLists.txt index bdb96de417..60d68e9d60 100644 --- a/src/3rd_party/CMakeLists.txt +++ b/src/3rd_party/CMakeLists.txt @@ -209,7 +209,7 @@ else() ) endif() -find_package(Boost 1.66.0 COMPONENTS system thread date_time filesystem) +find_package(Boost 1.66.0 COMPONENTS system thread date_time filesystem regex) set(BOOST_LIB_SOURCE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/boost_src) set(BOOST_LIBS_DIRECTORY ${3RD_PARTY_INSTALL_PREFIX}/lib) SET_PROPERTY(GLOBAL PROPERTY GLOBAL_BOOST_LIBS ${BOOST_LIBS_DIRECTORY}) @@ -226,9 +226,9 @@ if (NOT ${Boost_FOUND}) URL https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz DOWNLOAD_DIR ${BOOST_LIB_SOURCE_DIRECTORY} SOURCE_DIR ${BOOST_LIB_SOURCE_DIRECTORY} - CONFIGURE_COMMAND ./bootstrap.sh --with-libraries=system,thread,date_time,filesystem --prefix=${3RD_PARTY_INSTALL_PREFIX} + CONFIGURE_COMMAND ./bootstrap.sh --with-libraries=system,thread,date_time,filesystem,regex --prefix=${3RD_PARTY_INSTALL_PREFIX} BUILD_COMMAND ./b2 - INSTALL_COMMAND ${BOOST_INSTALL_COMMAND} --with-system --with-thread --with-date_time --with-filesystem --prefix=${3RD_PARTY_INSTALL_PREFIX} > boost_install.log + INSTALL_COMMAND ${BOOST_INSTALL_COMMAND} --with-system --with-thread --with-date_time --with-filesystem --with-regex --prefix=${3RD_PARTY_INSTALL_PREFIX} > boost_install.log INSTALL_DIR ${3RD_PARTY_INSTALL_PREFIX} BUILD_IN_SOURCE true ) diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 4a0bb63bae..061f3885a9 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -98,7 +98,9 @@ DeviceTypes devicesType = { std::make_pair(std::string("USB_IOS_DEVICE_MODE"), hmi_apis::Common_TransportType::USB_IOS), std::make_pair(std::string("CARPLAY_WIRELESS_IOS"), - hmi_apis::Common_TransportType::WIFI)}; + hmi_apis::Common_TransportType::WIFI), + std::make_pair(std::string("CLOUD_WEBSOCKET"), + hmi_apis::Common_TransportType::CLOUD_WEBSOCKET)}; } /** @@ -798,6 +800,16 @@ void ApplicationManagerImpl::CollectCloudAppInformation() { cloud_transport_type, hybrid_app_preference); connection_handler().AddCloudAppDevice(*it, endpoint, cloud_transport_type); + std::string device_mac; + std::string connection_type; + /*ApplicationSharedPtr application( + new ApplicationImpl(app_id, + policy_app_id, + device_mac, + device_id, + app_name, + GetPolicyHandler().GetStatisticManager(), + *this)); */ } } 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 5984f74c34..81db445829 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 @@ -164,6 +164,14 @@ class ConnectionHandlerImpl void OnScanDevicesFailed( const transport_manager::SearchDeviceError& error) OVERRIDE; + /** + * \brief Notifies about pending connection. + * + * \param connection_id ID of new connection. + **/ + void OnConnectionPending( + const transport_manager::DeviceInfo& device_info, + const transport_manager::ConnectionUID connection_id) OVERRIDE; /** * \brief Notifies about established connection. * diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index 290b1a650e..d1c62e36bb 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -246,6 +246,32 @@ void ConnectionHandlerImpl::OnScanDevicesFailed( LOG4CXX_WARN(logger_, "Scan devices failed. " << error.text()); } +void ConnectionHandlerImpl::OnConnectionPending( + const transport_manager::DeviceInfo& device_info, + const transport_manager::ConnectionUID connection_id) { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "OnConnectionEstablished!!!: " << device_info.device_handle() << " " << device_info.name() << " " << device_info.mac_address() << " " << device_info.connection_type()); + DeviceMap::iterator it = device_list_.find(device_info.device_handle()); + if (device_list_.end() == it) { + LOG4CXX_ERROR(logger_, "Unknown device!"); + return; + } + 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_list_.insert(ConnectionList::value_type( + connection_id, + new Connection(connection_id, + device_info.device_handle(), + this, + get_settings().heart_beat_timeout()))); + } +} + void ConnectionHandlerImpl::OnConnectionEstablished( const transport_manager::DeviceInfo& device_info, const transport_manager::ConnectionUID connection_id) { @@ -259,12 +285,14 @@ void ConnectionHandlerImpl::OnConnectionEstablished( LOG4CXX_DEBUG(logger_, "Add Connection #" << connection_id << " to the list."); sync_primitives::AutoWriteLock lock(connection_list_lock_); - connection_list_.insert(ConnectionList::value_type( - connection_id, - new Connection(connection_id, - device_info.device_handle(), - this, - get_settings().heart_beat_timeout()))); + if (connection_list_.find(connection_id) == connection_list_.end()) { + connection_list_.insert(ConnectionList::value_type( + connection_id, + new Connection(connection_id, + device_info.device_handle(), + this, + get_settings().heart_beat_timeout()))); + } } void ConnectionHandlerImpl::OnConnectionFailed( diff --git a/src/components/hmi_message_handler/src/websocket_session.cc b/src/components/hmi_message_handler/src/websocket_session.cc index 041a89ef82..a148f48661 100644 --- a/src/components/hmi_message_handler/src/websocket_session.cc +++ b/src/components/hmi_message_handler/src/websocket_session.cc @@ -71,7 +71,6 @@ bool WebsocketSession::IsShuttingDown() { } void WebsocketSession::Recv(boost::system::error_code ec) { - printf("!!!server recv connection accepted\n"); if (shutdown_) { return; } 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 6af29aa7c2..d47c53b69c 100644 --- a/src/components/include/transport_manager/transport_adapter/transport_adapter.h +++ b/src/components/include/transport_manager/transport_adapter/transport_adapter.h @@ -348,6 +348,8 @@ class TransportAdapter { */ virtual TransportConfig GetTransportConfiguration() const = 0; + virtual void CreateDevice(const std::string& uid) = 0; + #ifdef TELEMETRY_MONITOR /** * @brief Return Time metric observer diff --git a/src/components/include/transport_manager/transport_adapter/transport_adapter_event.h b/src/components/include/transport_manager/transport_adapter/transport_adapter_event.h index fd1d693067..921562333b 100644 --- a/src/components/include/transport_manager/transport_adapter/transport_adapter_event.h +++ b/src/components/include/transport_manager/transport_adapter/transport_adapter_event.h @@ -58,7 +58,8 @@ enum class EventTypeEnum { ON_COMMUNICATION_ERROR, ON_UNEXPECTED_DISCONNECT, ON_TRANSPORT_SWITCH_REQUESTED, - ON_TRANSPORT_CONFIG_UPDATED + ON_TRANSPORT_CONFIG_UPDATED, + ON_CONNECT_PENDING }; class TransportAdapterEvent { diff --git a/src/components/include/transport_manager/transport_manager_listener.h b/src/components/include/transport_manager/transport_manager_listener.h index 6c3f6e2eaa..2d7b2510a5 100644 --- a/src/components/include/transport_manager/transport_manager_listener.h +++ b/src/components/include/transport_manager/transport_manager_listener.h @@ -100,6 +100,14 @@ class TransportManagerListener { */ virtual void OnScanDevicesFailed(const SearchDeviceError& error) = 0; + /** + * @brief Reaction to the event, when connection is pending. + * + * @param devcie_info Variable that hold information about device. + * @param connection_id connection unique identifier. + */ + virtual void OnConnectionPending(const DeviceInfo& device_info, + const ConnectionUID connection_id) = 0; /** * @brief Reaction to the event, when connection is established. * diff --git a/src/components/include/transport_manager/transport_manager_listener_empty.h b/src/components/include/transport_manager/transport_manager_listener_empty.h index 08b2b77c30..d8104a62a9 100644 --- a/src/components/include/transport_manager/transport_manager_listener_empty.h +++ b/src/components/include/transport_manager/transport_manager_listener_empty.h @@ -98,6 +98,15 @@ class TransportManagerListenerEmpty : public TransportManagerListener { */ void OnScanDevicesFailed(const SearchDeviceError& error) OVERRIDE {} + /** + * @brief Reaction to the event, when connection is pending. + * + * @param devcie_info Variable that hold information about device. + * @param connection_id connection unique identifier. + */ + void OnConnectionPending(const DeviceInfo& device_info, + const ConnectionUID connection_id) OVERRIDE {} + /** * @brief Reaction to the event, when connection is established. * diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml index 97df559ef5..2c2adc6b36 100644 --- a/src/components/interfaces/HMI_API.xml +++ b/src/components/interfaces/HMI_API.xml @@ -72,6 +72,7 @@ + diff --git a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h index 3e7d64e9d2..ccf6082a18 100644 --- a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h +++ b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h @@ -512,6 +512,10 @@ class ProtocolHandlerImpl void OnTMMessageSendFailed(const transport_manager::DataSendError& error, const RawMessagePtr message) OVERRIDE; + void OnConnectionPending( + const transport_manager::DeviceInfo& device_info, + const transport_manager::ConnectionUID connection_id) OVERRIDE; + void OnConnectionEstablished( const transport_manager::DeviceInfo& device_info, const transport_manager::ConnectionUID connection_id) OVERRIDE; diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index d03030b747..3fb21d7d0d 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -1087,6 +1087,11 @@ void ProtocolHandlerImpl::OnTMMessageSendFailed( << "Error_text: " << error.text()); } +void ProtocolHandlerImpl::OnConnectionPending( + const transport_manager::DeviceInfo& device_info, + const transport_manager::ConnectionUID connection_id) { +} + void ProtocolHandlerImpl::OnConnectionEstablished( const transport_manager::DeviceInfo& device_info, const transport_manager::ConnectionUID connection_id) { diff --git a/src/components/transport_manager/CMakeLists.txt b/src/components/transport_manager/CMakeLists.txt index 2f734b3a05..286e62b795 100644 --- a/src/components/transport_manager/CMakeLists.txt +++ b/src/components/transport_manager/CMakeLists.txt @@ -72,6 +72,11 @@ else() ) endif() +if(BUILD_CLOUD_APP_SUPPORT) + GET_PROPERTY(BOOST_LIBS_DIRECTORY GLOBAL PROPERTY GLOBAL_BOOST_LIBS) + list(APPEND LIBRARIES boost_system boost_regex -L${BOOST_LIBS_DIRECTORY}) +endif() + if(BUILD_USB_SUPPORT) if (CMAKE_SYSTEM_NAME STREQUAL "Linux") set(EXCLUDE_PATHS @@ -129,3 +134,4 @@ endif() if(BUILD_TESTS) add_subdirectory(test) endif() + 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 ad31bd33b3..062b478c29 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 @@ -88,6 +88,8 @@ class CloudWebsocketTransportAdapter : public TransportAdapterImpl { */ virtual bool Restore(); + void CreateDevice(const std::string& uid) OVERRIDE; + private: /** * @brief Keeps transport specific configuration diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h index 69d76b4b2b..8bc39596b6 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h @@ -99,6 +99,16 @@ class TransportAdapterController { const DeviceUID& device_handle, const ApplicationHandle& app_handle) = 0; + /** + * @brief Set state of specified connection - PENDING and launch + *OnConnectPending event in device adapter listener. + * + * @param devcie_handle Device unique identifier. + * @param app_handle Handle of application. + */ + virtual void ConnectPending(const DeviceUID& device_handle, + const ApplicationHandle& app_handle) = 0; + /** * @brief Make state of specified connection - ESTABLISHED and launch *OnConnectDone event in device adapter listener. 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 078f93b32f..ccc025b60e 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 @@ -305,6 +305,16 @@ class TransportAdapterImpl : public TransportAdapter, const ApplicationHandle& app_handle, const CommunicationError& error) OVERRIDE; + /** + * @brief Set state of specified connection - PENDING and launch + *OnConnectPending event in device adapter listener. + * + * @param devcie_handle Device unique identifier. + * @param app_handle Handle of application. + */ + void ConnectPending(const DeviceUID& device_handle, + const ApplicationHandle& app_handle) OVERRIDE; + /** * @brief Set state of specified connection - ESTABLISHED and launch *OnConnectDone event in device adapter listener. @@ -434,6 +444,10 @@ class TransportAdapterImpl : public TransportAdapter, return TransportConfig(); } + void CreateDevice(const std::string& uid) OVERRIDE { + return; + } + /** * @brief Return name of device. * @@ -564,7 +578,7 @@ class TransportAdapterImpl : public TransportAdapter, ConnectionSPtr connection; DeviceUID device_id; ApplicationHandle app_handle; - enum { NEW, ESTABLISHED, FINALISING } state; + enum { NEW, ESTABLISHED, FINALISING, PENDING, RETRY } state; }; /** diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h index 4606bac2d4..fe71983ab7 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h @@ -91,6 +91,19 @@ class TransportAdapterListener { virtual void OnFindNewApplicationsRequest( const TransportAdapter* adapter) = 0; + /** + * @brief Search specified device adapter in the container of shared pointers + * to device adapters to be sure it is available, + * launch event ON_CONNECT_PENDING in transport manager. + * + * @param device_adater Pointer to the device adapter. + * @param device_handle Device unique identifier. + * @param app_id Handle of application. + */ + virtual void OnConnectPending(const TransportAdapter* adapter, + const DeviceUID& device_handle, + const ApplicationHandle& app_id) = 0; + /** * @brief Search specified device adapter in the container of shared pointers *to device adapters to be sure it is available, diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h index a744400279..f4a5062eac 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h @@ -87,6 +87,19 @@ class TransportAdapterListenerImpl virtual void OnFindNewApplicationsRequest(const TransportAdapter* adapter); + /** + * @brief Search specified device adapter in the container of shared pointers + * to device adapters to be sure it is available, + * launch event ON_CONNECT_PENDING in transport manager. + * + * @param device_adater Pointer to the device adapter. + * @param device_handle Device unique identifier. + * @param app_id Handle of application. + */ + virtual void OnConnectPending(const TransportAdapter* adapter, + const DeviceUID& device_handle, + const ApplicationHandle& app_id); + /** * @brief Search specified device adapter in the container of shared pointers *to device adapters to be sure it is available, diff --git a/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc b/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc index d566dd9bf8..9265adb7f3 100644 --- a/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc +++ b/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc @@ -50,7 +50,7 @@ CloudWebsocketConnectionFactory::CloudWebsocketConnectionFactory( : controller_(controller) {} TransportAdapter::Error CloudWebsocketConnectionFactory::Init() { - DeviceUID device_id = "Cloud"; + /*DeviceUID device_id = "Cloud"; ApplicationHandle app_handle = 100; printf("Calling create connection\n"); @@ -67,7 +67,7 @@ TransportAdapter::Error CloudWebsocketConnectionFactory::Init() { const TransportAdapter::Error err = this->CreateConnection(std::string(device_id+host+port), app_handle); - LOG4CXX_DEBUG(logger_, err); + LOG4CXX_DEBUG(logger_, err);*/ return TransportAdapter::OK; } 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 29ea6e5b27..746eafbcc3 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 @@ -33,6 +33,13 @@ #include "transport_manager/cloud/cloud_websocket_transport_adapter.h" #include "transport_manager/cloud/cloud_websocket_connection_factory.h" + +#include "transport_manager/cloud/cloud_device.h" +#include "transport_manager/cloud/websocket_client_connection.h" + + +#include + namespace transport_manager { namespace transport_adapter { @@ -65,6 +72,41 @@ bool CloudWebsocketTransportAdapter::Restore() { // todo decide if resumption is return true; } +void CloudWebsocketTransportAdapter::CreateDevice(const std::string& uid) { + boost::regex pattern ("(wss?):\\/\\/([A-Z\\d\\.-]{2,})\\.([A-Z]{2,})(:\\d{2,4})", boost::regex::icase); + std::string str = uid; + if (!boost::regex_match(str, pattern)) { + LOG4CXX_DEBUG(logger_, "Invalid Endpoint: " << uid); + return; + } + + LOG4CXX_DEBUG(logger_, "Valid Endpoint: " << uid); + std::size_t pos = uid.find(":"); + pos = uid.find(":", pos+1); + std::size_t size = uid.length(); + std::string host = uid.substr(0, size - pos); + std::string port = uid.substr(pos); + std::string device_id = uid; + + LOG4CXX_DEBUG(logger_, "Creating Cloud Device For Host: " << host << " and Port: " << port); + + auto cloud_device = std::make_shared(host, port, device_id); + + DeviceVector devices{cloud_device}; + + SearchDeviceDone(devices); + + //Create connection object, do not start until app is activated + std::shared_ptr connection = + std::make_shared( + uid, 0, this); + + ConnectionCreated(connection, uid, 0); + ConnectDone(uid, 0); + + return; +} + 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 346139cbd2..088cc2efb5 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 @@ -60,7 +60,9 @@ DeviceTypes devicesType = { std::make_pair(DeviceType::IOS_USB_DEVICE_MODE, std::string("USB_IOS_DEVICE_MODE")), std::make_pair(DeviceType::IOS_CARPLAY_WIRELESS, - std::string("CARPLAY_WIRELESS_IOS"))}; + std::string("CARPLAY_WIRELESS_IOS")), + std::make_pair(DeviceType::CLOUD_WEBSOCKET, std::string("CLOUD_WEBSOCKET")) + }; } TransportAdapterImpl::TransportAdapterImpl( @@ -743,6 +745,24 @@ DeviceSptr TransportAdapterImpl::FindDevice(const DeviceUID& device_id) const { return ret; } +void TransportAdapterImpl::ConnectPending(const DeviceUID& device_id, + const ApplicationHandle& app_handle) { + connections_lock_.AcquireForReading(); + ConnectionMap::iterator it_conn = + connections_.find(std::make_pair(device_id, app_handle)); + if (it_conn != connections_.end()) { + ConnectionInfo& info = it_conn->second; + info.state = ConnectionInfo::PENDING; + } + connections_lock_.Release(); + + for (TransportAdapterListenerList::iterator it = listeners_.begin(); + it != listeners_.end(); + ++it) { + (*it)->OnConnectPending(this, device_id, app_handle); + } +} + void TransportAdapterImpl::ConnectDone(const DeviceUID& device_id, const ApplicationHandle& app_handle) { LOG4CXX_TRACE(logger_, diff --git a/src/components/transport_manager/src/transport_adapter/transport_adapter_listener_impl.cc b/src/components/transport_manager/src/transport_adapter/transport_adapter_listener_impl.cc index 544cdde999..73750fe2f3 100644 --- a/src/components/transport_manager/src/transport_adapter/transport_adapter_listener_impl.cc +++ b/src/components/transport_manager/src/transport_adapter/transport_adapter_listener_impl.cc @@ -116,6 +116,27 @@ void TransportAdapterListenerImpl::OnFindNewApplicationsRequest( LOG4CXX_TRACE(logger_, "exit"); } +void TransportAdapterListenerImpl::OnConnectPending( + const TransportAdapter* adapter, + const DeviceUID& device, + const ApplicationHandle& application_id) { + LOG4CXX_TRACE(logger_, + "enter adapter*: " << adapter << ", device: " << &device + << ", application_id: " << &application_id); + const TransportAdapterEvent event(EventTypeEnum::ON_CONNECT_PENDING, + transport_adapter_, + device, + application_id, + ::protocol_handler::RawMessagePtr(), + BaseErrorPtr(new BaseError())); + if (transport_manager_ != NULL && + transport_manager::E_SUCCESS != + transport_manager_->ReceiveEventFromDevice(event)) { + LOG4CXX_WARN(logger_, "Failed to receive event from device"); + } + LOG4CXX_TRACE(logger_, "exit"); +} + void TransportAdapterListenerImpl::OnConnectDone( const TransportAdapter* adapter, const DeviceUID& device, diff --git a/src/components/transport_manager/src/transport_manager_impl.cc b/src/components/transport_manager/src/transport_manager_impl.cc index 63fa4b451d..693dc4406b 100644 --- a/src/components/transport_manager/src/transport_manager_impl.cc +++ b/src/components/transport_manager/src/transport_manager_impl.cc @@ -130,6 +130,22 @@ void TransportManagerImpl::ReconnectionTimeout() { } void TransportManagerImpl::AddCloudDevice(const std::string& endpoint, const std::string& cloud_transport_type) { + + //todo put conversion into own function + transport_adapter::DeviceType type = transport_adapter::DeviceType::UNKNOWN; + if (cloud_transport_type == "WS") { + type = transport_adapter::DeviceType::CLOUD_WEBSOCKET; + } else { + return; + } + + std::vector::iterator ta = transport_adapters_.begin(); + for (;ta != transport_adapters_.end(); ++ta) { + if ((*ta)->GetDeviceType() == type) { + (*ta)->CreateDevice(endpoint); + } + } + return; } @@ -958,6 +974,25 @@ void TransportManagerImpl::Handle(TransportAdapterEvent event) { LOG4CXX_DEBUG(logger_, "event_type = ON_FIND_NEW_APPLICATIONS_REQUEST"); break; } + case EventTypeEnum::ON_CONNECT_PENDING: { + const DeviceHandle device_handle = converter_.UidToHandle( + event.device_uid, event.transport_adapter->GetConnectionType()); + AddConnection(ConnectionInternal(this, + event.transport_adapter, + ++connection_id_counter_, + event.device_uid, + event.application_id, + device_handle)); + RaiseEvent( + &TransportManagerListener::OnConnectionPending, + DeviceInfo(device_handle, + event.device_uid, + event.transport_adapter->DeviceName(event.device_uid), + event.transport_adapter->GetConnectionType()), + connection_id_counter_); + LOG4CXX_DEBUG(logger_, "event_type = ON_CONNECT_PENDING"); + break; + } case EventTypeEnum::ON_CONNECT_DONE: { const DeviceHandle device_handle = converter_.UidToHandle( event.device_uid, event.transport_adapter->GetConnectionType()); -- cgit v1.2.1 From 6e88b9a92a0c75def3424b75b0a9195597349231 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Fri, 9 Nov 2018 14:01:14 -0500 Subject: Check if connection exists in internal connection list --- .../src/transport_manager_impl.cc | 39 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/components/transport_manager/src/transport_manager_impl.cc b/src/components/transport_manager/src/transport_manager_impl.cc index 693dc4406b..ea85e9a37b 100644 --- a/src/components/transport_manager/src/transport_manager_impl.cc +++ b/src/components/transport_manager/src/transport_manager_impl.cc @@ -996,19 +996,44 @@ void TransportManagerImpl::Handle(TransportAdapterEvent event) { case EventTypeEnum::ON_CONNECT_DONE: { const DeviceHandle device_handle = converter_.UidToHandle( event.device_uid, event.transport_adapter->GetConnectionType()); - AddConnection(ConnectionInternal(this, - event.transport_adapter, - ++connection_id_counter_, - event.device_uid, - event.application_id, - device_handle)); + + int connection_id = 0; + std::vector::iterator it = connections_.begin(); + std::vector::iterator end = connections_.end(); + for(; it != end; ++it){ + if(it->transport_adapter != event.transport_adapter) { + continue; + } else if(it->Connection::device != event.device_uid) { + continue; + } else if(it->Connection::application != event.application_id) { + continue; + } else if(it->device_handle_ != device_handle) { + continue; + } else { + LOG4CXX_DEBUG(logger_, "Connection Object Already Exists"); + connection_id = it->Connection::id; + break; + } + } + + + if(it == end) { + AddConnection(ConnectionInternal(this, + event.transport_adapter, + ++connection_id_counter_, + event.device_uid, + event.application_id, + device_handle)); + connection_id = connection_id_counter_; + } + RaiseEvent( &TransportManagerListener::OnConnectionEstablished, DeviceInfo(device_handle, event.device_uid, event.transport_adapter->DeviceName(event.device_uid), event.transport_adapter->GetConnectionType()), - connection_id_counter_); + connection_id); LOG4CXX_DEBUG(logger_, "event_type = ON_CONNECT_DONE"); break; } -- cgit v1.2.1 From 691d5e4c34206daefe685f836a7ac90e2a211379 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Tue, 13 Nov 2018 16:40:23 -0500 Subject: Show pending cloud apps in update app list --- .../application_manager/application_manager_impl.h | 4 ++ .../src/application_manager_impl.cc | 52 +++++++++++++++++----- .../src/connection_handler_impl.cc | 17 +++++-- .../connection_handler_observer.h | 2 + .../transport_manager/src/cloud/cloud_device.cc | 2 +- .../src/cloud/cloud_websocket_transport_adapter.cc | 9 ++-- 6 files changed, 67 insertions(+), 19 deletions(-) diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 23d7fc4892..6f6482e717 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -362,6 +362,8 @@ class ApplicationManagerImpl void CollectCloudAppInformation(); + void CreatePendingApplication(const transport_manager::ConnectionUID connection_id, const transport_manager::DeviceInfo& device_info, connection_handler::DeviceHandle device_id); + /* * @brief Returns unique correlation ID for HMI request * @@ -1451,6 +1453,8 @@ class ApplicationManagerImpl DeviceMap secondary_transport_devices_cache_; + std::map pending_device_map_; + #ifdef TELEMETRY_MONITOR AMTelemetryObserver* metric_observer_; #endif // TELEMETRY_MONITOR diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 061f3885a9..76067f1dc7 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -799,18 +799,50 @@ void ApplicationManagerImpl::CollectCloudAppInformation() { GetPolicyHandler().GetCloudAppParameters(*it, endpoint, certificate, auth_token, cloud_transport_type, hybrid_app_preference); + pending_device_map_.insert(std::pair(endpoint, *it)); + connection_handler().AddCloudAppDevice(*it, endpoint, cloud_transport_type); - std::string device_mac; - std::string connection_type; - /*ApplicationSharedPtr application( - new ApplicationImpl(app_id, - policy_app_id, - device_mac, - device_id, - app_name, - GetPolicyHandler().GetStatisticManager(), - *this)); */ + + + } +} + +void ApplicationManagerImpl::CreatePendingApplication(const transport_manager::ConnectionUID connection_id, const transport_manager::DeviceInfo& device_info, connection_handler::DeviceHandle device_id) { + LOG4CXX_AUTO_TRACE(logger_); + + std::string policy_app_id = ""; + std::string name = device_info.name(); + auto it = pending_device_map_.find(name); + if (it == pending_device_map_.end()) { + return; + } + + policy_app_id = it->second; + ApplicationSharedPtr application( + new ApplicationImpl(0, + policy_app_id, + device_info.mac_address(), + device_id, + custom_str::CustomString("CloudApp"), //todo replace this with policy nick name + GetPolicyHandler().GetStatisticManager(), + *this)); + + if(!application) { + LOG4CXX_INFO(logger_, "Could not streate application"); + return; } + + application->set_hmi_application_id(GenerateNewHMIAppID()); + + sync_primitives::AutoLock lock(apps_to_register_list_lock_ptr_); + LOG4CXX_DEBUG( + logger_, "apps_to_register_ size before: " << apps_to_register_.size()); + apps_to_register_.insert(application); + LOG4CXX_DEBUG(logger_, + "apps_to_register_ size after: " << apps_to_register_.size()); + + SendUpdateAppList(); + } uint32_t ApplicationManagerImpl::GetNextHMICorrelationID() { diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index d1c62e36bb..59fef50b0f 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -263,13 +263,22 @@ void ConnectionHandlerImpl::OnConnectionPending( //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_list_.insert(ConnectionList::value_type( - connection_id, - new Connection(connection_id, + + Connection* connection = new Connection(connection_id, device_info.device_handle(), this, - get_settings().heart_beat_timeout()))); + get_settings().heart_beat_timeout()); + + connection_list_.insert(ConnectionList::value_type( + connection_id, connection)); + + connection_handler::DeviceHandle device_id = connection->connection_device_handle(); + //uint32_t app_id = KeyFromPair(connection_id, session_id); + + connection_handler_observer_->CreatePendingApplication(connection_id, device_info, device_id); } + + } void ConnectionHandlerImpl::OnConnectionEstablished( diff --git a/src/components/include/connection_handler/connection_handler_observer.h b/src/components/include/connection_handler/connection_handler_observer.h index 154a2a8e34..9716f2c890 100644 --- a/src/components/include/connection_handler/connection_handler_observer.h +++ b/src/components/include/connection_handler/connection_handler_observer.h @@ -161,6 +161,8 @@ class ConnectionHandlerObserver { */ virtual void OnSecondaryTransportEndedCallback(const int32_t session_key) = 0; + virtual void CreatePendingApplication(const transport_manager::ConnectionUID connection_id, const transport_manager::DeviceInfo& device_info, connection_handler::DeviceHandle device_id) = 0; + protected: /** * \brief Destructor diff --git a/src/components/transport_manager/src/cloud/cloud_device.cc b/src/components/transport_manager/src/cloud/cloud_device.cc index ab7f8db69a..df17753ccc 100644 --- a/src/components/transport_manager/src/cloud/cloud_device.cc +++ b/src/components/transport_manager/src/cloud/cloud_device.cc @@ -42,7 +42,7 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") CloudDevice::CloudDevice(std::string& host, std::string& port, std::string& name) - : Device(name, std::string(name+host+port)) {} + : Device(name, std::string(name)) {} bool CloudDevice::IsSameAs(const Device* other) const { 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 746eafbcc3..49a0020423 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 @@ -83,13 +83,14 @@ void CloudWebsocketTransportAdapter::CreateDevice(const std::string& uid) { LOG4CXX_DEBUG(logger_, "Valid Endpoint: " << uid); std::size_t pos = uid.find(":"); pos = uid.find(":", pos+1); - std::size_t size = uid.length(); - std::string host = uid.substr(0, size - pos); - std::string port = uid.substr(pos); + //std::size_t size = uid.length(); + std::string host = uid.substr(0, pos); + std::string port = uid.substr(pos+1); std::string device_id = uid; LOG4CXX_DEBUG(logger_, "Creating Cloud Device For Host: " << host << " and Port: " << port); + //todo get nickname from policies to name device auto cloud_device = std::make_shared(host, port, device_id); DeviceVector devices{cloud_device}; @@ -102,7 +103,7 @@ void CloudWebsocketTransportAdapter::CreateDevice(const std::string& uid) { uid, 0, this); ConnectionCreated(connection, uid, 0); - ConnectDone(uid, 0); + ConnectPending(uid, 0); return; } -- cgit v1.2.1 From c178b9827d52fe1da535cc68f4628ade32f17f80 Mon Sep 17 00:00:00 2001 From: jacobkeeler Date: Wed, 14 Nov 2018 14:28:35 -0500 Subject: Fix style --- .../include/application_manager/application.h | 6 +- .../include/application_manager/application_impl.h | 5 +- .../application_manager/application_manager_impl.h | 5 +- .../application_manager/src/application_impl.cc | 9 +- .../src/application_manager_impl.cc | 52 +++++----- .../include/config_profile/profile.h | 2 +- .../connection_handler/connection_handler_impl.h | 4 +- .../src/connection_handler_impl.cc | 45 ++++++--- .../connection_handler/connection_handler.h | 4 +- .../connection_handler_observer.h | 5 +- .../transport_adapter/transport_adapter.h | 7 +- .../include/transport_manager/transport_manager.h | 3 +- .../transport_manager/transport_manager_listener.h | 2 +- .../transport_manager_listener_empty.h | 2 +- .../transport_manager/transport_manager_settings.h | 2 +- .../protocol_handler/src/protocol_handler_impl.cc | 3 +- .../include/transport_manager/cloud/cloud_device.h | 6 +- .../cloud/cloud_websocket_transport_adapter.h | 6 +- .../cloud/websocket_client_connection.h | 34 +++---- .../transport_adapter_controller.h | 2 +- .../transport_adapter/transport_adapter_impl.h | 2 +- .../transport_adapter/transport_adapter_listener.h | 4 +- .../transport_adapter_listener_impl.h | 4 +- .../transport_manager/transport_manager_impl.h | 3 +- .../transport_manager/src/cloud/cloud_device.cc | 10 +- .../cloud/cloud_websocket_connection_factory.cc | 7 +- .../src/cloud/cloud_websocket_transport_adapter.cc | 110 +++++++++++---------- .../src/cloud/websocket_client_connection.cc | 82 +++++++-------- .../transport_adapter/transport_adapter_impl.cc | 6 +- .../src/transport_manager_default.cc | 5 +- .../src/transport_manager_impl.cc | 21 ++-- 31 files changed, 252 insertions(+), 206 deletions(-) diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index 700c0e5d2c..ef11de90d2 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -960,9 +960,11 @@ class Application : public virtual InitialApplicationData, virtual void set_cloud_app_auth_token(const std::string& auth_token) = 0; - virtual void set_cloud_app_transport_type(const std::string& transport_type) = 0; + virtual void set_cloud_app_transport_type( + const std::string& transport_type) = 0; - virtual void set_hybrid_app_preference(const std::string& hybrid_app_preference) = 0; + virtual void set_hybrid_app_preference( + const std::string& hybrid_app_preference) = 0; virtual void set_cloud_app_certificate(const std::string& certificate) = 0; diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index 0c365fc752..5a1a385d1e 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -425,7 +425,8 @@ class ApplicationImpl : public virtual Application, void set_cloud_app_transport_type(const std::string& transport_type) OVERRIDE; - void set_hybrid_app_preference(const std::string& hybrid_app_preference) OVERRIDE; + void set_hybrid_app_preference( + const std::string& hybrid_app_preference) OVERRIDE; void set_cloud_app_certificate(const std::string& certificate) OVERRIDE; @@ -537,7 +538,7 @@ class ApplicationImpl : public virtual Application, std::string endpoint_; std::string auth_token_; std::string cloud_transport_type_; - std::string hybrid_app_preference_; + std::string hybrid_app_preference_; std::string certificate_; /** diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 6f6482e717..20b8c561a3 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -362,7 +362,10 @@ class ApplicationManagerImpl void CollectCloudAppInformation(); - void CreatePendingApplication(const transport_manager::ConnectionUID connection_id, const transport_manager::DeviceInfo& device_info, connection_handler::DeviceHandle device_id); + void CreatePendingApplication( + const transport_manager::ConnectionUID connection_id, + const transport_manager::DeviceInfo& device_info, + connection_handler::DeviceHandle device_id); /* * @brief Returns unique correlation ID for HMI request diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 65f2a36fa8..027beb9313 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -1191,15 +1191,18 @@ void ApplicationImpl::set_cloud_app_auth_token(const std::string& auth_token) { auth_token_ = auth_token; } -void ApplicationImpl::set_cloud_app_transport_type(const std::string& transport_type) { +void ApplicationImpl::set_cloud_app_transport_type( + const std::string& transport_type) { cloud_transport_type_ = transport_type; } -void ApplicationImpl::set_hybrid_app_preference(const std::string& hybrid_app_preference) { +void ApplicationImpl::set_hybrid_app_preference( + const std::string& hybrid_app_preference) { hybrid_app_preference_ = hybrid_app_preference; } -void ApplicationImpl::set_cloud_app_certificate(const std::string& certificate) { +void ApplicationImpl::set_cloud_app_certificate( + const std::string& certificate) { certificate_ = certificate; } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 76067f1dc7..192468023d 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -100,7 +100,7 @@ DeviceTypes devicesType = { std::make_pair(std::string("CARPLAY_WIRELESS_IOS"), hmi_apis::Common_TransportType::WIFI), std::make_pair(std::string("CLOUD_WEBSOCKET"), - hmi_apis::Common_TransportType::CLOUD_WEBSOCKET)}; + hmi_apis::Common_TransportType::CLOUD_WEBSOCKET)}; } /** @@ -795,39 +795,46 @@ void ApplicationManagerImpl::CollectCloudAppInformation() { std::string auth_token = ""; std::string cloud_transport_type = ""; std::string hybrid_app_preference = ""; - for (; it!=end; ++it) { - GetPolicyHandler().GetCloudAppParameters(*it, endpoint, certificate, auth_token, - cloud_transport_type, hybrid_app_preference); + for (; it != end; ++it) { + GetPolicyHandler().GetCloudAppParameters(*it, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); - pending_device_map_.insert(std::pair(endpoint, *it)); + pending_device_map_.insert( + std::pair(endpoint, *it)); connection_handler().AddCloudAppDevice(*it, endpoint, cloud_transport_type); - - } } -void ApplicationManagerImpl::CreatePendingApplication(const transport_manager::ConnectionUID connection_id, const transport_manager::DeviceInfo& device_info, connection_handler::DeviceHandle device_id) { +void ApplicationManagerImpl::CreatePendingApplication( + const transport_manager::ConnectionUID connection_id, + const transport_manager::DeviceInfo& device_info, + connection_handler::DeviceHandle device_id) { LOG4CXX_AUTO_TRACE(logger_); std::string policy_app_id = ""; std::string name = device_info.name(); auto it = pending_device_map_.find(name); if (it == pending_device_map_.end()) { - return; + return; } - + policy_app_id = it->second; - ApplicationSharedPtr application( - new ApplicationImpl(0, - policy_app_id, - device_info.mac_address(), - device_id, - custom_str::CustomString("CloudApp"), //todo replace this with policy nick name - GetPolicyHandler().GetStatisticManager(), - *this)); - - if(!application) { + ApplicationSharedPtr application(new ApplicationImpl( + 0, + policy_app_id, + device_info.mac_address(), + device_id, + custom_str::CustomString( + "CloudApp"), // todo replace this with policy nick name + GetPolicyHandler().GetStatisticManager(), + *this)); + + if (!application) { LOG4CXX_INFO(logger_, "Could not streate application"); return; } @@ -835,14 +842,13 @@ void ApplicationManagerImpl::CreatePendingApplication(const transport_manager::C application->set_hmi_application_id(GenerateNewHMIAppID()); sync_primitives::AutoLock lock(apps_to_register_list_lock_ptr_); - LOG4CXX_DEBUG( - logger_, "apps_to_register_ size before: " << apps_to_register_.size()); + LOG4CXX_DEBUG(logger_, + "apps_to_register_ size before: " << apps_to_register_.size()); apps_to_register_.insert(application); LOG4CXX_DEBUG(logger_, "apps_to_register_ size after: " << apps_to_register_.size()); SendUpdateAppList(); - } uint32_t ApplicationManagerImpl::GetNextHMICorrelationID() { diff --git a/src/components/config_profile/include/config_profile/profile.h b/src/components/config_profile/include/config_profile/profile.h index da087086c2..b332ed69f5 100644 --- a/src/components/config_profile/include/config_profile/profile.h +++ b/src/components/config_profile/include/config_profile/profile.h @@ -415,7 +415,7 @@ class Profile : public protocol_handler::ProtocolHandlerSettings, /** * @brief Returns retry timeout for cloud app connections - */ + */ uint16_t cloud_app_retry_timeout() const OVERRIDE; /** 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 81db445829..7be94c5f70 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 @@ -120,7 +120,9 @@ class ConnectionHandlerImpl void ConnectToAllDevices() OVERRIDE; - void AddCloudAppDevice(const std::string& policy_app_id, const std::string& endpoint, const std::string& cloud_transport_type) OVERRIDE; + void AddCloudAppDevice(const std::string& policy_app_id, + const std::string& endpoint, + const std::string& cloud_transport_type) OVERRIDE; void StartTransportManager() OVERRIDE; diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index 59fef50b0f..318224fcc7 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -142,7 +142,10 @@ void ConnectionHandlerImpl::OnDeviceAdded( LOG4CXX_AUTO_TRACE(logger_); auto handle = device_info.device_handle(); - LOG4CXX_DEBUG(logger_, "OnDeviceAdded!!!: " << handle << " " << device_info.name() << " " << device_info.mac_address() << " " << device_info.connection_type()); + LOG4CXX_DEBUG(logger_, + "OnDeviceAdded!!!: " << handle << " " << device_info.name() + << " " << device_info.mac_address() << " " + << device_info.connection_type()); Device device(handle, device_info.name(), @@ -250,7 +253,11 @@ void ConnectionHandlerImpl::OnConnectionPending( const transport_manager::DeviceInfo& device_info, const transport_manager::ConnectionUID connection_id) { LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG(logger_, "OnConnectionEstablished!!!: " << device_info.device_handle() << " " << device_info.name() << " " << device_info.mac_address() << " " << device_info.connection_type()); + LOG4CXX_DEBUG(logger_, + "OnConnectionEstablished!!!: " + << device_info.device_handle() << " " << device_info.name() + << " " << device_info.mac_address() << " " + << device_info.connection_type()); DeviceMap::iterator it = device_list_.find(device_info.device_handle()); if (device_list_.end() == it) { LOG4CXX_ERROR(logger_, "Unknown device!"); @@ -259,33 +266,36 @@ void ConnectionHandlerImpl::OnConnectionPending( LOG4CXX_DEBUG(logger_, "Add Pending Connection #" << connection_id << " to the list."); - - //todo maybe create a seperate "pending_connection_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 = new Connection(connection_id, + Connection* connection = + new Connection(connection_id, device_info.device_handle(), this, get_settings().heart_beat_timeout()); - connection_list_.insert(ConnectionList::value_type( - connection_id, connection)); - - connection_handler::DeviceHandle device_id = connection->connection_device_handle(); - //uint32_t app_id = KeyFromPair(connection_id, session_id); - - connection_handler_observer_->CreatePendingApplication(connection_id, device_info, device_id); - } + connection_list_.insert( + ConnectionList::value_type(connection_id, connection)); + connection_handler::DeviceHandle device_id = + connection->connection_device_handle(); + // uint32_t app_id = KeyFromPair(connection_id, session_id); + connection_handler_observer_->CreatePendingApplication( + connection_id, device_info, device_id); + } } void ConnectionHandlerImpl::OnConnectionEstablished( const transport_manager::DeviceInfo& device_info, const transport_manager::ConnectionUID connection_id) { LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG(logger_, "OnConnectionEstablished!!!: " << device_info.device_handle() << " " << device_info.name() << " " << device_info.mac_address() << " " << device_info.connection_type()); + LOG4CXX_DEBUG(logger_, + "OnConnectionEstablished!!!: " + << device_info.device_handle() << " " << device_info.name() + << " " << device_info.mac_address() << " " + << device_info.connection_type()); DeviceMap::iterator it = device_list_.find(device_info.device_handle()); if (device_list_.end() == it) { LOG4CXX_ERROR(logger_, "Unknown device!"); @@ -1306,7 +1316,10 @@ void ConnectionHandlerImpl::ConnectToAllDevices() { } } -void ConnectionHandlerImpl::AddCloudAppDevice(const std::string& policy_app_id, const std::string& endpoint, const std::string& cloud_transport_type) { +void ConnectionHandlerImpl::AddCloudAppDevice( + const std::string& policy_app_id, + const std::string& endpoint, + const std::string& cloud_transport_type) { transport_manager_.AddCloudDevice(endpoint, cloud_transport_type); } diff --git a/src/components/include/connection_handler/connection_handler.h b/src/components/include/connection_handler/connection_handler.h index 21c10dc3db..93939fc782 100644 --- a/src/components/include/connection_handler/connection_handler.h +++ b/src/components/include/connection_handler/connection_handler.h @@ -93,7 +93,9 @@ class ConnectionHandler { virtual void ConnectToAllDevices() = 0; - virtual void AddCloudAppDevice(const std::string& policy_app_id, const std::string& endpoint, const std::string& cloud_transport_type) = 0; + virtual void AddCloudAppDevice(const std::string& policy_app_id, + const std::string& endpoint, + const std::string& cloud_transport_type) = 0; /** * @brief Close the connection revoked by Policy diff --git a/src/components/include/connection_handler/connection_handler_observer.h b/src/components/include/connection_handler/connection_handler_observer.h index 9716f2c890..298f98803a 100644 --- a/src/components/include/connection_handler/connection_handler_observer.h +++ b/src/components/include/connection_handler/connection_handler_observer.h @@ -161,7 +161,10 @@ class ConnectionHandlerObserver { */ virtual void OnSecondaryTransportEndedCallback(const int32_t session_key) = 0; - virtual void CreatePendingApplication(const transport_manager::ConnectionUID connection_id, const transport_manager::DeviceInfo& device_info, connection_handler::DeviceHandle device_id) = 0; + virtual void CreatePendingApplication( + const transport_manager::ConnectionUID connection_id, + const transport_manager::DeviceInfo& device_info, + connection_handler::DeviceHandle device_id) = 0; protected: /** 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 d47c53b69c..4aa6e901ad 100644 --- a/src/components/include/transport_manager/transport_adapter/transport_adapter.h +++ b/src/components/include/transport_manager/transport_adapter/transport_adapter.h @@ -71,9 +71,9 @@ enum DeviceType { UNKNOWN }; -enum HybridAppPreference { // todo find correct place for this enum defintion. +enum HybridAppPreference { // todo find correct place for this enum defintion. MOBILE, - CLOUD, + CLOUD, BOTH }; @@ -105,7 +105,8 @@ typedef std::list TransportAdapterListenerList; typedef std::map TransportConfig; /** - * @brief Type definition of container indexed by app id that contains connection information for all cloud apps. + * @brief Type definition of container indexed by app id that contains + * connection information for all cloud apps. */ typedef std::map CloudAppTransportConfig; diff --git a/src/components/include/transport_manager/transport_manager.h b/src/components/include/transport_manager/transport_manager.h index f67923daef..b5dfa3671b 100644 --- a/src/components/include/transport_manager/transport_manager.h +++ b/src/components/include/transport_manager/transport_manager.h @@ -75,7 +75,8 @@ class TransportManager { **/ virtual int SearchDevices() = 0; - virtual void AddCloudDevice(const std::string& endpoint, const std::string& cloud_transport_type) = 0; + virtual void AddCloudDevice(const std::string& endpoint, + const std::string& cloud_transport_type) = 0; /** * @brief Connect to all applications discovered on device. diff --git a/src/components/include/transport_manager/transport_manager_listener.h b/src/components/include/transport_manager/transport_manager_listener.h index 2d7b2510a5..7da4bcc2f5 100644 --- a/src/components/include/transport_manager/transport_manager_listener.h +++ b/src/components/include/transport_manager/transport_manager_listener.h @@ -107,7 +107,7 @@ class TransportManagerListener { * @param connection_id connection unique identifier. */ virtual void OnConnectionPending(const DeviceInfo& device_info, - const ConnectionUID connection_id) = 0; + const ConnectionUID connection_id) = 0; /** * @brief Reaction to the event, when connection is established. * diff --git a/src/components/include/transport_manager/transport_manager_listener_empty.h b/src/components/include/transport_manager/transport_manager_listener_empty.h index d8104a62a9..c0a713f38e 100644 --- a/src/components/include/transport_manager/transport_manager_listener_empty.h +++ b/src/components/include/transport_manager/transport_manager_listener_empty.h @@ -105,7 +105,7 @@ class TransportManagerListenerEmpty : public TransportManagerListener { * @param connection_id connection unique identifier. */ void OnConnectionPending(const DeviceInfo& device_info, - const ConnectionUID connection_id) OVERRIDE {} + const ConnectionUID connection_id) OVERRIDE {} /** * @brief Reaction to the event, when connection is established. diff --git a/src/components/include/transport_manager/transport_manager_settings.h b/src/components/include/transport_manager/transport_manager_settings.h index d59038e5c6..30a5a98ae9 100644 --- a/src/components/include/transport_manager/transport_manager_settings.h +++ b/src/components/include/transport_manager/transport_manager_settings.h @@ -72,7 +72,7 @@ class TransportManagerSettings : public TransportManagerMMESettings { /** * @brief Returns retry timeout for cloud app connections - */ + */ virtual uint16_t cloud_app_retry_timeout() const = 0; /** diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index 3fb21d7d0d..ee2dc73780 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -1089,8 +1089,7 @@ void ProtocolHandlerImpl::OnTMMessageSendFailed( void ProtocolHandlerImpl::OnConnectionPending( const transport_manager::DeviceInfo& device_info, - const transport_manager::ConnectionUID connection_id) { -} + const transport_manager::ConnectionUID connection_id) {} void ProtocolHandlerImpl::OnConnectionEstablished( const transport_manager::DeviceInfo& device_info, 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 5792ba06a1..f80ad924e3 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 @@ -45,9 +45,7 @@ namespace transport_adapter { class CloudDevice : public Device { public: - CloudDevice(std::string& host, - std::string& port, - std::string& name); + CloudDevice(std::string& host, std::string& port, std::string& name); protected: virtual bool IsSameAs(const Device* other_device) const; @@ -55,7 +53,7 @@ class CloudDevice : public Device { virtual ApplicationList GetApplicationList() const; private: - //todo add private varaibles, maybe ip port or other connection information? + // todo add private varaibles, maybe ip port or other connection information? }; } // namespace transport_adapter 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 062b478c29..546ab71fbd 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 @@ -49,7 +49,9 @@ class CloudWebsocketTransportAdapter : public TransportAdapterImpl { /** * @brief Constructor. */ - explicit CloudWebsocketTransportAdapter(resumption::LastState& last_state, const TransportManagerSettings& settings); + explicit CloudWebsocketTransportAdapter( + resumption::LastState& last_state, + const TransportManagerSettings& settings); /** * @brief Destructor. @@ -93,7 +95,7 @@ class CloudWebsocketTransportAdapter : public TransportAdapterImpl { 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". diff --git a/src/components/transport_manager/include/transport_manager/cloud/websocket_client_connection.h b/src/components/transport_manager/include/transport_manager/cloud/websocket_client_connection.h index 38eb663b1c..da3a80e1b2 100644 --- a/src/components/transport_manager/include/transport_manager/cloud/websocket_client_connection.h +++ b/src/components/transport_manager/include/transport_manager/cloud/websocket_client_connection.h @@ -53,12 +53,13 @@ #include "utils/threads/message_loop_thread.h" #include "utils/message_queue.h" -using tcp = boost::asio::ip::tcp; // from -namespace ssl = boost::asio::ssl; // from -namespace websocket = boost::beast::websocket; // from +using tcp = boost::asio::ip::tcp; // from +namespace ssl = boost::asio::ssl; // from +namespace websocket = + boost::beast::websocket; // from using ::utils::MessageQueue; -typedef std::queue AsyncQueue; +typedef std::queue AsyncQueue; typedef protocol_handler::RawMessagePtr Message; namespace transport_manager { @@ -69,7 +70,9 @@ class TransportAdapterController; /** * @brief Class responsible for communication over bluetooth sockets. */ -class WebsocketClientConnection : public std::enable_shared_from_this, public Connection { +class WebsocketClientConnection + : public std::enable_shared_from_this, + public Connection { public: /** * @brief Constructor. @@ -98,13 +101,13 @@ class WebsocketClientConnection : public std::enable_shared_from_this message_queue_; - class LoopThreadDelegate : public threads::ThreadDelegate { public: LoopThreadDelegate(MessageQueue* message_queue, diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h index 8bc39596b6..6d97a55a70 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_controller.h @@ -107,7 +107,7 @@ class TransportAdapterController { * @param app_handle Handle of application. */ virtual void ConnectPending(const DeviceUID& device_handle, - const ApplicationHandle& app_handle) = 0; + const ApplicationHandle& app_handle) = 0; /** * @brief Make state of specified connection - ESTABLISHED and launch 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 ccc025b60e..0af1f2b614 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 @@ -313,7 +313,7 @@ class TransportAdapterImpl : public TransportAdapter, * @param app_handle Handle of application. */ void ConnectPending(const DeviceUID& device_handle, - const ApplicationHandle& app_handle) OVERRIDE; + const ApplicationHandle& app_handle) OVERRIDE; /** * @brief Set state of specified connection - ESTABLISHED and launch diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h index fe71983ab7..b0368869e7 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener.h @@ -101,8 +101,8 @@ class TransportAdapterListener { * @param app_id Handle of application. */ virtual void OnConnectPending(const TransportAdapter* adapter, - const DeviceUID& device_handle, - const ApplicationHandle& app_id) = 0; + const DeviceUID& device_handle, + const ApplicationHandle& app_id) = 0; /** * @brief Search specified device adapter in the container of shared pointers diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h index f4a5062eac..76271229ad 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_listener_impl.h @@ -97,8 +97,8 @@ class TransportAdapterListenerImpl * @param app_id Handle of application. */ virtual void OnConnectPending(const TransportAdapter* adapter, - const DeviceUID& device_handle, - const ApplicationHandle& app_id); + const DeviceUID& device_handle, + const ApplicationHandle& app_id); /** * @brief Search specified device adapter in the container of shared pointers diff --git a/src/components/transport_manager/include/transport_manager/transport_manager_impl.h b/src/components/transport_manager/include/transport_manager/transport_manager_impl.h index e2ce07ad18..dcb3b6922c 100644 --- a/src/components/transport_manager/include/transport_manager/transport_manager_impl.h +++ b/src/components/transport_manager/include/transport_manager/transport_manager_impl.h @@ -140,7 +140,8 @@ class TransportManagerImpl **/ int SearchDevices() OVERRIDE; - void AddCloudDevice(const std::string& endpoint, const std::string& cloud_transport_type) OVERRIDE; + void AddCloudDevice(const std::string& endpoint, + const std::string& cloud_transport_type) OVERRIDE; /** * @brief Connect to all applications discovered on device. diff --git a/src/components/transport_manager/src/cloud/cloud_device.cc b/src/components/transport_manager/src/cloud/cloud_device.cc index df17753ccc..699d79d52a 100644 --- a/src/components/transport_manager/src/cloud/cloud_device.cc +++ b/src/components/transport_manager/src/cloud/cloud_device.cc @@ -40,23 +40,21 @@ namespace transport_adapter { CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") CloudDevice::CloudDevice(std::string& host, - std::string& port, - std::string& name) + std::string& port, + std::string& name) : Device(name, std::string(name)) {} - bool CloudDevice::IsSameAs(const Device* other) const { LOG4CXX_TRACE(logger_, "enter. device: " << other); bool result = false; return result; } -//todo implement getApplicationList -//to be populated by policies +// todo implement getApplicationList +// to be populated by policies ApplicationList CloudDevice::GetApplicationList() const { return ApplicationList{100}; } - } // namespace transport_adapter } // namespace transport_manager diff --git a/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc b/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc index 9265adb7f3..2b2a5ee2aa 100644 --- a/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc +++ b/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc @@ -75,14 +75,15 @@ TransportAdapter::Error CloudWebsocketConnectionFactory::CreateConnection( const DeviceUID& device_uid, const ApplicationHandle& app_handle) { LOG4CXX_AUTO_TRACE(logger_); printf("Create connection()\n"); - std::shared_ptr connection = + std::shared_ptr connection = std::make_shared( device_uid, app_handle, controller_); controller_->ConnectionCreated(connection, device_uid, app_handle); TransportAdapter::Error error = connection->Start(); if (TransportAdapter::OK != error) { - LOG4CXX_ERROR(logger_, - "Cloud Websocket connection::Start() failed with error: " << error); + LOG4CXX_ERROR( + logger_, + "Cloud Websocket connection::Start() failed with error: " << error); } return error; } 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 49a0020423..978cfd191a 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 @@ -33,11 +33,9 @@ #include "transport_manager/cloud/cloud_websocket_transport_adapter.h" #include "transport_manager/cloud/cloud_websocket_connection_factory.h" - #include "transport_manager/cloud/cloud_device.h" #include "transport_manager/cloud/websocket_client_connection.h" - #include namespace transport_manager { @@ -45,72 +43,80 @@ namespace transport_adapter { CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") -CloudWebsocketTransportAdapter::CloudWebsocketTransportAdapter(resumption::LastState& last_state, const TransportManagerSettings& settings) -: TransportAdapterImpl(NULL, new CloudWebsocketConnectionFactory(this), NULL, last_state, settings) { - - /*DeviceUID device_id = "Cloud"; - ApplicationHandle app_handle = 100; - printf("Calling create connection\n"); - const TransportAdapter::Error err = +CloudWebsocketTransportAdapter::CloudWebsocketTransportAdapter( + resumption::LastState& last_state, const TransportManagerSettings& settings) + : TransportAdapterImpl(NULL, + new CloudWebsocketConnectionFactory(this), + NULL, + last_state, + settings) { + /*DeviceUID device_id = "Cloud"; + ApplicationHandle app_handle = 100; + printf("Calling create connection\n"); + const TransportAdapter::Error err = server_connection_factory_->CreateConnection(device_id, app_handle); LOG4CXX_DEBUG(logger_, err);*/ } CloudWebsocketTransportAdapter::~CloudWebsocketTransportAdapter() {} -void CloudWebsocketTransportAdapter::CloudTransportConfigUpdated(const CloudAppTransportConfig& new_config) {} +void CloudWebsocketTransportAdapter::CloudTransportConfigUpdated( + const CloudAppTransportConfig& new_config) {} -CloudAppTransportConfig CloudWebsocketTransportAdapter::GetCloudTransportConfiguration() const { return transport_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 { +} // todo decide if this is needed -bool CloudWebsocketTransportAdapter::Restore() { // todo decide if resumption is needed - return true; +bool CloudWebsocketTransportAdapter::Restore() { // todo decide if resumption + // is needed + return true; } void CloudWebsocketTransportAdapter::CreateDevice(const std::string& uid) { - boost::regex pattern ("(wss?):\\/\\/([A-Z\\d\\.-]{2,})\\.([A-Z]{2,})(:\\d{2,4})", boost::regex::icase); - std::string str = uid; - if (!boost::regex_match(str, pattern)) { - LOG4CXX_DEBUG(logger_, "Invalid Endpoint: " << uid); - return; - } - - LOG4CXX_DEBUG(logger_, "Valid Endpoint: " << uid); - std::size_t pos = uid.find(":"); - pos = uid.find(":", pos+1); - //std::size_t size = uid.length(); - std::string host = uid.substr(0, pos); - std::string port = uid.substr(pos+1); - std::string device_id = uid; - - LOG4CXX_DEBUG(logger_, "Creating Cloud Device For Host: " << host << " and Port: " << port); - - //todo get nickname from policies to name device - auto cloud_device = std::make_shared(host, port, device_id); - - DeviceVector devices{cloud_device}; - - SearchDeviceDone(devices); - - //Create connection object, do not start until app is activated - std::shared_ptr connection = - std::make_shared( - uid, 0, this); - - ConnectionCreated(connection, uid, 0); - ConnectPending(uid, 0); - - return; + boost::regex pattern( + "(wss?):\\/\\/([A-Z\\d\\.-]{2,})\\.([A-Z]{2,})(:\\d{2,4})", + boost::regex::icase); + std::string str = uid; + if (!boost::regex_match(str, pattern)) { + LOG4CXX_DEBUG(logger_, "Invalid Endpoint: " << uid); + return; + } + + LOG4CXX_DEBUG(logger_, "Valid Endpoint: " << uid); + std::size_t pos = uid.find(":"); + pos = uid.find(":", pos + 1); + // std::size_t size = uid.length(); + std::string host = uid.substr(0, pos); + std::string port = uid.substr(pos + 1); + std::string device_id = uid; + + LOG4CXX_DEBUG(logger_, + "Creating Cloud Device For Host: " << host + << " and Port: " << port); + + // todo get nickname from policies to name device + auto cloud_device = std::make_shared(host, port, device_id); + + DeviceVector devices{cloud_device}; + + SearchDeviceDone(devices); + + // Create connection object, do not start until app is activated + std::shared_ptr connection = + std::make_shared(uid, 0, this); + + ConnectionCreated(connection, uid, 0); + ConnectPending(uid, 0); + + return; } - - - - - } } \ No newline at end of file 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 96641f5cb2..c2dcc9f14a 100644 --- a/src/components/transport_manager/src/cloud/websocket_client_connection.cc +++ b/src/components/transport_manager/src/cloud/websocket_client_connection.cc @@ -44,18 +44,19 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") WebsocketClientConnection::WebsocketClientConnection( const DeviceUID& device_uid, const ApplicationHandle& app_handle, - TransportAdapterController* controller): controller_(controller) - , resolver_(ioc_) - , ws_(ioc_) - , shutdown_(false) - , thread_delegate_(new LoopThreadDelegate(&message_queue_, this)) - , write_thread_(threads::CreateThread("WS Async Send", thread_delegate_)) - , device_uid_(device_uid) - , app_handle_(app_handle) {} + TransportAdapterController* controller) + : controller_(controller) + , resolver_(ioc_) + , ws_(ioc_) + , shutdown_(false) + , thread_delegate_(new LoopThreadDelegate(&message_queue_, this)) + , write_thread_(threads::CreateThread("WS Async Send", thread_delegate_)) + , device_uid_(device_uid) + , app_handle_(app_handle) {} WebsocketClientConnection::~WebsocketClientConnection() { ioc_.stop(); - if(io_service_thread_.joinable()) { + if (io_service_thread_.joinable()) { io_service_thread_.join(); } } @@ -92,20 +93,20 @@ TransportAdapter::Error WebsocketClientConnection::Start() { controller_->ConnectDone(device_uid_, app_handle_); // Start async read - ws_.async_read( - buffer_, - std::bind( - &WebsocketClientConnection::OnRead, - this, - std::placeholders::_1, - std::placeholders::_2)); + ws_.async_read(buffer_, + std::bind(&WebsocketClientConnection::OnRead, + this, + std::placeholders::_1, + std::placeholders::_2)); // Start IO Service thread. Allows for async reads without blocking. - io_service_thread_ = std::thread([&](){ ioc_.run(); printf("io_service_thread_ END!!!\n"); - }); + io_service_thread_ = std::thread([&]() { + ioc_.run(); + printf("io_service_thread_ END!!!\n"); + }); // Start async write thread - + printf("End of websockets\n"); return TransportAdapter::OK; @@ -122,26 +123,24 @@ void WebsocketClientConnection::Recv(boost::system::error_code ec) { std::string str_err = "ErrorMessage: " + ec.message(); printf("%s\n", str_err.c_str()); LOG4CXX_ERROR(logger_, str_err); - //shutdown_ = true; - //ioc_.stop(); - //thread_delegate_->SetShutdown(); - //controller_->deleteController(this); + // shutdown_ = true; + // ioc_.stop(); + // thread_delegate_->SetShutdown(); + // controller_->deleteController(this); Shutdown(); return; } printf("calling async read\n"); - ws_.async_read( - buffer_, - std::bind( - &WebsocketClientConnection::OnRead, - this, - std::placeholders::_1, - std::placeholders::_2)); + ws_.async_read(buffer_, + std::bind(&WebsocketClientConnection::OnRead, + this, + std::placeholders::_1, + std::placeholders::_2)); } void WebsocketClientConnection::OnRead(boost::system::error_code ec, - std::size_t bytes_transferred) { + std::size_t bytes_transferred) { printf("OnRead\n"); boost::ignore_unused(bytes_transferred); if (ec) { @@ -151,7 +150,7 @@ void WebsocketClientConnection::OnRead(boost::system::error_code ec, Shutdown(); controller_->ConnectionAborted( device_uid_, app_handle_, CommunicationError()); - + printf("return error\n"); return; } @@ -160,11 +159,12 @@ void WebsocketClientConnection::OnRead(boost::system::error_code ec, LOG4CXX_DEBUG(logger_, "Cloud Transport Received: " << data_str); printf("%s\n", data_str.c_str()); - ssize_t size = (ssize_t)buffer_.size(); - const uint8_t* data = boost::asio::buffer_cast(boost::beast::buffers_front(buffer_.data())); + ssize_t size = (ssize_t)buffer_.size(); + const uint8_t* data = boost::asio::buffer_cast( + boost::beast::buffers_front(buffer_.data())); ::protocol_handler::RawMessagePtr frame( - new protocol_handler::RawMessage(0, 0, data, size)); + new protocol_handler::RawMessage(0, 0, data, size)); controller_->DataReceiveDone(device_uid_, app_handle_, frame); @@ -189,7 +189,6 @@ TransportAdapter::Error WebsocketClientConnection::Disconnect() { } void WebsocketClientConnection::Shutdown() { - shutdown_ = true; if (thread_delegate_) { @@ -205,7 +204,8 @@ void WebsocketClientConnection::Shutdown() { } WebsocketClientConnection::LoopThreadDelegate::LoopThreadDelegate( - MessageQueue* message_queue, WebsocketClientConnection* handler) + MessageQueue* message_queue, + WebsocketClientConnection* handler) : message_queue_(*message_queue), handler_(*handler), shutdown_(false) {} void WebsocketClientConnection::LoopThreadDelegate::threadMain() { @@ -231,11 +231,15 @@ void WebsocketClientConnection::LoopThreadDelegate::DrainQueue() { if (!shutdown_) { printf("Calling Write!!!\n"); boost::system::error_code ec; - handler_.ws_.write(boost::asio::buffer(message_ptr->data(), message_ptr->data_size())); + handler_.ws_.write( + boost::asio::buffer(message_ptr->data(), message_ptr->data_size())); if (ec) { LOG4CXX_ERROR(logger_, "Error writing to websocket"); handler_.Shutdown(); - handler_.controller_->DataSendFailed(handler_.device_uid_, handler_.app_handle_, message_ptr, DataSendError()); + handler_.controller_->DataSendFailed(handler_.device_uid_, + handler_.app_handle_, + message_ptr, + DataSendError()); } } } 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 088cc2efb5..38b9bd3998 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 @@ -61,8 +61,8 @@ DeviceTypes devicesType = { std::string("USB_IOS_DEVICE_MODE")), std::make_pair(DeviceType::IOS_CARPLAY_WIRELESS, std::string("CARPLAY_WIRELESS_IOS")), - std::make_pair(DeviceType::CLOUD_WEBSOCKET, std::string("CLOUD_WEBSOCKET")) - }; + std::make_pair(DeviceType::CLOUD_WEBSOCKET, + std::string("CLOUD_WEBSOCKET"))}; } TransportAdapterImpl::TransportAdapterImpl( @@ -746,7 +746,7 @@ DeviceSptr TransportAdapterImpl::FindDevice(const DeviceUID& device_id) const { } void TransportAdapterImpl::ConnectPending(const DeviceUID& device_id, - const ApplicationHandle& app_handle) { + const ApplicationHandle& app_handle) { connections_lock_.AcquireForReading(); ConnectionMap::iterator it_conn = connections_.find(std::make_pair(device_id, app_handle)); diff --git a/src/components/transport_manager/src/transport_manager_default.cc b/src/components/transport_manager/src/transport_manager_default.cc index f78c31c0d5..3beed2f763 100644 --- a/src/components/transport_manager/src/transport_manager_default.cc +++ b/src/components/transport_manager/src/transport_manager_default.cc @@ -107,7 +107,10 @@ int TransportManagerDefault::Init(resumption::LastState& last_state) { #if defined CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT printf("Creating cloud transport\n"); - transport_adapter::TransportAdapterImpl* ta_cloud = new transport_adapter::CloudWebsocketTransportAdapter(last_state, get_settings()); //Todo add retry connection logic from ini to initializer. + transport_adapter::TransportAdapterImpl* ta_cloud = + new transport_adapter::CloudWebsocketTransportAdapter( + last_state, get_settings()); // Todo add retry connection logic from + // ini to initializer. #ifdef TELEMETRY_MONITOR if (metric_observer_) { ta_cloud->SetTelemetryObserver(metric_observer_); diff --git a/src/components/transport_manager/src/transport_manager_impl.cc b/src/components/transport_manager/src/transport_manager_impl.cc index ea85e9a37b..300ed27718 100644 --- a/src/components/transport_manager/src/transport_manager_impl.cc +++ b/src/components/transport_manager/src/transport_manager_impl.cc @@ -129,9 +129,9 @@ void TransportManagerImpl::ReconnectionTimeout() { device_to_reconnect_); } -void TransportManagerImpl::AddCloudDevice(const std::string& endpoint, const std::string& cloud_transport_type) { - - //todo put conversion into own function +void TransportManagerImpl::AddCloudDevice( + const std::string& endpoint, const std::string& cloud_transport_type) { + // todo put conversion into own function transport_adapter::DeviceType type = transport_adapter::DeviceType::UNKNOWN; if (cloud_transport_type == "WS") { type = transport_adapter::DeviceType::CLOUD_WEBSOCKET; @@ -140,7 +140,7 @@ void TransportManagerImpl::AddCloudDevice(const std::string& endpoint, const std } std::vector::iterator ta = transport_adapters_.begin(); - for (;ta != transport_adapters_.end(); ++ta) { + for (; ta != transport_adapters_.end(); ++ta) { if ((*ta)->GetDeviceType() == type) { (*ta)->CreateDevice(endpoint); } @@ -1000,14 +1000,14 @@ void TransportManagerImpl::Handle(TransportAdapterEvent event) { int connection_id = 0; std::vector::iterator it = connections_.begin(); std::vector::iterator end = connections_.end(); - for(; it != end; ++it){ - if(it->transport_adapter != event.transport_adapter) { + for (; it != end; ++it) { + if (it->transport_adapter != event.transport_adapter) { continue; - } else if(it->Connection::device != event.device_uid) { + } else if (it->Connection::device != event.device_uid) { continue; - } else if(it->Connection::application != event.application_id) { + } else if (it->Connection::application != event.application_id) { continue; - } else if(it->device_handle_ != device_handle) { + } else if (it->device_handle_ != device_handle) { continue; } else { LOG4CXX_DEBUG(logger_, "Connection Object Already Exists"); @@ -1016,8 +1016,7 @@ void TransportManagerImpl::Handle(TransportAdapterEvent event) { } } - - if(it == end) { + if (it == end) { AddConnection(ConnectionInternal(this, event.transport_adapter, ++connection_id_counter_, -- cgit v1.2.1 From ed2b5929389a4de02e74242c47c89e85bd25f5be Mon Sep 17 00:00:00 2001 From: JackLivio Date: Wed, 14 Nov 2018 14:30:23 -0500 Subject: Update regex pattern to allow ip address format --- .../transport_manager/src/cloud/cloud_websocket_transport_adapter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 49a0020423..bdb52d1387 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 @@ -73,7 +73,7 @@ bool CloudWebsocketTransportAdapter::Restore() { // todo decide if resumption is } void CloudWebsocketTransportAdapter::CreateDevice(const std::string& uid) { - boost::regex pattern ("(wss?):\\/\\/([A-Z\\d\\.-]{2,})\\.([A-Z]{2,})(:\\d{2,4})", boost::regex::icase); + boost::regex pattern ("(wss?):\\/\\/([A-Z\\d\\.-]{2,})\\.?([A-Z]{2,})?(:\\d{2,4})\\/", boost::regex::icase); std::string str = uid; if (!boost::regex_match(str, pattern)) { LOG4CXX_DEBUG(logger_, "Invalid Endpoint: " << uid); -- cgit v1.2.1 From 00a81813d4de6e20bda021d4c19d7054f27d875c Mon Sep 17 00:00:00 2001 From: JackLivio Date: Wed, 14 Nov 2018 16:27:05 -0500 Subject: Set Application Parameters --- .../src/application_manager_impl.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 192468023d..c5daf4bdc0 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -817,6 +817,12 @@ void ApplicationManagerImpl::CreatePendingApplication( LOG4CXX_AUTO_TRACE(logger_); 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 = ""; + std::string name = device_info.name(); auto it = pending_device_map_.find(name); if (it == pending_device_map_.end()) { @@ -824,6 +830,7 @@ void ApplicationManagerImpl::CreatePendingApplication( } policy_app_id = it->second; + ApplicationSharedPtr application(new ApplicationImpl( 0, policy_app_id, @@ -839,7 +846,19 @@ void ApplicationManagerImpl::CreatePendingApplication( return; } + GetPolicyHandler().GetCloudAppParameters(*it, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); + application->set_hmi_application_id(GenerateNewHMIAppID()); + application->set_cloud_app_endpoint(endpoint); + application->set_cloud_app_auth_token(auth_token); + application->set_cloud_app_transport_type(cloud_transport_type); + application->set_hybrid_app_preference(hybrid_app_preference); + application->set_cloud_app_certificate(certificate); sync_primitives::AutoLock lock(apps_to_register_list_lock_ptr_); LOG4CXX_DEBUG(logger_, -- cgit v1.2.1 From fbfe1fc119aaecd5cf0a1c9dfd495089ae20dc49 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Fri, 16 Nov 2018 13:09:47 -0500 Subject: Clean up application and app manager code --- .../include/application_manager/application.h | 45 +++++++++++++++++++--- .../include/application_manager/application_impl.h | 45 +++++++++++++++++++--- .../application_manager/src/application_impl.cc | 10 ++--- .../src/application_manager_impl.cc | 19 +++++++-- .../include/config_profile/profile.h | 4 +- src/components/config_profile/src/profile.cc | 2 +- .../transport_manager/transport_manager_settings.h | 2 +- 7 files changed, 104 insertions(+), 23 deletions(-) diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index ef11de90d2..b68fc083d7 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -946,26 +946,61 @@ class Application : public virtual InitialApplicationData, */ virtual const std::list& Extensions() const = 0; - virtual std::string cloud_app_endpoint() = 0; + /** + * @brief Get cloud app endpoint for websocket connection + * @return cloud app endpoint + */ + const virtual std::string cloud_app_endpoint() = 0; - virtual std::string cloud_app_authtoken() = 0; + /** + * @brief Get cloud app authtoken to be used in connection handshake after websocket open. + * @return cloud app authtoken + */ + const virtual std::string cloud_app_authtoken() = 0; - virtual std::string cloud_app_transport_type() = 0; + /** + * @brief Get cloud app tranpsport type. Defines the type of websocket connection used. + * @return cloud app transport type + */ + const virtual std::string cloud_app_transport_type() = 0; - virtual std::string hybrid_app_preference() = 0; + /** + * @brief Get hybrid app preference. Defines behaviour for when a similar mobile and cloud app are connected simultaneously. + * @return hybrid app preference + */ + const virtual std::string hybrid_app_preference() = 0; - virtual std::string cloud_app_certificate() = 0; + /** + * @brief Get cloud app certificate. Used for secured websocket connections. + * @return cloud app certificate. + */ + const virtual std::string cloud_app_certificate() = 0; + /** + * @brief Set cloud app endpoint + */ virtual void set_cloud_app_endpoint(const std::string& endpoint) = 0; + /** + * @brief Set cloud app auth token + */ virtual void set_cloud_app_auth_token(const std::string& auth_token) = 0; + /** + * @brief Set cloud app transport type + */ virtual void set_cloud_app_transport_type( const std::string& transport_type) = 0; + /** + * @brief Set hybrid app preference + */ virtual void set_hybrid_app_preference( const std::string& hybrid_app_preference) = 0; + /** + * @brief Set cloud app certificate + */ virtual void set_cloud_app_certificate(const std::string& certificate) = 0; protected: diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index 5a1a385d1e..74b2be0934 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -409,25 +409,60 @@ class ApplicationImpl : public virtual Application, void SwapMobileMessageQueue(MobileMessageQueue& mobile_messages) OVERRIDE; - std::string cloud_app_endpoint() OVERRIDE; + /** + * @brief Get cloud app endpoint for websocket connection + * @return cloud app endpoint + */ + const std::string cloud_app_endpoint() OVERRIDE; - std::string cloud_app_authtoken() OVERRIDE; + /** + * @brief Get cloud app authtoken to be used in connection handshake after websocket open. + * @return cloud app authtoken + */ + const std::string cloud_app_authtoken() OVERRIDE; - std::string cloud_app_transport_type() OVERRIDE; + /** + * @brief Get cloud app tranpsport type. Defines the type of websocket connection used. + * @return cloud app transport type + */ + const std::string cloud_app_transport_type() OVERRIDE; - std::string hybrid_app_preference() OVERRIDE; + /** + * @brief Get hybrid app preference. Defines behaviour for when a similar mobile and cloud app are connected simultaneously. + * @return hybrid app preference + */ + const std::string hybrid_app_preference() OVERRIDE; - std::string cloud_app_certificate() OVERRIDE; + /** + * @brief Get cloud app certificate. Used for secured websocket connections. + * @return cloud app certificate. + */ + const std::string cloud_app_certificate() OVERRIDE; + /** + * @brief Set cloud app endpoint + */ void set_cloud_app_endpoint(const std::string& endpoint) OVERRIDE; + /** + * @brief Set cloud app auth token + */ void set_cloud_app_auth_token(const std::string& auth_token) OVERRIDE; + /** + * @brief Set cloud app transport type + */ void set_cloud_app_transport_type(const std::string& transport_type) OVERRIDE; + /** + * @brief Set hybrid app preference + */ void set_hybrid_app_preference( const std::string& hybrid_app_preference) OVERRIDE; + /** + * @brief Set cloud app certificate + */ void set_cloud_app_certificate(const std::string& certificate) OVERRIDE; protected: diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 027beb9313..c92823bf77 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -1163,23 +1163,23 @@ const std::list& ApplicationImpl::Extensions() const { return extensions_; } -std::string ApplicationImpl::cloud_app_endpoint() { +const std::string ApplicationImpl::cloud_app_endpoint() { return endpoint_; } -std::string ApplicationImpl::cloud_app_authtoken() { +const std::string ApplicationImpl::cloud_app_authtoken() { return auth_token_; } -std::string ApplicationImpl::cloud_app_transport_type() { +const std::string ApplicationImpl::cloud_app_transport_type() { return cloud_transport_type_; } -std::string ApplicationImpl::hybrid_app_preference() { +const std::string ApplicationImpl::hybrid_app_preference() { return hybrid_app_preference_; } -std::string ApplicationImpl::cloud_app_certificate() { +const std::string ApplicationImpl::cloud_app_certificate() { return certificate_; } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index c5daf4bdc0..c55adf84cb 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -816,7 +816,6 @@ void ApplicationManagerImpl::CreatePendingApplication( connection_handler::DeviceHandle device_id) { LOG4CXX_AUTO_TRACE(logger_); - std::string policy_app_id = ""; std::string endpoint = ""; std::string certificate = ""; std::string auth_token = ""; @@ -829,7 +828,19 @@ void ApplicationManagerImpl::CreatePendingApplication( return; } - policy_app_id = it->second; + const std::string policy_app_id = it->second; + + policy::StringArray nicknames; + policy::StringArray app_hmi_types; + + GetPolicyHandler().GetInitialAppData(policy_app_id, &nicknames, &app_hmi_types); + + if (!nicknames.size()) { + LOG4CXX_ERROR(logger_, "Cloud App missing nickname"); + return; + } + + const std::string display_name = nicknames[0]; ApplicationSharedPtr application(new ApplicationImpl( 0, @@ -837,7 +848,7 @@ void ApplicationManagerImpl::CreatePendingApplication( device_info.mac_address(), device_id, custom_str::CustomString( - "CloudApp"), // todo replace this with policy nick name + display_name), GetPolicyHandler().GetStatisticManager(), *this)); @@ -846,7 +857,7 @@ void ApplicationManagerImpl::CreatePendingApplication( return; } - GetPolicyHandler().GetCloudAppParameters(*it, + GetPolicyHandler().GetCloudAppParameters(policy_app_id, endpoint, certificate, auth_token, diff --git a/src/components/config_profile/include/config_profile/profile.h b/src/components/config_profile/include/config_profile/profile.h index b332ed69f5..4846648b2b 100644 --- a/src/components/config_profile/include/config_profile/profile.h +++ b/src/components/config_profile/include/config_profile/profile.h @@ -416,7 +416,7 @@ class Profile : public protocol_handler::ProtocolHandlerSettings, /** * @brief Returns retry timeout for cloud app connections */ - uint16_t cloud_app_retry_timeout() const OVERRIDE; + uint32_t cloud_app_retry_timeout() const OVERRIDE; /** * @brief Returns maximum retry attempts for cloud app connections @@ -970,7 +970,7 @@ class Profile : public protocol_handler::ProtocolHandlerSettings, std::string system_files_path_; uint16_t transport_manager_tcp_adapter_port_; std::string transport_manager_tcp_adapter_network_interface_; - uint16_t cloud_app_retry_timeout_; + uint32_t cloud_app_retry_timeout_; uint16_t cloud_app_max_retry_attempts_; std::string tts_delimiter_; uint32_t audio_data_stopped_timeout_; diff --git a/src/components/config_profile/src/profile.cc b/src/components/config_profile/src/profile.cc index 5b4c2e5f93..c10f81a869 100644 --- a/src/components/config_profile/src/profile.cc +++ b/src/components/config_profile/src/profile.cc @@ -791,7 +791,7 @@ const std::string& Profile::transport_manager_tcp_adapter_network_interface() return transport_manager_tcp_adapter_network_interface_; } -uint16_t Profile::cloud_app_retry_timeout() const { +uint32_t Profile::cloud_app_retry_timeout() const { return cloud_app_retry_timeout_; } diff --git a/src/components/include/transport_manager/transport_manager_settings.h b/src/components/include/transport_manager/transport_manager_settings.h index 30a5a98ae9..cbc1516c29 100644 --- a/src/components/include/transport_manager/transport_manager_settings.h +++ b/src/components/include/transport_manager/transport_manager_settings.h @@ -73,7 +73,7 @@ class TransportManagerSettings : public TransportManagerMMESettings { /** * @brief Returns retry timeout for cloud app connections */ - virtual uint16_t cloud_app_retry_timeout() const = 0; + virtual uint32_t cloud_app_retry_timeout() const = 0; /** * @brief Returns maximum retry attempts for cloud app connections -- cgit v1.2.1 From 23f7544cedbe2d5b6fa8a07d823c1c89338b8753 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Fri, 16 Nov 2018 13:56:17 -0500 Subject: Address comments --- .../include/application_manager/application.h | 14 ++++--- .../include/application_manager/application_impl.h | 20 +++++---- .../application_manager/src/application_impl.cc | 5 ++- .../src/application_manager_impl.cc | 47 ++++++++++++++-------- 4 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index b68fc083d7..4ddf1e1388 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -953,22 +953,26 @@ class Application : public virtual InitialApplicationData, const virtual std::string cloud_app_endpoint() = 0; /** - * @brief Get cloud app authtoken to be used in connection handshake after websocket open. + * @brief Get cloud app authtoken to be used in connection handshake after + * websocket open. * @return cloud app authtoken */ const virtual std::string cloud_app_authtoken() = 0; /** - * @brief Get cloud app tranpsport type. Defines the type of websocket connection used. + * @brief Get cloud app tranpsport type. Defines the type of websocket + * connection used. * @return cloud app transport type */ const virtual std::string cloud_app_transport_type() = 0; /** - * @brief Get hybrid app preference. Defines behaviour for when a similar mobile and cloud app are connected simultaneously. + * @brief Get hybrid app preference. Defines behaviour for when a similar + * mobile and cloud app are connected simultaneously. * @return hybrid app preference */ - const virtual std::string hybrid_app_preference() = 0; + const virtual mobile_apis::HybridAppPreference::eType + hybrid_app_preference() = 0; /** * @brief Get cloud app certificate. Used for secured websocket connections. @@ -996,7 +1000,7 @@ class Application : public virtual InitialApplicationData, * @brief Set hybrid app preference */ virtual void set_hybrid_app_preference( - const std::string& hybrid_app_preference) = 0; + const mobile_apis::HybridAppPreference::eType& hybrid_app_preference) = 0; /** * @brief Set cloud app certificate diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index 74b2be0934..26d8cd6159 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -416,27 +416,31 @@ class ApplicationImpl : public virtual Application, const std::string cloud_app_endpoint() OVERRIDE; /** - * @brief Get cloud app authtoken to be used in connection handshake after websocket open. + * @brief Get cloud app authtoken to be used in connection handshake after + * websocket open. * @return cloud app authtoken */ const std::string cloud_app_authtoken() OVERRIDE; /** - * @brief Get cloud app tranpsport type. Defines the type of websocket connection used. + * @brief Get cloud app tranpsport type. Defines the type of websocket + * connection used. * @return cloud app transport type */ const std::string cloud_app_transport_type() OVERRIDE; /** - * @brief Get hybrid app preference. Defines behaviour for when a similar mobile and cloud app are connected simultaneously. + * @brief Get hybrid app preference. Defines behaviour for when a similar + * mobile and cloud app are connected simultaneously. * @return hybrid app preference */ - const std::string hybrid_app_preference() OVERRIDE; + const mobile_apis::HybridAppPreference::eType hybrid_app_preference() + OVERRIDE; /** * @brief Get cloud app certificate. Used for secured websocket connections. * @return cloud app certificate. - */ + */ const std::string cloud_app_certificate() OVERRIDE; /** @@ -457,8 +461,8 @@ class ApplicationImpl : public virtual Application, /** * @brief Set hybrid app preference */ - void set_hybrid_app_preference( - const std::string& hybrid_app_preference) OVERRIDE; + void set_hybrid_app_preference(const mobile_apis::HybridAppPreference::eType& + hybrid_app_preference) OVERRIDE; /** * @brief Set cloud app certificate @@ -573,7 +577,7 @@ class ApplicationImpl : public virtual Application, std::string endpoint_; std::string auth_token_; std::string cloud_transport_type_; - std::string hybrid_app_preference_; + mobile_apis::HybridAppPreference::eType hybrid_app_preference_; std::string certificate_; /** diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index c92823bf77..31df4e821b 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -1175,7 +1175,8 @@ const std::string ApplicationImpl::cloud_app_transport_type() { return cloud_transport_type_; } -const std::string ApplicationImpl::hybrid_app_preference() { +const mobile_apis::HybridAppPreference::eType +ApplicationImpl::hybrid_app_preference() { return hybrid_app_preference_; } @@ -1197,7 +1198,7 @@ void ApplicationImpl::set_cloud_app_transport_type( } void ApplicationImpl::set_hybrid_app_preference( - const std::string& hybrid_app_preference) { + const mobile_apis::HybridAppPreference::eType& hybrid_app_preference) { hybrid_app_preference_ = hybrid_app_preference; } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index c55adf84cb..1cec8b5ca2 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -820,7 +820,7 @@ void ApplicationManagerImpl::CreatePendingApplication( std::string certificate = ""; std::string auth_token = ""; std::string cloud_transport_type = ""; - std::string hybrid_app_preference = ""; + std::string hybrid_app_preference_str = ""; std::string name = device_info.name(); auto it = pending_device_map_.find(name); @@ -833,7 +833,8 @@ void ApplicationManagerImpl::CreatePendingApplication( policy::StringArray nicknames; policy::StringArray app_hmi_types; - GetPolicyHandler().GetInitialAppData(policy_app_id, &nicknames, &app_hmi_types); + GetPolicyHandler().GetInitialAppData( + policy_app_id, &nicknames, &app_hmi_types); if (!nicknames.size()) { LOG4CXX_ERROR(logger_, "Cloud App missing nickname"); @@ -842,15 +843,14 @@ void ApplicationManagerImpl::CreatePendingApplication( const std::string display_name = nicknames[0]; - ApplicationSharedPtr application(new ApplicationImpl( - 0, - policy_app_id, - device_info.mac_address(), - device_id, - custom_str::CustomString( - display_name), - GetPolicyHandler().GetStatisticManager(), - *this)); + ApplicationSharedPtr application( + new ApplicationImpl(0, + policy_app_id, + device_info.mac_address(), + device_id, + custom_str::CustomString(display_name), + GetPolicyHandler().GetStatisticManager(), + *this)); if (!application) { LOG4CXX_INFO(logger_, "Could not streate application"); @@ -858,17 +858,30 @@ void ApplicationManagerImpl::CreatePendingApplication( } GetPolicyHandler().GetCloudAppParameters(policy_app_id, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference); + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference_str); + + mobile_apis::HybridAppPreference::eType hybrid_app_preference_enum; + + bool convert_result = smart_objects::EnumConversionHelper< + mobile_apis::HybridAppPreference::eType>:: + StringToEnum(hybrid_app_preference_str, &hybrid_app_preference_enum); + + if (!convert_result) { + LOG4CXX_ERROR( + logger_, + "Could not convert string to enum: " << hybrid_app_preference_str); + return; + } application->set_hmi_application_id(GenerateNewHMIAppID()); application->set_cloud_app_endpoint(endpoint); application->set_cloud_app_auth_token(auth_token); application->set_cloud_app_transport_type(cloud_transport_type); - application->set_hybrid_app_preference(hybrid_app_preference); + application->set_hybrid_app_preference(hybrid_app_preference_enum); application->set_cloud_app_certificate(certificate); sync_primitives::AutoLock lock(apps_to_register_list_lock_ptr_); -- cgit v1.2.1 From d8ad4e0427b33087340aa34cf1e1d3954cdb793e Mon Sep 17 00:00:00 2001 From: JackLivio Date: Fri, 16 Nov 2018 14:44:29 -0500 Subject: Remove printfs and hardcoded values --- .../include/transport_manager/cloud/cloud_device.h | 7 ++- .../transport_manager/src/cloud/cloud_device.cc | 10 ++++- .../cloud/cloud_websocket_connection_factory.cc | 19 -------- .../src/cloud/cloud_websocket_transport_adapter.cc | 9 +--- .../src/cloud/websocket_client_connection.cc | 52 +++++++++------------- .../src/transport_manager_default.cc | 1 - 6 files changed, 36 insertions(+), 62 deletions(-) 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 f80ad924e3..8eac8c6f75 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,13 +47,18 @@ class CloudDevice : public Device { public: CloudDevice(std::string& host, std::string& port, std::string& name); + virtual const std::string& GetHost(); + + virtual const std::string& GetPort(); + protected: virtual bool IsSameAs(const Device* other_device) const; virtual ApplicationList GetApplicationList() const; private: - // todo add private varaibles, maybe ip port or other connection information? + const std::string host_; + const std::string port_; }; } // namespace transport_adapter diff --git a/src/components/transport_manager/src/cloud/cloud_device.cc b/src/components/transport_manager/src/cloud/cloud_device.cc index 699d79d52a..6196bcc87e 100644 --- a/src/components/transport_manager/src/cloud/cloud_device.cc +++ b/src/components/transport_manager/src/cloud/cloud_device.cc @@ -42,7 +42,7 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") CloudDevice::CloudDevice(std::string& host, std::string& port, std::string& name) - : Device(name, std::string(name)) {} + : Device(name, std::string(name)), host_(host), port_(port) {} bool CloudDevice::IsSameAs(const Device* other) const { LOG4CXX_TRACE(logger_, "enter. device: " << other); @@ -56,5 +56,13 @@ ApplicationList CloudDevice::GetApplicationList() const { return ApplicationList{100}; } +const std::string& CloudDevice::GetHost() { + return host_; +} + +const std::string& CloudDevice::GetPort() { + return port_; +} + } // namespace transport_adapter } // namespace transport_manager diff --git a/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc b/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc index 2b2a5ee2aa..cdc27ed8ef 100644 --- a/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc +++ b/src/components/transport_manager/src/cloud/cloud_websocket_connection_factory.cc @@ -50,31 +50,12 @@ CloudWebsocketConnectionFactory::CloudWebsocketConnectionFactory( : controller_(controller) {} TransportAdapter::Error CloudWebsocketConnectionFactory::Init() { - /*DeviceUID device_id = "Cloud"; - ApplicationHandle app_handle = 100; - printf("Calling create connection\n"); - - std::string host("192.168.1.69"); - std::string port("8080"); - - //todo move this device logic to the correct place. - auto cloud_device = std::make_shared( - host,port,device_id); - DeviceVector devices{cloud_device}; - - controller_->SearchDeviceDone(devices); - - - const TransportAdapter::Error err = - this->CreateConnection(std::string(device_id+host+port), app_handle); - LOG4CXX_DEBUG(logger_, err);*/ return TransportAdapter::OK; } TransportAdapter::Error CloudWebsocketConnectionFactory::CreateConnection( const DeviceUID& device_uid, const ApplicationHandle& app_handle) { LOG4CXX_AUTO_TRACE(logger_); - printf("Create connection()\n"); std::shared_ptr connection = std::make_shared( device_uid, app_handle, controller_); 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 23cee31002..874f158145 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 @@ -49,14 +49,7 @@ CloudWebsocketTransportAdapter::CloudWebsocketTransportAdapter( new CloudWebsocketConnectionFactory(this), NULL, last_state, - settings) { - /*DeviceUID device_id = "Cloud"; - ApplicationHandle app_handle = 100; - printf("Calling create connection\n"); - const TransportAdapter::Error err = - server_connection_factory_->CreateConnection(device_id, app_handle); - LOG4CXX_DEBUG(logger_, err);*/ -} + settings) {} CloudWebsocketTransportAdapter::~CloudWebsocketTransportAdapter() {} 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 c2dcc9f14a..0912a07999 100644 --- a/src/components/transport_manager/src/cloud/websocket_client_connection.cc +++ b/src/components/transport_manager/src/cloud/websocket_client_connection.cc @@ -32,6 +32,7 @@ */ #include "transport_manager/cloud/websocket_client_connection.h" +#include "transport_manager/cloud/cloud_device.h" #include "transport_manager/transport_adapter/transport_adapter_controller.h" @@ -63,28 +64,34 @@ WebsocketClientConnection::~WebsocketClientConnection() { TransportAdapter::Error WebsocketClientConnection::Start() { LOG4CXX_AUTO_TRACE(logger_); - printf("Calling websocket start\n"); - auto const host = "192.168.1.69"; - auto const port = "8080"; + DeviceSptr device = controller_->FindDevice(device_uid_); + CloudDevice* cloud_device = static_cast(device.get()); + auto const host = cloud_device->GetHost(); + auto const port = cloud_device->GetPort(); boost::system::error_code ec; auto const results = resolver_.resolve(host, port, ec); if (ec) { - std::string str_err = "ErrorMessage1: " + ec.message(); - printf("%s\n", str_err.c_str()); + std::string str_err = "ErrorMessage: " + ec.message(); + LOG4CXX_ERROR(logger_, "Could not resolve host/port: " << str_err); Shutdown(); return TransportAdapter::FAIL; } boost::asio::connect(ws_.next_layer(), results.begin(), results.end(), ec); if (ec) { - std::string str_err = "ErrorMessage2: " + ec.message(); - printf("%s\n", str_err.c_str()); + std::string str_err = "ErrorMessage: " + ec.message(); + LOG4CXX_ERROR(logger_, + "Could not connect to websocket: " << host << ":" << port); + LOG4CXX_ERROR(logger_, str_err); Shutdown(); return TransportAdapter::FAIL; } ws_.handshake(host, "/", ec); if (ec) { - std::string str_err = "ErrorMessage3: " + ec.message(); - printf("%s\n", str_err.c_str()); + std::string str_err = "ErrorMessage: " + ec.message(); + LOG4CXX_ERROR(logger_, + "Could not complete handshake with host/port: " << host << ":" + << port); + LOG4CXX_ERROR(logger_, str_err); Shutdown(); return TransportAdapter::FAIL; } @@ -102,35 +109,27 @@ TransportAdapter::Error WebsocketClientConnection::Start() { // Start IO Service thread. Allows for async reads without blocking. io_service_thread_ = std::thread([&]() { ioc_.run(); - printf("io_service_thread_ END!!!\n"); + LOG4CXX_DEBUG(logger_, "Ending Boost IO Thread"); }); - // Start async write thread - - printf("End of websockets\n"); + LOG4CXX_DEBUG(logger_, + "Successfully started websocket connection @: " << host << ":" + << port); return TransportAdapter::OK; } void WebsocketClientConnection::Recv(boost::system::error_code ec) { - printf("Recv\n"); if (shutdown_) { - printf("shutdown_\n"); return; } if (ec) { std::string str_err = "ErrorMessage: " + ec.message(); - printf("%s\n", str_err.c_str()); LOG4CXX_ERROR(logger_, str_err); - // shutdown_ = true; - // ioc_.stop(); - // thread_delegate_->SetShutdown(); - // controller_->deleteController(this); Shutdown(); return; } - printf("calling async read\n"); ws_.async_read(buffer_, std::bind(&WebsocketClientConnection::OnRead, @@ -141,23 +140,18 @@ void WebsocketClientConnection::Recv(boost::system::error_code ec) { void WebsocketClientConnection::OnRead(boost::system::error_code ec, std::size_t bytes_transferred) { - printf("OnRead\n"); boost::ignore_unused(bytes_transferred); if (ec) { std::string str_err = "ErrorMessage: " + ec.message(); - printf("%s\n", str_err.c_str()); LOG4CXX_ERROR(logger_, str_err); Shutdown(); controller_->ConnectionAborted( device_uid_, app_handle_, CommunicationError()); - - printf("return error\n"); return; } std::string data_str = boost::beast::buffers_to_string(buffer_.data()); LOG4CXX_DEBUG(logger_, "Cloud Transport Received: " << data_str); - printf("%s\n", data_str.c_str()); ssize_t size = (ssize_t)buffer_.size(); const uint8_t* data = boost::asio::buffer_cast( @@ -175,10 +169,8 @@ void WebsocketClientConnection::OnRead(boost::system::error_code ec, TransportAdapter::Error WebsocketClientConnection::SendData( ::protocol_handler::RawMessagePtr message) { LOG4CXX_AUTO_TRACE(logger_); - printf("Send DATA!!!\n"); sync_primitives::AutoLock auto_lock(frames_to_send_mutex_); message_queue_.push(message); - printf("Data pushed to queue!!!\n"); return TransportAdapter::OK; } @@ -194,13 +186,11 @@ void WebsocketClientConnection::Shutdown() { if (thread_delegate_) { thread_delegate_->SetShutdown(); write_thread_->join(); - printf("Joined Thread Delegate!!!\n"); delete thread_delegate_; } if (buffer_.size()) { buffer_.consume(buffer_.size()); } - printf("End of shutdown!!!\n"); } WebsocketClientConnection::LoopThreadDelegate::LoopThreadDelegate( @@ -209,7 +199,6 @@ WebsocketClientConnection::LoopThreadDelegate::LoopThreadDelegate( : message_queue_(*message_queue), handler_(*handler), shutdown_(false) {} void WebsocketClientConnection::LoopThreadDelegate::threadMain() { - printf("Starting write thread\n"); while (!message_queue_.IsShuttingDown() && !shutdown_) { DrainQueue(); message_queue_.wait(); @@ -229,7 +218,6 @@ void WebsocketClientConnection::LoopThreadDelegate::DrainQueue() { Message message_ptr; message_queue_.pop(message_ptr); if (!shutdown_) { - printf("Calling Write!!!\n"); boost::system::error_code ec; handler_.ws_.write( boost::asio::buffer(message_ptr->data(), message_ptr->data_size())); diff --git a/src/components/transport_manager/src/transport_manager_default.cc b/src/components/transport_manager/src/transport_manager_default.cc index 3beed2f763..bf692de24c 100644 --- a/src/components/transport_manager/src/transport_manager_default.cc +++ b/src/components/transport_manager/src/transport_manager_default.cc @@ -106,7 +106,6 @@ int TransportManagerDefault::Init(resumption::LastState& last_state) { #endif // USB_SUPPORT #if defined CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT - printf("Creating cloud transport\n"); transport_adapter::TransportAdapterImpl* ta_cloud = new transport_adapter::CloudWebsocketTransportAdapter( last_state, get_settings()); // Todo add retry connection logic from -- cgit v1.2.1 From 4103779a0b69a029720141dbda934151e8321ba0 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Tue, 20 Nov 2018 13:28:58 -0500 Subject: Address comments, fix unit test failures --- .../include/application_manager/application.h | 12 ++++++------ .../include/application_manager/application_impl.h | 12 ++++++------ src/components/application_manager/src/application_impl.cc | 12 ++++++------ .../test/include/application_manager/mock_application.h | 14 ++++++++++++++ .../test/connection_handler/mock_connection_handler.h | 4 ++++ .../connection_handler/mock_connection_handler_observer.h | 4 ++++ .../test/transport_manager/mock_transport_manager.h | 3 +++ .../transport_manager/mock_transport_manager_listener.h | 3 +++ .../transport_manager/mock_transport_manager_settings.h | 2 ++ .../transport_adapter/mock_transport_adapter.h | 2 ++ src/components/transport_manager/test/CMakeLists.txt | 5 +++++ .../transport_manager/mock_transport_manager_listener.h | 3 +++ .../transport_adapter/mock_transport_adapter_listener.h | 4 ++++ .../transport_manager/test/tcp_client_listener_test.cc | 3 +++ 14 files changed, 65 insertions(+), 18 deletions(-) diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index 4ddf1e1388..963f93ce5c 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -950,35 +950,35 @@ class Application : public virtual InitialApplicationData, * @brief Get cloud app endpoint for websocket connection * @return cloud app endpoint */ - const virtual std::string cloud_app_endpoint() = 0; + virtual const std::string& cloud_app_endpoint() const = 0; /** * @brief Get cloud app authtoken to be used in connection handshake after * websocket open. * @return cloud app authtoken */ - const virtual std::string cloud_app_authtoken() = 0; + virtual const std::string& cloud_app_authtoken() const = 0; /** * @brief Get cloud app tranpsport type. Defines the type of websocket * connection used. * @return cloud app transport type */ - const virtual std::string cloud_app_transport_type() = 0; + virtual const std::string& cloud_app_transport_type() const = 0; /** * @brief Get hybrid app preference. Defines behaviour for when a similar * mobile and cloud app are connected simultaneously. * @return hybrid app preference */ - const virtual mobile_apis::HybridAppPreference::eType - hybrid_app_preference() = 0; + virtual const mobile_apis::HybridAppPreference::eType& hybrid_app_preference() + const = 0; /** * @brief Get cloud app certificate. Used for secured websocket connections. * @return cloud app certificate. */ - const virtual std::string cloud_app_certificate() = 0; + virtual const std::string& cloud_app_certificate() const = 0; /** * @brief Set cloud app endpoint diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index 26d8cd6159..8fa1553811 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -413,35 +413,35 @@ class ApplicationImpl : public virtual Application, * @brief Get cloud app endpoint for websocket connection * @return cloud app endpoint */ - const std::string cloud_app_endpoint() OVERRIDE; + const std::string& cloud_app_endpoint() const OVERRIDE; /** * @brief Get cloud app authtoken to be used in connection handshake after * websocket open. * @return cloud app authtoken */ - const std::string cloud_app_authtoken() OVERRIDE; + const std::string& cloud_app_authtoken() const OVERRIDE; /** * @brief Get cloud app tranpsport type. Defines the type of websocket * connection used. * @return cloud app transport type */ - const std::string cloud_app_transport_type() OVERRIDE; + const std::string& cloud_app_transport_type() const OVERRIDE; /** * @brief Get hybrid app preference. Defines behaviour for when a similar * mobile and cloud app are connected simultaneously. * @return hybrid app preference */ - const mobile_apis::HybridAppPreference::eType hybrid_app_preference() - OVERRIDE; + const mobile_apis::HybridAppPreference::eType& hybrid_app_preference() + const OVERRIDE; /** * @brief Get cloud app certificate. Used for secured websocket connections. * @return cloud app certificate. */ - const std::string cloud_app_certificate() OVERRIDE; + const std::string& cloud_app_certificate() const OVERRIDE; /** * @brief Set cloud app endpoint diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 31df4e821b..732e5bc804 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -1163,24 +1163,24 @@ const std::list& ApplicationImpl::Extensions() const { return extensions_; } -const std::string ApplicationImpl::cloud_app_endpoint() { +const std::string& ApplicationImpl::cloud_app_endpoint() const { return endpoint_; } -const std::string ApplicationImpl::cloud_app_authtoken() { +const std::string& ApplicationImpl::cloud_app_authtoken() const { return auth_token_; } -const std::string ApplicationImpl::cloud_app_transport_type() { +const std::string& ApplicationImpl::cloud_app_transport_type() const { return cloud_transport_type_; } -const mobile_apis::HybridAppPreference::eType -ApplicationImpl::hybrid_app_preference() { +const mobile_apis::HybridAppPreference::eType& +ApplicationImpl::hybrid_app_preference() const { return hybrid_app_preference_; } -const std::string ApplicationImpl::cloud_app_certificate() { +const std::string& ApplicationImpl::cloud_app_certificate() const { return certificate_; } diff --git a/src/components/application_manager/test/include/application_manager/mock_application.h b/src/components/application_manager/test/include/application_manager/mock_application.h index fe16e8ce6e..486871b5de 100644 --- a/src/components/application_manager/test/include/application_manager/mock_application.h +++ b/src/components/application_manager/test/include/application_manager/mock_application.h @@ -342,6 +342,20 @@ class MockApplication : public ::application_manager::Application { const std::list&()); MOCK_CONST_METHOD0(is_remote_control_supported, bool()); MOCK_METHOD1(set_remote_control_supported, void(const bool allow)); + MOCK_CONST_METHOD0(cloud_app_endpoint, const std::string&()); + MOCK_CONST_METHOD0(cloud_app_authtoken, const std::string&()); + MOCK_CONST_METHOD0(cloud_app_transport_type, const std::string&()); + MOCK_CONST_METHOD0(hybrid_app_preference, + const mobile_apis::HybridAppPreference::eType&()); + MOCK_CONST_METHOD0(cloud_app_certificate, const std::string&()); + MOCK_METHOD1(set_cloud_app_endpoint, void(const std::string& endpoint)); + MOCK_METHOD1(set_cloud_app_auth_token, void(const std::string& auth_token)); + MOCK_METHOD1(set_cloud_app_transport_type, + void(const std::string& transport_type)); + MOCK_METHOD1(set_hybrid_app_preference, + void(const mobile_apis::HybridAppPreference::eType& + hybrid_app_preference)); + MOCK_METHOD1(set_cloud_app_certificate, void(const std::string& certificate)); }; } // namespace application_manager_test diff --git a/src/components/include/test/connection_handler/mock_connection_handler.h b/src/components/include/test/connection_handler/mock_connection_handler.h index 2de3a0f9a7..bdc0469844 100644 --- a/src/components/include/test/connection_handler/mock_connection_handler.h +++ b/src/components/include/test/connection_handler/mock_connection_handler.h @@ -63,6 +63,10 @@ class MockConnectionHandler : public connection_handler::ConnectionHandler { MOCK_CONST_METHOD2(RunAppOnDevice, void(const std::string&, const std::string&)); MOCK_METHOD0(ConnectToAllDevices, void()); + MOCK_METHOD3(AddCloudAppDevice, + void(const std::string& policy_app_id, + const std::string& endpoint, + const std::string& cloud_transport_type)); MOCK_METHOD1(CloseRevokedConnection, void(uint32_t connection_key)); MOCK_METHOD1(CloseConnection, void(ConnectionHandle connection_handle)); MOCK_METHOD1(GetConnectionSessionsCount, uint32_t(uint32_t connection_key)); diff --git a/src/components/include/test/connection_handler/mock_connection_handler_observer.h b/src/components/include/test/connection_handler/mock_connection_handler_observer.h index a9e4349bec..2984b2e471 100644 --- a/src/components/include/test/connection_handler/mock_connection_handler_observer.h +++ b/src/components/include/test/connection_handler/mock_connection_handler_observer.h @@ -74,6 +74,10 @@ class MockConnectionHandlerObserver const int32_t session_key)); MOCK_METHOD1(OnSecondaryTransportEndedCallback, void(const int32_t session_key)); + MOCK_METHOD3(CreatePendingApplication, + void(const transport_manager::ConnectionUID connection_id, + const transport_manager::DeviceInfo& device_info, + connection_handler::DeviceHandle device_id)); }; } // namespace connection_handler_test diff --git a/src/components/include/test/transport_manager/mock_transport_manager.h b/src/components/include/test/transport_manager/mock_transport_manager.h index cc8bd5ab85..e3f01fccb5 100644 --- a/src/components/include/test/transport_manager/mock_transport_manager.h +++ b/src/components/include/test/transport_manager/mock_transport_manager.h @@ -59,6 +59,9 @@ class MockTransportManager : public ::transport_manager::TransportManager, MOCK_METHOD1(Init, int(resumption::LastState& last_state)); MOCK_METHOD0(Reinit, int()); MOCK_METHOD0(SearchDevices, int()); + MOCK_METHOD2(AddCloudDevice, + void(const std::string& endpoint, + const std::string& cloud_transport_type)); MOCK_METHOD1(ConnectDevice, int(const DeviceHandle)); MOCK_METHOD1(DisconnectDevice, int(const DeviceHandle)); MOCK_METHOD1(Disconnect, int(const ConnectionUID)); diff --git a/src/components/include/test/transport_manager/mock_transport_manager_listener.h b/src/components/include/test/transport_manager/mock_transport_manager_listener.h index 133dabe732..734651f455 100644 --- a/src/components/include/test/transport_manager/mock_transport_manager_listener.h +++ b/src/components/include/test/transport_manager/mock_transport_manager_listener.h @@ -55,6 +55,9 @@ class MockTransportManagerListener : public TransportManagerListener { MOCK_METHOD1(OnDeviceRemoved, void(const DeviceInfo& device_info)); MOCK_METHOD0(OnScanDevicesFinished, void()); MOCK_METHOD1(OnScanDevicesFailed, void(const SearchDeviceError& error)); + MOCK_METHOD2(OnConnectionPending, + void(const DeviceInfo& device_info, + const ConnectionUID connection_id)); MOCK_METHOD2(OnConnectionEstablished, void(const DeviceInfo& device_info, const ConnectionUID connection_id)); diff --git a/src/components/include/test/transport_manager/mock_transport_manager_settings.h b/src/components/include/test/transport_manager/mock_transport_manager_settings.h index 3e7c8f36f7..bed0d5e6e6 100644 --- a/src/components/include/test/transport_manager/mock_transport_manager_settings.h +++ b/src/components/include/test/transport_manager/mock_transport_manager_settings.h @@ -63,6 +63,8 @@ class MockTransportManagerSettings MOCK_CONST_METHOD0(app_transport_change_timer_addition, uint32_t()); MOCK_CONST_METHOD0(transport_manager_tcp_adapter_network_interface, std::string&()); + MOCK_CONST_METHOD0(cloud_app_retry_timeout, uint32_t()); + MOCK_CONST_METHOD0(cloud_app_max_retry_attempts, uint16_t()); }; } // namespace transport_manager_test 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 eff0abdcd3..0be4da1063 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 @@ -105,6 +105,8 @@ class MockTransportAdapter transport_manager::SwitchableDevices()); MOCK_CONST_METHOD0(GetTransportConfiguration, transport_manager::transport_adapter::TransportConfig()); + MOCK_METHOD1(CreateDevice, void(const std::string& uid)); + #ifdef TELEMETRY_MONITOR MOCK_METHOD0(GetTelemetryObserver, ::transport_manager::TMTelemetryObserver*()); diff --git a/src/components/transport_manager/test/CMakeLists.txt b/src/components/transport_manager/test/CMakeLists.txt index 240784436b..5288d8c697 100644 --- a/src/components/transport_manager/test/CMakeLists.txt +++ b/src/components/transport_manager/test/CMakeLists.txt @@ -75,6 +75,11 @@ if (BUILD_BT_SUPPORT) endif() endif() +if(BUILD_CLOUD_APP_SUPPORT) + GET_PROPERTY(BOOST_LIBS_DIRECTORY GLOBAL PROPERTY GLOBAL_BOOST_LIBS) + list(APPEND LIBRARIES boost_system boost_regex crypto ssl -L${BOOST_LIBS_DIRECTORY}) +endif() + create_test("transport_manager_test" "${SOURCES}" "${LIBRARIES}") file(COPY smartDeviceLink_test.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/components/transport_manager/test/include/transport_manager/mock_transport_manager_listener.h b/src/components/transport_manager/test/include/transport_manager/mock_transport_manager_listener.h index 58e143342a..4eaf34d041 100644 --- a/src/components/transport_manager/test/include/transport_manager/mock_transport_manager_listener.h +++ b/src/components/transport_manager/test/include/transport_manager/mock_transport_manager_listener.h @@ -56,6 +56,9 @@ class MockTransportManagerListener : public TransportManagerListener { MOCK_METHOD1(OnDeviceRemoved, void(const DeviceInfo& device_info)); MOCK_METHOD0(OnScanDevicesFinished, void()); MOCK_METHOD1(OnScanDevicesFailed, void(const SearchDeviceError& error)); + MOCK_METHOD2(OnConnectionPending, + void(const DeviceInfo& device_info, + const ConnectionUID connection_id)); MOCK_METHOD2(OnConnectionEstablished, void(const DeviceInfo& device_info, const ConnectionUID connection_id)); diff --git a/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_listener.h b/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_listener.h index dce23189c8..81e133ec2b 100644 --- a/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_listener.h +++ b/src/components/transport_manager/test/include/transport_manager/transport_adapter/mock_transport_adapter_listener.h @@ -59,6 +59,10 @@ class MockTransportAdapterListener : public TransportAdapterListener { const SearchDeviceError& error)); MOCK_METHOD1(OnFindNewApplicationsRequest, void(const TransportAdapter* adapter)); + MOCK_METHOD3(OnConnectPending, + void(const TransportAdapter* adapter, + const DeviceUID& device_handle, + const ApplicationHandle& app_id)); MOCK_METHOD1(OnDeviceListUpdated, void(const TransportAdapter* transport_adapter)); MOCK_METHOD3(OnConnectDone, diff --git a/src/components/transport_manager/test/tcp_client_listener_test.cc b/src/components/transport_manager/test/tcp_client_listener_test.cc index 5205d6ae3c..f44f8785aa 100644 --- a/src/components/transport_manager/test/tcp_client_listener_test.cc +++ b/src/components/transport_manager/test/tcp_client_listener_test.cc @@ -73,6 +73,9 @@ class MockTransportAdapterController : public TransportAdapterController { void(ConnectionSPtr connection, const DeviceUID& device_handle, const ApplicationHandle& app_handle)); + MOCK_METHOD2(ConnectPending, + void(const DeviceUID& device_handle, + const ApplicationHandle& app_handle)); MOCK_METHOD2(ConnectDone, void(const DeviceUID& device_handle, const ApplicationHandle& app_handle)); -- cgit v1.2.1 From a6c0deddae788352f4b0e7bf238b37db43386489 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Tue, 20 Nov 2018 13:40:48 -0500 Subject: Fix auth_token typo --- .../application_manager/include/application_manager/application.h | 6 +++--- .../include/application_manager/application_impl.h | 6 +++--- src/components/application_manager/src/application_impl.cc | 2 +- .../test/include/application_manager/mock_application.h | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index 963f93ce5c..2abd2eaea0 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -953,11 +953,11 @@ class Application : public virtual InitialApplicationData, virtual const std::string& cloud_app_endpoint() const = 0; /** - * @brief Get cloud app authtoken to be used in connection handshake after + * @brief Get cloud app auth token to be used in connection handshake after * websocket open. - * @return cloud app authtoken + * @return cloud app auth token */ - virtual const std::string& cloud_app_authtoken() const = 0; + virtual const std::string& cloud_app_auth_token() const = 0; /** * @brief Get cloud app tranpsport type. Defines the type of websocket diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index 8fa1553811..0b43b014b6 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -416,11 +416,11 @@ class ApplicationImpl : public virtual Application, const std::string& cloud_app_endpoint() const OVERRIDE; /** - * @brief Get cloud app authtoken to be used in connection handshake after + * @brief Get cloud app auth token to be used in connection handshake after * websocket open. - * @return cloud app authtoken + * @return cloud app auth token */ - const std::string& cloud_app_authtoken() const OVERRIDE; + const std::string& cloud_app_auth_token() const OVERRIDE; /** * @brief Get cloud app tranpsport type. Defines the type of websocket diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 732e5bc804..558a4638c1 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -1167,7 +1167,7 @@ const std::string& ApplicationImpl::cloud_app_endpoint() const { return endpoint_; } -const std::string& ApplicationImpl::cloud_app_authtoken() const { +const std::string& ApplicationImpl::cloud_app_auth_token() const { return auth_token_; } diff --git a/src/components/application_manager/test/include/application_manager/mock_application.h b/src/components/application_manager/test/include/application_manager/mock_application.h index 486871b5de..9c9041284c 100644 --- a/src/components/application_manager/test/include/application_manager/mock_application.h +++ b/src/components/application_manager/test/include/application_manager/mock_application.h @@ -343,7 +343,7 @@ class MockApplication : public ::application_manager::Application { MOCK_CONST_METHOD0(is_remote_control_supported, bool()); MOCK_METHOD1(set_remote_control_supported, void(const bool allow)); MOCK_CONST_METHOD0(cloud_app_endpoint, const std::string&()); - MOCK_CONST_METHOD0(cloud_app_authtoken, const std::string&()); + MOCK_CONST_METHOD0(cloud_app_auth_token, const std::string&()); MOCK_CONST_METHOD0(cloud_app_transport_type, const std::string&()); MOCK_CONST_METHOD0(hybrid_app_preference, const mobile_apis::HybridAppPreference::eType&()); -- cgit v1.2.1 From b6d7da141931249923729c9f14ae5bf9109e9a82 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Tue, 27 Nov 2018 15:08:05 -0500 Subject: Address Comments and Remove Unused Code --- src/appMain/smartDeviceLink.ini | 2 +- .../src/application_manager_impl.cc | 5 ++++- src/components/config_profile/src/profile.cc | 2 +- .../src/connection_handler_impl.cc | 2 -- .../transport_adapter/transport_adapter.h | 21 --------------------- .../include/transport_manager/cloud/cloud_device.h | 4 ++-- .../cloud/cloud_websocket_transport_adapter.h | 20 -------------------- .../transport_manager/src/cloud/cloud_device.cc | 19 +++++++++++++------ .../src/cloud/cloud_websocket_transport_adapter.cc | 15 ++------------- .../src/cloud/websocket_client_connection.cc | 2 +- 10 files changed, 24 insertions(+), 68 deletions(-) diff --git a/src/appMain/smartDeviceLink.ini b/src/appMain/smartDeviceLink.ini index ac3e1c983a..ccb377d1e6 100644 --- a/src/appMain/smartDeviceLink.ini +++ b/src/appMain/smartDeviceLink.ini @@ -202,7 +202,7 @@ TCPAdapterPort = 12345 ; If the name is omitted, Core will listen on all network interfaces by binding to INADDR_ANY. TCPAdapterNetworkInterface = -[Cloud App Connections] +[CloudAppConnections] ; Value in milliseconds for time between retry attempts on a failed websocket connection CloudAppRetryTimeout = 1000 ; MaxNn number of retry attempts for a cloud websocket connection diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 1cec8b5ca2..ef008b7200 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -795,8 +795,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, @@ -821,7 +823,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()) { @@ -858,6 +860,7 @@ void ApplicationManagerImpl::CreatePendingApplication( } GetPolicyHandler().GetCloudAppParameters(policy_app_id, + enabled, endpoint, certificate, auth_token, 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 318224fcc7..ed2522593c 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -266,7 +266,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 = @@ -280,7 +279,6 @@ void ConnectionHandlerImpl::OnConnectionPending( connection_handler::DeviceHandle device_id = connection->connection_device_handle(); - // uint32_t app_id = KeyFromPair(connection_id, session_id); connection_handler_observer_->CreatePendingApplication( connection_id, device_info, device_id); 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 4aa6e901ad..aae4a8b569 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 DeviceTypes; /** @@ -104,12 +89,6 @@ typedef std::list TransportAdapterListenerList; */ typedef std::map TransportConfig; -/** - * @brief Type definition of container indexed by app id that contains - * connection information for all cloud apps. - */ -typedef std::map CloudAppTransportConfig; - /** * @brief TransportConfig keys */ 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/src/cloud/cloud_device.cc b/src/components/transport_manager/src/cloud/cloud_device.cc index 6196bcc87e..90a485c069 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(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{100}; } -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 874f158145..24efdfb2a4 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; } @@ -95,7 +85,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(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 0912a07999..4f585c8efb 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 -- cgit v1.2.1 From d67a37a5dedfe696dd4308fd0eb53ee48e15daf8 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Mon, 21 Jan 2019 12:28:13 -0500 Subject: Update based on comments --- src/components/application_manager/src/application_manager_impl.cc | 4 ++-- .../include/connection_handler/connection_handler_impl.h | 3 +-- src/components/connection_handler/src/connection_handler_impl.cc | 1 - src/components/include/connection_handler/connection_handler.h | 3 +-- .../include/test/connection_handler/mock_connection_handler.h | 5 ++--- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index ef008b7200..3b5c1b2c7c 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -808,7 +808,7 @@ void ApplicationManagerImpl::CollectCloudAppInformation() { pending_device_map_.insert( std::pair(endpoint, *it)); - connection_handler().AddCloudAppDevice(*it, endpoint, cloud_transport_type); + connection_handler().AddCloudAppDevice(endpoint, cloud_transport_type); } } @@ -873,7 +873,7 @@ void ApplicationManagerImpl::CreatePendingApplication( mobile_apis::HybridAppPreference::eType>:: StringToEnum(hybrid_app_preference_str, &hybrid_app_preference_enum); - if (!convert_result) { + if (!hybrid_app_preference_str.empty() && !convert_result) { LOG4CXX_ERROR( logger_, "Could not convert string to enum: " << hybrid_app_preference_str); 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 7be94c5f70..899d17995c 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 @@ -120,8 +120,7 @@ class ConnectionHandlerImpl void ConnectToAllDevices() OVERRIDE; - void AddCloudAppDevice(const std::string& policy_app_id, - const std::string& endpoint, + void AddCloudAppDevice(const std::string& endpoint, const std::string& cloud_transport_type) OVERRIDE; void StartTransportManager() OVERRIDE; diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index ed2522593c..9060350c9b 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -1315,7 +1315,6 @@ void ConnectionHandlerImpl::ConnectToAllDevices() { } void ConnectionHandlerImpl::AddCloudAppDevice( - const std::string& policy_app_id, const std::string& endpoint, const std::string& cloud_transport_type) { transport_manager_.AddCloudDevice(endpoint, cloud_transport_type); diff --git a/src/components/include/connection_handler/connection_handler.h b/src/components/include/connection_handler/connection_handler.h index 93939fc782..9ca9a8d144 100644 --- a/src/components/include/connection_handler/connection_handler.h +++ b/src/components/include/connection_handler/connection_handler.h @@ -93,8 +93,7 @@ class ConnectionHandler { virtual void ConnectToAllDevices() = 0; - virtual void AddCloudAppDevice(const std::string& policy_app_id, - const std::string& endpoint, + virtual void AddCloudAppDevice(const std::string& endpoint, const std::string& cloud_transport_type) = 0; /** diff --git a/src/components/include/test/connection_handler/mock_connection_handler.h b/src/components/include/test/connection_handler/mock_connection_handler.h index bdc0469844..cde835759f 100644 --- a/src/components/include/test/connection_handler/mock_connection_handler.h +++ b/src/components/include/test/connection_handler/mock_connection_handler.h @@ -63,9 +63,8 @@ class MockConnectionHandler : public connection_handler::ConnectionHandler { MOCK_CONST_METHOD2(RunAppOnDevice, void(const std::string&, const std::string&)); MOCK_METHOD0(ConnectToAllDevices, void()); - MOCK_METHOD3(AddCloudAppDevice, - void(const std::string& policy_app_id, - const std::string& endpoint, + MOCK_METHOD2(AddCloudAppDevice, + void(const std::string& endpoint, const std::string& cloud_transport_type)); MOCK_METHOD1(CloseRevokedConnection, void(uint32_t connection_key)); MOCK_METHOD1(CloseConnection, void(ConnectionHandle connection_handle)); -- cgit v1.2.1 From 9f48c541b2ffefb0c34aacc22075cab849dcaea4 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Tue, 22 Jan 2019 13:24:34 -0500 Subject: Fix Style --- src/components/connection_handler/src/connection_handler_impl.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index 9060350c9b..9dc78613fc 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -1315,8 +1315,7 @@ void ConnectionHandlerImpl::ConnectToAllDevices() { } void ConnectionHandlerImpl::AddCloudAppDevice( - const std::string& endpoint, - const std::string& cloud_transport_type) { + const std::string& endpoint, const std::string& cloud_transport_type) { transport_manager_.AddCloudDevice(endpoint, cloud_transport_type); } -- cgit v1.2.1