summaryrefslogtreecommitdiff
path: root/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc
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 /src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc
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
Diffstat (limited to 'src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc')
-rw-r--r--src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc98
1 files changed, 98 insertions, 0 deletions
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(