summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/app_service_manager.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/src/app_service_manager.cc')
-rw-r--r--src/components/application_manager/src/app_service_manager.cc114
1 files changed, 65 insertions, 49 deletions
diff --git a/src/components/application_manager/src/app_service_manager.cc b/src/components/application_manager/src/app_service_manager.cc
index ed9120ad19..24c21dc201 100644
--- a/src/components/application_manager/src/app_service_manager.cc
+++ b/src/components/application_manager/src/app_service_manager.cc
@@ -70,6 +70,7 @@ smart_objects::SmartObject AppServiceManager::PublishAppService(
std::string str_to_hash = "";
std::string service_id = "";
+ published_services_lock_.Acquire();
do {
str_to_hash = manifest[strings::service_type].asString() +
std::to_string(std::rand());
@@ -104,8 +105,10 @@ smart_objects::SmartObject AppServiceManager::PublishAppService(
}
app_service.default_service = GetPolicyAppID(app_service) == default_app_id;
- published_services_.insert(
+ auto ret = published_services_.insert(
std::pair<std::string, AppService>(service_id, app_service));
+ smart_objects::SmartObject& published_record = ret.first->second.record;
+ published_services_lock_.Release();
smart_objects::SmartObject msg_params;
msg_params[strings::system_capability][strings::system_capability_type] =
@@ -117,18 +120,17 @@ smart_objects::SmartObject AppServiceManager::PublishAppService(
// Activate the new service if it is the default for its service type, or if
// no service is active of its service type
- std::pair<std::string, AppService> active_service =
- ActiveServiceByType(service_type);
- if (active_service.first.empty() || app_service.default_service) {
+ AppService* active_service = ActiveServiceByType(service_type);
+ if (!active_service || app_service.default_service) {
ActivateAppService(service_id);
}
- return service_record;
+ return published_record;
}
bool AppServiceManager::UnpublishAppService(const std::string service_id) {
LOG4CXX_AUTO_TRACE(logger_);
-
+ sync_primitives::AutoLock lock(published_services_lock_);
auto it = published_services_.find(service_id);
if (it == published_services_.end()) {
LOG4CXX_ERROR(logger_, "Service id does not exist in published services");
@@ -141,22 +143,22 @@ bool AppServiceManager::UnpublishAppService(const std::string service_id) {
msg_params[strings::system_capability][strings::system_capability_type] =
mobile_apis::SystemCapabilityType::APP_SERVICES;
- auto record = it->second.record;
+ auto& record = it->second.record;
if (record[strings::service_active].asBool()) {
record[strings::service_active] = false;
// Activate embedded service, if available
auto embedded_service = EmbeddedServiceForType(
record[strings::service_manifest][strings::service_type].asString());
- if (!embedded_service.first.empty()) {
- embedded_service.second.record[strings::service_active] = true;
- AppServiceUpdated(embedded_service.second.record,
+ if (embedded_service) {
+ embedded_service->record[strings::service_active] = true;
+ AppServiceUpdated(embedded_service->record,
mobile_apis::ServiceUpdateReason::ACTIVATED,
msg_params);
}
}
AppServiceUpdated(
- it->second.record, mobile_apis::ServiceUpdateReason::REMOVED, msg_params);
+ record, mobile_apis::ServiceUpdateReason::REMOVED, msg_params);
MessageHelper::BroadcastCapabilityUpdate(msg_params, app_manager_);
published_services_.erase(it);
@@ -166,6 +168,7 @@ bool AppServiceManager::UnpublishAppService(const std::string service_id) {
void AppServiceManager::UnpublishServices(const uint32_t connection_key) {
LOG4CXX_AUTO_TRACE(logger_);
LOG4CXX_DEBUG(logger_, "Unpublishing all app services: " << connection_key);
+ sync_primitives::AutoLock lock(published_services_lock_);
for (auto it = published_services_.begin(); it != published_services_.end();
++it) {
if (it->second.connection_key == connection_key) {
@@ -176,6 +179,7 @@ void AppServiceManager::UnpublishServices(const uint32_t connection_key) {
void AppServiceManager::OnAppActivated(ApplicationConstSharedPtr app) {
LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
auto it = published_services_.begin();
// Activate all services published by the app
for (; it != published_services_.end(); ++it) {
@@ -188,6 +192,7 @@ void AppServiceManager::OnAppActivated(ApplicationConstSharedPtr app) {
std::vector<smart_objects::SmartObject> AppServiceManager::GetAllServices() {
LOG4CXX_AUTO_TRACE(logger_);
std::vector<smart_objects::SmartObject> services;
+ sync_primitives::AutoLock lock(published_services_lock_);
for (auto it = published_services_.begin(); it != published_services_.end();
++it) {
services.push_back(it->second.record);
@@ -196,11 +201,12 @@ std::vector<smart_objects::SmartObject> AppServiceManager::GetAllServices() {
}
void AppServiceManager::GetProviderByType(const std::string& service_type,
+ bool mobile_consumer,
ApplicationSharedPtr& app,
bool& hmi_service) {
LOG4CXX_AUTO_TRACE(logger_);
auto active_service = ActiveServiceByType(service_type);
- if (active_service.first.empty()) {
+ if (!active_service) {
LOG4CXX_ERROR(logger_,
"There is no active service for the given service type: "
<< service_type);
@@ -208,13 +214,15 @@ void AppServiceManager::GetProviderByType(const std::string& service_type,
}
LOG4CXX_DEBUG(logger_, "Found provider for service type: " << service_type);
- GetProviderFromService(active_service.second, app, hmi_service);
+ GetProviderFromService(*active_service, mobile_consumer, app, hmi_service);
}
void AppServiceManager::GetProviderByID(const std::string& service_id,
+ bool mobile_consumer,
ApplicationSharedPtr& app,
bool& hmi_service) {
LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
auto it = published_services_.find(service_id);
if (it == published_services_.end()) {
LOG4CXX_ERROR(logger_, "Service id does not exist in published services");
@@ -222,13 +230,20 @@ void AppServiceManager::GetProviderByID(const std::string& service_id,
}
LOG4CXX_DEBUG(logger_, "Found provider with service ID: " << service_id);
- GetProviderFromService(it->second, app, hmi_service);
+ GetProviderFromService(it->second, mobile_consumer, app, hmi_service);
}
void AppServiceManager::GetProviderFromService(const AppService& service,
+ bool mobile_consumer,
ApplicationSharedPtr& app,
bool& hmi_service) {
LOG4CXX_AUTO_TRACE(logger_);
+ if (mobile_consumer &&
+ !service.record[strings::service_manifest][strings::allow_app_consumers]
+ .asBool()) {
+ LOG4CXX_ERROR(logger_, "Service does not support app consumers");
+ return;
+ }
bool mobile_service = service.mobile_service;
if (mobile_service) {
app = app_manager_.application(service.connection_key);
@@ -240,6 +255,7 @@ void AppServiceManager::GetProviderFromService(const AppService& service,
bool AppServiceManager::SetDefaultService(const std::string service_id) {
LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
auto it = published_services_.find(service_id);
if (it == published_services_.end()) {
LOG4CXX_ERROR(logger_, "Unable to find published service " << service_id);
@@ -254,8 +270,8 @@ bool AppServiceManager::SetDefaultService(const std::string service_id) {
if (!default_app_id.empty()) {
auto default_service =
FindServiceByPolicyAppID(default_app_id, service_type);
- if (!default_service.first.empty()) {
- default_service.second.default_service = false;
+ if (default_service) {
+ default_service->default_service = false;
}
}
service.default_service = true;
@@ -268,6 +284,7 @@ bool AppServiceManager::SetDefaultService(const std::string service_id) {
bool AppServiceManager::RemoveDefaultService(const std::string service_id) {
LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
auto it = published_services_.find(service_id);
if (it == published_services_.end()) {
LOG4CXX_ERROR(logger_, "Unable to find published service " << service_id);
@@ -291,6 +308,7 @@ bool AppServiceManager::RemoveDefaultService(const std::string service_id) {
bool AppServiceManager::ActivateAppService(const std::string service_id) {
LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
auto it = published_services_.find(service_id);
if (it == published_services_.end()) {
LOG4CXX_ERROR(logger_, "Unable to find published service " << service_id);
@@ -310,9 +328,9 @@ bool AppServiceManager::ActivateAppService(const std::string service_id) {
const std::string service_type =
service[strings::service_manifest][strings::service_type].asString();
auto active_service = ActiveServiceByType(service_type);
- if (!active_service.first.empty()) {
- active_service.second.record[strings::service_active] = false;
- AppServiceUpdated(active_service.second.record,
+ if (active_service) {
+ active_service->record[strings::service_active] = false;
+ AppServiceUpdated(active_service->record,
mobile_apis::ServiceUpdateReason::DEACTIVATED,
msg_params);
}
@@ -337,6 +355,7 @@ bool AppServiceManager::ActivateAppService(const std::string service_id) {
bool AppServiceManager::DeactivateAppService(const std::string service_id) {
LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
auto it = published_services_.find(service_id);
if (it == published_services_.end()) {
LOG4CXX_ERROR(logger_, "Unable to find published service " << service_id);
@@ -355,9 +374,9 @@ bool AppServiceManager::DeactivateAppService(const std::string service_id) {
const std::string service_type =
service[strings::service_manifest][strings::service_type].asString();
auto embedded_service = EmbeddedServiceForType(service_type);
- if (!embedded_service.first.empty()) {
- embedded_service.second.record[strings::service_active] = true;
- AppServiceUpdated(embedded_service.second.record,
+ if (embedded_service) {
+ embedded_service->record[strings::service_active] = true;
+ AppServiceUpdated(embedded_service->record,
mobile_apis::ServiceUpdateReason::ACTIVATED,
msg_params);
}
@@ -372,54 +391,53 @@ bool AppServiceManager::DeactivateAppService(const std::string service_id) {
return true;
}
-std::pair<std::string, AppService> AppServiceManager::ActiveServiceByType(
- std::string service_type) {
+AppService* AppServiceManager::ActiveServiceByType(std::string service_type) {
LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
for (auto it = published_services_.begin(); it != published_services_.end();
++it) {
if (it->second.record[strings::service_manifest][strings::service_type]
.asString() == service_type &&
it->second.record[strings::service_published].asBool() &&
it->second.record[strings::service_active].asBool()) {
- return *it;
+ return &(it->second);
}
}
- AppService empty;
- return std::make_pair(std::string(), empty);
+ return NULL;
}
-std::pair<std::string, AppService> AppServiceManager::EmbeddedServiceForType(
+AppService* AppServiceManager::EmbeddedServiceForType(
std::string service_type) {
LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
for (auto it = published_services_.begin(); it != published_services_.end();
++it) {
if (it->second.record[strings::service_manifest][strings::service_type]
.asString() == service_type &&
!it->second.mobile_service) {
- return *it;
+ return &(it->second);
}
}
- AppService empty;
- return std::make_pair(std::string(), empty);
+ return NULL;
}
-std::pair<std::string, AppService> AppServiceManager::FindServiceByName(
- std::string name) {
+AppService* AppServiceManager::FindServiceByName(std::string name) {
LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
for (auto it = published_services_.begin(); it != published_services_.end();
++it) {
if (it->second.record[strings::service_manifest][strings::service_name]
.asString() == name) {
- return *it;
+ return &(it->second);
}
}
- AppService empty;
- return std::make_pair(std::string(), empty);
+ return NULL;
}
-std::pair<std::string, AppService> AppServiceManager::FindServiceByPolicyAppID(
+AppService* AppServiceManager::FindServiceByPolicyAppID(
std::string policy_app_id, std::string type) {
LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
for (auto it = published_services_.begin(); it != published_services_.end();
++it) {
if (it->second.record[strings::service_manifest][strings::service_type]
@@ -428,25 +446,22 @@ std::pair<std::string, AppService> AppServiceManager::FindServiceByPolicyAppID(
}
if (policy_app_id == GetPolicyAppID(it->second)) {
- return *it;
+ return &(it->second);
}
}
- AppService empty;
- return std::make_pair(std::string(), empty);
+ return NULL;
}
-std::pair<std::string, AppService> AppServiceManager::FindServiceByID(
- std::string service_id) {
+AppService* AppServiceManager::FindServiceByID(std::string service_id) {
LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
auto it = published_services_.find(service_id);
if (it == published_services_.end()) {
LOG4CXX_ERROR(logger_, "Service id does not exist in published services");
- AppService empty;
- return std::make_pair(std::string(), empty);
+ return NULL;
}
-
- return *it;
+ return &(it->second);
}
std::string AppServiceManager::DefaultServiceByType(std::string service_type) {
@@ -461,6 +476,7 @@ std::string AppServiceManager::DefaultServiceByType(std::string service_type) {
void AppServiceManager::SetServicePublished(const std::string service_id,
bool service_published) {
LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
auto it = published_services_.find(service_id);
if (it == published_services_.end()) {
LOG4CXX_ERROR(logger_, "Service id does not exist in published services");
@@ -485,7 +501,7 @@ bool AppServiceManager::UpdateNavigationCapabilities(
EnumConversionHelper<mobile_apis::AppServiceType::eType>::EnumToString(
mobile_apis::AppServiceType::NAVIGATION, &navi_service_type);
auto service = ActiveServiceByType(navi_service_type);
- if (service.first.empty()) {
+ if (!service) {
return false;
}
@@ -496,13 +512,13 @@ bool AppServiceManager::UpdateNavigationCapabilities(
out_params[strings::get_way_points_enabled] = false;
}
- if (!service.second.record[strings::service_manifest].keyExists(
+ if (!service->record[strings::service_manifest].keyExists(
strings::handled_rpcs)) {
return true;
}
smart_objects::SmartObject& handled_rpcs =
- service.second.record[strings::service_manifest][strings::handled_rpcs];
+ service->record[strings::service_manifest][strings::handled_rpcs];
for (size_t i = 0; i < handled_rpcs.length(); ++i) {
if (handled_rpcs[i].asInt() == mobile_apis::FunctionID::SendLocationID) {
out_params[strings::send_location_enabled] = true;