diff options
author | jacobkeeler <jacob.keeler@livioradio.com> | 2018-11-16 16:25:39 -0500 |
---|---|---|
committer | jacobkeeler <jacob.keeler@livioradio.com> | 2018-11-16 16:25:39 -0500 |
commit | 551e5eeed41767ab11e677ce345c67b661b687c8 (patch) | |
tree | 3794c0153e930c791039ed6351b77b8904bcec23 | |
parent | dc2dc33575394ae16d72a745e278279e0a2700a1 (diff) | |
parent | d8ad4e0427b33087340aa34cf1e1d3954cdb793e (diff) | |
download | sdl_core-551e5eeed41767ab11e677ce345c67b661b687c8.tar.gz |
Merge remote-tracking branch 'origin/feature/cloud_app_connection_flow' into feature/cloud_app_connection_status
# Conflicts:
# src/components/application_manager/include/application_manager/application.h
# src/components/application_manager/include/application_manager/application_impl.h
26 files changed, 509 insertions, 106 deletions
diff --git a/src/appMain/sdl_preloaded_pt.json b/src/appMain/sdl_preloaded_pt.json index 8a75cd3dab..3c84fc96bd 100644 --- a/src/appMain/sdl_preloaded_pt.json +++ b/src/appMain/sdl_preloaded_pt.json @@ -533,6 +533,47 @@ }
}
},
+ "CloudApp":{
+ "rpcs":{
+ "SetCloudAppProperties":{
+ "hmi_levels":["BACKGROUND",
+ "FULL",
+ "LIMITED"]
+ },
+ "GetVehicleData": {
+ "hmi_levels": ["BACKGROUND",
+ "FULL",
+ "LIMITED"],
+ "parameters": [
+ "cloudAppVehicleID"
+ ]
+ },
+ "OnVehicleData": {
+ "hmi_levels": ["BACKGROUND",
+ "FULL",
+ "LIMITED"],
+ "parameters": [
+ "cloudAppVehicleID"
+ ]
+ },
+ "SubscribeVehicleData": {
+ "hmi_levels": ["BACKGROUND",
+ "FULL",
+ "LIMITED"],
+ "parameters": [
+ "cloudAppVehicleID"
+ ]
+ },
+ "UnsubscribeVehicleData": {
+ "hmi_levels": ["BACKGROUND",
+ "FULL",
+ "LIMITED"],
+ "parameters": [
+ "cloudAppVehicleID"
+ ]
+ }
+ }
+ },
"RemoteControl": {
"rpcs": {
"ButtonPress": {
diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index 02fff1cabb..dade5f75c8 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -946,28 +946,67 @@ class Application : public virtual InitialApplicationData, */ virtual const std::list<AppExtensionPtr>& 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 mobile_apis::HybridAppPreference::eType + 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; virtual bool is_cloud_app() const = 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; + const mobile_apis::HybridAppPreference::eType& 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 3401322d59..f2072a9c37 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -409,27 +409,66 @@ 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 mobile_apis::HybridAppPreference::eType 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; bool is_cloud_app() const 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; - void set_hybrid_app_preference( - const std::string& hybrid_app_preference) OVERRIDE; + /** + * @brief Set hybrid app preference + */ + void set_hybrid_app_preference(const mobile_apis::HybridAppPreference::eType& + hybrid_app_preference) OVERRIDE; + /** + * @brief Set cloud app certificate + */ void set_cloud_app_certificate(const std::string& certificate) OVERRIDE; protected: @@ -540,7 +579,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/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_cloudapp_properties_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_cloudapp_properties_request.h new file mode 100644 index 0000000000..0c62b248b4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_cloudapp_properties_request.h @@ -0,0 +1,31 @@ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_SET_CLOUDAPP_PROPERTIES_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_SET_CLOUDAPP_PROPERTIES_REQUEST_H_ + +#include "application_manager/commands/command_request_impl.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +class SetCloudAppPropertiesRequest + : public app_mngr::commands::CommandRequestImpl { + public: + SetCloudAppPropertiesRequest( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler); + virtual ~SetCloudAppPropertiesRequest(); + virtual void Run(); + virtual void on_event(const app_mngr::event_engine::Event& event); + + private: + DISALLOW_COPY_AND_ASSIGN(SetCloudAppPropertiesRequest); +}; // SetCloudAppPropertiesRequest + +} // namespace commands +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_SET_CLOUDAPP_PROPERTIES_REQUEST_H_
\ No newline at end of file diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_cloudapp_properties_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_cloudapp_properties_response.h new file mode 100644 index 0000000000..9037cb3b73 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_cloudapp_properties_response.h @@ -0,0 +1,31 @@ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_SET_CLOUDAPP_PROPERTIES_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_SET_CLOUDAPP_PROPERTIES_RESPONSE_H_ + +#include "application_manager/commands/command_response_impl.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +class SetCloudAppPropertiesResponse + : public app_mngr::commands::CommandResponseImpl { + public: + SetCloudAppPropertiesResponse( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler); + virtual ~SetCloudAppPropertiesResponse(); + virtual void Run(); + + private: + DISALLOW_COPY_AND_ASSIGN(SetCloudAppPropertiesResponse); + +}; // SetCloudAppPropertiesResponse + +} // namespace commands +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_SET_CLOUDAPP_PROPERTIES_RESPONSE_H_
\ No newline at end of file diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_request.cc new file mode 100644 index 0000000000..ca5a46e3dc --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_request.cc @@ -0,0 +1,81 @@ +#include "sdl_rpc_plugin/commands/mobile/set_cloudapp_properties_request.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +SetCloudAppPropertiesRequest::SetCloudAppPropertiesRequest( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandRequestImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +SetCloudAppPropertiesRequest::~SetCloudAppPropertiesRequest() {} +void SetCloudAppPropertiesRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + ApplicationSharedPtr app = application_manager_.application(connection_key()); + + if (!app) { + LOG4CXX_ERROR(logger_, "Application is not registered"); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); + return; + } + + if ((*message_)[strings::msg_params].empty()) { + LOG4CXX_ERROR(logger_, strings::msg_params << " is empty."); + SendResponse(false, mobile_apis::Result::INVALID_DATA); + return; + } + + smart_objects::SmartObject cloud_app_properties(smart_objects::SmartType_Map); + + cloud_app_properties[strings::msg_params][strings::app_name] = + (*message_)[strings::msg_params][strings::app_name]; + cloud_app_properties[strings::msg_params][strings::app_id] = + (*message_)[strings::msg_params][strings::app_id]; + + if ((*message_)[strings::msg_params].keyExists(strings::enabled)) { + smart_objects::SmartObject enabled = + (*message_)[strings::msg_params][strings::enabled]; + cloud_app_properties[strings::msg_params][strings::enabled] = enabled; + } + if ((*message_)[strings::msg_params].keyExists( + strings::cloud_app_auth_token)) { + smart_objects::SmartObject auth_token = + (*message_)[strings::msg_params][strings::cloud_app_auth_token]; + cloud_app_properties[strings::msg_params][strings::cloud_app_auth_token] = + auth_token; + } + if ((*message_)[strings::msg_params].keyExists( + strings::cloud_transport_type)) { + smart_objects::SmartObject transport_type = + (*message_)[strings::msg_params][strings::cloud_transport_type]; + cloud_app_properties[strings::msg_params][strings::cloud_transport_type] = + transport_type; + } + if ((*message_)[strings::msg_params].keyExists( + strings::hybrid_app_preference)) { + smart_objects::SmartObject hybrid_app_preference = + (*message_)[strings::msg_params][strings::hybrid_app_preference]; + cloud_app_properties[strings::msg_params][strings::hybrid_app_preference] = + hybrid_app_preference; + } + + policy_handler_.OnSetCloudAppProperties(cloud_app_properties); + SendResponse(true, mobile_apis::Result::SUCCESS); +} + +void SetCloudAppPropertiesRequest::on_event( + const app_mngr::event_engine::Event& event) { + LOG4CXX_INFO(logger_, "SetCloudAppPropertiesRequest on_event"); +} + +} // namespace commands +} // namespace sdl_rpc_plugin
\ No newline at end of file diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_response.cc new file mode 100644 index 0000000000..6acfb2423d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_response.cc @@ -0,0 +1,31 @@ +#include "application_manager/application_manager.h" +#include "application_manager/rpc_service.h" +#include "sdl_rpc_plugin/commands/mobile/set_cloudapp_properties_response.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +SetCloudAppPropertiesResponse::SetCloudAppPropertiesResponse( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandResponseImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +SetCloudAppPropertiesResponse::~SetCloudAppPropertiesResponse() {} + +void SetCloudAppPropertiesResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + rpc_service_.SendMessageToMobile(message_); +} + +} // namespace commands +} // namespace sdl_rpc_plugins diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc index 5207c7e432..dc5298813b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc @@ -124,6 +124,8 @@ #include "sdl_rpc_plugin/commands/mobile/dial_number_response.h" #include "sdl_rpc_plugin/commands/mobile/send_haptic_data_request.h" #include "sdl_rpc_plugin/commands/mobile/send_haptic_data_response.h" +#include "sdl_rpc_plugin/commands/mobile/set_cloudapp_properties_request.h" +#include "sdl_rpc_plugin/commands/mobile/set_cloudapp_properties_response.h" #include "interfaces/MOBILE_API.h" CREATE_LOGGERPTR_GLOBAL(logger_, "ApplicationManager") @@ -337,6 +339,12 @@ CommandCreator& MobileCommandFactory::get_creator_factory( ? factory.GetCreator<commands::SendHapticDataRequest>() : factory.GetCreator<commands::SendHapticDataResponse>(); } + case mobile_apis::FunctionID::SetCloudAppPropertiesID: { + return mobile_api::messageType::request == message_type + ? factory.GetCreator<commands::SetCloudAppPropertiesRequest>() + : factory + .GetCreator<commands::SetCloudAppPropertiesResponse>(); + } case mobile_apis::FunctionID::OnButtonEventID: { return factory.GetCreator<commands::mobile::OnButtonEventNotification>(); } diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 23376f944a..1f372122c0 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -1163,28 +1163,31 @@ const std::list<AppExtensionPtr>& 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 mobile_apis::HybridAppPreference::eType +ApplicationImpl::hybrid_app_preference() { return hybrid_app_preference_; } -std::string ApplicationImpl::cloud_app_certificate() { +const std::string ApplicationImpl::cloud_app_certificate() { return certificate_; } bool ApplicationImpl::is_cloud_app() const { - return !endpoint_.empty() && hybrid_app_preference_ != "MOBILE"; + return !endpoint_.empty() && + hybrid_app_preference_ != + hmi_apis::Common_CloudConnectionStatus::MOBILE; } void ApplicationImpl::set_cloud_app_endpoint(const std::string& endpoint) { @@ -1201,7 +1204,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 174e134ca8..79bd00b37d 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -852,30 +852,73 @@ 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 = ""; + std::string cloud_transport_type = ""; + std::string hybrid_app_preference_str = ""; + 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)); + 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, + policy_app_id, + device_info.mac_address(), + device_id, + custom_str::CustomString(display_name), + GetPolicyHandler().GetStatisticManager(), + *this)); if (!application) { LOG4CXX_INFO(logger_, "Could not create application"); return; } + GetPolicyHandler().GetCloudAppParameters(policy_app_id, + 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_enum); + application->set_cloud_app_certificate(certificate); sync_primitives::AutoLock lock(apps_to_register_list_lock_ptr_); LOG4CXX_DEBUG(logger_, diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index cc62d9f6f8..8c6de5482c 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -54,6 +54,7 @@ #include "interfaces/MOBILE_API.h" #include "utils/file_system.h" #include "utils/scope_guard.h" +#include "smart_objects/enum_schema_item.h" #include "utils/helpers.h" #include "policy/policy_manager.h" @@ -1913,10 +1914,16 @@ void PolicyHandler::OnSetCloudAppProperties( 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<HybridAppPreference>::EnumToString(msg_params[strings::hybrid_app_preference]); - // policy_manager_->SetHybridAppPreference( - // policy_app_id, hybrid_app_preference); + std::string hybrid_app_preference; + + mobile_apis::HybridAppPreference::eType value = + static_cast<mobile_apis::HybridAppPreference::eType>( + msg_params[strings::hybrid_app_preference].asUInt()); + smart_objects::EnumConversionHelper< + mobile_apis::HybridAppPreference::eType>:: + EnumToString(value, &hybrid_app_preference); + policy_manager_->SetHybridAppPreference(policy_app_id, + hybrid_app_preference); } } 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 diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index 6ed42c3588..1707f65bad 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -545,6 +545,13 @@ <element name="VEHICLEDATA_CLOUDAPPVEHICLEID" since="5.1"/> </enum> + <enum name="HybridAppPreference" since="5.1"> + <description>Enumeration for the user's preference of which app type to use when both are available</description> + <element name = "MOBILE" /> + <element name = "CLOUD" /> + <element name = "BOTH" /> + </enum> + <enum name="ButtonName" since="1.0"> <description>Defines the hard (physical) and soft (touchscreen) buttons available from the module</description> <element name="OK" /> @@ -2609,6 +2616,7 @@ <element name="UnsubscribeWayPointsID" value="47" hexvalue="2F" since="4.1" /> <element name="GetSystemCapabilityID" value="48" hexvalue="30" since="4.5" /> <element name="SendHapticDataID" value="49" hexvalue="31" since="4.5" /> + <element name="SetCloudAppPropertiesID" value="50" hexvalue="32" since="5.1" /> <!-- Base Notifications @@ -6626,6 +6634,51 @@ </param> </function> + <function name="SetCloudAppProperties" functionID="SetCloudAppPropertiesID" messagetype="request" since="5.1"> + <description> + RPC used to enable/disable a cloud application and set authentication data + </description> + <param name="appName" type="String" maxlength="100" mandatory="true"></param> + <param name="appID" type="String" maxlength="100" mandatory="true"></param> + <param name="enabled" type="Boolean" mandatory="false"> + <description>If true, cloud app will be included in HMI RPC UpdateAppList</description> + </param> + <param name="cloudAppAuthToken" type="String" maxlength="100" mandatory="false"> + <description>Used to authenticate websocket connection on app activation</description> + </param> + <param name="cloudTransportType" type="String" maxlength="100" mandatory="false"> + <description>Specifies the connection type Core should use</description> + </param> + <param name="hybridAppPreference" type="HybridAppPreference" mandatory="false"> + <description>Specifies the user preference to use the cloud app version or mobile app version when both are available</description> + </param> + </function> + + <function name="SetCloudAppProperties" functionID="SetCloudAppPropertiesID" messagetype="response" since="5.1"> + <description> + The response to registerAppInterface + </description> + <param name="success" type="Boolean" platform="documentation" mandatory="true"> + <description> true if successful; false if failed </description> + </param> + <param name="resultCode" type="Result" platform="documentation" mandatory="true"> + <description>See Result</description> + <element name="SUCCESS" /> + <element name="INVALID_DATA" /> + <element name="OUT_OF_MEMORY" /> + <element name="TOO_MANY_PENDING_REQUESTS" /> + <element name="GENERIC_ERROR" /> + <element name="DUPLICATE_NAME" /> + <element name="TOO_MANY_APPLICATIONS" /> + <element name="APPLICATION_REGISTERED_ALREADY" /> + <element name="UNSUPPORTED_VERSION" /> + <element name="WRONG_LANGUAGE" /> + <element name="DISALLOWED" /> + <element name="WARNINGS" /> + <element name="RESUME_FAILED" /> + </param> + </function> + <!-- Notifications --> <function name="OnHMIStatus" functionID="OnHMIStatusID" messagetype="notification" since="1.0"> 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 dc2fdab2fa..5b494629bb 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 @@ -441,6 +441,11 @@ enum FunctionID { SendHapticDataID = 49, /** + * @brief SetCloudAppPropertiesID. + */ + SetCloudAppPropertiesID = 50, + + /** * @brief OnHMIStatusID. */ OnHMIStatusID = 32768, 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 48ce4d4f72..d7d5a241de 100644 --- a/src/components/policy/policy_external/src/policy_table/enums.cc +++ b/src/components/policy/policy_external/src/policy_table/enums.cc @@ -1121,6 +1121,11 @@ bool EnumFromJsonString(const std::string& literal, FunctionID* result) { return true; } + if ("SetCloudAppProperties" == literal) { + *result = SetCloudAppPropertiesID; + return true; + } + if ("OnHMIStatus" == literal) { *result = OnHMIStatusID; return true; 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 fce6b7b865..563e822a36 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 @@ -427,6 +427,11 @@ enum FunctionID { SendHapticDataID = 49, /** + * @brief SetCloudAppPropertiesID. + */ + SetCloudAppPropertiesID = 50, + + /** * @brief OnHMIStatusID. */ OnHMIStatusID = 32768, 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 2ddf74af7e..91d0a6990f 100644 --- a/src/components/policy/policy_regular/src/policy_table/enums.cc +++ b/src/components/policy/policy_regular/src/policy_table/enums.cc @@ -847,6 +847,8 @@ bool IsValidEnum(FunctionID val) { return true; case SendHapticDataID: return true; + case SetCloudAppPropertiesID: + return true; case OnHMIStatusID: return true; case OnAppInterfaceUnregisteredID: @@ -994,6 +996,8 @@ const char* EnumToJsonString(FunctionID val) { return "GetSystemCapability"; case SendHapticDataID: return "SendHapticData"; + case SetCloudAppPropertiesID: + return "SetCloudAppProperties"; case OnHMIStatusID: return "OnHMIStatus"; case OnAppInterfaceUnregisteredID: @@ -1283,6 +1287,10 @@ bool EnumFromJsonString(const std::string& literal, FunctionID* result) { *result = SendHapticDataID; return true; } + if ("SetCloudAppProperties" == literal) { + *result = SetCloudAppPropertiesID; + return true; + } if ("OnHMIStatus" == literal) { *result = OnHMIStatusID; diff --git a/src/components/smart_objects/include/smart_objects/enum_schema_item.h b/src/components/smart_objects/include/smart_objects/enum_schema_item.h index cbba5bd7cd..942b491927 100644 --- a/src/components/smart_objects/include/smart_objects/enum_schema_item.h +++ b/src/components/smart_objects/include/smart_objects/enum_schema_item.h @@ -220,11 +220,10 @@ class EnumConversionHelper { static bool EnumToString(const EnumType value, std::string* str) { const char* cstr; - if (EnumToCString(value, &cstr)) { - return false; - } - if (str) { + bool success = EnumToCString(value, &cstr); + if (success && str) { *str = cstr; + return true; } return false; } 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<CloudDevice>( - 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<WebsocketClientConnection> connection = std::make_shared<WebsocketClientConnection>( 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 2ec2e5d1a0..2ad1a66126 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<CloudDevice*>(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<const uint8_t*>( @@ -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 |