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/interior vehicle data resumption #2674

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ namespace smart_objects = ns_smart_device_link::ns_smart_objects;

namespace resumption {
struct ResumptionRequest;
struct ResumptionHandlingCallbacks;
using Subscriber = std::function<void(const int32_t, const ResumptionRequest)>;
using ConcludeResumptionCallback = std::function<void(const int32_t)>;
} // namespace resumption

namespace application_manager {
Expand Down Expand Up @@ -76,7 +78,7 @@ class AppExtension {
*/
virtual void ProcessResumption(
const smart_objects::SmartObject& resumption_data,
resumption::Subscriber subscriber) = 0;
resumption::ResumptionHandlingCallbacks) = 0;

/**
* @brief RevertResumption Method called by SDL during revert resumption.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ class ApplicationManagerImpl
*/
void UnregisterAllApplications();

DEPRECATED bool RemoveAppDataFromHMI(ApplicationSharedPtr app);
bool RemoveAppDataFromHMI(ApplicationSharedPtr app);

DEPRECATED bool LoadAppDataToHMI(ApplicationSharedPtr app);
bool LoadAppDataToHMI(ApplicationSharedPtr app);
bool ActivateApplication(ApplicationSharedPtr app) OVERRIDE;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace resumption {

struct ResumptionHandlingCallbacks;

namespace app_mngr = application_manager;

class ExtensionPendingResumptionHandler
Expand All @@ -22,8 +24,8 @@ class ExtensionPendingResumptionHandler

virtual void HandleResumptionSubscriptionRequest(
app_mngr::AppExtension& extension,
Subscriber& subscriber,
application_manager::Application& app) = 0;
app_mngr::Application& app,
ResumptionHandlingCallbacks callbacks) = 0;

virtual void ClearPendingResumptionRequests() = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ struct ApplicationResumptionStatus {
std::vector<ResumptionRequest> successful_requests;
std::vector<std::string> unsuccesfull_vehicle_data_subscriptions_;
std::vector<std::string> succesfull_vehicle_data_subscriptions_;
std::vector<std::string> successful_ivd_subscriptions_;
};

struct ResumptionHandlingCallbacks {
using Subscriber =
std::function<void(const int32_t, const ResumptionRequest)>;
using ConcludeResumptionCallback = std::function<void(const int32_t)>;
Subscriber subscriber_;
ConcludeResumptionCallback conclude_resumption_callback_;
};

/**
Expand Down Expand Up @@ -326,6 +335,11 @@ class ResumptionDataProcessor : public app_mngr::event_engine::EventObserver {
bool HasSubscriptionsToRestore(
const smart_objects::SmartObject& saved_app) const;

void ConcludeResumption(const uint32_t app_id,
const ApplicationResumptionStatus& status);

ResumptionHandlingCallbacks GetResumptionHandlingCallbacks();

/**
* @brief A map of the IDs and Application Resumption Status for these ID
**/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@
#include <memory>
#include "utils/macro.h"
#include "application_manager/app_extension.h"
#include "application_manager/application.h"

namespace rc_rpc_plugin {
class RCRPCPlugin;

class RCAppExtension : public application_manager::AppExtension {
public:
explicit RCAppExtension(application_manager::AppExtensionUID uid);
RCAppExtension(application_manager::AppExtensionUID uid,
RCRPCPlugin* plugin,
application_manager::Application& app);
~RCAppExtension();

/**
Expand Down Expand Up @@ -73,10 +78,12 @@ class RCAppExtension : public application_manager::AppExtension {
* @brief get list of subscriptions of application
* @return list of subscriptions of application
*/
std::set<std::string> InteriorVehicleDataSubscriptions() const;
std::set<std::string> Subscriptions() const;

private:
std::set<std::string> subscribed_interior_vehicle_data_;
RCRPCPlugin* plugin_;
application_manager::Application& app_;

// AppExtension interface
public:
Expand All @@ -89,10 +96,11 @@ class RCAppExtension : public application_manager::AppExtension {
/**
* @brief Running resumption data process.
* @param saved_app saved data for resumption
* @param subscriber callback for subscription
* @param callbacks callback for handling resumption
**/
void ProcessResumption(const smart_objects::SmartObject& saved_app,
resumption::Subscriber subscriber) OVERRIDE;
void ProcessResumption(
const smart_objects::SmartObject& saved_app,
resumption::ResumptionHandlingCallbacks callbacks) OVERRIDE;

/**
* @brief Revert the data to the state before Resumption.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
namespace rc_rpc_plugin {
class RCRPCPlugin;

enum class RCModuleTypeIDs {
CLIMATE = 0,
RADIO,
SEAT,
AUDIO,
LIGHT,
HMI_SETTINGS
};

/**
* @brief The RCHelpers class contains frequently used static data
* structures related strictly to RC
Expand All @@ -64,6 +73,9 @@ class RCHelpers {
static const std::function<std::string(const std::string& module_type)>
GetModuleTypeToCapabilitiesMapping();

static const std::function<std::string(const RCModuleTypeIDs module_type)>
GetModuleTypeToEnumMapping();

/**
* @brief GetModulesList get list of all known modules
* @return vector contains all known modules
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_PENDING_RESUMPTION_HANDLER_H
#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_PENDING_RESUMPTION_HANDLER_H

#include "application_manager/resumption/extension_pending_resumption_handler.h"
#include "application_manager/resumption/resumption_data_processor.h"
#include "rc_rpc_plugin.h"

namespace rc_rpc_plugin {

namespace app_mngr = application_manager;

using InteriorDataCacheSptr = std::shared_ptr<InteriorDataCache>;

class RCPendingResumptionHandler
: public resumption::ExtensionPendingResumptionHandler {
public:
RCPendingResumptionHandler(app_mngr::ApplicationManager& application_manager,
InteriorDataCacheSptr interior_data_cache);

~RCPendingResumptionHandler() {}

void on_event(const app_mngr::event_engine::Event& event) OVERRIDE;

void HandleResumptionSubscriptionRequest(
app_mngr::AppExtension& extension,
app_mngr::Application& app,
resumption::ResumptionHandlingCallbacks callbacks) OVERRIDE;

void ClearPendingResumptionRequests() OVERRIDE;

private:
struct ResumptionAwaitingHandling {
app_mngr::AppExtension& extension;
const uint32_t application_id;
resumption::ResumptionHandlingCallbacks callbacks;
std::map<std::string, bool> handled_subscriptions;

ResumptionAwaitingHandling(const uint32_t app_id,
app_mngr::AppExtension& ext,
resumption::ResumptionHandlingCallbacks cb);
};

smart_objects::SmartObjectList CreateSubscriptionRequests(
const std::set<std::string> subscriptions, const uint32_t application_id);

void ProcessSubscriptionRequests(
const smart_objects::SmartObjectList& subscription_requests,
const ResumptionAwaitingHandling& resumption);

std::set<std::string> GetFrozenResumptionUnhandledSubscriptions(
const ResumptionAwaitingHandling& frozen_resumption);

bool NeedsToConcludeResumption(
const ResumptionAwaitingHandling& resumption_awaiting_handling) const;

std::shared_ptr<InteriorDataCache> interior_data_cache_;
std::map<uint32_t, smart_objects::SmartObject> pending_subscription_requests_;
std::deque<ResumptionAwaitingHandling> frozen_resumptions_;
};

} // namespace rc_rpc_plugin

#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_PENDING_RESUMPTION_HANDLER_H
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@
#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_RC_RPC_PLUGIN_H_

#include <memory>
#include <string>
#include <vector>

#include "application_manager/plugin_manager/rpc_plugin.h"
#include "application_manager/command_factory.h"
#include "rc_rpc_plugin/resource_allocation_manager.h"
#include "rc_rpc_plugin/interior_data_cache.h"
#include "rc_rpc_plugin/interior_data_manager.h"
#include "application_manager/resumption/extension_pending_resumption_handler.h"

namespace rc_rpc_plugin {
namespace plugins = application_manager::plugin_manager;
Expand Down Expand Up @@ -92,19 +95,52 @@ class RCRPCPlugin : public plugins::RPCPlugin {
void OnApplicationEvent(plugins::ApplicationEvent event,
app_mngr::ApplicationSharedPtr application) OVERRIDE;

/**
* @brief ProcessResumptionSubscription send Subscribe interior vehicle data
* requests to HMI
* @param app application for subscription
* @param ext application extension
* @param subscriber callback for subscription
*/
void ProcessResumptionSubscription(
app_mngr::Application& app,
RCAppExtension& ext,
resumption::ResumptionHandlingCallbacks callbacks);

/**
* @brief Revert the data to the state before Resumption.
* @param app application for which revert sould be performed
* @param list_of_subscriptions Subscriptions to be returned
**/
void RevertResumption(application_manager::Application& app,
const std::set<std::string>& list_of_subscriptions);

static const uint32_t kRCPluginID = 153;

typedef std::vector<application_manager::ApplicationSharedPtr> Apps;
static Apps GetRCApplications(
application_manager::ApplicationManager& app_mngr);

bool IsSubscribedAppExist(const std::string& subscription);

smart_objects::SmartObjectSPtr CreateUnsubscriptionRequest(
const std::string& module_type);

private:
void DeleteSubscriptions(app_mngr::ApplicationSharedPtr app);

RCAppExtension& ExtractInteriorVehicleDataExtension(
application_manager::Application& app);

application_manager::rpc_service::RPCService* rpc_service_;
application_manager::ApplicationManager* app_mngr_;
std::unique_ptr<application_manager::CommandFactory> command_factory_;
std::unique_ptr<ResourceAllocationManager> resource_allocation_manager_;
std::unique_ptr<InteriorDataCache> interior_data_cache_;
std::shared_ptr<InteriorDataCache> interior_data_cache_;
std::unique_ptr<InteriorDataManager> interior_data_manager_;
using ExtensionPendingResumptionHandlerSPtr =
std::shared_ptr<resumption::ExtensionPendingResumptionHandler>;
ExtensionPendingResumptionHandlerSPtr pending_resumption_handler_;
};
} // namespace rc_rpc_plugin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "rc_rpc_plugin/rc_helpers.h"
#include "rc_rpc_plugin/rc_rpc_plugin.h"
#include "smart_objects/enum_schema_item.h"
#include "application_manager/message_helper.h"
#include "utils/macro.h"
#include "interfaces/MOBILE_API.h"

Expand Down Expand Up @@ -134,17 +135,31 @@ void GetInteriorVehicleDataRequest::ProcessResponseToMobileFromCache(
response_msg_params[message_params::kIsSubscribed] =
request_msg_params[message_params::kSubscribe].asBool();
if (request_msg_params[message_params::kSubscribe].asBool()) {
auto extension = RCHelpers::GetRCExtension(*app);
const auto extension = RCHelpers::GetRCExtension(*app);
DCHECK(extension);
const bool is_app_already_subscribed =
extension->IsSubscibedToInteriorVehicleData(ModuleType());
if (is_app_already_subscribed) {
LOG4CXX_WARN(logger_, "Application is already subscribed");
SendResponse(
true, mobile_apis::Result::WARNINGS, nullptr, &response_msg_params);
return;
}

extension->SubscribeToInteriorVehicleData(ModuleType());
app->UpdateHash();
}
}
LOG4CXX_DEBUG(logger_, "sending response to mobile");
SendResponse(
true, mobile_apis::Result::SUCCESS, nullptr, &response_msg_params);
if (AppShouldBeUnsubscribed()) {
auto extension = RCHelpers::GetRCExtension(*app);
DCHECK(extension);
extension->UnsubscribeFromInteriorVehicleData(ModuleType());
if (extension->IsSubscibedToInteriorVehicleData(ModuleType())) {
extension->UnsubscribeFromInteriorVehicleData(ModuleType());
app->UpdateHash();
}
}
}

Expand Down Expand Up @@ -196,7 +211,6 @@ void GetInteriorVehicleDataRequest::Execute() {
is_subscribed =
(*message_)[app_mngr::strings::msg_params][message_params::kSubscribe]
.asBool();
RemoveExcessiveSubscription();
}
if (!CheckRateLimits()) {
LOG4CXX_WARN(logger_, "GetInteriorVehicleData frequency is too high.");
Expand Down Expand Up @@ -246,6 +260,8 @@ void GetInteriorVehicleDataRequest::on_event(

DCHECK_OR_RETURN_VOID(app);
if (TheLastAppShouldBeUnsubscribed(app)) {
LOG4CXX_DEBUG(logger_,
"removing module type " << ModuleType() << "from cache");
interior_data_cache_.Remove(ModuleType());
}
ProccessSubscription(hmi_response);
Expand Down Expand Up @@ -351,11 +367,13 @@ void GetInteriorVehicleDataRequest::ProccessSubscription(
"SubscribeToInteriorVehicleData " << app->app_id() << " "
<< module_type);
extension->SubscribeToInteriorVehicleData(module_type);
app->UpdateHash();
} else {
LOG4CXX_DEBUG(logger_,
"UnsubscribeFromInteriorVehicleData "
<< app->app_id() << " " << module_type);
extension->UnsubscribeFromInteriorVehicleData(module_type);
app->UpdateHash();
}
}
}
Expand All @@ -377,6 +395,8 @@ bool GetInteriorVehicleDataRequest::HasRequestExcessiveSubscription() {
(*message_)[app_mngr::strings::msg_params][message_params::kSubscribe]
.asBool();
if (!app_wants_to_subscribe && !is_app_already_subscribed) {
LOG4CXX_DEBUG(logger_,
"(!app_wants_to_subscribe && !is_app_already_subscribed)");
return true;
}
return app_wants_to_subscribe && is_app_already_subscribed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void InteriorDataManagerImpl::UpdateHMISubscriptionsOnAppUnregistered(
application_manager::Application& app) {
LOG4CXX_AUTO_TRACE(logger_);
auto rc_extension = RCHelpers::GetRCExtension(app);
auto subscribed_data = rc_extension->InteriorVehicleDataSubscriptions();
auto subscribed_data = rc_extension->Subscriptions();
rc_extension->UnsubscribeFromInteriorVehicleData();
for (auto& data : subscribed_data) {
auto apps_subscribed =
Expand Down Expand Up @@ -147,7 +147,7 @@ InteriorDataManagerImpl::AppsSubscribedModules() {
InteriorDataManagerImpl::AppsModules result;
for (auto& app_ptr : apps_list) {
const auto rc_extension = RCHelpers::GetRCExtension(*app_ptr);
auto app_subscriptions = rc_extension->InteriorVehicleDataSubscriptions();
auto app_subscriptions = rc_extension->Subscriptions();
result[app_ptr] = std::vector<std::string>(app_subscriptions.size());
std::copy(app_subscriptions.begin(),
app_subscriptions.end(),
Expand Down
Loading