Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/close application rpc #5

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/appMain/sdl_preloaded_pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
"LIMITED",
"NONE"]
},
"CloseApplication": {
"hmi_levels": ["BACKGROUND",
"FULL",
"LIMITED",
"NONE"]
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IGapchuk It seems to me, that FULL HMI level is the only option to be used for CloseApplication RPC

"CreateInteractionChoiceSet": {
"hmi_levels": ["BACKGROUND",
"FULL",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IGapchuk please consider using the same style of copyright for all the files.

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
* @param application_manager - reference to ApplicationManager instance.
* @param rpc_service - reference to RPCService instance.
* @param hmi_capabilities - reference to HMICapabilities instance.
* @param policy_handler - reference to PolicyHandlerInterface instance.
*/
CloseApplicationRequest(const app_mngr::commands::MessageSharedPtr& message,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IGapchuk please update description as your ctor contains more parameters than described

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
*/
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:
/**
* @brief Sends ActivateApp 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
* @param activate_app_corr_id - Variable for detting ActivateAppRequest
* correlation id.
* @return - True if command is executed, otherwise return false.
*/
bool SendBCActivateApp(app_mngr::ApplicationConstSharedPtr app,
const hmi_apis::Common_HMILevel::eType hmi_level,
const bool send_policy_priority);

DISALLOW_COPY_AND_ASSIGN(CloseApplicationRequest);
};

} // 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,83 @@
/*

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
* @param application_manager - reference to ApplicationManager instance.
* @param rpc_service - reference to RPCService instance.
* @param hmi_capabilities - reference to HMICapabilities instance.
* @param policy_handler - reference to PolicyHandlerInterface instance.
**/
CloseApplicationResponse(const app_mngr::commands::MessageSharedPtr& message,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IGapchuk update description

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,155 @@
/*

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IGapchuk using should be used only in function body.


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_);

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

if (!application) {
LOG4CXX_ERROR(logger_, "No such application registered.");
SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED);
return;
}

const auto 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);
return;
}

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

if (!sending_result) {
LOG4CXX_ERROR(logger_, "Unable to send BC.ActivateApp");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IGapchuk seems to be a redundant message

SendResponse(false, mobile_apis::Result::INVALID_DATA);
}
}

void CloseApplicationRequest::on_event(const event_engine::Event& event) {
using namespace helpers;
LOG4CXX_AUTO_TRACE(logger_);

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

const auto message = event.smart_object();
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());
if (!application) {
LOG4CXX_DEBUG(logger_, "No such application registered");
SendResponse(false, mobile_apis::Result::INVALID_DATA);
return;
}
application->set_hmi_level(mobile_apis::HMILevel::HMI_NONE);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IGapchuk I think you must do this via state controller otherwise you will get an inconsistent state of application against state controller. For example check how it works for ApplicationManagerImpl::ActivateApplication. You definitely should have something similar for your case

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AKalinich-Luxoft Inside ApplicationImpl::set_hmi_level calls SetRegularState method from state controller and sets the specified hmi_state.

LOG4CXX_DEBUG(logger_,
"Application with id " << application->app_id()
<< " has switched to HMI_level NONE.");
} else {
LOG4CXX_WARN(logger_, "Application hasn't switched to HMI_level NONE.");
}
SendResponse(success, mobile_result);
}

bool CloseApplicationRequest::SendBCActivateApp(
ApplicationConstSharedPtr app,
const hmi_apis::Common_HMILevel::eType hmi_level,
const bool send_policy_priority) {
LOG4CXX_AUTO_TRACE(logger_);
auto 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;
}
const auto activate_app_corr_id =
(*bc_activate_app_request)[strings::params][strings::correlation_id]
.asUInt();
subscribe_on_event(hmi_apis::FunctionID::BasicCommunication_ActivateApp,
activate_app_corr_id);
return true;
}

} // namespace commands
} // namespace sdl_rpc_plugin
Loading