diff options
Diffstat (limited to 'src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc')
-rw-r--r-- | src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc | 136 |
1 files changed, 131 insertions, 5 deletions
diff --git a/src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc b/src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc index 72abf233c..af55040ad 100644 --- a/src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc +++ b/src/components/application_manager/src/commands/hmi/sdl_activate_app_request.cc @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2013, Ford Motor Company * All rights reserved. * @@ -32,6 +32,7 @@ #include "application_manager/commands/hmi/sdl_activate_app_request.h" #include "application_manager/policies/policy_handler.h" +#include "application_manager/message_helper.h" namespace application_manager { @@ -45,10 +46,135 @@ SDLActivateAppRequest::~SDLActivateAppRequest() { } void SDLActivateAppRequest::Run() { - LOG4CXX_INFO(logger_, "SDLActivateAppRequest::Run"); - policy::PolicyHandler::instance()->OnActivateApp( - (*message_)[strings::msg_params][strings::app_id].asUInt(), - (*message_)[strings::params][strings::correlation_id].asInt()); + LOG4CXX_AUTO_TRACE(logger_); + using namespace hmi_apis::FunctionID; + using namespace hmi_apis::Common_Result; + + const uint32_t application_id = app_id(); + + ApplicationConstSharedPtr app = + ApplicationManagerImpl::instance()->application(application_id); + + if (!app) { + LOG4CXX_WARN(logger_, "Can't find application within regular apps: " + << application_id); + + app = ApplicationManagerImpl::instance()->waiting_app(application_id); + + if (!app) { + LOG4CXX_WARN(logger_, "Can't find application within waiting apps: " + << application_id); + return; + } + } + + if (!app->IsRegistered()) { + DevicesApps devices_apps = + FindAllAppOnParticularDevice(app->device()); + if (!devices_apps.first && devices_apps.second.empty()) { + LOG4CXX_ERROR(logger_, "Can't find regular foreground app with the same " + "connection id:" << app->device()); + SendResponse(correlation_id(), + SDL_ActivateApp, NO_APPS_REGISTERED); + return; + } + if (devices_apps.first) { + MessageHelper::SendLaunchApp(devices_apps.first->app_id(), + app->SchemaUrl(), + app->PackageName()); + } else { + std::vector<ApplicationSharedPtr>::const_iterator it = devices_apps.second.begin(); + for (; it != devices_apps.second.end(); ++it) { + MessageHelper::SendLaunchApp((*it)->app_id(), + app->SchemaUrl(), + app->PackageName()); + } + } + subscribe_on_event(BasicCommunication_OnAppRegistered); + } else { + policy::PolicyHandler::instance()->OnActivateApp(application_id, + correlation_id()); + } +} + +void SDLActivateAppRequest::onTimeOut() { + using namespace hmi_apis::FunctionID; + using namespace hmi_apis::Common_Result; + using namespace application_manager; + unsubscribe_from_event(BasicCommunication_OnAppRegistered); + SendResponse(correlation_id(), + SDL_ActivateApp, APPLICATION_NOT_REGISTERED); +} + +void SDLActivateAppRequest::on_event(const event_engine::Event& event) { + using namespace hmi_apis::FunctionID; + if (event.id() != BasicCommunication_OnAppRegistered) { + return; + } + unsubscribe_from_event(BasicCommunication_OnAppRegistered); + + // Have to use HMI app id from event, since HMI app id from original request + // message will be changed after app, initially requested for launch via + // SDL.ActivateApp, will be registered + const uint32_t hmi_application_id = hmi_app_id(event.smart_object()); + + ApplicationSharedPtr app = + application_manager::ApplicationManagerImpl::instance()-> + application_by_hmi_app(hmi_application_id); + if (!app) { + LOG4CXX_ERROR(logger_, "Application not found by HMI app id: " + << hmi_application_id); + return; + } + policy::PolicyHandler::instance()->OnActivateApp(app->app_id(), + correlation_id()); +} + +uint32_t SDLActivateAppRequest::app_id() const { + if ((*message_).keyExists(strings::msg_params)) { + if ((*message_)[strings::msg_params].keyExists(strings::app_id)){ + return (*message_)[strings::msg_params][strings::app_id].asUInt(); + } + } + LOG4CXX_DEBUG(logger_, "app_id section is absent in the message."); + return 0; +} + +uint32_t SDLActivateAppRequest::hmi_app_id( + const smart_objects::SmartObject& so) const { + if (so.keyExists(strings::params)) { + if (so[strings::msg_params].keyExists(strings::application)){ + if (so[strings::msg_params][strings::application]. + keyExists(strings::app_id)) { + return so[strings::msg_params][strings::application] + [strings::app_id].asUInt(); + } + } + } + LOG4CXX_DEBUG(logger_, "Can't find app_id section is absent in the message."); + return 0; +} + +DevicesApps +SDLActivateAppRequest::FindAllAppOnParticularDevice( + const connection_handler::DeviceHandle handle) { + DevicesApps apps; + + ApplicationManagerImpl::ApplicationListAccessor accessor; + ApplicationManagerImpl::ApplictionSet app_list = accessor.GetData(); + + ApplicationManagerImpl::ApplictionSetIt it = app_list.begin(); + ApplicationManagerImpl::ApplictionSetIt it_end = app_list.end(); + + for (;it != it_end; ++it) { + if (handle == (*it)->device()) { + if ((*it)->is_foreground()) { + apps.first = *it; + } + apps.second.push_back(*it); + } + } + return apps; } } // namespace commands |