summaryrefslogtreecommitdiff
path: root/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc')
-rw-r--r--src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc143
1 files changed, 100 insertions, 43 deletions
diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc
index 1c553fb84d..718814b201 100644
--- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc
+++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc
@@ -33,20 +33,23 @@
#include "vehicle_info_plugin/vehicle_info_plugin.h"
#include "application_manager/message_helper.h"
#include "application_manager/plugin_manager/plugin_keys.h"
+#include "application_manager/resumption/resumption_data_processor.h"
#include "application_manager/rpc_handler.h"
#include "application_manager/smart_object_keys.h"
#include "vehicle_info_plugin/custom_vehicle_data_manager_impl.h"
#include "vehicle_info_plugin/vehicle_info_app_extension.h"
#include "vehicle_info_plugin/vehicle_info_command_factory.h"
+#include "vehicle_info_plugin/vehicle_info_pending_resumption_handler.h"
namespace vehicle_info_plugin {
-CREATE_LOGGERPTR_GLOBAL(logger_, "VehicleInfoPlugin")
+SDL_CREATE_LOG_VARIABLE("VehicleInfoPlugin")
namespace strings = application_manager::strings;
namespace plugins = application_manager::plugin_manager;
namespace commands = application_manager::commands;
-VehicleInfoPlugin::VehicleInfoPlugin() : application_manager_(nullptr) {}
+VehicleInfoPlugin::VehicleInfoPlugin()
+ : application_manager_(nullptr), pending_resumption_handler_(nullptr) {}
bool VehicleInfoPlugin::Init(
application_manager::ApplicationManager& app_manager,
@@ -58,6 +61,9 @@ bool VehicleInfoPlugin::Init(
application_manager_ = &app_manager;
custom_vehicle_data_manager_.reset(
new CustomVehicleDataManagerImpl(policy_handler, rpc_service));
+ pending_resumption_handler_ =
+ std::make_shared<VehicleInfoPendingResumptionHandler>(
+ app_manager, *custom_vehicle_data_manager_);
command_factory_.reset(new vehicle_info_plugin::VehicleInfoCommandFactory(
app_manager,
rpc_service,
@@ -107,6 +113,7 @@ void VehicleInfoPlugin::OnPolicyEvent(plugins::PolicyEvent event) {
void VehicleInfoPlugin::OnApplicationEvent(
plugins::ApplicationEvent event,
app_mngr::ApplicationSharedPtr application) {
+ SDL_LOG_AUTO_TRACE();
if (plugins::ApplicationEvent::kApplicationRegistered == event) {
application->AddExtension(
std::make_shared<VehicleInfoAppExtension>(*this, *application));
@@ -117,7 +124,7 @@ void VehicleInfoPlugin::OnApplicationEvent(
}
void VehicleInfoPlugin::UnsubscribeFromRemovedVDItems() {
- LOG4CXX_AUTO_TRACE(logger_);
+ SDL_LOG_AUTO_TRACE();
typedef std::vector<std::string> StringsVector;
auto get_items_to_unsubscribe = [this]() -> StringsVector {
@@ -125,16 +132,15 @@ void VehicleInfoPlugin::UnsubscribeFromRemovedVDItems() {
auto applications = application_manager_->applications();
for (auto& app : applications.GetData()) {
auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app);
- auto subscription_names = ext.Subscriptions();
+ auto subscription_names = ext.Subscriptions().GetData();
for (auto& subscription_name : subscription_names) {
if (custom_vehicle_data_manager_->IsRemovedCustomVehicleDataName(
subscription_name)) {
ext.unsubscribeFromVehicleInfo(subscription_name);
if (!helpers::in_range(output_items_list, subscription_name)) {
- LOG4CXX_DEBUG(logger_,
- "Vehicle data item "
- << subscription_name
- << " has been removed by policy");
+ SDL_LOG_DEBUG("Vehicle data item "
+ << subscription_name
+ << " has been removed by policy");
output_items_list.push_back(subscription_name);
}
}
@@ -146,7 +152,7 @@ void VehicleInfoPlugin::UnsubscribeFromRemovedVDItems() {
const StringsVector items_to_unsubscribe = get_items_to_unsubscribe();
if (items_to_unsubscribe.empty()) {
- LOG4CXX_DEBUG(logger_, "There is no data to unsubscribe");
+ SDL_LOG_DEBUG("There is no data to unsubscribe");
return;
}
@@ -154,50 +160,101 @@ void VehicleInfoPlugin::UnsubscribeFromRemovedVDItems() {
application_manager_->GetRPCService().ManageHMICommand(message);
}
-bool IsOtherAppAlreadySubscribedFor(
- const std::string& ivi_name,
- const application_manager::ApplicationManager& app_mngr,
- const uint32_t current_app_id) {
- auto applications = app_mngr.applications();
+void VehicleInfoPlugin::ProcessResumptionSubscription(
+ application_manager::Application& app, VehicleInfoAppExtension& ext) {
+ SDL_LOG_AUTO_TRACE();
- for (auto& app : applications.GetData()) {
- auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app);
- if (ext.isSubscribedToVehicleInfo(ivi_name) &&
- (app->app_id() != current_app_id)) {
- return true;
+ auto pending = ext.PendingSubscriptions().GetData();
+ for (const auto& ivi : pending) {
+ if (IsSubscribedAppExist(ivi)) {
+ ext.RemovePendingSubscription(ivi);
+ ext.subscribeToVehicleInfo(ivi);
}
}
- return false;
+ pending_resumption_handler_->HandleResumptionSubscriptionRequest(ext, app);
}
-void VehicleInfoPlugin::ProcessResumptionSubscription(
- application_manager::Application& app, VehicleInfoAppExtension& ext) {
- LOG4CXX_AUTO_TRACE(logger_);
- smart_objects::SmartObject msg_params =
- smart_objects::SmartObject(smart_objects::SmartType_Map);
+void VehicleInfoPlugin::RevertResumption(
+ application_manager::Application& app,
+ const std::set<std::string>& list_of_subscriptions) {
+ SDL_LOG_AUTO_TRACE();
+ UNUSED(app);
- const auto& subscriptions = ext.Subscriptions();
+ pending_resumption_handler_->OnResumptionRevert();
- if (subscriptions.empty()) {
- LOG4CXX_DEBUG(logger_, "No vehicle data to subscribe. Exiting");
+ std::set<std::string> subscriptions_to_revert;
+ for (auto& ivi_data : list_of_subscriptions) {
+ if (!IsSubscribedAppExist(ivi_data) &&
+ !IsAnyPendingSubscriptionExist(ivi_data)) {
+ subscriptions_to_revert.insert(ivi_data);
+ }
+ }
+
+ if (subscriptions_to_revert.empty()) {
+ SDL_LOG_DEBUG("No data to unsubscribe");
return;
}
+ const auto request = CreateUnsubscriptionRequest(subscriptions_to_revert);
+ application_manager_->GetRPCService().ManageHMICommand(request);
+}
- for (auto& ivi : subscriptions) {
- if (!IsOtherAppAlreadySubscribedFor(
- ivi, *application_manager_, app.app_id())) {
- msg_params[ivi] = true;
+smart_objects::SmartObjectSPtr VehicleInfoPlugin::CreateSubscriptionRequest(
+ const std::set<std::string>& list_of_subscriptions) {
+ SDL_LOG_AUTO_TRACE();
+ auto msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map);
+ for (auto& ivi_data : list_of_subscriptions) {
+ msg_params[ivi_data] = true;
+ }
+
+ auto request = application_manager::MessageHelper::CreateModuleInfoSO(
+ hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData,
+ *application_manager_);
+ (*request)[strings::msg_params] = msg_params;
+ return request;
+}
+
+smart_objects::SmartObjectSPtr VehicleInfoPlugin::CreateUnsubscriptionRequest(
+ const std::set<std::string>& list_of_subscriptions) {
+ SDL_LOG_AUTO_TRACE();
+ auto msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map);
+
+ for (auto& ivi_data : list_of_subscriptions) {
+ msg_params[ivi_data] = true;
+ }
+
+ auto request = application_manager::MessageHelper::CreateModuleInfoSO(
+ hmi_apis::FunctionID::VehicleInfo_UnsubscribeVehicleData,
+ *application_manager_);
+ (*request)[strings::msg_params] = msg_params;
+
+ return request;
+}
+
+bool VehicleInfoPlugin::IsSubscribedAppExist(const std::string& ivi) {
+ SDL_LOG_AUTO_TRACE();
+ auto apps_accessor = application_manager_->applications();
+
+ for (auto& app : apps_accessor.GetData()) {
+ auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app);
+ if (ext.isSubscribedToVehicleInfo(ivi)) {
+ return true;
}
}
+ return false;
+}
- if (!msg_params.empty()) {
- auto request = application_manager::MessageHelper::CreateModuleInfoSO(
- hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData,
- *application_manager_);
- msg_params[strings::app_id] = app.app_id();
- (*request)[strings::msg_params] = msg_params;
- application_manager_->GetRPCService().ManageHMICommand(request);
+bool VehicleInfoPlugin::IsAnyPendingSubscriptionExist(const std::string& ivi) {
+ SDL_LOG_AUTO_TRACE();
+ auto apps_accessor = application_manager_->applications();
+
+ for (auto& app : apps_accessor.GetData()) {
+ auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app);
+ if (ext.isPendingSubscriptionToVehicleInfo(ivi)) {
+ return true;
+ }
}
+
+ return false;
}
application_manager::ApplicationSharedPtr FindAppSubscribedToIVI(
@@ -216,7 +273,7 @@ application_manager::ApplicationSharedPtr FindAppSubscribedToIVI(
smart_objects::SmartObjectSPtr VehicleInfoPlugin::GetUnsubscribeIVIRequest(
const std::vector<std::string>& ivi_names) {
- LOG4CXX_AUTO_TRACE(logger_);
+ SDL_LOG_AUTO_TRACE();
using namespace smart_objects;
auto msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map);
@@ -264,7 +321,7 @@ smart_objects::SmartObjectSPtr VehicleInfoPlugin::GetUnsubscribeIVIRequest(
void VehicleInfoPlugin::DeleteSubscriptions(
application_manager::ApplicationSharedPtr app) {
auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app);
- auto subscriptions = ext.Subscriptions();
+ auto subscriptions = ext.Subscriptions().GetData();
std::vector<std::string> ivi_to_unsubscribe;
for (auto& ivi : subscriptions) {
ext.unsubscribeFromVehicleInfo(ivi);
@@ -284,12 +341,12 @@ void VehicleInfoPlugin::DeleteSubscriptions(
extern "C" __attribute__((visibility("default")))
application_manager::plugin_manager::RPCPlugin*
-Create() {
+Create(logger::Logger* logger_instance) {
+ logger::Logger::instance(logger_instance);
return new vehicle_info_plugin::VehicleInfoPlugin();
}
extern "C" __attribute__((visibility("default"))) void Delete(
application_manager::plugin_manager::RPCPlugin* data) {
delete data;
- DELETE_THREAD_LOGGER(vehicle_info_plugin::logger_);
}