diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src')
35 files changed, 3072 insertions, 0 deletions
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_app_extension.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_app_extension.cc new file mode 100644 index 0000000000..6d8b0c08cc --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_app_extension.cc @@ -0,0 +1,122 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/app_service_app_extension.h" +#include "app_service_rpc_plugin/app_service_rpc_plugin.h" + +CREATE_LOGGERPTR_GLOBAL(logger_, "AppServiceRpcPlugin") + +namespace app_service_rpc_plugin { + +const AppExtensionUID AppServiceAppExtensionUID = 455; + +AppServiceAppExtension::AppServiceAppExtension( + AppServiceRpcPlugin& plugin, application_manager::Application& app) + : app_mngr::AppExtension(AppServiceAppExtensionUID) + , plugin_(plugin) + , app_(app) { + LOG4CXX_AUTO_TRACE(logger_); +} + +AppServiceAppExtension::~AppServiceAppExtension() { + LOG4CXX_AUTO_TRACE(logger_); +} + +bool AppServiceAppExtension::SubscribeToAppService( + const std::string app_service_type) { + LOG4CXX_DEBUG(logger_, "Subscribe to app service: " << app_service_type); + return subscribed_data_.insert(app_service_type).second; +} + +bool AppServiceAppExtension::UnsubscribeFromAppService( + const std::string app_service_type) { + LOG4CXX_DEBUG(logger_, app_service_type); + auto it = subscribed_data_.find(app_service_type); + if (it != subscribed_data_.end()) { + subscribed_data_.erase(it); + return true; + } + return false; +} + +void AppServiceAppExtension::UnsubscribeFromAppService() { + LOG4CXX_AUTO_TRACE(logger_); + subscribed_data_.clear(); +} + +bool AppServiceAppExtension::IsSubscribedToAppService( + const std::string app_service_type) const { + LOG4CXX_DEBUG(logger_, + "isSubscribedToAppService for type: " << app_service_type); + return subscribed_data_.find(app_service_type) != subscribed_data_.end(); +} + +AppServiceSubscriptions AppServiceAppExtension::Subscriptions() { + return subscribed_data_; +} + +void AppServiceAppExtension::SaveResumptionData( + smart_objects::SmartObject& resumption_data) { + const char* app_service_info = "appService"; + resumption_data[app_service_info] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + int i = 0; + for (const auto& subscription : subscribed_data_) { + resumption_data[app_service_info][i] = subscription; + i++; + } +} + +void AppServiceAppExtension::ProcessResumption( + const smart_objects::SmartObject& resumption_data) { + const char* app_service_info = "appService"; + if (resumption_data.keyExists(app_service_info)) { + const smart_objects::SmartObject& subscriptions_app_services = + resumption_data[app_service_info]; + for (size_t i = 0; i < subscriptions_app_services.length(); ++i) { + std::string service_type = resumption_data[i].asString(); + SubscribeToAppService(service_type); + } + } +} + +AppServiceAppExtension& AppServiceAppExtension::ExtractASExtension( + application_manager::Application& app) { + auto ext_ptr = app.QueryInterface(AppServiceAppExtensionUID); + DCHECK(ext_ptr); + DCHECK(dynamic_cast<AppServiceAppExtension*>(ext_ptr.get())); + auto vi_app_extension = + std::static_pointer_cast<AppServiceAppExtension>(ext_ptr); + DCHECK(vi_app_extension); + return *vi_app_extension; +} +} diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_command_factory.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_command_factory.cc new file mode 100644 index 0000000000..f0a0698bb7 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_command_factory.cc @@ -0,0 +1,77 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/app_service_command_factory.h" + +CREATE_LOGGERPTR_GLOBAL(logger_, "AppServiceRpcPlugin") + +namespace app_service_rpc_plugin { + +AppServiceCommandFactory::AppServiceCommandFactory( + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : hmi_command_factory_(new AppServiceHmiCommandFactory( + application_manager, rpc_service, hmi_capabilities, policy_handler)) + , mobile_command_factory_(new AppServiceMobileCommandFactory( + application_manager, rpc_service, hmi_capabilities, policy_handler)) { + LOG4CXX_AUTO_TRACE(logger_); +} + +AppServiceCommandFactory::~AppServiceCommandFactory() { + LOG4CXX_AUTO_TRACE(logger_); +} + +app_mngr::CommandSharedPtr AppServiceCommandFactory::CreateCommand( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::commands::Command::CommandSource source) { + if (app_mngr::commands::Command::SOURCE_HMI == source || + app_mngr::commands::Command::SOURCE_SDL_TO_HMI == source) { + return hmi_command_factory_->CreateCommand(message, source); + } else { + return mobile_command_factory_->CreateCommand(message, source); + } +} + +bool AppServiceCommandFactory::IsAbleToProcess( + const int32_t function_id, + const commands::Command::CommandSource source) const { + LOG4CXX_DEBUG(logger_, + "AppServiceCommandFactory::IsAbleToProcess" << function_id + << " " << source); + return (commands::Command::SOURCE_HMI == source || + commands::Command::SOURCE_SDL_TO_HMI == source) + ? hmi_command_factory_->IsAbleToProcess(function_id, source) + : mobile_command_factory_->IsAbleToProcess(function_id, source); +} +} // namespace service_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_hmi_command_factory.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_hmi_command_factory.cc new file mode 100644 index 0000000000..7cfbdd22d0 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_hmi_command_factory.cc @@ -0,0 +1,191 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/app_service_hmi_command_factory.h" +#include "application_manager/message.h" +#include "interfaces/HMI_API.h" + +#include "app_service_rpc_plugin/commands/hmi/as_app_service_activation_request.h" +#include "app_service_rpc_plugin/commands/hmi/as_app_service_activation_response.h" +#include "app_service_rpc_plugin/commands/hmi/as_get_active_service_consent_request.h" +#include "app_service_rpc_plugin/commands/hmi/as_get_active_service_consent_response.h" +#include "app_service_rpc_plugin/commands/hmi/as_get_app_service_data_request_from_hmi.h" +#include "app_service_rpc_plugin/commands/hmi/as_get_app_service_data_request_to_hmi.h" +#include "app_service_rpc_plugin/commands/hmi/as_get_app_service_data_response_from_hmi.h" +#include "app_service_rpc_plugin/commands/hmi/as_get_app_service_data_response_to_hmi.h" +#include "app_service_rpc_plugin/commands/hmi/as_get_app_service_records_request.h" +#include "app_service_rpc_plugin/commands/hmi/as_get_app_service_records_response.h" +#include "app_service_rpc_plugin/commands/hmi/as_perform_app_service_interaction_request_from_hmi.h" +#include "app_service_rpc_plugin/commands/hmi/as_perform_app_service_interaction_request_to_hmi.h" +#include "app_service_rpc_plugin/commands/hmi/as_perform_app_service_interaction_response_from_hmi.h" +#include "app_service_rpc_plugin/commands/hmi/as_perform_app_service_interaction_response_to_hmi.h" +#include "app_service_rpc_plugin/commands/hmi/as_publish_app_service_request.h" +#include "app_service_rpc_plugin/commands/hmi/as_publish_app_service_response.h" +#include "app_service_rpc_plugin/commands/hmi/on_as_app_service_data_notification.h" +#include "app_service_rpc_plugin/commands/hmi/on_as_app_service_data_notification_from_hmi.h" + +CREATE_LOGGERPTR_GLOBAL(logger_, "AppServiceRpcPlugin") + +namespace app_service_rpc_plugin { +namespace strings = app_mngr::strings; + +AppServiceHmiCommandFactory::AppServiceHmiCommandFactory( + application_manager::ApplicationManager& application_manager, + application_manager::rpc_service::RPCService& rpc_service, + application_manager::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : application_manager_(application_manager) + , rpc_service_(rpc_service) + , hmi_capabilities_(hmi_capabilities) + , policy_handler_(policy_handler) { + LOG4CXX_AUTO_TRACE(logger_); +} + +app_mngr::CommandSharedPtr AppServiceHmiCommandFactory::CreateCommand( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::commands::Command::CommandSource source) { + UNUSED(source); + + const hmi_apis::FunctionID::eType function_id = + static_cast<hmi_apis::FunctionID::eType>( + (*message)[strings::params][strings::function_id].asInt()); + + const hmi_apis::messageType::eType message_type = + static_cast<hmi_apis::messageType::eType>( + (*message)[strings::params][strings::message_type].asInt()); + + auto message_type_str = "request"; + if (hmi_apis::messageType::response == message_type) { + message_type_str = "response"; + } else if (hmi_apis::messageType::error_response == message_type) { + message_type_str = "error response"; + } else if (hmi_apis::messageType::notification == message_type) { + message_type_str = "notification"; + } + + UNUSED(message_type_str); + LOG4CXX_DEBUG(logger_, + "HMICommandFactory::CreateCommand function_id: " + << function_id << ", message type: " << message_type_str); + + return buildCommandCreator(function_id, message_type, source).create(message); +} + +bool AppServiceHmiCommandFactory::IsAbleToProcess( + const int32_t function_id, + const app_mngr::commands::Command::CommandSource source) const { + LOG4CXX_DEBUG(logger_, + "HMI App Service Plugin IsAbleToProcess: " << function_id); + UNUSED(source); + return buildCommandCreator(function_id, + hmi_apis::messageType::INVALID_ENUM, + source).CanBeCreated(); +} + +app_mngr::CommandCreator& AppServiceHmiCommandFactory::buildCommandCreator( + const int32_t function_id, + const int32_t message_type, + const app_mngr::commands::Command::CommandSource source) const { + auto factory = app_mngr::CommandCreatorFactory( + application_manager_, rpc_service_, hmi_capabilities_, policy_handler_); + + LOG4CXX_DEBUG(logger_, + "buildCommandCreator: " << function_id << " " << source); + + switch (function_id) { + case hmi_apis::FunctionID::AppService_PublishAppService: + return hmi_apis::messageType::request == message_type + ? factory.GetCreator<commands::ASPublishAppServiceRequest>() + : factory.GetCreator<commands::ASPublishAppServiceResponse>(); + case hmi_apis::FunctionID::AppService_OnAppServiceData: + return app_mngr::commands::Command::CommandSource::SOURCE_HMI == source + ? factory.GetCreator< + commands::OnASAppServiceDataNotificationFromHMI>() + : factory + .GetCreator<commands::OnASAppServiceDataNotification>(); + case hmi_apis::FunctionID::AppService_GetAppServiceData: + if (app_mngr::commands::Command::CommandSource::SOURCE_HMI == source) { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator< + commands::ASGetAppServiceDataRequestFromHMI>() + : factory.GetCreator< + commands::ASGetAppServiceDataResponseFromHMI>(); + } else if (app_mngr::commands::Command::CommandSource:: + SOURCE_SDL_TO_HMI == source) { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator< + commands::ASGetAppServiceDataRequestToHMI>() + : factory.GetCreator< + commands::ASGetAppServiceDataResponseToHMI>(); + } + break; + case hmi_apis::FunctionID::AppService_GetAppServiceRecords: + return hmi_apis::messageType::request == message_type + ? factory.GetCreator<commands::ASGetAppServiceRecordsRequest>() + : factory + .GetCreator<commands::ASGetAppServiceRecordsResponse>(); + case hmi_apis::FunctionID::AppService_AppServiceActivation: + return hmi_apis::messageType::request == message_type + ? factory.GetCreator<commands::ASAppServiceActivationRequest>() + : factory + .GetCreator<commands::ASAppServiceActivationResponse>(); + case hmi_apis::FunctionID::AppService_PerformAppServiceInteraction: + if (app_mngr::commands::Command::CommandSource::SOURCE_HMI == source) { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator< + commands:: + ASPerformAppServiceInteractionRequestFromHMI>() + : factory.GetCreator< + commands:: + ASPerformAppServiceInteractionResponseFromHMI>(); + } else if (app_mngr::commands::Command::CommandSource:: + SOURCE_SDL_TO_HMI == source) { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator< + commands::ASPerformAppServiceInteractionRequestToHMI>() + : factory.GetCreator< + commands:: + ASPerformAppServiceInteractionResponseToHMI>(); + } + break; + case hmi_apis::FunctionID::AppService_GetActiveServiceConsent: + return hmi_apis::messageType::request == message_type + ? factory + .GetCreator<commands::ASGetActiveServiceConsentRequest>() + : factory.GetCreator< + commands::ASGetActiveServiceConsentResponse>(); + default: + LOG4CXX_WARN(logger_, "Unsupported HMI function_id: " << function_id); + } + return factory.GetCreator<app_mngr::InvalidCommand>(); +} +} diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_mobile_command_factory.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_mobile_command_factory.cc new file mode 100644 index 0000000000..4b4da5e3e9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_mobile_command_factory.cc @@ -0,0 +1,159 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/app_service_mobile_command_factory.h" + +#include "application_manager/message.h" +#include "interfaces/MOBILE_API.h" + +#include "app_service_rpc_plugin/commands/mobile/get_app_service_data_request.h" +#include "app_service_rpc_plugin/commands/mobile/get_app_service_data_request_to_mobile.h" +#include "app_service_rpc_plugin/commands/mobile/get_app_service_data_response.h" +#include "app_service_rpc_plugin/commands/mobile/get_app_service_data_response_from_mobile.h" +#include "app_service_rpc_plugin/commands/mobile/on_app_service_data_notification.h" +#include "app_service_rpc_plugin/commands/mobile/on_app_service_data_notification_from_mobile.h" +#include "app_service_rpc_plugin/commands/mobile/perform_app_service_interaction_request.h" +#include "app_service_rpc_plugin/commands/mobile/perform_app_service_interaction_request_to_mobile.h" +#include "app_service_rpc_plugin/commands/mobile/perform_app_service_interaction_response.h" +#include "app_service_rpc_plugin/commands/mobile/perform_app_service_interaction_response_from_mobile.h" +#include "app_service_rpc_plugin/commands/mobile/publish_app_service_request.h" +#include "app_service_rpc_plugin/commands/mobile/publish_app_service_response.h" + +CREATE_LOGGERPTR_GLOBAL(logger_, "AppServiceRpcPlugin") + +namespace app_service_rpc_plugin { +namespace strings = app_mngr::strings; + +AppServiceMobileCommandFactory::AppServiceMobileCommandFactory( + application_manager::ApplicationManager& application_manager, + application_manager::rpc_service::RPCService& rpc_service, + application_manager::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : application_manager_(application_manager) + , rpc_service_(rpc_service) + , hmi_capabilities_(hmi_capabilities) + , policy_handler_(policy_handler) { + LOG4CXX_AUTO_TRACE(logger_); +} + +app_mngr::CommandSharedPtr AppServiceMobileCommandFactory::CreateCommand( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::commands::Command::CommandSource source) { + UNUSED(source); + + const mobile_apis::FunctionID::eType function_id = + static_cast<mobile_apis::FunctionID::eType>( + (*message)[strings::params][strings::function_id].asInt()); + + const mobile_apis::messageType::eType message_type = + static_cast<mobile_apis::messageType::eType>( + (*message)[strings::params][strings::message_type].asInt()); + + auto message_type_str = "request"; + if (mobile_apis::messageType::response == message_type) { + message_type_str = "response"; + } else if (mobile_apis::messageType::notification == message_type) { + message_type_str = "notification"; + } + + UNUSED(message_type_str); + LOG4CXX_DEBUG(logger_, + "HMICommandFactory::CreateCommand function_id: " + << function_id << ", message type: " << message_type_str); + + return buildCommandCreator(function_id, message_type, source).create(message); +} + +bool AppServiceMobileCommandFactory::IsAbleToProcess( + const int32_t function_id, + const app_mngr::commands::Command::CommandSource source) const { + UNUSED(source); + return buildCommandCreator(function_id, + mobile_apis::messageType::INVALID_ENUM, + source).CanBeCreated(); +} + +app_mngr::CommandCreator& AppServiceMobileCommandFactory::buildCommandCreator( + const int32_t function_id, + const int32_t message_type, + const app_mngr::commands::Command::CommandSource source) const { + auto factory = app_mngr::CommandCreatorFactory( + application_manager_, rpc_service_, hmi_capabilities_, policy_handler_); + + switch (function_id) { + case mobile_apis::FunctionID::PublishAppServiceID: + return mobile_apis::messageType::request == message_type + ? factory.GetCreator<commands::PublishAppServiceRequest>() + : factory.GetCreator<commands::PublishAppServiceResponse>(); + case mobile_apis::FunctionID::OnAppServiceDataID: + return app_mngr::commands::Command::CommandSource::SOURCE_MOBILE == source + ? factory.GetCreator< + commands::OnAppServiceDataNotificationFromMobile>() + : factory.GetCreator<commands::OnAppServiceDataNotification>(); + case mobile_apis::FunctionID::GetAppServiceDataID: + if (app_mngr::commands::Command::CommandSource::SOURCE_MOBILE == source) { + return mobile_apis::messageType::request == message_type + ? factory.GetCreator<commands::GetAppServiceDataRequest>() + : factory.GetCreator< + commands::GetAppServiceDataResponseFromMobile>(); + } else if (app_mngr::commands::Command::CommandSource::SOURCE_SDL == + source) { + return mobile_apis::messageType::request == message_type + ? factory.GetCreator< + commands::GetAppServiceDataRequestToMobile>() + : factory.GetCreator<commands::GetAppServiceDataResponse>(); + } + break; + case mobile_apis::FunctionID::PerformAppServiceInteractionID: + if (app_mngr::commands::Command::CommandSource::SOURCE_MOBILE == source) { + return mobile_apis::messageType::request == message_type + ? factory.GetCreator< + commands::PerformAppServiceInteractionRequest>() + : factory.GetCreator< + commands:: + PerformAppServiceInteractionResponseFromMobile>(); + } else if (app_mngr::commands::Command::CommandSource::SOURCE_SDL == + source) { + return mobile_apis::messageType::request == message_type + ? factory.GetCreator< + commands:: + PerformAppServiceInteractionRequestToMobile>() + : factory.GetCreator< + commands::PerformAppServiceInteractionResponse>(); + } + break; + default: + LOG4CXX_WARN(logger_, "Unsupported function_id: " << function_id); + } + return factory.GetCreator<app_mngr::InvalidCommand>(); +} +} // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_rpc_plugin.cc new file mode 100644 index 0000000000..b96e5c199d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_rpc_plugin.cc @@ -0,0 +1,98 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "application_manager/message_helper.h" +#include "application_manager/smart_object_keys.h" +#include "app_service_rpc_plugin/app_service_app_extension.h" +#include "app_service_rpc_plugin/app_service_command_factory.h" +#include "app_service_rpc_plugin/app_service_rpc_plugin.h" +#include "application_manager/plugin_manager/plugin_keys.h" + +namespace app_service_rpc_plugin { +CREATE_LOGGERPTR_GLOBAL(logger_, "AppServiceRpcPlugin") + +namespace strings = application_manager::strings; +namespace plugins = application_manager::plugin_manager; + +AppServiceRpcPlugin::AppServiceRpcPlugin() : application_manager_(nullptr) {} + +bool AppServiceRpcPlugin::Init( + application_manager::ApplicationManager& app_manager, + application_manager::rpc_service::RPCService& rpc_service, + application_manager::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) { + application_manager_ = &app_manager; + command_factory_.reset(new app_service_rpc_plugin::AppServiceCommandFactory( + app_manager, rpc_service, hmi_capabilities, policy_handler)); + return true; +} + +bool AppServiceRpcPlugin::IsAbleToProcess( + const int32_t function_id, const commands::Command::CommandSource source) { + return command_factory_->IsAbleToProcess(function_id, source); +} + +std::string AppServiceRpcPlugin::PluginName() { + return plugins::plugin_names::app_service_rpc_plugin; +} + +app_mngr::CommandFactory& AppServiceRpcPlugin::GetCommandFactory() { + return *command_factory_; +} + +void AppServiceRpcPlugin::OnPolicyEvent(plugins::PolicyEvent event) {} + +void AppServiceRpcPlugin::OnApplicationEvent( + plugins::ApplicationEvent event, + app_mngr::ApplicationSharedPtr application) { + if (plugins::ApplicationEvent::kApplicationRegistered == event) { + application->AddExtension( + std::make_shared<AppServiceAppExtension>(*this, *application)); + } else if (plugins::ApplicationEvent::kDeleteApplicationData == event) { + DeleteSubscriptions(application); + } +} + +void AppServiceRpcPlugin::DeleteSubscriptions( + application_manager::ApplicationSharedPtr app) { + auto& ext = AppServiceAppExtension::ExtractASExtension(*app); + auto subscriptions = ext.Subscriptions(); + for (auto& service_type : subscriptions) { + ext.UnsubscribeFromAppService(service_type); + } +} + +} // namespace app_service_rpc_plugin + +extern "C" application_manager::plugin_manager::RPCPlugin* Create() { + return new app_service_rpc_plugin::AppServiceRpcPlugin(); +} diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_app_service_activation_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_app_service_activation_request.cc new file mode 100644 index 0000000000..fd7312ca98 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_app_service_activation_request.cc @@ -0,0 +1,89 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_app_service_activation_request.h" + +#include "application_manager/app_service_manager.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASAppServiceActivationRequest::ASAppServiceActivationRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : RequestFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASAppServiceActivationRequest::~ASAppServiceActivationRequest() {} + +void ASAppServiceActivationRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + AppServiceManager& service_manager = + application_manager_.GetAppServiceManager(); + smart_objects::SmartObject params = (*message_)[strings::msg_params]; + smart_objects::SmartObject response_params(smart_objects::SmartType_Map); + std::string service_id = params[strings::service_id].asString(); + response_params[strings::service_id] = service_id; + if (params[strings::activate].asBool()) { + response_params[strings::activate] = + service_manager.ActivateAppService(service_id); + } else { + service_manager.DeactivateAppService(service_id); + response_params[strings::activate] = false; + } + + if (params.keyExists(strings::set_as_default)) { + if (params[strings::set_as_default].asBool()) { + response_params[strings::set_as_default] = + service_manager.SetDefaultService(service_id); + } else { + service_manager.RemoveDefaultService(service_id); + response_params[strings::set_as_default] = false; + } + } + + SendResponse(true, + (*message_)[strings::params][strings::correlation_id].asUInt(), + hmi_apis::FunctionID::AppService_AppServiceActivation, + hmi_apis::Common_Result::SUCCESS, + &response_params); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_app_service_activation_response.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_app_service_activation_response.cc new file mode 100644 index 0000000000..c77d3ed381 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_app_service_activation_response.cc @@ -0,0 +1,59 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_app_service_activation_response.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASAppServiceActivationResponse::ASAppServiceActivationResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : ResponseToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASAppServiceActivationResponse::~ASAppServiceActivationResponse() {} + +void ASAppServiceActivationResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToHMI(message_); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_active_service_consent_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_active_service_consent_request.cc new file mode 100644 index 0000000000..b1f3d6fdbf --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_active_service_consent_request.cc @@ -0,0 +1,59 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_get_active_service_consent_request.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASGetActiveServiceConsentRequest::ASGetActiveServiceConsentRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : RequestToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASGetActiveServiceConsentRequest::~ASGetActiveServiceConsentRequest() {} + +void ASGetActiveServiceConsentRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + SendRequest(); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_active_service_consent_response.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_active_service_consent_response.cc new file mode 100644 index 0000000000..038c2922ad --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_active_service_consent_response.cc @@ -0,0 +1,62 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_get_active_service_consent_response.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASGetActiveServiceConsentResponse::ASGetActiveServiceConsentResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : ResponseFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASGetActiveServiceConsentResponse::~ASGetActiveServiceConsentResponse() {} + +void ASGetActiveServiceConsentResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + event_engine::Event event( + hmi_apis::FunctionID::AppService_GetActiveServiceConsent); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc new file mode 100644 index 0000000000..a339ffb9a6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc @@ -0,0 +1,126 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_get_app_service_data_request_from_hmi.h" +#include "application_manager/application_impl.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" +#include "smart_objects/enum_schema_item.h" + +#include "application_manager/message_helper.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASGetAppServiceDataRequestFromHMI::ASGetAppServiceDataRequestFromHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : RequestFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASGetAppServiceDataRequestFromHMI::~ASGetAppServiceDataRequestFromHMI() {} + +void ASGetAppServiceDataRequestFromHMI::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + std::string service_type = + (*message_)[strings::msg_params][strings::service_type].asString(); + + LOG4CXX_DEBUG(logger_, "Get Service Type: " << service_type); + + SendProviderRequest(mobile_apis::FunctionID::GetAppServiceDataID, + hmi_apis::FunctionID::AppService_GetAppServiceData, + &(*message_), + true); +} + +void ASGetAppServiceDataRequestFromHMI::on_event( + const event_engine::Event& event) { + const smart_objects::SmartObject& event_message = event.smart_object(); + + auto msg_params = event_message[strings::msg_params]; + + hmi_apis::Common_Result::eType result = + static_cast<hmi_apis::Common_Result::eType>( + event_message[strings::params][hmi_response::code].asInt()); + bool success = + IsHMIResultSuccess(result, HmiInterfaces::HMI_INTERFACE_AppService); + SendResponse(success, + correlation_id(), + hmi_apis::FunctionID::AppService_GetAppServiceData, + result, + &msg_params, + application_manager::commands::Command::SOURCE_SDL_TO_HMI); +} + +void ASGetAppServiceDataRequestFromHMI::on_event( + const event_engine::MobileEvent& event) { + const smart_objects::SmartObject& event_message = event.smart_object(); + + auto msg_params = event_message[strings::msg_params]; + + mobile_apis::Result::eType mobile_result = + static_cast<mobile_apis::Result::eType>( + msg_params[strings::result_code].asInt()); + hmi_apis::Common_Result::eType result = + MessageHelper::MobileToHMIResult(mobile_result); + bool success = IsMobileResultSuccess(mobile_result); + + SendResponse(success, + correlation_id(), + hmi_apis::FunctionID::AppService_GetAppServiceData, + result, + &msg_params, + application_manager::commands::Command::SOURCE_SDL_TO_HMI); +} + +void ASGetAppServiceDataRequestFromHMI::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObject response_params; + response_params[strings::info] = + "The provider did not respond to the request"; + SendErrorResponse(correlation_id(), + hmi_apis::FunctionID::AppService_GetAppServiceData, + hmi_apis::Common_Result::GENERIC_ERROR, + "The provider did not respond to the request", + application_manager::commands::Command::SOURCE_SDL_TO_HMI); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_to_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_to_hmi.cc new file mode 100644 index 0000000000..635cd7319a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_to_hmi.cc @@ -0,0 +1,61 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_get_app_service_data_request_to_hmi.h" +#include "application_manager/application_impl.h" +#include "application_manager/rpc_service.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASGetAppServiceDataRequestToHMI::ASGetAppServiceDataRequestToHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : RequestToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASGetAppServiceDataRequestToHMI::~ASGetAppServiceDataRequestToHMI() {} + +void ASGetAppServiceDataRequestToHMI::Run() { + LOG4CXX_AUTO_TRACE(logger_); + SendRequest(); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_from_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_from_hmi.cc new file mode 100644 index 0000000000..c0b1b274fb --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_from_hmi.cc @@ -0,0 +1,67 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_get_app_service_data_response_from_hmi.h" +#include "application_manager/application_impl.h" +#include "application_manager/rpc_service.h" +#include "interfaces/HMI_API.h" + +#include "application_manager/message_helper.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASGetAppServiceDataResponseFromHMI::ASGetAppServiceDataResponseFromHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : ResponseFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASGetAppServiceDataResponseFromHMI::~ASGetAppServiceDataResponseFromHMI() {} + +void ASGetAppServiceDataResponseFromHMI::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + event_engine::Event event(hmi_apis::FunctionID::AppService_GetAppServiceData); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_to_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_to_hmi.cc new file mode 100644 index 0000000000..b489ec4765 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_to_hmi.cc @@ -0,0 +1,61 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_get_app_service_data_response_to_hmi.h" +#include "application_manager/application_impl.h" +#include "application_manager/rpc_service.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASGetAppServiceDataResponseToHMI::ASGetAppServiceDataResponseToHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : ResponseToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASGetAppServiceDataResponseToHMI::~ASGetAppServiceDataResponseToHMI() {} + +void ASGetAppServiceDataResponseToHMI::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToHMI(message_); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_records_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_records_request.cc new file mode 100644 index 0000000000..fa704c1995 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_records_request.cc @@ -0,0 +1,90 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_get_app_service_records_request.h" + +#include "application_manager/app_service_manager.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASGetAppServiceRecordsRequest::ASGetAppServiceRecordsRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : RequestFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASGetAppServiceRecordsRequest::~ASGetAppServiceRecordsRequest() {} + +void ASGetAppServiceRecordsRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + std::string type; + if ((*message_)[strings::msg_params].keyExists(strings::service_type)) { + type = (*message_)[strings::msg_params][strings::service_type].asString(); + } + smart_objects::SmartObject response_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + smart_objects::SmartObject records = + smart_objects::SmartObject(smart_objects::SmartType_Array); + std::vector<smart_objects::SmartObject> service_records = + application_manager_.GetAppServiceManager().GetAllServiceRecords(); + + int index = 0; + for (auto& record : service_records) { + if (!type.empty() && + record[strings::service_manifest][strings::service_type].asString() != + type) { + continue; + } + records[index] = record; + index++; + } + + if (!records.empty()) { + response_params[strings::service_records] = records; + } + SendResponse(true, + (*message_)[strings::params][strings::correlation_id].asUInt(), + hmi_apis::FunctionID::AppService_GetAppServiceRecords, + hmi_apis::Common_Result::SUCCESS, + &response_params); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_records_response.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_records_response.cc new file mode 100644 index 0000000000..0479aa8d31 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_records_response.cc @@ -0,0 +1,59 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_get_app_service_records_response.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASGetAppServiceRecordsResponse::ASGetAppServiceRecordsResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : ResponseToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASGetAppServiceRecordsResponse::~ASGetAppServiceRecordsResponse() {} + +void ASGetAppServiceRecordsResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToHMI(message_); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_from_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_from_hmi.cc new file mode 100644 index 0000000000..6499b08c28 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_from_hmi.cc @@ -0,0 +1,164 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_perform_app_service_interaction_request_from_hmi.h" + +#include "application_manager/app_service_manager.h" +#include "application_manager/message_helper.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASPerformAppServiceInteractionRequestFromHMI:: + ASPerformAppServiceInteractionRequestFromHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : RequestFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASPerformAppServiceInteractionRequestFromHMI:: + ~ASPerformAppServiceInteractionRequestFromHMI() {} + +void ASPerformAppServiceInteractionRequestFromHMI::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; + std::string hmi_origin_id = + application_manager_.get_settings().hmi_origin_id(); + if (!msg_params.keyExists(strings::origin_app)) { + if (hmi_origin_id.empty()) { + SendErrorResponse( + correlation_id(), + hmi_apis::FunctionID::AppService_PerformAppServiceInteraction, + hmi_apis::Common_Result::INVALID_DATA, + "No HMI origin ID to use for interaction passthrough", + application_manager::commands::Command::SOURCE_SDL_TO_HMI); + return; + } + msg_params[strings::origin_app] = hmi_origin_id; + } + + std::string service_id = msg_params[strings::service_id].asString(); + auto service = + application_manager_.GetAppServiceManager().FindServiceByID(service_id); + if (!service) { + SendErrorResponse( + correlation_id(), + hmi_apis::FunctionID::AppService_PerformAppServiceInteraction, + hmi_apis::Common_Result::INVALID_ID, + "The requested service ID does not exist", + application_manager::commands::Command::SOURCE_SDL_TO_HMI); + return; + } + + bool request_service_active = false; + if (msg_params.keyExists(strings::request_service_active)) { + request_service_active = + msg_params[strings::request_service_active].asBool(); + msg_params.erase(strings::request_service_active); + } + + // Only activate service if it is not already active + bool activate_service = request_service_active && + !service->record[strings::service_active].asBool(); + if (activate_service) { + application_manager_.GetAppServiceManager().ActivateAppService(service_id); + } + + SendProviderRequest( + mobile_apis::FunctionID::PerformAppServiceInteractionID, + hmi_apis::FunctionID::AppService_PerformAppServiceInteraction, + &(*message_), + true); +} + +void ASPerformAppServiceInteractionRequestFromHMI::on_event( + const event_engine::Event& event) { + const smart_objects::SmartObject& event_message = event.smart_object(); + + auto msg_params = event_message[strings::msg_params]; + + hmi_apis::Common_Result::eType result = + static_cast<hmi_apis::Common_Result::eType>( + event_message[strings::params][hmi_response::code].asInt()); + bool success = + IsHMIResultSuccess(result, HmiInterfaces::HMI_INTERFACE_AppService); + SendResponse(success, + correlation_id(), + hmi_apis::FunctionID::AppService_PerformAppServiceInteraction, + result, + &msg_params, + application_manager::commands::Command::SOURCE_SDL_TO_HMI); +} + +void ASPerformAppServiceInteractionRequestFromHMI::on_event( + const event_engine::MobileEvent& event) { + const smart_objects::SmartObject& event_message = event.smart_object(); + + auto msg_params = event_message[strings::msg_params]; + + mobile_apis::Result::eType mobile_result = + static_cast<mobile_apis::Result::eType>( + msg_params[strings::result_code].asInt()); + hmi_apis::Common_Result::eType result = + MessageHelper::MobileToHMIResult(mobile_result); + bool success = IsMobileResultSuccess(mobile_result); + SendResponse(success, + correlation_id(), + hmi_apis::FunctionID::AppService_PerformAppServiceInteraction, + result, + &msg_params, + application_manager::commands::Command::SOURCE_SDL_TO_HMI); +} + +void ASPerformAppServiceInteractionRequestFromHMI::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObject response_params; + response_params[strings::info] = + "The provider did not respond to the request"; + SendErrorResponse( + correlation_id(), + hmi_apis::FunctionID::AppService_PerformAppServiceInteraction, + hmi_apis::Common_Result::GENERIC_ERROR, + "The provider did not respond to the request", + application_manager::commands::Command::SOURCE_SDL_TO_HMI); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_to_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_to_hmi.cc new file mode 100644 index 0000000000..22876328de --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_to_hmi.cc @@ -0,0 +1,61 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_perform_app_service_interaction_request_to_hmi.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASPerformAppServiceInteractionRequestToHMI:: + ASPerformAppServiceInteractionRequestToHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : RequestToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASPerformAppServiceInteractionRequestToHMI:: + ~ASPerformAppServiceInteractionRequestToHMI() {} + +void ASPerformAppServiceInteractionRequestToHMI::Run() { + LOG4CXX_AUTO_TRACE(logger_); + SendRequest(); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_response_from_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_response_from_hmi.cc new file mode 100644 index 0000000000..a2ffa65a73 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_response_from_hmi.cc @@ -0,0 +1,64 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_perform_app_service_interaction_response_from_hmi.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASPerformAppServiceInteractionResponseFromHMI:: + ASPerformAppServiceInteractionResponseFromHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : ResponseFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASPerformAppServiceInteractionResponseFromHMI:: + ~ASPerformAppServiceInteractionResponseFromHMI() {} + +void ASPerformAppServiceInteractionResponseFromHMI::Run() { + LOG4CXX_AUTO_TRACE(logger_); + event_engine::Event event( + hmi_apis::FunctionID::AppService_PerformAppServiceInteraction); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_response_to_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_response_to_hmi.cc new file mode 100644 index 0000000000..5ddef55c2a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_response_to_hmi.cc @@ -0,0 +1,61 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_perform_app_service_interaction_response_to_hmi.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASPerformAppServiceInteractionResponseToHMI:: + ASPerformAppServiceInteractionResponseToHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : ResponseToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASPerformAppServiceInteractionResponseToHMI:: + ~ASPerformAppServiceInteractionResponseToHMI() {} + +void ASPerformAppServiceInteractionResponseToHMI::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToHMI(message_); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc new file mode 100644 index 0000000000..637240666d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc @@ -0,0 +1,76 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_publish_app_service_request.h" + +#include "application_manager/app_service_manager.h" +#include "application_manager/message_helper.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASPublishAppServiceRequest::ASPublishAppServiceRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : RequestFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASPublishAppServiceRequest::~ASPublishAppServiceRequest() {} + +void ASPublishAppServiceRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Received a PublishAppService request from HMI"); + smart_objects::SmartObject response_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + smart_objects::SmartObject manifest = + (*message_)[strings::msg_params][strings::app_service_manifest]; + smart_objects::SmartObject service_record = + application_manager_.GetAppServiceManager().PublishAppService(manifest, + false); + + response_params[strings::app_service_record] = service_record; + SendResponse(true, + (*message_)[strings::params][strings::correlation_id].asUInt(), + hmi_apis::FunctionID::AppService_PublishAppService, + hmi_apis::Common_Result::SUCCESS, + &response_params); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_response.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_response.cc new file mode 100644 index 0000000000..c143315b8c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_response.cc @@ -0,0 +1,60 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/as_publish_app_service_response.h" +#include "application_manager/message_helper.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +ASPublishAppServiceResponse::ASPublishAppServiceResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : ResponseToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +ASPublishAppServiceResponse::~ASPublishAppServiceResponse() {} + +void ASPublishAppServiceResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToHMI(message_); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/on_as_app_service_data_notification.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/on_as_app_service_data_notification.cc new file mode 100644 index 0000000000..80dd88c15f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/on_as_app_service_data_notification.cc @@ -0,0 +1,60 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/on_as_app_service_data_notification.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +OnASAppServiceDataNotification::OnASAppServiceDataNotification( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : NotificationToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +OnASAppServiceDataNotification::~OnASAppServiceDataNotification() {} + +void OnASAppServiceDataNotification::Run() { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Sending AS data to HMI"); + SendNotification(); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/on_as_app_service_data_notification_from_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/on_as_app_service_data_notification_from_hmi.cc new file mode 100644 index 0000000000..05266f834b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/on_as_app_service_data_notification_from_hmi.cc @@ -0,0 +1,62 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/hmi/on_as_app_service_data_notification_from_hmi.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +OnASAppServiceDataNotificationFromHMI::OnASAppServiceDataNotificationFromHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : NotificationFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +OnASAppServiceDataNotificationFromHMI:: + ~OnASAppServiceDataNotificationFromHMI() {} + +void OnASAppServiceDataNotificationFromHMI::Run() { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Received an OnAppServiceData from HMI"); + SendNotificationToConsumers( + mobile_apis::FunctionID::eType::OnAppServiceDataID); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc new file mode 100644 index 0000000000..7c2e62abe2 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc @@ -0,0 +1,129 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/mobile/get_app_service_data_request.h" +#include "app_service_rpc_plugin/app_service_app_extension.h" +#include "application_manager/application_impl.h" +#include "application_manager/message_helper.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" +#include "smart_objects/enum_schema_item.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +GetAppServiceDataRequest::GetAppServiceDataRequest( + const application_manager::commands::MessageSharedPtr& message, + 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) {} + +GetAppServiceDataRequest::~GetAppServiceDataRequest() {} + +void GetAppServiceDataRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + SendProviderRequest(mobile_apis::FunctionID::GetAppServiceDataID, + hmi_apis::FunctionID::AppService_GetAppServiceData, + &(*message_), + true); +} + +void GetAppServiceDataRequest::HandleSubscribe() { + std::string service_type = + (*message_)[strings::msg_params][strings::service_type].asString(); + ApplicationSharedPtr app = application_manager_.application(connection_key()); + if (app && (*message_)[strings::msg_params].keyExists(strings::subscribe)) { + bool subscribe = + (*message_)[strings::msg_params][strings::subscribe].asBool(); + auto& ext = AppServiceAppExtension::ExtractASExtension(*app); + if (subscribe) { + ext.SubscribeToAppService(service_type); + } else { + ext.UnsubscribeFromAppService(service_type); + } + } +} + +void GetAppServiceDataRequest::on_event( + const event_engine::MobileEvent& event) { + const smart_objects::SmartObject& event_message = event.smart_object(); + + auto msg_params = event_message[strings::msg_params]; + + mobile_apis::Result::eType result = static_cast<mobile_apis::Result::eType>( + msg_params[strings::result_code].asInt()); + bool success = IsMobileResultSuccess(result); + if (success) { + HandleSubscribe(); + } + + const char* info = msg_params.keyExists(strings::info) + ? msg_params[strings::info].asCharArray() + : NULL; + + SendResponse(success, result, info, &msg_params); +} + +void GetAppServiceDataRequest::on_event(const event_engine::Event& event) { + const smart_objects::SmartObject& event_message = event.smart_object(); + + auto msg_params = event_message[strings::msg_params]; + + hmi_apis::Common_Result::eType hmi_result = + static_cast<hmi_apis::Common_Result::eType>( + event_message[strings::params][hmi_response::code].asInt()); + + mobile_apis::Result::eType result = + MessageHelper::HMIToMobileResult(hmi_result); + bool success = PrepareResultForMobileResponse( + hmi_result, HmiInterfaces::HMI_INTERFACE_AppService); + if (success) { + HandleSubscribe(); + } + + const char* info = msg_params.keyExists(strings::info) + ? msg_params[strings::info].asCharArray() + : NULL; + + SendResponse(success, result, info, &msg_params); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request_to_mobile.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request_to_mobile.cc new file mode 100644 index 0000000000..0af1a5436b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request_to_mobile.cc @@ -0,0 +1,61 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/mobile/get_app_service_data_request_to_mobile.h" +#include "application_manager/application_impl.h" +#include "application_manager/rpc_service.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +GetAppServiceDataRequestToMobile::GetAppServiceDataRequestToMobile( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandRequestToMobile(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +GetAppServiceDataRequestToMobile::~GetAppServiceDataRequestToMobile() {} + +void GetAppServiceDataRequestToMobile::Run() { + LOG4CXX_AUTO_TRACE(logger_); + SendRequest(); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response.cc new file mode 100644 index 0000000000..32ad8e014d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response.cc @@ -0,0 +1,61 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/mobile/get_app_service_data_response.h" +#include "application_manager/application_impl.h" +#include "application_manager/rpc_service.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +GetAppServiceDataResponse::GetAppServiceDataResponse( + const application_manager::commands::MessageSharedPtr& message, + 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) {} + +GetAppServiceDataResponse::~GetAppServiceDataResponse() {} + +void GetAppServiceDataResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToMobile(message_); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response_from_mobile.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response_from_mobile.cc new file mode 100644 index 0000000000..90fca04eb2 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response_from_mobile.cc @@ -0,0 +1,66 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/mobile/get_app_service_data_response_from_mobile.h" +#include "application_manager/application_impl.h" +#include "application_manager/message_helper.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +GetAppServiceDataResponseFromMobile::GetAppServiceDataResponseFromMobile( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandResponseFromMobile(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +GetAppServiceDataResponseFromMobile::~GetAppServiceDataResponseFromMobile() {} + +void GetAppServiceDataResponseFromMobile::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + event_engine::MobileEvent event(mobile_apis::FunctionID::GetAppServiceDataID); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/on_app_service_data_notification.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/on_app_service_data_notification.cc new file mode 100644 index 0000000000..fd3891e0e8 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/on_app_service_data_notification.cc @@ -0,0 +1,119 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/mobile/on_app_service_data_notification.h" + +#include "app_service_rpc_plugin/app_service_app_extension.h" +#include "application_manager/app_service_manager.h" +#include "application_manager/application_impl.h" +#include "application_manager/helpers/application_helper.h" +#include "application_manager/message_helper.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" + +#include "smart_objects/enum_schema_item.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +OnAppServiceDataNotification::OnAppServiceDataNotification( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandNotificationImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +OnAppServiceDataNotification::~OnAppServiceDataNotification() {} + +void OnAppServiceDataNotification::Run() { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Sending OnAppServiceData to consumer"); + + std::string service_id = + (*message_)[strings::msg_params][strings::service_data] + [strings::service_id].asString(); + auto service = + application_manager_.GetAppServiceManager().FindServiceByID(service_id); + + if (!service) { + LOG4CXX_ERROR(logger_, "Service sending OnAppServiceData is not published"); + return; + } else if (!service->record[strings::service_manifest] + [strings::allow_app_consumers].asBool()) { + LOG4CXX_ERROR(logger_, + "Service does not allow for app consumers, skipping mobile " + "OnAppServiceData notification"); + return; + } + + std::string service_type = + (*message_)[strings::msg_params][strings::service_data] + [strings::service_type].asString(); + + auto subscribed_to_app_service_predicate = + [service_type](const ApplicationSharedPtr app) { + DCHECK_OR_RETURN(app, false); + auto& ext = AppServiceAppExtension::ExtractASExtension(*app); + LOG4CXX_DEBUG(logger_, "Check subscription for type: " << service_type); + return ext.IsSubscribedToAppService(service_type); + }; + + const std::vector<ApplicationSharedPtr>& applications = + application_manager::FindAllApps(application_manager_.applications(), + subscribed_to_app_service_predicate); + + std::vector<ApplicationSharedPtr>::const_iterator app_it = + applications.begin(); + + for (; applications.end() != app_it; ++app_it) { + const ApplicationSharedPtr app = *app_it; + if (!app) { + LOG4CXX_ERROR(logger_, "NULL pointer"); + continue; + } + LOG4CXX_DEBUG(logger_, + "Sending OnAppServiceDataNotification to mobile connection: " + << app->app_id()); + (*message_)[app_mngr::strings::params][app_mngr::strings::connection_key] = + app->app_id(); + SendNotification(); + } +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/on_app_service_data_notification_from_mobile.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/on_app_service_data_notification_from_mobile.cc new file mode 100644 index 0000000000..7bb62d298d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/on_app_service_data_notification_from_mobile.cc @@ -0,0 +1,84 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/mobile/on_app_service_data_notification_from_mobile.h" +#include "application_manager/application_impl.h" +#include "application_manager/message_helper.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +OnAppServiceDataNotificationFromMobile::OnAppServiceDataNotificationFromMobile( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandNotificationFromMobileImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +OnAppServiceDataNotificationFromMobile:: + ~OnAppServiceDataNotificationFromMobile() {} + +void OnAppServiceDataNotificationFromMobile::Run() { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Received an OnAppServiceData"); + MessageHelper::PrintSmartObject(*message_); + + std::string service_type = + (*message_)[strings::msg_params][strings::service_data] + [strings::service_type].asString(); + + ApplicationSharedPtr app = application_manager_.application(connection_key()); + + bool result = policy_handler_.CheckAppServiceParameters( + app->policy_app_id(), std::string(), service_type, NULL); + + if (!result) { + LOG4CXX_DEBUG(logger_, + "Incorrect service type received in " + "OnAppServiceDataNotificationFromMobile"); + return; + } + + SendNotificationToConsumers( + hmi_apis::FunctionID::eType::AppService_OnAppServiceData); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc new file mode 100644 index 0000000000..63b6e47d8e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc @@ -0,0 +1,188 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/mobile/perform_app_service_interaction_request.h" + +#include "application_manager/app_service_manager.h" +#include "application_manager/application_impl.h" +#include "application_manager/message_helper.h" +#include "interfaces/MOBILE_API.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +PerformAppServiceInteractionRequest::PerformAppServiceInteractionRequest( + const application_manager::commands::MessageSharedPtr& message, + 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) {} + +PerformAppServiceInteractionRequest::~PerformAppServiceInteractionRequest() {} + +void PerformAppServiceInteractionRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + auto app = application_manager_.application(connection_key()); + if (!app) { + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); + return; + } + + smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; + std::string service_id = msg_params[strings::service_id].asString(); + auto service = + application_manager_.GetAppServiceManager().FindServiceByID(service_id); + if (!service) { + SendResponse(false, + mobile_apis::Result::INVALID_ID, + "The requested service ID does not exist"); + return; + } + + if (!service->record[strings::service_manifest][strings::allow_app_consumers] + .asBool()) { + SendResponse( + false, + mobile_apis::Result::REJECTED, + "The requested service ID does not allow mobile app consumers"); + return; + } + + bool request_service_active = false; + if (msg_params.keyExists(strings::request_service_active)) { + request_service_active = + msg_params[strings::request_service_active].asBool(); + msg_params.erase(strings::request_service_active); + } + + // Only activate service if it is not already active + bool activate_service = request_service_active && + !service->record[strings::service_active].asBool(); + if (activate_service) { + if (app->IsFullscreen()) { + // App is in foreground, we can just activate the service + application_manager_.GetAppServiceManager().ActivateAppService( + service_id); + } else { + // App is not in foreground, we need to prompt the user to activate the + // service + smart_objects::SmartObject request_params; + request_params[strings::service_id] = service_id; + application_manager_.IncreaseForwardedRequestTimeout(connection_key(), + correlation_id()); + SendHMIRequest(hmi_apis::FunctionID::AppService_GetActiveServiceConsent, + &request_params, + true); + return; + } + } + + SendProviderRequest( + mobile_apis::FunctionID::PerformAppServiceInteractionID, + hmi_apis::FunctionID::AppService_PerformAppServiceInteraction, + &(*message_), + true); +} + +void PerformAppServiceInteractionRequest::on_event( + const event_engine::Event& event) { + LOG4CXX_DEBUG(logger_, "HMI PerformAppServiceInteraction on_event"); + const smart_objects::SmartObject& event_message = event.smart_object(); + + auto msg_params = event_message[strings::msg_params]; + + const char* info = msg_params.keyExists(strings::info) + ? msg_params[strings::info].asCharArray() + : NULL; + hmi_apis::Common_Result::eType hmi_result = + static_cast<hmi_apis::Common_Result::eType>( + event_message[strings::params][hmi_response::code].asInt()); + mobile_apis::Result::eType result = + MessageHelper::HMIToMobileResult(hmi_result); + bool success = PrepareResultForMobileResponse( + hmi_result, HmiInterfaces::HMI_INTERFACE_AppService); + + switch (event.id()) { + case hmi_apis::FunctionID::AppService_PerformAppServiceInteraction: + SendResponse(success, result, info, &msg_params); + break; + case hmi_apis::FunctionID::AppService_GetActiveServiceConsent: + if (msg_params[strings::activate].asBool()) { + // User agreed to activate service, we can now send the provider request + application_manager_.GetAppServiceManager().ActivateAppService( + (*message_)[strings::msg_params][strings::service_id].asString()); + SendProviderRequest( + mobile_apis::FunctionID::PerformAppServiceInteractionID, + hmi_apis::FunctionID::AppService_PerformAppServiceInteraction, + &(*message_), + true); + } else if (mobile_apis::Result::SUCCESS == result) { + // Request was successful, but user denied the request to activate the + // service + SendResponse(false, + mobile_apis::Result::USER_DISALLOWED, + "Request to activate service was denied by driver"); + } else { + SendResponse(success, result, info); + } + break; + default: + break; + } +} + +void PerformAppServiceInteractionRequest::on_event( + const event_engine::MobileEvent& event) { + LOG4CXX_DEBUG(logger_, "Mobile PerformAppServiceInteraction on_event"); + const smart_objects::SmartObject& event_message = event.smart_object(); + + auto msg_params = event_message[strings::msg_params]; + + const char* info = msg_params.keyExists(strings::info) + ? msg_params[strings::info].asCharArray() + : NULL; + mobile_apis::Result::eType result = static_cast<mobile_apis::Result::eType>( + msg_params[strings::result_code].asInt()); + bool success = IsMobileResultSuccess(result); + + SendResponse(success, result, info, &msg_params); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request_to_mobile.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request_to_mobile.cc new file mode 100644 index 0000000000..2a7b644cb3 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request_to_mobile.cc @@ -0,0 +1,62 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/mobile/perform_app_service_interaction_request_to_mobile.h" +#include "application_manager/application_impl.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +PerformAppServiceInteractionRequestToMobile:: + PerformAppServiceInteractionRequestToMobile( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandRequestToMobile(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +PerformAppServiceInteractionRequestToMobile:: + ~PerformAppServiceInteractionRequestToMobile() {} + +void PerformAppServiceInteractionRequestToMobile::Run() { + LOG4CXX_AUTO_TRACE(logger_); + SendRequest(); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_response.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_response.cc new file mode 100644 index 0000000000..5e84f42c34 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_response.cc @@ -0,0 +1,60 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/mobile/perform_app_service_interaction_response.h" +#include "application_manager/application_impl.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +PerformAppServiceInteractionResponse::PerformAppServiceInteractionResponse( + const application_manager::commands::MessageSharedPtr& message, + 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) {} + +PerformAppServiceInteractionResponse::~PerformAppServiceInteractionResponse() {} + +void PerformAppServiceInteractionResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToMobile(message_); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_response_from_mobile.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_response_from_mobile.cc new file mode 100644 index 0000000000..9912df84ce --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_response_from_mobile.cc @@ -0,0 +1,66 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/mobile/perform_app_service_interaction_response_from_mobile.h" +#include "application_manager/application_impl.h" +#include "interfaces/MOBILE_API.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +PerformAppServiceInteractionResponseFromMobile:: + PerformAppServiceInteractionResponseFromMobile( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandResponseFromMobile(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +PerformAppServiceInteractionResponseFromMobile:: + ~PerformAppServiceInteractionResponseFromMobile() {} + +void PerformAppServiceInteractionResponseFromMobile::Run() { + LOG4CXX_AUTO_TRACE(logger_); + event_engine::MobileEvent event( + mobile_apis::FunctionID::PerformAppServiceInteractionID); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc new file mode 100644 index 0000000000..bb0855d42f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc @@ -0,0 +1,126 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/mobile/publish_app_service_request.h" + +#include "application_manager/app_service_manager.h" +#include "application_manager/application_impl.h" +#include "application_manager/message_helper.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" +#include "sdl_rpc_plugin/extensions/system_capability_app_extension.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +PublishAppServiceRequest::PublishAppServiceRequest( + const application_manager::commands::MessageSharedPtr& message, + 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) {} + +PublishAppServiceRequest::~PublishAppServiceRequest() {} + +void PublishAppServiceRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Received a PublishAppService " << connection_key()); + MessageHelper::PrintSmartObject(*message_); + + smart_objects::SmartObject response_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + smart_objects::SmartObject manifest = + (*message_)[strings::msg_params][strings::app_service_manifest]; + + ApplicationSharedPtr app = application_manager_.application(connection_key()); + + std::string requested_service_name = ""; + + if ((*message_)[strings::msg_params][strings::app_service_manifest].keyExists( + strings::service_name)) { + requested_service_name = + (*message_)[strings::msg_params][strings::app_service_manifest] + [strings::service_name].asString(); + } + + std::string requested_service_type = + (*message_)[strings::msg_params][strings::app_service_manifest] + [strings::service_type].asString(); + + smart_objects::SmartArray* requested_handled_rpcs = NULL; + if ((*message_)[strings::msg_params][strings::app_service_manifest].keyExists( + strings::handled_rpcs)) { + requested_handled_rpcs = + (*message_)[strings::msg_params][strings::app_service_manifest] + [strings::handled_rpcs].asArray(); + } + + bool result = + policy_handler_.CheckAppServiceParameters(app->policy_app_id(), + requested_service_name, + requested_service_type, + requested_handled_rpcs); + + if (!result) { + SendResponse(false, + mobile_apis::Result::DISALLOWED, + "Service disallowed by policies", + NULL); + return; + } + + auto& ext = + sdl_rpc_plugin::SystemCapabilityAppExtension::ExtractExtension(*app); + ext.SubscribeTo(mobile_apis::SystemCapabilityType::APP_SERVICES); + + smart_objects::SmartObject service_record = + application_manager_.GetAppServiceManager().PublishAppService( + manifest, true, connection_key()); + if (app->IsFullscreen()) { + // Service should be activated if app is in the foreground + application_manager_.GetAppServiceManager().ActivateAppService( + service_record[strings::service_id].asString()); + } + + response_params[strings::app_service_record] = service_record; + + SendResponse(true, mobile_apis::Result::SUCCESS, NULL, &response_params); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_response.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_response.cc new file mode 100644 index 0000000000..d1bfc6e154 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_response.cc @@ -0,0 +1,62 @@ +/* + Copyright (c) 2019, Ford Motor Company, 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 the copyright holders nor the names of their + 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 "app_service_rpc_plugin/commands/mobile/publish_app_service_response.h" +#include "application_manager/application_impl.h" +#include "application_manager/message_helper.h" +#include "application_manager/rpc_service.h" + +namespace app_service_rpc_plugin { +using namespace application_manager; +namespace commands { + +PublishAppServiceResponse::PublishAppServiceResponse( + const application_manager::commands::MessageSharedPtr& message, + 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) {} + +PublishAppServiceResponse::~PublishAppServiceResponse() {} + +void PublishAppServiceResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToMobile(message_); +} + +} // namespace commands +} // namespace app_service_rpc_plugin |