summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Kutsan <akutsan@luxoft.com>2018-02-28 20:29:48 +0200
committerIra Lytvynenko (GitHub) <ILytvynenko@luxoft.com>2018-07-12 13:31:02 +0300
commitbf6958061ce28e291d1b826410a1fa0317b05140 (patch)
treea8d9a1d3c7d2bc1fffb2c7e9dbf2ef47930e2e0e
parent88cbe025519b0791bd736f1227cf66e0dff49aa5 (diff)
downloadsdl_core-bf6958061ce28e291d1b826410a1fa0317b05140.tar.gz
Create and send on RC status notifications
Add comments and mock missed methods Conflicts: src/components/include/test/application_manager/mock_rpc_service.h
-rw-r--r--src/components/application_manager/include/application_manager/message_helper.h17
-rw-r--r--src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h5
-rw-r--r--src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h14
-rw-r--r--src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc2
-rw-r--r--src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc98
-rw-r--r--src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt1
-rw-r--r--src/components/application_manager/src/message_helper/message_helper.cc35
-rw-r--r--src/components/application_manager/test/include/application_manager/mock_message_helper.h7
-rw-r--r--src/components/application_manager/test/mock_message_helper.cc12
9 files changed, 189 insertions, 2 deletions
diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h
index f28b7950f9..84106555e7 100644
--- a/src/components/application_manager/include/application_manager/message_helper.h
+++ b/src/components/application_manager/include/application_manager/message_helper.h
@@ -71,6 +71,23 @@ typedef std::map<std::string, mobile_apis::VehicleDataType::eType> VehicleData;
**/
class MessageHelper {
public:
+
+ /**
+ * @brief CreateNotification creates basic mobile notification smart object
+ * @param function_id Notificaiton function ID
+ * @param app_id application to send notification
+ * @return basic mobile notification smart object
+ */
+ static smart_objects::SmartObjectSPtr CreateNotification(mobile_apis::FunctionID::eType function_id,
+ uint32_t app_id);
+ /**
+ * @brief CreateHMINotification creates basic hmi notification smart object
+ * @param function_id Notificaiton function ID
+ * @return basic hmi notification smart object
+ */
+ static smart_objects::SmartObjectSPtr CreateHMINotification(
+ hmi_apis::FunctionID::eType function_id);
+
/**
* @brief Creates request for different interfaces(JSON)
* @param correlation_id unique ID
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h
index e22f2b64a8..181c536b8a 100644
--- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h
+++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h
@@ -114,6 +114,11 @@ const char kButtonName[] = "buttonName";
const char kButtonPressMode[] = "buttonPressMode";
// ButtonPress request
+// OnRCStatusNotification
+const char kAllocatedModules[] = "allocatedModules";
+const char kFreeModules[] = "freeModules";
+// OnRCStatusNotification
+
// RdsData struct
const char kPS[] = "PS";
const char kRT[] = "RT";
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h
index bb875bb180..0bbea236e3 100644
--- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h
+++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h
@@ -119,6 +119,20 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager {
application_manager::ApplicationSharedPtr application) FINAL;
private:
+ typedef std::vector<application_manager::ApplicationSharedPtr> Apps;
+
+ /**
+ * @brief Create OnRCStatusNotification creates OnRCStatus notification smart
+ * object for mobile application
+ * @param app_id application to send OnRCStatusNotification
+ * @return smart object with mobile OnRCStatusNotification
+ */
+ smart_objects::SmartObjectSPtr CreateOnRCStatusNotification(
+ const uint32_t app_id);
+
+ smart_objects::SmartObjectSPtr CreateOnRCStatusNotification();
+
+
/**
* @brief IsModuleTypeRejected check if current resource was rejected by
* driver for current application
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc
index 36377c620b..bb32f1d7fd 100644
--- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc
+++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc
@@ -125,4 +125,4 @@ RCRPCPlugin::Apps RCRPCPlugin::GetRCApplications(
extern "C" application_manager::plugin_manager::RPCPlugin* Create() {
return new rc_rpc_plugin::RCRPCPlugin();
-}
+} // namespace rc_rpc_plugin
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc
index c2962863e3..606b8aa592 100644
--- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc
+++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc
@@ -213,9 +213,92 @@ void ResourceAllocationManagerImpl::RemoveAppsSubscriptions(const Apps& apps) {
}
}
+template <typename EnumType>
+std::string EnumToString(EnumType enum_type) {
+ using smart_objects::EnumConversionHelper;
+ const char* str = 0;
+ if (EnumConversionHelper<EnumType>::EnumToCString(enum_type, &str)) {
+ return str;
+ }
+ return std::string("INVALID_ENUM");
+}
+
+template <typename EnumType>
+EnumType StringToEnum(const std::string& str) {
+ using smart_objects::EnumConversionHelper;
+ EnumType val;
+ EnumConversionHelper<EnumType>::StringToEnum(str, &val);
+ return val;
+}
+
+void ConstructOnRCStatusNotificationParams(
+ smart_objects::SmartObject msg_params,
+ const std::map<std::string, uint32_t>& allocated_resources,
+ const std::vector<std::string>& supported_resources) {
+ namespace strings = application_manager::strings;
+ namespace message_params = rc_rpc_plugin::message_params;
+ using smart_objects::SmartObject;
+ using smart_objects::SmartType_Map;
+ using smart_objects::SmartType_Map;
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ auto modules_inserter = [](SmartObject& result_modules) {
+ return [&result_modules](const std::string& module_name) {
+ smart_objects::SmartObject module_data =
+ SmartObject(smart_objects::SmartType_Map);
+ auto module_type =
+ StringToEnum<mobile_apis::ModuleType::eType>(module_name);
+ module_data[message_params::kModuleType] = module_type;
+ };
+ };
+ SmartObject allocated_modules = SmartObject(SmartType_Map);
+ for (auto& module : allocated_resources) {
+ modules_inserter(allocated_modules)(module.first);
+ }
+ SmartObject free_modules = SmartObject(SmartType_Map);
+ for (auto& module : supported_resources) {
+ if (allocated_resources.find(module) == allocated_resources.end()) {
+ modules_inserter(free_modules)(module);
+ }
+ }
+ msg_params[message_params::kAllocatedModules] = allocated_modules;
+ msg_params[message_params::kFreeModules] = free_modules;
+}
+
+smart_objects::SmartObjectSPtr
+ResourceAllocationManagerImpl::CreateOnRCStatusNotification(
+ const uint32_t app_id) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ using application_manager::MessageHelper;
+ auto to_mobile_msg = MessageHelper::CreateNotification(
+ mobile_apis::FunctionID::OnRCStatusID, app_id);
+ auto& msg_params = (*to_mobile_msg)[application_manager::strings::msg_params];
+ ConstructOnRCStatusNotificationParams(
+ msg_params, allocated_resources_, all_supported_modules());
+ return to_mobile_msg;
+}
+
+smart_objects::SmartObjectSPtr
+ResourceAllocationManagerImpl::CreateOnRCStatusNotification() {
+ using application_manager::MessageHelper;
+ auto to_hmi_msg =
+ MessageHelper::CreateHMINotification(hmi_apis::FunctionID::RC_OnRCStatus);
+ auto& msg_params = (*to_hmi_msg)[application_manager::strings::msg_params];
+ ConstructOnRCStatusNotificationParams(
+ msg_params, allocated_resources_, all_supported_modules());
+ return to_hmi_msg;
+}
+
void ResourceAllocationManagerImpl::SetResourceAquired(
const std::string& module_type, const uint32_t app_id) {
LOG4CXX_AUTO_TRACE(logger_);
+ auto rc_apps = RCRPCPlugin::GetRCApplications(app_mngr_);
+ for (auto& rc_app : rc_apps) {
+ auto notification = CreateOnRCStatusNotification(rc_app->app_id());
+ rpc_service_.SendMessageToMobile(notification);
+ }
+ auto notification = CreateOnRCStatusNotification();
+ rpc_service_.SendMessageToHMI(notification);
allocated_resources_[module_type] = app_id;
}
@@ -235,6 +318,21 @@ void ResourceAllocationManagerImpl::SetResourceFree(
}
allocated_resources_.erase(allocation);
LOG4CXX_DEBUG(logger_, "Resource " << module_type << " is released.");
+ auto rc_apps = RCRPCPlugin::GetRCApplications(app_mngr_);
+ for (auto& rc_app : rc_apps) {
+ auto notification = CreateOnRCStatusNotification(rc_app->app_id());
+ rpc_service_.SendMessageToMobile(notification);
+ }
+ auto notification = CreateOnRCStatusNotification();
+ rpc_service_.SendMessageToHMI(notification);
+}
+
+std::vector<std::string>
+ResourceAllocationManagerImpl::all_supported_modules() {
+ std::vector<std::string> result;
+ result.push_back(enums_value::kClimate);
+ result.push_back(enums_value::kRadio);
+ return result;
}
std::vector<std::string> ResourceAllocationManagerImpl::GetAcquiredResources(
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt
index a66ab107be..a1f0f5a6ff 100644
--- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt
+++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt
@@ -53,6 +53,7 @@ file(GLOB SOURCES
set(LIBRARIES
RCRpcPluginStaticLib
ApplicationManager
+ connectionHandler
SmartObjects
ProtocolHandler
MessageHelper
diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc
index 3b6b720b19..3f92631e5e 100644
--- a/src/components/application_manager/src/message_helper/message_helper.cc
+++ b/src/components/application_manager/src/message_helper/message_helper.cc
@@ -232,6 +232,41 @@ const VehicleData MessageHelper::vehicle_data_(
kVehicleDataInitializer,
kVehicleDataInitializer + ARRAYSIZE(kVehicleDataInitializer));
+smart_objects::SmartObjectSPtr MessageHelper::CreateNotification(
+ mobile_apis::FunctionID::eType function_id, uint32_t app_id) {
+ using smart_objects::SmartObject;
+ LOG4CXX_AUTO_TRACE(logger_);
+ smart_objects::SmartObjectSPtr object(
+ new SmartObject(smart_objects::SmartType_Map));
+ (*object)[strings::params][strings::message_type] =
+ static_cast<int>(kNotification);
+ (*object)[strings::params][strings::function_id] = function_id;
+ (*object)[strings::params][strings::connection_key] = app_id;
+ (*object)[strings::msg_params] =
+ smart_objects::SmartObject(smart_objects::SmartType_Map);
+ return object;
+}
+
+NsSmartDeviceLink::NsSmartObjects::SmartObjectSPtr
+MessageHelper::CreateHMINotification(hmi_apis::FunctionID::eType function_id) {
+ using smart_objects::SmartObject;
+ using smart_objects::SmartObjectSPtr;
+ using smart_objects::SmartType_Map;
+ LOG4CXX_AUTO_TRACE(logger_);
+ SmartObjectSPtr notification_ptr =
+ utils::MakeShared<SmartObject>(SmartType_Map);
+ SmartObject& notification = *notification_ptr;
+ notification[strings::params][strings::message_type] =
+ static_cast<int32_t>(application_manager::MessageType::kNotification);
+ notification[strings::params][strings::protocol_version] =
+ commands::CommandImpl::protocol_version_;
+ notification[strings::params][strings::protocol_type] =
+ commands::CommandImpl::hmi_protocol_type_;
+ notification[strings::params][strings::function_id] = function_id;
+
+ return notification_ptr;
+}
+
const uint32_t MessageHelper::GetPriorityCode(const std::string& priority) {
CommonAppPriorityMap::const_iterator it = app_priority_values.find(priority);
if (app_priority_values.end() != it) {
diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h
index 07c3f78b51..099f150709 100644
--- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h
+++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h
@@ -46,7 +46,12 @@ namespace application_manager {
class MockMessageHelper {
public:
- MOCK_METHOD1(GetHashUpdateNotification,
+ MOCK_METHOD2(CreateNotification,
+ smart_objects::SmartObjectSPtr(mobile_apis::FunctionID::eType, uint32_t));
+ MOCK_METHOD1(CreateHMINotification,
+ smart_objects::SmartObjectSPtr(hmi_apis::FunctionID::eType));
+
+ MOCK_METHOD1(GetHashUpdateNotification,
smart_objects::SmartObjectSPtr(const uint32_t app_id));
MOCK_METHOD2(SendHashUpdateNotification,
void(const uint32_t app_id, ApplicationManager& app_mngr));
diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc
index 4c673ae523..95d8686081 100644
--- a/src/components/application_manager/test/mock_message_helper.cc
+++ b/src/components/application_manager/test/mock_message_helper.cc
@@ -39,6 +39,18 @@
namespace application_manager {
+smart_objects::SmartObjectSPtr MessageHelper::CreateNotification(
+ mobile_apis::FunctionID::eType function_id, uint32_t app_id) {
+ return MockMessageHelper::message_helper_mock()->CreateNotification(
+ function_id, app_id);
+}
+
+smart_objects::SmartObjectSPtr MessageHelper::CreateHMINotification(
+ hmi_apis::FunctionID::eType function_id) {
+ return MockMessageHelper::message_helper_mock()->CreateHMINotification(
+ function_id);
+}
+
void MessageHelper::SendHashUpdateNotification(uint32_t const app_id,
ApplicationManager& app_mngr) {
MockMessageHelper::message_helper_mock()->SendHashUpdateNotification(