summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander <akutsan@luxoft.com>2018-06-15 15:36:54 +0300
committerIra Lytvynenko (GitHub) <ILytvynenko@luxoft.com>2018-06-27 18:20:30 +0300
commit79a86d7668d2f4dde28a40ec81014116dc7fa809 (patch)
treed40bc32bbf15b5045babe262f784c8381e7a71ee
parent41aff44d8f250ce3e97de40fd6920dcf606ed263 (diff)
downloadsdl_core-79a86d7668d2f4dde28a40ec81014116dc7fa809.tar.gz
Add resumption processing in VehicleInfoAppExtension
-rw-r--r--src/components/application_manager/include/application_manager/app_extension.h23
-rw-r--r--src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_app_extension.h7
-rw-r--r--src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc6
-rw-r--r--src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h21
-rw-r--r--src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h11
-rw-r--r--src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc28
-rw-r--r--src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc96
-rw-r--r--src/components/application_manager/src/resumption/resume_ctrl_impl.cc13
8 files changed, 188 insertions, 17 deletions
diff --git a/src/components/application_manager/include/application_manager/app_extension.h b/src/components/application_manager/include/application_manager/app_extension.h
index 221601a307..ee7eca190c 100644
--- a/src/components/application_manager/include/application_manager/app_extension.h
+++ b/src/components/application_manager/include/application_manager/app_extension.h
@@ -35,6 +35,12 @@
#include "utils/shared_ptr.h"
+namespace NsSmartDeviceLink {
+namespace NsSmartObjects {
+class SmartObject;
+}
+}
+
namespace application_manager {
typedef int AppExtensionUID;
@@ -47,6 +53,23 @@ class AppExtension {
return kUid_;
}
+ /**
+ * @brief SaveResumptionData method called by SDL when it saves resumption
+ * data.
+ * @param resumption_data data reference to data, that will be appended by
+ * plugin
+ */
+ virtual void SaveResumptionData(
+ NsSmartDeviceLink::NsSmartObjects::SmartObject& resumption_data) = 0;
+
+ /**
+ * @brief ProcessResumption Method called by SDL during resumption.
+ * @param resumption_data list of resumption data
+ */
+ virtual void ProcessResumption(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject&
+ resumption_data) = 0;
+
private:
const AppExtensionUID kUid_;
};
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_app_extension.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_app_extension.h
index 76381ac8c3..05994492c2 100644
--- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_app_extension.h
+++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_app_extension.h
@@ -69,6 +69,13 @@ class RCAppExtension : public application_manager::AppExtension {
private:
std::set<std::string> subscribed_interior_vehicle_data_;
+
+ // AppExtension interface
+ public:
+ void SaveResumptionData(
+ NsSmartDeviceLink::NsSmartObjects::SmartObject& resumption_data) OVERRIDE;
+ void ProcessResumption(const NsSmartDeviceLink::NsSmartObjects::SmartObject&
+ resumption_data) OVERRIDE;
};
typedef utils::SharedPtr<RCAppExtension> RCAppExtensionPtr;
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc
index 3dc6d044e1..5c0a94cccc 100644
--- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc
+++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc
@@ -58,5 +58,11 @@ bool RCAppExtension::IsSubscibedToInteriorVehicleData(
return (it != subscribed_interior_vehicle_data_.end());
}
+void RCAppExtension::SaveResumptionData(
+ NsSmartDeviceLink::NsSmartObjects::SmartObject& resumption_data) {}
+
+void RCAppExtension::ProcessResumption(
+ const NsSmartDeviceLink::NsSmartObjects::SmartObject& resumption_data) {}
+
RCAppExtension::~RCAppExtension() {}
} // namespace rc_rpc_plugin
diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h
index 95e1fc771b..aa9b5d482f 100644
--- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h
+++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h
@@ -39,6 +39,8 @@
#include <string>
namespace vehicle_info_plugin {
+class VehicleInfoPlugin;
+
namespace app_mngr = application_manager;
typedef mobile_apis::VehicleDataType::eType VehicleDataType;
@@ -47,20 +49,31 @@ typedef mobile_apis::VehicleDataType::eType VehicleDataType;
*/
typedef std::set<mobile_apis::VehicleDataType::eType> VehicleInfoSubscriptions;
-class VehicleInfoAppExtension : app_mngr::AppExtension {
+class VehicleInfoAppExtension : public app_mngr::AppExtension {
public:
- explicit VehicleInfoAppExtension(app_mngr::AppExtensionUID uid);
+ explicit VehicleInfoAppExtension(VehicleInfoPlugin& plugin,
+ app_mngr::Application& app);
virtual ~VehicleInfoAppExtension();
- void subscribeToVehicleInfo(const VehicleDataType vehicle_data);
- void unsubscribeFromVehicleInfo(const VehicleDataType vehicle_data);
+ bool subscribeToVehicleInfo(const VehicleDataType vehicle_data);
+ bool unsubscribeFromVehicleInfo(const VehicleDataType vehicle_data);
void unsubscribeFromVehicleInfo();
bool isSubscribedToVehicleInfo(const VehicleDataType vehicle_data_type) const;
VehicleInfoSubscriptions Subscriptions();
+ void SaveResumptionData(
+ NsSmartDeviceLink::NsSmartObjects::SmartObject& resumption_data) OVERRIDE;
+ void ProcessResumption(
+ const smart_objects::SmartObject& resumption_data) OVERRIDE;
+
+ static unsigned VehicleInfoAppExtensionUID;
+ static VehicleInfoAppExtension& ExtractVIExtension(
+ application_manager::Application& app);
private:
VehicleInfoSubscriptions subscribed_data_;
+ VehicleInfoPlugin& plugin_;
+ app_mngr::Application& app_;
};
}
diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h
index 547a17753c..2e4978a40e 100644
--- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h
+++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h
@@ -36,13 +36,17 @@
#include "application_manager/command_factory.h"
namespace vehicle_info_plugin {
-
+class VehicleInfoAppExtension;
namespace app_mngr = application_manager;
namespace commands = application_manager::commands;
namespace plugins = application_manager::plugin_manager;
class VehicleInfoPlugin : public plugins::RPCPlugin {
+ typedef std::map<std::string, mobile_apis::VehicleDataType::eType>
+ VehicleData;
+
public:
+ VehicleInfoPlugin();
bool Init(app_mngr::ApplicationManager& application_manager,
app_mngr::rpc_service::RPCService& rpc_service,
app_mngr::HMICapabilities& hmi_capabilities,
@@ -58,8 +62,13 @@ class VehicleInfoPlugin : public plugins::RPCPlugin {
void OnApplicationEvent(plugins::ApplicationEvent event,
app_mngr::ApplicationSharedPtr application) OVERRIDE;
+ void ProcessResumptionSubscription(app_mngr::ApplicationSharedPtr app,
+ VehicleInfoAppExtension& ext);
+
private:
std::unique_ptr<app_mngr::CommandFactory> command_factory_;
+ app_mngr::ApplicationManager* application_manager_;
+ static const VehicleData vehicle_data_;
};
}
diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc
index cfd4a403a6..f5e944a38d 100644
--- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc
+++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc
@@ -75,4 +75,32 @@ bool VehicleInfoAppExtension::isSubscribedToVehicleInfo(
VehicleInfoSubscriptions VehicleInfoAppExtension::Subscriptions() {
return subscribed_data_;
}
+
+void VehicleInfoAppExtension::SaveResumptionData(
+ smart_objects::SmartObject& resumption_data) {
+ const char* application_vehicle_info = "vehicleInfo";
+ resumption_data[application_vehicle_info] =
+ smart_objects::SmartObject(smart_objects::SmartType_Array);
+ int i = 0;
+ for (const auto& subscription : subscribed_data_) {
+ resumption_data[application_vehicle_info][i] = subscription;
+ }
+}
+
+void VehicleInfoAppExtension::ProcessResumption(
+ const smart_objects::SmartObject& resumption_data) {
+ const char* application_vehicle_info = "vehicleInfo";
+ if (resumption_data.keyExists(application_vehicle_info)) {
+ const smart_objects::SmartObject& subscriptions_ivi =
+ resumption_data[application_vehicle_info];
+ for (size_t i = 0; i < subscriptions_ivi.length(); ++i) {
+ mobile_apis::VehicleDataType::eType ivi =
+ static_cast<mobile_apis::VehicleDataType::eType>(
+ (resumption_data[i]).asInt());
+ subscribeToVehicleInfo(ivi);
+ }
+ // ProcessHMIRequests(MessageHelper::GetIVISubscriptionRequests(
+ // application, application_manager_));
+ }
+}
}
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 bb22434440..7b94d22312 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
@@ -32,14 +32,24 @@
#include "vehicle_info_plugin/vehicle_info_plugin.h"
#include "vehicle_info_plugin/vehicle_info_command_factory.h"
+#include "vehicle_info_plugin/vehicle_info_app_extension.h"
+#include "application_manager/smart_object_keys.h"
+#include "application_manager/message_helper.h"
+#include "application_manager/message_helper.h"
namespace vehicle_info_plugin {
+CREATE_LOGGERPTR_GLOBAL(logger_, "VehicleInfoPlugin")
+
+namespace strings = application_manager::strings;
+
+VehicleInfoPlugin::VehicleInfoPlugin() : application_manager_(nullptr) {}
bool VehicleInfoPlugin::Init(
application_manager::ApplicationManager& app_manager,
application_manager::rpc_service::RPCService& rpc_service,
application_manager::HMICapabilities& hmi_capabilities,
policy::PolicyHandlerInterface& policy_handler) {
+ application_manager_ = &app_manager;
command_factory_.reset(new vehicle_info_plugin::VehicleInfoCommandFactory(
app_manager, rpc_service, hmi_capabilities, policy_handler));
return true;
@@ -62,7 +72,91 @@ void VehicleInfoPlugin::OnPolicyEvent(plugins::PolicyEvent event) {}
void VehicleInfoPlugin::OnApplicationEvent(
plugins::ApplicationEvent event,
- app_mngr::ApplicationSharedPtr application) {}
+ app_mngr::ApplicationSharedPtr application) {
+ if (plugins::ApplicationEvent::kApplicationRegistered == event) {
+ application->AddExtension(new VehicleInfoAppExtension(*this, *application));
+ }
+}
+
+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);
+ msg_params[strings::app_id] = app.app_id();
+ const auto& subscriptions = ext.Subscriptions();
+ for (auto& ivi_data : application_manager::MessageHelper::vehicle_data()) {
+ mobile_apis::VehicleDataType::eType type_id = ivi_data.second;
+ if (subscriptions.end() != subscriptions.find(type_id)) {
+ std::string key_name = ivi_data.first;
+ msg_params[key_name] = true;
+ }
+ }
+ smart_objects::SmartObjectSPtr request =
+ application_manager::MessageHelper::CreateModuleInfoSO(
+ hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData,
+ *application_manager_);
+ (*request)[strings::msg_params] = msg_params;
+ application_manager_->GetRPCService().ManageHMICommand(request);
+}
+
+application_manager::ApplicationSharedPtr FindAppSubscribedToIVI(
+ mobile_apis::VehicleDataType::eType ivi_data,
+ application_manager::ApplicationManager& app_mngr) {
+ auto applications = app_mngr.applications();
+
+ for (auto& app : applications.GetData()) {
+ auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app);
+ if (ext.isSubscribedToVehicleInfo(ivi_data)) {
+ return app;
+ }
+ }
+ return application_manager::ApplicationSharedPtr();
+}
+
+smart_objects::SmartObjectSPtr GetUnsubscribeIVIRequest(
+ int32_t ivi_id, application_manager::ApplicationManager& app_mngr) {
+ using namespace smart_objects;
+
+ auto find_ivi_name = [ivi_id]() {
+ for (auto item : application_manager::MessageHelper::vehicle_data()) {
+ if (ivi_id == item.second) {
+ return item.first;
+ }
+ }
+ return std::string();
+ };
+ std::string key_name = find_ivi_name();
+ DCHECK_OR_RETURN(!key_name.empty(), smart_objects::SmartObjectSPtr());
+ auto msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map);
+ msg_params[key_name] = true;
+
+ auto message = application_manager::MessageHelper::CreateMessageForHMI(
+ hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID());
+ DCHECK(message);
+
+ SmartObject& object = *message;
+ object[strings::params][strings::function_id] =
+ hmi_apis::FunctionID::VehicleInfo_UnsubscribeVehicleData;
+
+ object[strings::msg_params] = msg_params;
+ return message;
+}
+
+void VehicleInfoPlugin::DeleteSubscriptions(
+ application_manager::ApplicationSharedPtr app) {
+ auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app);
+ auto subscriptions = ext.Subscriptions();
+ for (auto& ivi : subscriptions) {
+ ext.unsubscribeFromVehicleInfo(ivi);
+ auto still_subscribed_app =
+ FindAppSubscribedToIVI(ivi, *application_manager_);
+ if (!still_subscribed_app) {
+ auto message = GetUnsubscribeIVIRequest(ivi, *application_manager_);
+ application_manager_->GetRPCService().ManageHMICommand(message);
+ }
+ }
+}
}
extern "C" application_manager::plugin_manager::RPCPlugin* Create() {
diff --git a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc
index 157aff7704..b7fc9f0b70 100644
--- a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc
+++ b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc
@@ -624,17 +624,8 @@ void ResumeCtrlImpl::AddSubscriptions(
MessageHelper::SendAllOnButtonSubscriptionNotificationsForApp(
application, application_manager_);
- if (subscriptions.keyExists(strings::application_vehicle_info)) {
- const smart_objects::SmartObject& subscriptions_ivi =
- subscriptions[strings::application_vehicle_info];
- mobile_apis::VehicleDataType::eType ivi;
- for (size_t i = 0; i < subscriptions_ivi.length(); ++i) {
- ivi = static_cast<mobile_apis::VehicleDataType::eType>(
- (subscriptions_ivi[i]).asInt());
- application->SubscribeToIVI(ivi);
- }
- ProcessHMIRequests(MessageHelper::GetIVISubscriptionRequests(
- application, application_manager_));
+ for (auto& extension : application->Extensions()) {
+ extension->ProcessResumption(subscriptions);
}
}
}