diff options
author | Shobhit Adlakha <ShobhitAd@users.noreply.github.com> | 2019-02-21 17:53:08 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-21 17:53:08 -0500 |
commit | a4011490d9aa4606d6d835690bc8703c4375526b (patch) | |
tree | b422413f94d20fd00cf7d7b653865d5f5434a22e /src/components/application_manager | |
parent | 1660c7950143cf1b79b8e5b1fabd2d18ad95af6f (diff) | |
download | sdl_core-a4011490d9aa4606d6d835690bc8703c4375526b.tar.gz |
SystemCapability Subscription (#2800)
* Added subscribe paramater and SystemCapability App Extension
* Added SystemCapability app extension in sdl_rpc_plugin
* Added enabling/disabling subscription in
* Added and implemented OnSystemCapabilityUpdated notification
* Add binary data to OEM_SPECIFIC request type
* Add check for missing presetBankCapabilities in Buttons.GetCapabilities
* Revert "Add missing resource close in LoadPlugin"
This reverts commit 35defc42777c57412cbf8b793489ab0dac502f4e.
* Genericize vehicle info in hmi_capabilities.json
* Added subscribe paramater and SystemCapability App Extension
* Added SystemCapability app extension in sdl_rpc_plugin
* Added enabling/disabling subscription in
* Added and implemented OnSystemCapabilityUpdated notification
* Added AppServices structs to MOBILE API
* Add binary data to OEM_SPECIFIC request type
* Add check for missing presetBankCapabilities in Buttons.GetCapabilities
* Revert "Add missing resource close in LoadPlugin"
This reverts commit 35defc42777c57412cbf8b793489ab0dac502f4e.
* Genericize vehicle info in hmi_capabilities.json
* Added subscribe paramater and SystemCapability App Extension
* Added SystemCapability app extension in sdl_rpc_plugin
* Added enabling/disabling subscription in
* Added and implemented OnSystemCapabilityUpdated notification
* Added and implemented OnSystemCapabilityUpdated notification
* Added AppServices structs to MOBILE API
* Add binary data to OEM_SPECIFIC request type
* Add check for missing presetBankCapabilities in Buttons.GetCapabilities
* Revert "Add missing resource close in LoadPlugin"
This reverts commit 35defc42777c57412cbf8b793489ab0dac502f4e.
* Genericize vehicle info in hmi_capabilities.json
* Added subscribe paramater and SystemCapability App Extension
* Added SystemCapability app extension in sdl_rpc_plugin
* Added enabling/disabling subscription in
* Added and implemented OnSystemCapabilityUpdated notification
* Added AppServices structs to MOBILE API
* Implemented AppServiceCapabilities response
* Renamed SystemCapability App Extension filename and ExtractExtension function
* Fix style
* Add OnSystemCapabilityUpdated(APP_SERVICES) handling
* Fix missing include and unused variables
* Made fix in App service manager and added notifcation RPC to policy table
* Implemented automatic app system capability subscription of App Service Provider
* Add binary data to OEM_SPECIFIC request type
* Add check for missing presetBankCapabilities in Buttons.GetCapabilities
* Revert "Add missing resource close in LoadPlugin"
This reverts commit 35defc42777c57412cbf8b793489ab0dac502f4e.
* Genericize vehicle info in hmi_capabilities.json
* Added subscribe paramater and SystemCapability App Extension
* Added SystemCapability app extension in sdl_rpc_plugin
* Added enabling/disabling subscription in
* Added and implemented OnSystemCapabilityUpdated notification
* Added AppServices structs to MOBILE API
* Implemented AppServiceCapabilities response
* Renamed SystemCapability App Extension filename and ExtractExtension function
* Fix style
* Add OnSystemCapabilityUpdated(APP_SERVICES) handling
* Fix missing include and unused variables
* Made fix in App service manager and added notifcation RPC to policy table
* Implemented automatic app system capability subscription of App Service Provider
* Rebase and style fix
* Added all published app services in OnSystemCapabilityUpdate notification
* Add binary data to OEM_SPECIFIC request type
* Add check for missing presetBankCapabilities in Buttons.GetCapabilities
* Revert "Add missing resource close in LoadPlugin"
This reverts commit 35defc42777c57412cbf8b793489ab0dac502f4e.
* Genericize vehicle info in hmi_capabilities.json
* Added subscribe paramater and SystemCapability App Extension
* Added SystemCapability app extension in sdl_rpc_plugin
* Added enabling/disabling subscription in
* Added and implemented OnSystemCapabilityUpdated notification
* Added AppServices structs to MOBILE API
* Implemented AppServiceCapabilities response
* Renamed SystemCapability App Extension filename and ExtractExtension function
* Fix style
* Add OnSystemCapabilityUpdated(APP_SERVICES) handling
* Fix missing include and unused variables
* Made fix in App service manager and added notifcation RPC to policy table
* Implemented automatic app system capability subscription of App Service Provider
* Added subscribe paramater and SystemCapability App Extension
* Added SystemCapability app extension in sdl_rpc_plugin
* Added and implemented OnSystemCapabilityUpdated notification
* Renamed SystemCapability App Extension filename and ExtractExtension function
* Fix style
* Add OnSystemCapabilityUpdated(APP_SERVICES) handling
* Made fix in App service manager and added notifcation RPC to policy table
* Rebase and style fix
* Added all published app services in OnSystemCapabilityUpdate notification
* Applied parameter updateReason only to published app service which triggers OnSystemCapabilityUpdated notification
* Implemented OnSystemCapabilityUpdated notification to HMI
* Addressed review comments
* Implemented UnPublishAppService in ASM
* Implemented ASP removal notification
* Moved ASP removal notification to ApplicationManagerImpl::UnregisterApplication
* Moved HMI OSCU notification from app services plugin to sdl rpc plugin
* Initialize AppServiceManager in Application manager tests
* Moved create notification functions to message helper class
* Fix style
* Removed setServiceActive function
* Update SystemCapability structs with new revisions
* Fixed error from previous commit and addressed style comments
* Addressed review comments
* Addressed review comments and removed extra debug statements
Diffstat (limited to 'src/components/application_manager')
26 files changed, 781 insertions, 29 deletions
diff --git a/src/components/application_manager/include/application_manager/app_service_manager.h b/src/components/application_manager/include/application_manager/app_service_manager.h index 97df35e2b4..c1f8a52370 100644 --- a/src/components/application_manager/include/application_manager/app_service_manager.h +++ b/src/components/application_manager/include/application_manager/app_service_manager.h @@ -79,6 +79,20 @@ class AppServiceManager { /** * @brief TODO + * @param connection_key + */ + void UnpublishServices(const uint32_t connection_key); + + /** + * @brief TODO + * @param service_id + * @param service_published + */ + void SetServicePublished(const std::string service_id, + bool service_published); + + /** + * @brief TODO * @param service_id */ bool SetDefaultService(const std::string service_id); diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index f72b02e320..16bfb9e7de 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -1535,6 +1535,11 @@ class ApplicationManagerImpl plugin_manager_.reset(plugin_manager.release()); } + virtual void SetAppServiceManager( + std::unique_ptr<AppServiceManager>& app_service_manager) { + app_service_manager_.reset(app_service_manager.release()); + } + private: #endif 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 609b240301..0487355056 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -878,6 +878,16 @@ class MessageHelper { static smart_objects::SmartObjectSPtr CreateMessageForHMI( hmi_apis::messageType::eType message_type, const uint32_t correlation_id); + static smart_objects::SmartObject CreateMobileSystemCapabilityNotification( + std::vector<smart_objects::SmartObject>& all_services, + const std::string service_id, + mobile_apis::ServiceUpdateReason::eType update_reason); + + static smart_objects::SmartObject CreateHMISystemCapabilityNotification( + std::vector<smart_objects::SmartObject>& all_services, + const std::string service_id, + mobile_apis::ServiceUpdateReason::eType update_reason); + private: /** * @brief Allows to fill SO according to the current permissions. diff --git a/src/components/application_manager/include/application_manager/smart_object_keys.h b/src/components/application_manager/include/application_manager/smart_object_keys.h index 19b2daaaf4..af334d5e97 100644 --- a/src/components/application_manager/include/application_manager/smart_object_keys.h +++ b/src/components/application_manager/include/application_manager/smart_object_keys.h @@ -60,6 +60,7 @@ extern const char* app_launch_last_session; extern const char* policy_app_id; extern const char* hmi_app_id; extern const char* device_id; +extern const char* subscribe; extern const char* subscribed_for_way_points; extern const char* url; extern const char* urlScheme; @@ -178,6 +179,7 @@ extern const char* navigation_capability; extern const char* phone_capability; extern const char* video_streaming_capability; extern const char* rc_capability; +extern const char* app_services_capabilities; extern const char* day_color_scheme; extern const char* night_color_scheme; extern const char* primary_color; @@ -316,6 +318,9 @@ extern const char* service_id; extern const char* service_manifest; extern const char* service_published; extern const char* service_active; +extern const char* app_services; +extern const char* update_reason; +extern const char* updated_app_service_record; // resuming extern const char* application_commands; diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt index e254c36587..2bdc150906 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt @@ -28,7 +28,10 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -include_directories(include) +include_directories( + include + ${COMPONENTS_DIR}/application_manager/rpc_plugins/sdl_rpc_plugin/include + ) set (COMMANDS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/commands @@ -54,6 +57,7 @@ set(LIBRARIES v4_protocol_v1_2_no_extra SmartObjects Utils + sdl_rpc_plugin ) if(ENABLE_LOG) diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc index 89da1e744c..a3e6bfed2a 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc @@ -78,6 +78,7 @@ bool ASPublishAppServiceRequest::ValidateManifest( void ASPublishAppServiceRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Received a PublishAppService request from HMI"); smart_objects::SmartObject response_params = smart_objects::SmartObject(smart_objects::SmartType_Map); smart_objects::SmartObject manifest = diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc index 7a0333e763..96f17f732a 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc @@ -35,6 +35,7 @@ #include "application_manager/message_helper.h" #include "application_manager/rpc_service.h" #include "interfaces/MOBILE_API.h" +#include "sdl_rpc_plugin/extensions/system_capability_app_extension.h" namespace app_service_rpc_plugin { using namespace application_manager; @@ -79,7 +80,7 @@ bool PublishAppServiceRequest::ValidateManifest( void PublishAppServiceRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG(logger_, "Received a PublishAppService"); + LOG4CXX_DEBUG(logger_, "Received a PublishAppService " << connection_key()); MessageHelper::PrintSmartObject(*message_); smart_objects::SmartObject response_params = @@ -89,6 +90,12 @@ void PublishAppServiceRequest::Run() { if (!ValidateManifest(manifest)) { return; } + + ApplicationSharedPtr app = application_manager_.application(connection_key()); + auto& ext = + sdl_rpc_plugin::SystemCapabilityAppExtension::ExtractExtension(*app); + ext.SubscribeTo(mobile_apis::SystemCapabilityType::APP_SERVICES); + smart_objects::SmartObject service_record = application_manager_.GetAppServiceManager().PublishAppService( manifest, true, connection_key()); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/CMakeLists.txt index 11dd35d061..fdf02b57cb 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/CMakeLists.txt @@ -42,8 +42,12 @@ set (HMI_COMMANDS_SOURCE_DIR ${COMMANDS_SOURCE_DIR}/hmi ) +set (EXTENSIONS_SOURCE_DIR + ${CMAKE_CURRENT_SOURCE_DIR}/src/extensions +) collect_sources(MOBILE_COMMANDS "${MOBILE_COMMANDS_SOURCE_DIR}") collect_sources(HMI_COMMANDS "${HMI_COMMANDS_SOURCE_DIR}") +collect_sources(APP_EXTENSIONS "${EXTENSIONS_SOURCE_DIR}") collect_sources(RPC_PLUGIN_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src") set(LIBRARIES @@ -60,7 +64,7 @@ if(ENABLE_LOG) list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() -add_library("sdl_rpc_plugin" SHARED ${MOBILE_COMMANDS} ${HMI_COMMANDS} ${RPC_PLUGIN_SOURCES}) +add_library("sdl_rpc_plugin" SHARED ${MOBILE_COMMANDS} ${HMI_COMMANDS} ${RPC_PLUGIN_SOURCES} ${APP_EXTENSIONS}) target_link_libraries("sdl_rpc_plugin" ${LIBRARIES}) set(INSTALL_DESTINATION bin) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification.h new file mode 100644 index 0000000000..17f8a5b3c8 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification.h @@ -0,0 +1,79 @@ +/* + Copyright (c) 2019, Ford Motor Company, Livio + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the the copyright holders nor the names of their + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_BC_SYSTEM_CAPABILITY_UPDATED_NOTIFICATION_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_BC_SYSTEM_CAPABILITY_UPDATED_NOTIFICATION_H_ + +#include "application_manager/commands/notification_to_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief OnASSystemCapabilityUpdatedNotification command class + **/ +class OnBCSystemCapabilityUpdatedNotification + : public app_mngr::commands::NotificationToHMI { + public: + /** + * @brief OnASSystemCapabilityUpdatedNotification class constructor + * + * @param message Incoming SmartObject message + **/ + OnBCSystemCapabilityUpdatedNotification( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle); + + /** + * @brief OnASSystemCapabilityUpdatedNotification class destructor + **/ + virtual ~OnBCSystemCapabilityUpdatedNotification(); + + /** + * @brief Execute command + **/ + virtual void Run(); + + private: + DISALLOW_COPY_AND_ASSIGN(OnBCSystemCapabilityUpdatedNotification); +}; + +} // namespace commands + +} // namespace app_service_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_BC_SYSTEM_CAPABILITY_UPDATED_NOTIFICATION_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_system_capability_updated_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_system_capability_updated_notification.h new file mode 100644 index 0000000000..1f7e8468db --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_system_capability_updated_notification.h @@ -0,0 +1,84 @@ +/* + Copyright (c) 2018, Ford Motor Company + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the Ford Motor Company nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_ON_SYSTEM_CAPABILITY_UPDATED_NOTIFICATION_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_ON_SYSTEM_CAPABILITY_UPDATED_NOTIFICATION_H_ + +#include "application_manager/commands/command_notification_impl.h" +#include "policy/policy_table/enums.h" +#include <vector> + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +namespace mobile { + +/** + * @brief OnSystemCapabilityUpdatedNotification class + **/ +class OnSystemCapabilityUpdatedNotification + : public app_mngr::commands::CommandNotificationImpl { + public: + typedef std::vector<uint8_t> BinaryMessage; + /** + * @brief OnSystemCapabilityUpdatedNotification class constructor + * + * @param message Incoming SmartObject message + **/ + OnSystemCapabilityUpdatedNotification( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler); + + /** + * @brief OnSystemCapabilityUpdatedNotification class destructor + **/ + ~OnSystemCapabilityUpdatedNotification() OVERRIDE; + + /** + * @brief Execute command + **/ + void Run() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(OnSystemCapabilityUpdatedNotification); +}; + +} // namespace mobile +} // namespace commands +} // namespace application_manager + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_ON_SYSTEM_CAPABILITY_UPDATED_NOTIFICATION_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/extensions/system_capability_app_extension.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/extensions/system_capability_app_extension.h new file mode 100644 index 0000000000..fb82cf37c2 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/extensions/system_capability_app_extension.h @@ -0,0 +1,83 @@ +/* + Copyright (c) 2018, Ford Motor Company + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the Ford Motor Company nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_EXTENSIONS_SYSTEM_CAPABILITY_APP_EXTENSION_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_EXTENSIONS_SYSTEM_CAPABILITY_APP_EXTENSION_H +#include <application_manager/application_manager.h> +#include <set> +#include <string> +#include "sdl_rpc_plugin/sdl_rpc_plugin.h" + +namespace sdl_rpc_plugin { +class SDLRPCPlugin; + +namespace app_mngr_ = application_manager; + +typedef mobile_apis::SystemCapabilityType::eType SystemCapabilityType; +typedef std::set<mobile_apis::SystemCapabilityType::eType> + SystemCapabilitySubscriptions; + +class SystemCapabilityAppExtension : public app_mngr_::AppExtension { + public: + SystemCapabilityAppExtension(SDLRPCPlugin& plugin, + app_mngr_::Application& app); + virtual ~SystemCapabilityAppExtension(); + + bool SubscribeTo(const SystemCapabilityType system_capability_type); + + bool UnsubscribeFrom(const SystemCapabilityType system_capability_type); + + void UnsubscribeFromAll(); + + bool IsSubscribedTo(const SystemCapabilityType system_capability_type) const; + + SystemCapabilitySubscriptions Subscriptions(); + + void SaveResumptionData(ns_smart_device_link::ns_smart_objects::SmartObject& + resumption_data) OVERRIDE; + + void ProcessResumption( + const smart_objects::SmartObject& resumption_data) OVERRIDE; + + static const app_mngr_::AppExtensionUID SystemCapabilityAppExtensionUID; + + static SystemCapabilityAppExtension& ExtractExtension( + app_mngr_::Application& app); + + private: + SystemCapabilitySubscriptions subscribed_data_; + SDLRPCPlugin& plugin_; + app_mngr_::Application& app_; +}; +} + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_EXTENSIONS_SYSTEM_CAPABILITY_APP_EXTENSION_H diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/sdl_rpc_plugin.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/sdl_rpc_plugin.h index 6ae3a0b6bc..b57fcbec12 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/sdl_rpc_plugin.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/sdl_rpc_plugin.h @@ -36,29 +36,32 @@ #include "application_manager/command_factory.h" namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; namespace plugins = application_manager::plugin_manager; + +class SystemCapabilityAppExtension; + class SDLRPCPlugin : public plugins::RPCPlugin { // RPCPlugin interface public: - bool Init(application_manager::ApplicationManager& app_manager, - application_manager::rpc_service::RPCService& rpc_service, - application_manager::HMICapabilities& hmi_capabilities, + bool Init(app_mngr::ApplicationManager& app_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, policy::PolicyHandlerInterface& policy_handler) OVERRIDE; bool IsAbleToProcess( const int32_t function_id, - const application_manager::commands::Command::CommandSource - message_source) OVERRIDE; + const app_mngr::commands::Command::CommandSource message_source) OVERRIDE; std::string PluginName() OVERRIDE; - application_manager::CommandFactory& GetCommandFactory() OVERRIDE; - void OnPolicyEvent( - application_manager::plugin_manager::PolicyEvent event) OVERRIDE; - void OnApplicationEvent( - application_manager::plugin_manager::ApplicationEvent event, - application_manager::ApplicationSharedPtr application) OVERRIDE; + app_mngr::CommandFactory& GetCommandFactory() OVERRIDE; + void OnPolicyEvent(plugins::PolicyEvent event) OVERRIDE; + void OnApplicationEvent(plugins::ApplicationEvent event, + app_mngr::ApplicationSharedPtr application) OVERRIDE; private: + void ClearSubscriptions(app_mngr::ApplicationSharedPtr app); + std::unique_ptr<application_manager::CommandFactory> command_factory_; }; } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification.cc new file mode 100644 index 0000000000..3f8dcf08f6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification.cc @@ -0,0 +1,67 @@ +/* + Copyright (c) 2019, Ford Motor Company, Livio + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the the copyright holders nor the names of their + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#include "sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification.h" +#include "application_manager/application_impl.h" +#include "application_manager/rpc_service.h" +#include "interfaces/HMI_API.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +OnBCSystemCapabilityUpdatedNotification:: + OnBCSystemCapabilityUpdatedNotification( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : NotificationToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +OnBCSystemCapabilityUpdatedNotification:: + ~OnBCSystemCapabilityUpdatedNotification() {} + +void OnBCSystemCapabilityUpdatedNotification::Run() { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, + "Sending BasicCommunication.OnSystemCapabilityUpdated " + "Notification to HMI"); + SendNotification(); +} + +} // namespace commands +} // namespace app_service_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc index a6c627aad2..1449f0e061 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_system_capability_request.cc @@ -31,6 +31,9 @@ */ #include "sdl_rpc_plugin/commands/mobile/get_system_capability_request.h" +#include "sdl_rpc_plugin/extensions/system_capability_app_extension.h" +#include "application_manager/message_helper.h" +#include <set> namespace sdl_rpc_plugin { using namespace application_manager; @@ -128,10 +131,48 @@ void GetSystemCapabilityRequest::Run() { return; } break; + case mobile_apis::SystemCapabilityType::APP_SERVICES: { + smart_objects::SmartObject app_service_capabilities( + smart_objects::SmartType_Map); + smart_objects::SmartObject app_services(smart_objects::SmartType_Array); + + std::vector<smart_objects::SmartObject> service_records = + application_manager_.GetAppServiceManager().GetAllServices(); + + for (auto& record : service_records) { + smart_objects::SmartObject app_services_capabilities( + smart_objects::SmartType_Map); + app_services_capabilities[strings::updated_app_service_record] = record; + app_services.asArray()->push_back(app_services_capabilities); + } + + app_service_capabilities[strings::app_services] = app_services; + response_params[strings::system_capability] + [strings::app_services_capabilities] = + app_service_capabilities; + + break; + } default: // Return unsupported resource SendResponse(false, mobile_apis::Result::UNSUPPORTED_RESOURCE); return; } + + if ((*message_)[app_mngr::strings::msg_params].keyExists( + strings::subscribe)) { + auto& ext = SystemCapabilityAppExtension::ExtractExtension(*app); + if ((*message_)[app_mngr::strings::msg_params][strings::subscribe] + .asBool() == true) { + LOG4CXX_DEBUG(logger_, + "Subscribe to system capability: " << response_type); + ext.SubscribeTo(response_type); + } else { + LOG4CXX_DEBUG(logger_, + "Unsubscribe from system capability: " << response_type); + ext.UnsubscribeFrom(response_type); + } + } + SendResponse(true, mobile_apis::Result::SUCCESS, NULL, &response_params); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_capability_updated_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_capability_updated_notification.cc new file mode 100644 index 0000000000..6a1f0844d9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_capability_updated_notification.cc @@ -0,0 +1,70 @@ +#include "sdl_rpc_plugin/commands/mobile/on_system_capability_updated_notification.h" +#include "application_manager/application_manager.h" +#include "application_manager/helpers/application_helper.h" +#include "application_manager/message_helper.h" +#include "sdl_rpc_plugin/extensions/system_capability_app_extension.h" +#include "smart_objects/enum_schema_item.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { +namespace mobile { + +OnSystemCapabilityUpdatedNotification::OnSystemCapabilityUpdatedNotification( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandNotificationImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +OnSystemCapabilityUpdatedNotification:: + ~OnSystemCapabilityUpdatedNotification() {} + +void OnSystemCapabilityUpdatedNotification::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + mobile_apis::SystemCapabilityType::eType system_capability_type = + static_cast<mobile_apis::SystemCapabilityType::eType>( + (*message_)[strings::msg_params][strings::system_capability] + [strings::system_capability_type].asInt()); + + const char* capability_type_string; + ns_smart_device_link::ns_smart_objects::EnumConversionHelper< + mobile_apis::SystemCapabilityType::eType>:: + EnumToCString(system_capability_type, &capability_type_string); + + auto subscribed_to_capability_predicate = + [&system_capability_type](const ApplicationSharedPtr app) { + DCHECK_OR_RETURN(app, false); + auto& ext = SystemCapabilityAppExtension::ExtractExtension(*app); + return ext.IsSubscribedTo(system_capability_type); + }; + + const std::vector<ApplicationSharedPtr>& applications = FindAllApps( + application_manager_.applications(), subscribed_to_capability_predicate); + + LOG4CXX_DEBUG(logger_, + "Number of Notifications to be sent: " << applications.size()); + + std::vector<ApplicationSharedPtr>::const_iterator app_it = + applications.begin(); + + for (; applications.end() != app_it; ++app_it) { + const ApplicationSharedPtr app = *app_it; + LOG4CXX_INFO(logger_, + "Sending OnSystemCapabilityUpdated " << capability_type_string + << " application id " + << app->app_id()); + (*message_)[strings::params][strings::connection_key] = app->app_id(); + SendNotification(); + } +} + +} // namespace mobile +} // namespace commands +} // namespace application_manager diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/extensions/system_capability_app_extension.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/extensions/system_capability_app_extension.cc new file mode 100644 index 0000000000..130585a927 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/extensions/system_capability_app_extension.cc @@ -0,0 +1,98 @@ +#include "sdl_rpc_plugin/extensions/system_capability_app_extension.h" + +namespace sdl_rpc_plugin { +CREATE_LOGGERPTR_GLOBAL(logger_, "GetSystemCapabilitiesAppExtension") + +namespace app_mngr_ = application_manager; +const app_mngr_::AppExtensionUID + SystemCapabilityAppExtension::SystemCapabilityAppExtensionUID = 200; + +SystemCapabilityAppExtension::SystemCapabilityAppExtension( + sdl_rpc_plugin::SDLRPCPlugin& plugin, app_mngr_::Application& app) + : app_mngr_::AppExtension( + SystemCapabilityAppExtension::SystemCapabilityAppExtensionUID) + , plugin_(plugin) + , app_(app) {} + +SystemCapabilityAppExtension::~SystemCapabilityAppExtension() {} + +bool SystemCapabilityAppExtension::SubscribeTo( + const SystemCapabilityType system_capability_type) { + LOG4CXX_INFO(logger_, + "Subscribing to System Capability " << system_capability_type); + return subscribed_data_.insert(system_capability_type).second; +} + +bool SystemCapabilityAppExtension::UnsubscribeFrom( + const SystemCapabilityType system_capability_type) { + LOG4CXX_INFO(logger_, + "Unsubscribing from System Capability " + << system_capability_type); + auto it = subscribed_data_.find(system_capability_type); + if (it != subscribed_data_.end()) { + subscribed_data_.erase(it); + return true; + } + return false; +} + +void SystemCapabilityAppExtension::UnsubscribeFromAll() { + LOG4CXX_INFO(logger_, "Unsubscribing from ALL System Capabilities"); + subscribed_data_.clear(); +} + +bool SystemCapabilityAppExtension::IsSubscribedTo( + const SystemCapabilityType system_capability_type) const { + LOG4CXX_DEBUG(logger_, system_capability_type); + return subscribed_data_.find(system_capability_type) != + subscribed_data_.end(); +} + +SystemCapabilitySubscriptions SystemCapabilityAppExtension::Subscriptions() { + return subscribed_data_; +} + +void SystemCapabilityAppExtension::SaveResumptionData( + ns_smart_device_link::ns_smart_objects::SmartObject& resumption_data) { + LOG4CXX_AUTO_TRACE(logger_); + const char* application_system_capability = "systemCapability"; + + resumption_data[application_system_capability] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + int i = 0; + for (const auto& subscription : subscribed_data_) { + resumption_data[application_system_capability][i] = subscription; + i++; + } +} + +void SystemCapabilityAppExtension::ProcessResumption( + const smart_objects::SmartObject& resumption_data) { + LOG4CXX_AUTO_TRACE(logger_); + + const char* application_system_capability = "systemCapability"; + if (resumption_data.keyExists(application_system_capability)) { + const smart_objects::SmartObject& subscriptions = + resumption_data[application_system_capability]; + for (size_t i = 0; i < subscriptions.length(); ++i) { + SystemCapabilityType capability_type = + static_cast<SystemCapabilityType>((resumption_data[i]).asInt()); + SubscribeTo(capability_type); + } + } +} + +SystemCapabilityAppExtension& SystemCapabilityAppExtension::ExtractExtension( + app_mngr_::Application& app) { + LOG4CXX_AUTO_TRACE(logger_); + auto ext_ptr = app.QueryInterface( + SystemCapabilityAppExtension::SystemCapabilityAppExtensionUID); + DCHECK(ext_ptr); + DCHECK(dynamic_cast<SystemCapabilityAppExtension*>(ext_ptr.get())); + auto app_extension = + std::static_pointer_cast<SystemCapabilityAppExtension>(ext_ptr); + DCHECK(app_extension); + return *app_extension; +} +}
\ No newline at end of file diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc index 7065c7cf7d..dc94474b9d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc @@ -241,6 +241,8 @@ #include "sdl_rpc_plugin/commands/hmi/rc_get_capabilities_request.h" #include "sdl_rpc_plugin/commands/hmi/rc_get_capabilities_response.h" +#include "sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification.h" + namespace sdl_rpc_plugin { using namespace application_manager; @@ -840,6 +842,10 @@ CommandCreator& HMICommandFactory::get_creator_factory( ? factory.GetCreator<commands::UISendHapticDataRequest>() : factory.GetCreator<commands::UISendHapticDataResponse>(); } + case hmi_apis::FunctionID::BasicCommunication_OnSystemCapabilityUpdated: { + return factory + .GetCreator<commands::OnBCSystemCapabilityUpdatedNotification>(); + } default: { return factory.GetCreator<InvalidCommand>(); } } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc index 8eab054be3..77be545e0b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc @@ -73,6 +73,7 @@ #include "sdl_rpc_plugin/commands/mobile/on_tbt_client_state_notification.h" #include "sdl_rpc_plugin/commands/mobile/on_hash_change_notification.h" #include "sdl_rpc_plugin/commands/mobile/on_way_point_change_notification.h" +#include "sdl_rpc_plugin/commands/mobile/on_system_capability_updated_notification.h" #include "sdl_rpc_plugin/commands/mobile/perform_audio_pass_thru_request.h" #include "sdl_rpc_plugin/commands/mobile/perform_audio_pass_thru_response.h" #include "sdl_rpc_plugin/commands/mobile/perform_interaction_request.h" @@ -388,6 +389,10 @@ CommandCreator& MobileCommandFactory::get_creator_factory( case mobile_apis::FunctionID::OnTouchEventID: { return factory.GetCreator<commands::mobile::OnTouchEventNotification>(); } + case mobile_apis::FunctionID::OnSystemCapabilityUpdatedID: { + return factory.GetCreator< + commands::mobile::OnSystemCapabilityUpdatedNotification>(); + } case mobile_apis::FunctionID::OnSystemRequestID: { return factory .GetCreator<commands::mobile::OnSystemRequestNotification>(); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/sdl_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/sdl_rpc_plugin.cc index 22b818f5e0..aa82c74098 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/sdl_rpc_plugin.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/sdl_rpc_plugin.cc @@ -32,15 +32,18 @@ #include "sdl_rpc_plugin/sdl_rpc_plugin.h" #include "sdl_rpc_plugin/sdl_command_factory.h" +#include "sdl_rpc_plugin/extensions/system_capability_app_extension.h" namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; namespace plugins = application_manager::plugin_manager; -bool SDLRPCPlugin::Init( - application_manager::ApplicationManager& app_manager, - application_manager::rpc_service::RPCService& rpc_service, - application_manager::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) { +CREATE_LOGGERPTR_GLOBAL(logger_, "SdlRPCPlugin") + +bool SDLRPCPlugin::Init(app_mngr::ApplicationManager& app_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) { command_factory_.reset(new sdl_rpc_plugin::SDLCommandFactory( app_manager, rpc_service, hmi_capabilities, policy_handler)); return true; @@ -48,8 +51,7 @@ bool SDLRPCPlugin::Init( bool SDLRPCPlugin::IsAbleToProcess( const int32_t function_id, - const application_manager::commands::Command::CommandSource - message_source) { + const app_mngr::commands::Command::CommandSource message_source) { return command_factory_->IsAbleToProcess(function_id, message_source); } @@ -57,16 +59,27 @@ std::string SDLRPCPlugin::PluginName() { return "SDL RPC Plugin"; } -application_manager::CommandFactory& SDLRPCPlugin::GetCommandFactory() { +app_mngr::CommandFactory& SDLRPCPlugin::GetCommandFactory() { return *command_factory_; } -void SDLRPCPlugin::OnPolicyEvent( - application_manager::plugin_manager::PolicyEvent event) {} +void SDLRPCPlugin::OnPolicyEvent(plugins::PolicyEvent event) {} void SDLRPCPlugin::OnApplicationEvent( - application_manager::plugin_manager::ApplicationEvent event, - application_manager::ApplicationSharedPtr application) {} + plugins::ApplicationEvent event, + app_mngr::ApplicationSharedPtr application) { + if (plugins::ApplicationEvent::kApplicationRegistered == event) { + application->AddExtension( + std::make_shared<SystemCapabilityAppExtension>(*this, *application)); + } else if (plugins::ApplicationEvent::kDeleteApplicationData == event) { + ClearSubscriptions(application); + } +} + +void SDLRPCPlugin::ClearSubscriptions(app_mngr::ApplicationSharedPtr app) { + auto& ext = SystemCapabilityAppExtension::ExtractExtension(*app); + ext.UnsubscribeFromAll(); +} } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/src/app_service_manager.cc b/src/components/application_manager/src/app_service_manager.cc index 8fea64b228..57b319c680 100644 --- a/src/components/application_manager/src/app_service_manager.cc +++ b/src/components/application_manager/src/app_service_manager.cc @@ -37,6 +37,7 @@ #include "application_manager/app_service_manager.h" #include "application_manager/application.h" +#include "application_manager/app_service_manager.h" #include "application_manager/application_manager.h" #include "application_manager/commands/command_impl.h" #include "application_manager/message_helper.h" @@ -78,19 +79,73 @@ smart_objects::SmartObject AppServiceManager::PublishAppService( service_record[strings::service_id] = service_id; service_record[strings::service_published] = true; service_record[strings::service_active] = true; - app_service.record = service_record; published_services_.insert( std::pair<std::string, AppService>(service_id, app_service)); + auto all_services = GetAllServices(); + smart_objects::SmartObjectSPtr notification = + std::make_shared<smart_objects::SmartObject>( + MessageHelper::CreateMobileSystemCapabilityNotification( + all_services, + service_id, + mobile_apis::ServiceUpdateReason::PUBLISHED)); + app_manager_.GetRPCService().ManageMobileCommand( + notification, commands::Command::CommandSource::SOURCE_SDL); + smart_objects::SmartObjectSPtr hmi_notification = + std::make_shared<smart_objects::SmartObject>( + MessageHelper::CreateHMISystemCapabilityNotification( + all_services, + service_id, + mobile_apis::ServiceUpdateReason::PUBLISHED)); + app_manager_.GetRPCService().ManageHMICommand(hmi_notification); return service_record; } bool AppServiceManager::UnpublishAppService(const std::string service_id) { LOG4CXX_AUTO_TRACE(logger_); - // TODO - return false; + + auto it = published_services_.find(service_id); + if (it == published_services_.end()) { + LOG4CXX_ERROR(logger_, "Service id does not exist in published services"); + return false; + } + LOG4CXX_DEBUG(logger_, "Unpublishing app service: " << service_id); + + SetServicePublished(service_id, false); + + auto all_services = GetAllServices(); + smart_objects::SmartObjectSPtr notification = + std::make_shared<smart_objects::SmartObject>( + MessageHelper::CreateMobileSystemCapabilityNotification( + all_services, + service_id, + mobile_apis::ServiceUpdateReason::REMOVED)); + app_manager_.GetRPCService().ManageMobileCommand( + notification, commands::Command::CommandSource::SOURCE_SDL); + smart_objects::SmartObjectSPtr hmi_notification = + std::make_shared<smart_objects::SmartObject>( + MessageHelper::CreateHMISystemCapabilityNotification( + all_services, + service_id, + mobile_apis::ServiceUpdateReason::REMOVED)); + app_manager_.GetRPCService().ManageHMICommand(hmi_notification); + + published_services_.erase(it); + + return true; +} + +void AppServiceManager::UnpublishServices(const uint32_t connection_key) { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Unpublishing all app services: " << connection_key); + for (auto it = published_services_.begin(); it != published_services_.end(); + ++it) { + if (it->second.connection_key == connection_key) { + UnpublishAppService(it->first); + } + } } std::vector<smart_objects::SmartObject> AppServiceManager::GetAllServices() { @@ -103,6 +158,15 @@ std::vector<smart_objects::SmartObject> AppServiceManager::GetAllServices() { return services; } +void AppServiceManager::SetServicePublished(const std::string service_id, + bool service_published) { + auto it = published_services_.find(service_id); + if (it == published_services_.end()) { + LOG4CXX_ERROR(logger_, "Service id does not exist in published services"); + return; + } + it->second.record[strings::service_published] = service_published; +} std::pair<std::string, AppService> AppServiceManager::ActiveServiceByType( std::string service_type) { diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index d82eeb776c..6ee221f56f 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -2619,6 +2619,8 @@ void ApplicationManagerImpl::UnregisterApplication( << is_unexpected_disconnect); size_t subscribed_for_way_points_app_count = 0; + GetAppServiceManager().UnpublishServices(app_id); + // SDL sends UnsubscribeWayPoints only for last application { sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); 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 58d5171f84..1d3a553711 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -327,6 +327,57 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateMessageForHMI( return message; } +smart_objects::SmartObject +MessageHelper::CreateMobileSystemCapabilityNotification( + std::vector<smart_objects::SmartObject>& all_services, + const std::string service_id, + mobile_apis::ServiceUpdateReason::eType update_reason) { + smart_objects::SmartObject message(smart_objects::SmartType_Map); + + message[strings::params][strings::message_type] = MessageType::kNotification; + message[strings::params][strings::function_id] = + mobile_apis::FunctionID::OnSystemCapabilityUpdatedID; + + smart_objects::SmartObject system_capability = + smart_objects::SmartObject(smart_objects::SmartType_Map); + system_capability[strings::system_capability_type] = + mobile_apis::SystemCapabilityType::APP_SERVICES; + + smart_objects::SmartObject app_service_capabilities( + smart_objects::SmartType_Map); + smart_objects::SmartObject app_services(smart_objects::SmartType_Array); + + std::vector<smart_objects::SmartObject> service_records = all_services; + + for (auto& record : service_records) { + smart_objects::SmartObject app_services_capabilities( + smart_objects::SmartType_Map); + app_services_capabilities[strings::updated_app_service_record] = record; + if (record[strings::service_id].asString() == service_id) { + app_services_capabilities[strings::update_reason] = update_reason; + } + app_services.asArray()->push_back(app_services_capabilities); + } + + app_service_capabilities[strings::app_services] = app_services; + system_capability[strings::app_services_capabilities] = + app_service_capabilities; + + message[strings::msg_params][strings::system_capability] = system_capability; + return message; +} + +smart_objects::SmartObject MessageHelper::CreateHMISystemCapabilityNotification( + std::vector<smart_objects::SmartObject>& all_services, + const std::string service_id, + mobile_apis::ServiceUpdateReason::eType update_reason) { + auto message = CreateMobileSystemCapabilityNotification( + all_services, service_id, update_reason); + message[strings::params][strings::function_id] = + hmi_apis::FunctionID::BasicCommunication_OnSystemCapabilityUpdated; + return message; +} + smart_objects::SmartObjectSPtr MessageHelper::CreateHashUpdateNotification( const uint32_t app_id) { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc index 1b6dfe2b8b..4900726d48 100644 --- a/src/components/application_manager/src/smart_object_keys.cc +++ b/src/components/application_manager/src/smart_object_keys.cc @@ -27,6 +27,7 @@ const char* app_launch_last_session = "app_launch_last_session"; const char* policy_app_id = "policyAppID"; const char* hmi_app_id = "hmiAppID"; const char* device_id = "deviceID"; +const char* subscribe = "subscribe"; const char* subscribed_for_way_points = "subscribed_for_way_points"; const char* url = "url"; const char* urlScheme = "urlScheme"; @@ -145,6 +146,7 @@ const char* navigation_capability = "navigationCapability"; const char* phone_capability = "phoneCapability"; const char* video_streaming_capability = "videoStreamingCapability"; const char* rc_capability = "remoteControlCapability"; +const char* app_services_capabilities = "appServicesCapabilities"; const char* day_color_scheme = "dayColorScheme"; const char* night_color_scheme = "nightColorScheme"; const char* primary_color = "primaryColor"; @@ -283,6 +285,9 @@ const char* service_id = "serviceID"; const char* service_manifest = "serviceManifest"; const char* service_published = "servicePublished"; const char* service_active = "serviceActive"; +const char* app_services = "appServices"; +const char* update_reason = "updateReason"; +const char* updated_app_service_record = "updatedAppServiceRecord"; // resuming const char* application_commands = "applicationCommands"; diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc index 4ea44e5aca..0b24fa8032 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -138,6 +138,9 @@ class ApplicationManagerImplTest : public ::testing::Test { app_manager_impl_->resume_controller().set_resumption_storage( mock_storage_); app_manager_impl_->set_connection_handler(&mock_connection_handler_); + std::unique_ptr<AppServiceManager> app_service_manager_ptr( + new AppServiceManager(*app_manager_impl_)); + app_manager_impl_->SetAppServiceManager(app_service_manager_ptr); } void CreateAppManager() { 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 84a3b6bc87..878d3e7dd7 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 @@ -308,6 +308,16 @@ class MockMessageHelper { void(mobile_apis::ButtonName::eType button, ApplicationSharedPtr application, ApplicationManager& app_mngr)); + MOCK_METHOD3(CreateMobileSystemCapabilityNotification, + smart_objects::SmartObject( + std::vector<smart_objects::SmartObject>& all_services, + const std::string service_id, + mobile_apis::ServiceUpdateReason::eType update_reason)); + MOCK_METHOD3(CreateHMISystemCapabilityNotification, + smart_objects::SmartObject( + std::vector<smart_objects::SmartObject>& all_services, + const std::string service_id, + mobile_apis::ServiceUpdateReason::eType update_reason)); static MockMessageHelper* message_helper_mock(); }; diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index f091e183dc..6bd42a44a1 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -572,4 +572,22 @@ void MessageHelper::SendUnsubscribeButtonNotification( ->SendUnsubscribeButtonNotification(button, application, app_mngr); } +smart_objects::SmartObject +MessageHelper::CreateMobileSystemCapabilityNotification( + std::vector<smart_objects::SmartObject>& all_services, + const std::string service_id, + mobile_apis::ServiceUpdateReason::eType update_reason) { + return MockMessageHelper::message_helper_mock() + ->CreateMobileSystemCapabilityNotification( + all_services, service_id, update_reason); +} + +smart_objects::SmartObject MessageHelper::CreateHMISystemCapabilityNotification( + std::vector<smart_objects::SmartObject>& all_services, + const std::string service_id, + mobile_apis::ServiceUpdateReason::eType update_reason) { + return MockMessageHelper::message_helper_mock() + ->CreateHMISystemCapabilityNotification( + all_services, service_id, update_reason); +} } // namespace application_manager |