Skip to content

Commit

Permalink
Feature/CloseApplication RPC.
Browse files Browse the repository at this point in the history
This PR provides a new RPC called CloseApplication, which can be used by an app
to send itself into HMI_NONE.

A registered application sends CloseApplicationRequest to SDL. SDL will
checks if specified application is registered and it is not in
HMI level NONE. After that, SDL will sends ActivateAppRequest to HMI with
HMI level parameter as NONE. When SDL will received ActivateAppResponse
from HMI, if result code will be as SUCCESS or WARNING, SDL will
sets application(which has sent this request) HMI level NONE and sends
OnHMIStatusNotification to Mobile with HMI level NONE. After that SDL will
sends CloseApplicationResponse to Mobile.
  • Loading branch information
IGapchuk committed Nov 16, 2018
1 parent d363167 commit da8a1b0
Show file tree
Hide file tree
Showing 6 changed files with 448 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
Copyright (c) 2018, Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the
distribution.
Neither the name of the Ford Motor Company nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CLOSE_APPLICATION_REQUEST_H_
#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CLOSE_APPLICATION_REQUEST_H_

#include <cstdint>

#include "application_manager/commands/command_request_impl.h"
#include "application_manager/event_engine/event_observer.h"
#include "utils/macro.h"

namespace sdl_rpc_plugin {
namespace app_mngr = application_manager;

namespace commands {

/**
* @brief CloseApplicationRequest command class
*/
class CloseApplicationRequest : public app_mngr::commands::CommandRequestImpl {
public:
/**
* @brief CloseApplicationRequest class constructor
*
* @param message Incoming SmartObject message
*/
CloseApplicationRequest(const app_mngr::commands::MessageSharedPtr& message,
app_mngr::ApplicationManager& application_manager,
app_mngr::rpc_service::RPCService& rpc_service,
app_mngr::HMICapabilities& hmi_capabilities,
policy::PolicyHandlerInterface& policy_handler);
/**
* @brief CloseApplicationRequest class destructor
*/
~CloseApplicationRequest() FINAL;

/**
* @brief Execute command
*/
virtual void Run() FINAL;

/**
* @brief Interface method that is called whenever new event received
*
* @param event The received event
*/
void on_event(const app_mngr::event_engine::Event& event) FINAL;

private:
DISALLOW_COPY_AND_ASSIGN(CloseApplicationRequest);

/**
* @brief Send Basic Communication Request to HMI.
*
* @param app - Application which have to set specified HMI level.
* @param hmi_level - New HMI level for specified application.
* @param send_policy_priority - Defines whether to send "priority" field
* with request
* @return - True if command is executed, otherwise return false.
*/
bool SendBCActivateApp(app_mngr::ApplicationConstSharedPtr app,
hmi_apis::Common_HMILevel::eType hmi_level,
bool send_policy_priority);

/**
* @brief Send OnHMIStatus notification to mobile.
* @param app - Application to with will send OnHMIStatus.
* @param app_manager - Referance to Application Manager instance.
*/
void SendHMIStatusNotification(app_mngr::ApplicationConstSharedPtr app,
app_mngr::ApplicationManager& app_manager);
};

} // namespace commands
} // namespace sdl_rpc_plugin

#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CLOSE_APPLICATION_REQUEST_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Copyright (c) 2018, Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the
distribution.
Neither the name of the Ford Motor Company nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CLOSE_APPLICATION_RESPONSE_H_
#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CLOSE_APPLICATION_RESPONSE_H_

#include "application_manager/commands/command_response_impl.h"
#include "utils/macro.h"

namespace sdl_rpc_plugin {
namespace app_mngr = application_manager;

namespace commands {

/**
* @brief CloseApplicationResponse command class
**/
class CloseApplicationResponse
: public app_mngr::commands::CommandResponseImpl {
public:
/**
* @brief CloseApplicationResponse class constructor
*
* @param message - Incoming SmartObject message
**/
CloseApplicationResponse(const app_mngr::commands::MessageSharedPtr& message,
app_mngr::ApplicationManager& application_manager,
app_mngr::rpc_service::RPCService& rpc_service,
app_mngr::HMICapabilities& hmi_capabilities,
policy::PolicyHandlerInterface& policy_handler);

/**
* @brief CloseApplicationResponse class destructor
**/
~CloseApplicationResponse() FINAL;

/**
* @brief Execute command
**/
void Run() FINAL;

private:
DISALLOW_COPY_AND_ASSIGN(CloseApplicationResponse);
};

} // namespace commands
} // namespace sdl_rpc_plugin

#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_CLOSE_APPLICATION_RESPONSE_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
Copyright (c) 2018, Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the
distribution.
Neither the name of the Ford Motor Company nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

#include "sdl_rpc_plugin/commands/mobile/close_application_request.h"
#include "application_manager/rpc_service.h"
#include "application_manager/message_helper.h"
#include "utils/include/utils/helpers.h"

namespace sdl_rpc_plugin {
using namespace application_manager;

namespace commands {

CloseApplicationRequest::CloseApplicationRequest(
const app_mngr::commands::MessageSharedPtr& message,
app_mngr::ApplicationManager& application_manager,
app_mngr::rpc_service::RPCService& rpc_service,
app_mngr::HMICapabilities& hmi_capabilities,
policy::PolicyHandlerInterface& policy_handler)
: CommandRequestImpl(message,
application_manager,
rpc_service,
hmi_capabilities,
policy_handler) {}

CloseApplicationRequest::~CloseApplicationRequest() {}

void CloseApplicationRequest::Run() {
LOG4CXX_AUTO_TRACE(logger_);

ApplicationSharedPtr application =
application_manager_.application(connection_key());

if (!application) {
LOG4CXX_ERROR(logger_, "Application is not registered");
SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED);
return;
}

const mobile_apis::HMILevel::eType app_hmi_level = application->hmi_level();

if (mobile_apis::HMILevel::HMI_NONE == app_hmi_level) {
LOG4CXX_DEBUG(logger_,
"Application with id " << connection_key()
<< " is already in hmi_level NONE.");
SendResponse(false, mobile_apis::Result::IGNORED);
}

const bool sent_success =
SendBCActivateApp(application, hmi_apis::Common_HMILevel::NONE, true);

if (sent_success) {
const uint32_t corr_id = static_cast<uint32_t>(
(*message_)[strings::params][strings::correlation_id].asUInt());
subscribe_on_event(hmi_apis::FunctionID::BasicCommunication_ActivateApp,
corr_id);
} else {
LOG4CXX_ERROR(logger_, "Unable to send BC.ActivateApp");
SendResponse(false, mobile_apis::Result::IGNORED);
}
}

void CloseApplicationRequest::on_event(const event_engine::Event& event) {
using namespace helpers;
LOG4CXX_AUTO_TRACE(logger_);
const smart_objects::SmartObject& message = event.smart_object();

if (hmi_apis::FunctionID::BasicCommunication_ActivateApp != event.id()) {
LOG4CXX_ERROR(logger_, "Received unknown event" << event.id());
return;
}

const auto hmi_result = static_cast<hmi_apis::Common_Result::eType>(
message[strings::params][hmi_response::code].asInt());

const auto mobile_result = MessageHelper::HMIToMobileResult(hmi_result);
const bool success = Compare<hmi_apis::Common_Result::eType, EQ, ONE>(
hmi_result,
hmi_apis::Common_Result::SUCCESS,
hmi_apis::Common_Result::WARNINGS);

if (success) {
auto application = application_manager_.application(connection_key());
application->set_hmi_level(mobile_apis::HMILevel::HMI_NONE);
SendHMIStatusNotification(application, application_manager_);
LOG4CXX_DEBUG(logger_,
"OnHMIStatusNotification did send to Mobile with HMI_level: "
<< application->hmi_level());
} else {
LOG4CXX_WARN(logger_, "OnHMIStatusNotification didn't send to Mobile.");
}
SendResponse(success, mobile_result);
}

bool CloseApplicationRequest::SendBCActivateApp(
ApplicationConstSharedPtr app,
hmi_apis::Common_HMILevel::eType hmi_level,
bool send_policy_priority) {
LOG4CXX_AUTO_TRACE(logger_);
smart_objects::SmartObjectSPtr bc_activate_app_request =
MessageHelper::GetBCActivateAppRequestToHMI(
app,
application_manager_.connection_handler().get_session_observer(),
application_manager_.GetPolicyHandler(),
hmi_level,
send_policy_priority,
application_manager_);
if (!bc_activate_app_request) {
LOG4CXX_ERROR(logger_, "Unable to create BC.ActivateAppRequest");
return false;
}

if (!application_manager_.GetRPCService().ManageHMICommand(
bc_activate_app_request)) {
LOG4CXX_ERROR(logger_, "Unable to send BC.ActivateAppRequest");
return false;
}
return true;
}

void CloseApplicationRequest::SendHMIStatusNotification(
ApplicationConstSharedPtr app, ApplicationManager& app_manager) {
using namespace application_manager;
LOG4CXX_AUTO_TRACE(logger_);

smart_objects::SmartObjectSPtr message = MessageHelper::CreateNotification(
mobile_apis::FunctionID::OnHMIStatusID, app->app_id());

(*message)[strings::msg_params][strings::hmi_level] =
static_cast<int32_t>(app->hmi_level());
(*message)[strings::msg_params][strings::audio_streaming_state] =
static_cast<int32_t>(app->audio_streaming_state());
(*message)[strings::msg_params][strings::system_context] =
static_cast<int32_t>(app->system_context());
application_manager_.GetRPCService().ManageMobileCommand(message,
Command::SOURCE_SDL);
}

} // namespace commands
} // namespace sdl_rpc_plugin
Loading

0 comments on commit da8a1b0

Please sign in to comment.