diff options
author | Kozoriz <kozorizandriy@gmail.com> | 2016-04-11 16:26:03 +0300 |
---|---|---|
committer | Kozoriz <kozorizandriy@gmail.com> | 2016-04-25 12:15:46 +0300 |
commit | daf2d2134715074cc58ae0264606c3349851bae1 (patch) | |
tree | c946d28f188a48c339cd26a722f0d2daed6271ca /src/components/application_manager/include | |
parent | 313ed4ba92a5eb75befe9ede65eef5c15dac068c (diff) | |
download | sdl_core-daf2d2134715074cc58ae0264606c3349851bae1.tar.gz |
ApplicationManager correctives after remove all singletones
Removed singletone from AM
Updated after removing Profile singleton
Diffstat (limited to 'src/components/application_manager/include')
23 files changed, 754 insertions, 754 deletions
diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index ee4b12a367..c40ebe68cd 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -109,7 +109,7 @@ class InitialApplicationData { virtual const smart_objects::SmartObject* app_types() const = 0; virtual const smart_objects::SmartObject* vr_synonyms() const = 0; virtual const std::string& mac_address() const = 0; - virtual std::string mobile_app_id() const = 0; + virtual std::string policy_app_id() const = 0; virtual const smart_objects::SmartObject* tts_name() const = 0; virtual const smart_objects::SmartObject* ngn_media_screen_name() const = 0; virtual const mobile_api::Language::eType& language() const = 0; @@ -117,7 +117,7 @@ class InitialApplicationData { virtual void set_app_types(const smart_objects::SmartObject& app_types) = 0; virtual void set_vr_synonyms( const smart_objects::SmartObject& vr_synonyms) = 0; - virtual void set_mobile_app_id(const std::string& mobile_app_id) = 0; + virtual void set_mobile_app_id(const std::string& policy_app_id) = 0; virtual void set_tts_name(const smart_objects::SmartObject& tts_name) = 0; virtual void set_ngn_media_screen_name( const smart_objects::SmartObject& ngn_name) = 0; @@ -766,6 +766,12 @@ class Application : public virtual InitialApplicationData, */ virtual void LoadPersistentFiles() = 0; + /** + * @brief Get available app space + * @param name of the app folder(make + mobile app id) + * @return free app space. + */ + virtual uint32_t GetAvailableDiskSpace() = 0; protected: mutable sync_primitives::Lock hmi_states_lock_; diff --git a/src/components/application_manager/include/application_manager/application_data_impl.h b/src/components/application_manager/include/application_manager/application_data_impl.h index 35c638e207..b6653bc3ee 100644 --- a/src/components/application_manager/include/application_manager/application_data_impl.h +++ b/src/components/application_manager/include/application_manager/application_data_impl.h @@ -50,14 +50,14 @@ class InitialApplicationDataImpl : public virtual Application { const smart_objects::SmartObject* app_types() const; const smart_objects::SmartObject* vr_synonyms() const; - virtual std::string mobile_app_id() const; + virtual std::string policy_app_id() const; const smart_objects::SmartObject* tts_name() const; const smart_objects::SmartObject* ngn_media_screen_name() const; const mobile_api::Language::eType& language() const; const mobile_api::Language::eType& ui_language() const; void set_app_types(const smart_objects::SmartObject& app_types); void set_vr_synonyms(const smart_objects::SmartObject& vr_synonyms); - void set_mobile_app_id(const std::string& mobile_app_id); + void set_mobile_app_id(const std::string& policy_app_id); void set_tts_name(const smart_objects::SmartObject& tts_name); void set_ngn_media_screen_name(const smart_objects::SmartObject& ngn_name); void set_language(const mobile_api::Language::eType& language); diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index dbe7ee9b2b..bdef552c0b 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -68,10 +68,11 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, public: ApplicationImpl( uint32_t application_id, - const std::string& mobile_app_id, + const std::string& policy_app_id, const std::string& mac_address, const custom_str::CustomString& app_name, - utils::SharedPtr<usage_statistics::StatisticsManager> statistics_manager); + utils::SharedPtr<usage_statistics::StatisticsManager> statistics_manager, + ApplicationManager& application_manager); ~ApplicationImpl(); @@ -130,9 +131,9 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, void set_folder_name(const std::string& folder_name) OVERRIDE; const std::string folder_name() const; bool is_media_application() const; - virtual bool is_foreground() const; - virtual void set_foreground(bool is_foreground); - virtual const mobile_api::HMILevel::eType hmi_level() const; + bool is_foreground() const OVERRIDE; + void set_foreground(bool is_foreground) OVERRIDE; + const mobile_apis::HMILevel::eType hmi_level() const; const uint32_t put_file_in_none_count() const; const uint32_t delete_file_in_none_count() const; const uint32_t list_files_in_none_count() const; @@ -188,6 +189,10 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, virtual DataAccessor<ButtonSubscriptions> SubscribedButtons() const OVERRIDE; virtual const std::string& curHash() const; +#ifdef CUSTOMER_PASA + virtual bool flag_sending_hash_change_after_awake() const; + virtual void set_flag_sending_hash_change_after_awake(bool flag); +#endif // CUSTOMER_PASA /** * @brief Change Hash for current application * and send notification to mobile @@ -218,11 +223,6 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, virtual bool IsAudioApplication() const; /** - * @brief Load persistent files from application folder. - */ - virtual void LoadPersistentFiles(); - - /** * @brief SetRegularState set permanent state of application * * @param state state to setup @@ -287,6 +287,17 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, void set_video_stream_retry_number(const uint32_t& video_stream_retry_number); + /** + * @brief Load persistent files from application folder. + */ + void LoadPersistentFiles() OVERRIDE; + + /** + * @brief Get available app space + * @param name of the app folder(make + mobile app id) + * @return free app space. + */ + uint32_t GetAvailableDiskSpace() OVERRIDE; protected: /** * @brief Clean up application folder. Persistent files will stay @@ -294,7 +305,6 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, void CleanupFiles(); private: - /** * @brief Callback for video streaming suspend timer. * Suspends video streaming process for application @@ -387,6 +397,7 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, mutable sync_primitives::Lock vi_lock_; sync_primitives::Lock button_lock_; std::string folder_name_; + ApplicationManager& application_manager_; DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); }; diff --git a/src/components/application_manager/include/application_manager/application_manager.h b/src/components/application_manager/include/application_manager/application_manager.h index dba3357d42..298abcca59 100644 --- a/src/components/application_manager/include/application_manager/application_manager.h +++ b/src/components/application_manager/include/application_manager/application_manager.h @@ -36,15 +36,17 @@ #include <string> #include <vector> #include <set> - +#include "vehicle_info_data.h" #include "application_manager/application.h" #include "application_manager/hmi_capabilities.h" #include "application_manager/commands/command.h" - +#include "connection_handler/connection_handler.h" #include "utils/data_accessor.h" #include "utils/shared_ptr.h" #include "telemetry_monitor/telemetry_observable.h" #include "application_manager/policies/policy_handler_interface.h" +#include "application_manager/application_manager_settings.h" +#include "application_manager/state_controller.h" namespace resumption { class LastState; @@ -64,9 +66,21 @@ class ProtocolHandler; namespace connection_handler { class ConnectionHandler; } +namespace resumption { +class ResumeCtrl; +} namespace application_manager { +namespace event_engine { +class EventDispatcher; +} + +class Application; +class StateControllerImpl; +struct CommandParametersPermissions; +typedef std::vector<std::string> RPCParams; + struct ApplicationsAppIdSorter { bool operator()(const ApplicationSharedPtr lhs, const ApplicationSharedPtr rhs) const { @@ -104,13 +118,11 @@ class ApplicationManager { protocol_handler::ProtocolHandler* handler) = 0; virtual void set_connection_handler( connection_handler::ConnectionHandler* handler) = 0; - virtual connection_handler::ConnectionHandler& connection_handler() const = 0; virtual DataAccessor<ApplicationSet> applications() const = 0; virtual ApplicationSharedPtr application(uint32_t app_id) const = 0; virtual ApplicationSharedPtr active_application() const = 0; - // /** * Function used only by HMI request/response/notification base classes @@ -159,7 +171,7 @@ class ApplicationManager { * * @return application id associated with correlation id */ - virtual const uint32_t application_id(const int32_t correlation_id) = 0; + virtual uint32_t application_id(const int32_t correlation_id) = 0; /** * @brief Sets application id correlation id @@ -192,6 +204,38 @@ class ApplicationManager { virtual void SendHMIStatusNotification( const utils::SharedPtr<Application> app) = 0; + /** + * @brief Checks if Application is subscribed for way points + * @param Application AppID + * @return true if Application is subscribed for way points + * otherwise false + */ + virtual bool IsAppSubscribedForWayPoints(const uint32_t app_id) const = 0; + + /** + * @brief Subscribe Application for way points + * @param Application AppID + */ + virtual void SubscribeAppForWayPoints(const uint32_t app_id) = 0; + + /** + * @brief Unsubscribe Application for way points + * @param Application AppID + */ + virtual void UnsubscribeAppFromWayPoints(const uint32_t app_id) = 0; + + /** + * @brief Is Any Application is subscribed for way points + * @return true if some app is subscribed otherwise false + */ + virtual bool IsAnyAppSubscribedForWayPoints() const = 0; + + /** + * @brief Get subscribed for way points + * @return reference to set of subscribed apps for way points + */ + virtual const std::set<int32_t> GetAppsSubscribedForWayPoints() const = 0; + virtual void SendMessageToMobile(const commands::MessageSharedPtr message, bool final_message = false) = 0; @@ -200,8 +244,6 @@ class ApplicationManager { virtual bool ManageHMICommand(const commands::MessageSharedPtr message) = 0; virtual bool ManageMobileCommand(const commands::MessageSharedPtr message, commands::Command::CommandOrigin origin) = 0; - - virtual mobile_api::HMILevel::eType GetDefaultHmiLevel( ApplicationConstSharedPtr application) const = 0; /** @@ -210,7 +252,12 @@ class ApplicationManager { */ virtual HMICapabilities& hmi_capabilities() = 0; - virtual bool is_attenuated_supported() = 0; + virtual const HMICapabilities& hmi_capabilities() const = 0; + + virtual void ProcessQueryApp(const smart_objects::SmartObject& sm_object, + const uint32_t connection_key) = 0; + + virtual bool is_attenuated_supported() const = 0; /** * @brief Checks if application with the same HMI type @@ -231,6 +278,252 @@ class ApplicationManager { */ virtual void OnApplicationRegistered(ApplicationSharedPtr app) = 0; + virtual connection_handler::ConnectionHandler& connection_handler() const = 0; + virtual protocol_handler::ProtocolHandler& protocol_handler() const = 0; + virtual policy::PolicyHandlerInterface& GetPolicyHandler() = 0; + + virtual uint32_t GetNextHMICorrelationID() = 0; + virtual uint32_t GenerateNewHMIAppID() = 0 ; + + /** + * @brief Ends opened navi services (audio/video) for application + * @param app_id Application id + */ + virtual void EndNaviServices(uint32_t app_id) = 0; + + /* @brief Starts audio passthru process + * + * @return true on success, false if passthru is already in process + */ + virtual bool BeginAudioPassThrough() = 0; + + /* + * @brief Finishes already started audio passthru process + * + * @return true on success, false if passthru is not active + */ + virtual bool EndAudioPassThrough() = 0 ; + + + virtual void ConnectToDevice(const std::string& device_mac) = 0; + + virtual void OnHMIStartedCooperation() = 0 ; + + virtual bool IsHMICooperating() const = 0; + /** + * @brief Notifies all components interested in Vehicle Data update + * i.e. new value of odometer etc and returns list of applications + * subscribed for event. + * @param vehicle_info Enum value of type of vehicle data + * @param new value (for integer values currently) of vehicle data + */ + virtual std::vector<ApplicationSharedPtr> IviInfoUpdated( + VehicleDataType vehicle_info, int value) = 0; + + virtual ApplicationSharedPtr RegisterApplication(const utils::SharedPtr< + smart_objects::SmartObject>& request_for_registration) = 0; + + virtual void SendUpdateAppList() = 0; + + virtual void MarkAppsGreyOut(const connection_handler::DeviceHandle handle, + bool is_greyed_out) = 0; + virtual bool IsAppsQueriedFrom( + const connection_handler::DeviceHandle handle) const = 0; + + virtual bool IsStopping() const = 0; + + virtual void RemoveAppFromTTSGlobalPropertiesList(const uint32_t app_id) = 0; + + virtual mobile_apis::Result::eType SaveBinary(const std::vector<uint8_t>& binary_data, + const std::string& file_path, + const std::string& file_name, + const int64_t offset) = 0; + /* + * @brief Sets SDL access to all mobile apps + * + * @param allowed SDL access to all mobile apps + */ + virtual void SetAllAppsAllowed(const bool& allowed) = 0; + + /* + * @brief Sets state for driver distraction + * + * @param state New state to be set + */ + virtual void set_driver_distraction(bool is_distracting) = 0; + + /* + * @brief Starts audio pass thru thread + * + * @param session_key Session key of connection for Mobile side + * @param correlation_id Correlation id for response for Mobile side + * @param max_duration Max duration of audio recording in milliseconds + * @param sampling_rate Value for rate(8, 16, 22, 44 kHz) + * @param bits_per_sample The quality the audio is recorded. + * @param audio_type Type of audio data + */ + virtual void StartAudioPassThruThread(int32_t session_key, + int32_t correlation_id, + int32_t max_duration, + int32_t sampling_rate, + int32_t bits_per_sample, + int32_t audio_type) = 0; + + virtual void StartDevicesDiscovery() = 0; + + virtual void StopAudioPassThru(int32_t application_key) = 0; + + /** + * @brief TerminateRequest forces termination of request + * @param connection_key - application id of request + * @param corr_id correlation id of request + */ + virtual void TerminateRequest(uint32_t connection_key, uint32_t corr_id) = 0; + + /* + * @brief Closes application by id + * + * @param app_id Application id + * @param reason reason of unregistering application + * @param is_resuming describes - is this unregister + * is normal or need to be resumed\ + * @param is_unexpected_disconnect + * Indicates if connection was unexpectedly lost(TM layer, HB) + */ + virtual void UnregisterApplication(const uint32_t& app_id, + mobile_apis::Result::eType reason, + bool is_resuming = false, + bool is_unexpected_disconnect = false) = 0; + + /** + * @ Updates request timeout + * + * @param connection_key Connection key of application + * @param mobile_correlation_id Correlation ID of the mobile request + * @param new_timeout_value New timeout in milliseconds to be set + */ + virtual void updateRequestTimeout(uint32_t connection_key, + uint32_t mobile_correlation_id, + uint32_t new_timeout_value) = 0; + + virtual StateController& state_controller() = 0; + + virtual void SetUnregisterAllApplicationsReason( + mobile_api::AppInterfaceUnregisteredReason::eType reason) = 0; + + /* + * @brief Called on Master_reset or Factory_defaults + * when User chooses to reset HU. + * Resets Policy Table if applicable. + */ + virtual void HeadUnitReset(mobile_api::AppInterfaceUnregisteredReason::eType reason) = 0; + + /** + * @brief Checks HMI level and returns true if streaming is allowed + * @param app_id Application id + * @param service_type Service type to check + * @return True if streaming is allowed, false in other case + */ + virtual bool HMILevelAllowsStreaming( + uint32_t app_id, protocol_handler::ServiceType service_type) const = 0; + + /** + * @brief Checks, if given RPC is allowed at current HMI level for specific + * application in policy table + * @param policy_app_id Application id + * @param hmi_level Current HMI level of application + * @param function_id FunctionID of RPC + * @param params_permissions Permissions for RPC parameters (e.g. + * SubscribeVehicleData) defined in policy table + * @return SUCCESS, if allowed, otherwise result code of check + */ + virtual mobile_apis::Result::eType CheckPolicyPermissions( + const std::string& policy_app_id, + mobile_apis::HMILevel::eType hmi_level, + mobile_apis::FunctionID::eType function_id, + const RPCParams& rpc_params, + CommandParametersPermissions* params_permissions = NULL) = 0; + + + /** + * @brief IsApplicationForbidden allows to distinguish if application is + * not allowed to register, because of spamming. + * + * @param connection_key the connection key ofthe required application + * + * @param policy_app_id application's mobile(policy) identifier. + * + * @return true in case application is allowed to register, false otherwise. + */ + virtual bool IsApplicationForbidden(uint32_t connection_key, + const std::string& policy_app_id) const = 0; + + virtual resumption::ResumeCtrl& resume_controller() = 0 ; + /* + * @brief Converts connection string transport type representation + * to HMI Common_TransportType + * + * @param transport_type String representing connection type + * + * @return Corresponding HMI TransporType value + */ + virtual hmi_apis::Common_TransportType::eType GetDeviceTransportType( + const std::string& transport_type) = 0; + + /** + * @brief method adds application + * to tts_global_properties_app_list_ + * @param app_id contains application which will + * send TTS global properties after timeout + */ + virtual void AddAppToTTSGlobalPropertiesList(const uint32_t app_id) = 0; + + /** + * Generate grammar ID + * + * @return New grammar ID + */ + virtual uint32_t GenerateGrammarID() = 0; + + virtual policy::DeviceConsent GetUserConsentForDevice( + const std::string& device_id) const = 0; + + /** + * @brief Handle sequence for unauthorized application + * @param app_id Application id + */ + virtual void OnAppUnauthorized(const uint32_t& app_id) = 0; + + virtual bool ActivateApplication(ApplicationSharedPtr app) = 0; + + /** + * @brief Callback calls when application starts/stops data streaming + * @param app_id Streaming application id + * @param service_type Streaming service type + * @param state Shows if streaming started or stopped + */ + virtual void OnAppStreaming(uint32_t app_id, + protocol_handler::ServiceType service_type, + bool state) = 0; + + + /** + * @brief CreateRegularState create regular HMI state for application + * @param app_id + * @param hmi_level of returned state + * @param audio_state of returned state + * @param system_context of returned state + * @return new regular HMI state + */ + virtual HmiStatePtr CreateRegularState( + uint32_t app_id, + mobile_apis::HMILevel::eType hmi_level, + mobile_apis::AudioStreamingState::eType audio_state, + mobile_apis::SystemContext::eType system_context) const = 0; + + virtual void SendAudioPassThroughNotification(uint32_t session_key, + std::vector<uint8_t>& binary_data) = 0; + /** * @brief Checks if application can stream (streaming service is started and * streaming is enabled in application) @@ -238,27 +531,19 @@ class ApplicationManager { * @param service_type Service type to check * @return True if streaming is allowed, false in other case */ - virtual bool CanAppStream( - uint32_t app_id, protocol_handler::ServiceType service_type) const = 0; + virtual bool CanAppStream(uint32_t app_id, + protocol_handler::ServiceType service_type) const = 0; - /** - * @brief ForbidStreaming forbids the stream over the certain application. - * @param app_id the application's id which should stop streaming. - */ - virtual void ForbidStreaming(uint32_t app_id) = 0; + /** + * @brief ForbidStreaming forbid the stream over the certain application. + * @param app_id the application's id which should stop streaming. + */ + virtual void ForbidStreaming(uint32_t app_id) = 0; + + virtual const ApplicationManagerSettings& get_settings() const = 0; + + virtual event_engine::EventDispatcher& event_dispatcher() = 0; - /* - * @brief Creates AudioPassThru data chunk and inserts it - * to audio_pass_thru_messages_ - * - * @param session_key Id of application for which - * audio pass thru should be sent - * - * @param binary_data AudioPassThru data chunk - */ - virtual void SendAudioPassThroughNotification(uint32_t session_key, - std::vector<uint8_t>& binary_data) = 0; - virtual policy::PolicyHandlerInterface& GetPolicyHandler() = 0; }; } // namespace application_manager 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 2134fd3b18..6b286e5af6 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 @@ -48,7 +48,10 @@ #include "application_manager/request_controller.h" #include "application_manager/resumption/resume_ctrl.h" #include "application_manager/vehicle_info_data.h" -#include "application_manager/state_controller.h" +#include "application_manager/state_controller_impl.h" +#include "application_manager/application_manager_settings.h" +#include "application_manager/event_engine/event_dispatcher_impl.h" + #include "protocol_handler/protocol_observer.h" #include "protocol_handler/protocol_handler.h" #include "hmi_message_handler/hmi_message_observer.h" @@ -83,7 +86,6 @@ #include "utils/threads/thread.h" #include "utils/threads/message_loop_thread.h" #include "utils/lock.h" -#include "utils/singleton.h" #include "utils/data_accessor.h" #include "utils/timer.h" @@ -170,13 +172,13 @@ struct MessageToHmi : public utils::SharedPtr<Message> { }; // Short type names for prioritized message queues -typedef threads::MessageLoopThread<utils::PrioritizedQueue<MessageFromMobile>> +typedef threads::MessageLoopThread<utils::PrioritizedQueue<MessageFromMobile> > FromMobileQueue; -typedef threads::MessageLoopThread<utils::PrioritizedQueue<MessageToMobile>> +typedef threads::MessageLoopThread<utils::PrioritizedQueue<MessageToMobile> > ToMobileQueue; -typedef threads::MessageLoopThread<utils::PrioritizedQueue<MessageFromHmi>> +typedef threads::MessageLoopThread<utils::PrioritizedQueue<MessageFromHmi> > FromHmiQueue; -typedef threads::MessageLoopThread<utils::PrioritizedQueue<MessageToHmi>> +typedef threads::MessageLoopThread<utils::PrioritizedQueue<MessageToHmi> > ToHmiQueue; // AudioPassThru @@ -189,6 +191,7 @@ typedef threads::MessageLoopThread<RawAudioDataQueue> AudioPassThruQueue; } CREATE_LOGGERPTR_GLOBAL(logger_, "ApplicationManager") typedef std::vector<std::string> RPCParams; +typedef utils::SharedPtr<timer::Timer> TimerSPtr; class ApplicationManagerImpl : public ApplicationManager, @@ -203,16 +206,18 @@ class ApplicationManagerImpl public impl::ToMobileQueue::Handler, public impl::FromHmiQueue::Handler, public impl::ToHmiQueue::Handler, - public impl::AudioPassThruQueue::Handler, + public impl::AudioPassThruQueue::Handler #ifdef TELEMETRY_MONITOR - public telemetry_monitor::TelemetryObservable<AMTelemetryObserver>, + , public telemetry_monitor::TelemetryObservable<AMTelemetryObserver> #endif // TELEMETRY_MONITOR - public utils::Singleton<ApplicationManagerImpl> { +{ friend class ResumeCtrl; friend class CommandImpl; public: + ApplicationManagerImpl(const ApplicationManagerSettings& am_settings, + const policy::PolicySettings& policy_settings); ~ApplicationManagerImpl(); /** @@ -228,47 +233,34 @@ class ApplicationManagerImpl **/ bool Stop() OVERRIDE; - ///////////////////////////////////////////////////// - DataAccessor<ApplicationSet> applications() const OVERRIDE; - ApplicationSharedPtr application(uint32_t app_id) const; + ApplicationSharedPtr application(uint32_t app_id) const OVERRIDE; + + ApplicationSharedPtr active_application() const OVERRIDE; + + ApplicationSharedPtr application_by_hmi_app( + uint32_t hmi_app_id) const OVERRIDE; ApplicationSharedPtr application_by_policy_id( - const std::string& policy_app_id) const; - ApplicationSharedPtr active_application() const; - std::vector<ApplicationSharedPtr> applications_by_button(uint32_t button); - std::vector<ApplicationSharedPtr> applications_by_ivi(uint32_t vehicle_info); - std::vector<ApplicationSharedPtr> applications_with_navi(); + const std::string& policy_app_id) const OVERRIDE; - /** - * @brief Returns media application with LIMITED HMI Level if exist. - * - * @return Shared pointer to application if application does not - * exist returns empty shared pointer. - */ - ApplicationSharedPtr get_limited_media_application() const; + std::vector<ApplicationSharedPtr> applications_by_button( + uint32_t button) OVERRIDE; + std::vector<ApplicationSharedPtr> applications_with_navi() OVERRIDE; - /** - * @brief Returns navigation application with LIMITED HMI Level if exist. - * - * @return Shared pointer to application if application does not - * exist returns empty shared pointer - */ - ApplicationSharedPtr get_limited_navi_application() const; + ApplicationSharedPtr get_limited_media_application() const OVERRIDE; + ApplicationSharedPtr get_limited_navi_application() const OVERRIDE; + ApplicationSharedPtr get_limited_voice_application() const OVERRIDE; - /** - * @brief Returns voice communication application with LIMITED HMI Level if - * exist. - * - * @return Shared pointer to application if application does not - * exist returns empty shared pointer - */ - ApplicationSharedPtr get_limited_voice_application() const; + uint32_t application_id(const int32_t correlation_id) OVERRIDE; + void set_application_id(const int32_t correlation_id, + const uint32_t app_id) OVERRIDE; void OnHMILevelChanged(uint32_t app_id, mobile_apis::HMILevel::eType from, mobile_apis::HMILevel::eType to) OVERRIDE; - void SendHMIStatusNotification(const ApplicationSharedPtr app) OVERRIDE; + void SendHMIStatusNotification( + const utils::SharedPtr<Application> app) OVERRIDE; /** * @brief Checks if application with the same HMI type * (media, voice communication or navi) exists @@ -286,31 +278,31 @@ class ApplicationManagerImpl * @return true if Application is subscribed for way points * otherwise false */ - bool IsAppSubscribedForWayPoints(const uint32_t app_id) const; + bool IsAppSubscribedForWayPoints(const uint32_t app_id) const OVERRIDE; /** * @brief Subscribe Application for way points * @param Application AppID */ - void SubscribeAppForWayPoints(const uint32_t app_id); + void SubscribeAppForWayPoints(const uint32_t app_id) OVERRIDE; /** * @brief Unsubscribe Application for way points * @param Application AppID */ - void UnsubscribeAppFromWayPoints(const uint32_t app_id); + void UnsubscribeAppFromWayPoints(const uint32_t app_id) OVERRIDE; /** * @brief Is Any Application is subscribed for way points * @return true if some app is subscribed otherwise false */ - bool IsAnyAppSubscribedForWayPoints() const; + bool IsAnyAppSubscribedForWayPoints() const OVERRIDE; /** * @brief Get subscribed for way points * @return reference to set of subscribed apps for way points */ - const std::set<int32_t> GetAppsSubscribedForWayPoints() const; + const std::set<int32_t> GetAppsSubscribedForWayPoints() const OVERRIDE; /** * @brief Notifies all components interested in Vehicle Data update @@ -320,12 +312,12 @@ class ApplicationManagerImpl * @param new value (for integer values currently) of vehicle data */ std::vector<ApplicationSharedPtr> IviInfoUpdated(VehicleDataType vehicle_info, - int value); + int value) OVERRIDE; void OnApplicationRegistered(ApplicationSharedPtr app) OVERRIDE; - ///////////////////////////////////////////////////// HMICapabilities& hmi_capabilities(); + const HMICapabilities& hmi_capabilities() const; /** * @brief ProcessQueryApp executes logic related to QUERY_APP system request. @@ -335,9 +327,9 @@ class ApplicationManagerImpl * @param connection_key connection key for app, which sent system request */ void ProcessQueryApp(const smart_objects::SmartObject& sm_object, - const uint32_t connection_key); + const uint32_t connection_key) OVERRIDE; - bool is_attenuated_supported() OVERRIDE; + bool is_attenuated_supported() const OVERRIDE; #ifdef TELEMETRY_MONITOR /** @@ -345,12 +337,11 @@ class ApplicationManagerImpl * * @param observer - pointer to observer */ - void SetTelemetryObserver(AMTelemetryObserver* observer); + void SetTelemetryObserver(AMTelemetryObserver* observer) OVERRIDE; #endif // TELEMETRY_MONITOR - ApplicationSharedPtr RegisterApplication( - const utils::SharedPtr<smart_objects::SmartObject>& - request_for_registration); + ApplicationSharedPtr RegisterApplication(const utils::SharedPtr< + smart_objects::SmartObject>& request_for_registration) OVERRIDE; /* * @brief Closes application by id * @@ -364,13 +355,13 @@ class ApplicationManagerImpl void UnregisterApplication(const uint32_t& app_id, mobile_apis::Result::eType reason, bool is_resuming = false, - bool is_unexpected_disconnect = false); + bool is_unexpected_disconnect = false) OVERRIDE; /** * @brief Handle sequence for unauthorized application * @param app_id Application id */ - void OnAppUnauthorized(const uint32_t& app_id); + void OnAppUnauthorized(const uint32_t& app_id) OVERRIDE; /* * @brief Sets unregister reason for closing all registered applications @@ -379,14 +370,15 @@ class ApplicationManagerImpl * @param reason Describes the reason for HU switching off */ void SetUnregisterAllApplicationsReason( - mobile_api::AppInterfaceUnregisteredReason::eType reason); + mobile_api::AppInterfaceUnregisteredReason::eType reason) OVERRIDE; /* * @brief Called on Master_reset or Factory_defaults * when User chooses to reset HU. * Resets Policy Table if applicable. */ - void HeadUnitReset(mobile_api::AppInterfaceUnregisteredReason::eType reason); + void HeadUnitReset( + mobile_api::AppInterfaceUnregisteredReason::eType reason) OVERRIDE; /* * @brief Closes all registered applications @@ -395,7 +387,7 @@ class ApplicationManagerImpl bool RemoveAppDataFromHMI(ApplicationSharedPtr app); bool LoadAppDataToHMI(ApplicationSharedPtr app); - bool ActivateApplication(ApplicationSharedPtr app); + bool ActivateApplication(ApplicationSharedPtr app) OVERRIDE; /** * @brief Put application in FULL HMI Level if possible, @@ -406,28 +398,28 @@ class ApplicationManagerImpl */ mobile_api::HMILevel::eType IsHmiLevelFullAllowed(ApplicationSharedPtr app); - void ConnectToDevice(const std::string& device_mac); - void OnHMIStartedCooperation(); + void ConnectToDevice(const std::string& device_mac) OVERRIDE; + void OnHMIStartedCooperation() OVERRIDE; /* * @brief Returns unique correlation ID for HMI request * * @return Unique correlation ID */ - uint32_t GetNextHMICorrelationID(); + uint32_t GetNextHMICorrelationID() OVERRIDE; /* @brief Starts audio passthru process * * @return true on success, false if passthru is already in process */ - bool begin_audio_pass_thru(); + bool BeginAudioPassThrough() OVERRIDE; /* * @brief Finishes already started audio passthru process * * @return true on success, false if passthru is not active */ - bool end_audio_pass_thru(); + bool EndAudioPassThrough() OVERRIDE; /* * @brief Retrieves driver distraction state @@ -441,7 +433,7 @@ class ApplicationManagerImpl * * @param state New state to be set */ - void set_driver_distraction(bool is_distracting); + void set_driver_distraction(bool is_distracting) OVERRIDE; /* * @brief Retrieves if VR session has started @@ -469,7 +461,7 @@ class ApplicationManagerImpl * * @param allowed SDL access to all mobile apps */ - void set_all_apps_allowed(const bool& allowed); + void SetAllAppsAllowed(const bool& allowed) OVERRIDE; /** * @brief CreateRegularState create regular HMI state for application @@ -483,7 +475,7 @@ class ApplicationManagerImpl uint32_t app_id, mobile_apis::HMILevel::eType hmi_level, mobile_apis::AudioStreamingState::eType audio_state, - mobile_apis::SystemContext::eType system_context) const; + mobile_apis::SystemContext::eType system_context) const OVERRIDE; /** * @brief SetState set regular audio state @@ -515,7 +507,7 @@ class ApplicationManagerImpl "Application with appID=" << app_id << " does not exist"); return; } - state_ctrl_.SetRegularState<SendActivateApp>(app, new_state); + state_ctrl_.SetRegularState(app, new_state, SendActivateApp); } /** @@ -531,7 +523,7 @@ class ApplicationManagerImpl "Application with appID=" << app_id << " does not exist"); return; } - state_ctrl_.SetRegularState<SendActivateApp>(app, hmi_level); + state_ctrl_.SetRegularState(app, hmi_level, SendActivateApp); } /** @@ -551,7 +543,7 @@ class ApplicationManagerImpl "Application with appID=" << app_id << " does not exist"); return; } - state_ctrl_.SetRegularState<SendActivateApp>(app, hmi_level, audio_state); + state_ctrl_.SetRegularState(app, hmi_level, audio_state, SendActivateApp); } /** @@ -572,8 +564,8 @@ class ApplicationManagerImpl "Application with appID=" << app_id << " does not exist"); return; } - state_ctrl_.SetRegularState<SendActivateApp>( - app, hmi_level, audio_state, system_context); + state_ctrl_.SetRegularState( + app, hmi_level, audio_state, system_context, SendActivateApp); } /** @@ -622,7 +614,7 @@ class ApplicationManagerImpl state_ctrl_.SetRegularState(app, state); } - /** + /** * @brief Checks, if particular state is active * @param state_id State * @return True, if state is active, otherwise - false @@ -642,7 +634,7 @@ class ApplicationManagerImpl * for app with HMI level BACKGROUND. */ void OnUpdateHMIAppType( - std::map<std::string, std::vector<std::string>> app_hmi_types) OVERRIDE; + std::map<std::string, std::vector<std::string> > app_hmi_types) OVERRIDE; /* * @brief Starts audio pass thru thread @@ -659,14 +651,14 @@ class ApplicationManagerImpl int32_t max_duration, int32_t sampling_rate, int32_t bits_per_sample, - int32_t audio_type); + int32_t audio_type) OVERRIDE; /* * @brief Terminates audio pass thru thread * @param application_key Id of application for which * audio pass thru should be stopped */ - void StopAudioPassThru(int32_t application_key); + void StopAudioPassThru(int32_t application_key) OVERRIDE; /* * @brief Creates AudioPassThru data chunk and inserts it @@ -678,7 +670,7 @@ class ApplicationManagerImpl * @param binary_data AudioPassThru data chunk */ void SendAudioPassThroughNotification(uint32_t session_key, - std::vector<uint8_t>& binary_data); + std::vector<uint8_t>& binary_data) OVERRIDE; std::string GetDeviceName(connection_handler::DeviceHandle handle); @@ -692,12 +684,10 @@ class ApplicationManagerImpl */ hmi_apis::Common_TransportType::eType GetDeviceTransportType( const std::string& transport_type); - ///////////////////////////////////////////////////// void set_hmi_message_handler(hmi_message_handler::HMIMessageHandler* handler); void set_connection_handler(connection_handler::ConnectionHandler* handler); void set_protocol_handler(protocol_handler::ProtocolHandler* handler); - /////////////////////////////////////////////////////// void StartDevicesDiscovery(); @@ -707,20 +697,18 @@ class ApplicationManagerImpl void SendMessageToMobile(const commands::MessageSharedPtr message, bool final_message = false) OVERRIDE; + void SendMessageToHMI(const commands::MessageSharedPtr message) OVERRIDE; + + bool ManageMobileCommand(const commands::MessageSharedPtr message, + commands::Command::CommandOrigin origin) OVERRIDE; + bool ManageHMICommand(const commands::MessageSharedPtr message) OVERRIDE; + /** * @brief TerminateRequest forces termination of request * @param connection_key - application id of request * @param corr_id correlation id of request */ - void TerminateRequest(uint32_t connection_key, uint32_t corr_id); - - bool ManageMobileCommand( - const commands::MessageSharedPtr message, - commands::Command::CommandOrigin origin = commands::Command::ORIGIN_SDL) OVERRIDE; - void SendMessageToHMI(const commands::MessageSharedPtr message) OVERRIDE; - bool ManageHMICommand(const commands::MessageSharedPtr message) OVERRIDE; - - ///////////////////////////////////////////////////////// + void TerminateRequest(uint32_t connection_key, uint32_t corr_id)OVERRIDE; // Overriden ProtocolObserver method void OnMessageReceived( const ::protocol_handler::RawMessagePtr message) OVERRIDE; @@ -736,7 +724,6 @@ class ApplicationManagerImpl // Overriden ConnectionHandlerObserver method void OnDeviceListUpdated( const connection_handler::DeviceMap& device_list) OVERRIDE; - // TODO (EZamakhov): fix all indentations in this file void OnFindNewApplicationsRequest() OVERRIDE; void RemoveDevice( const connection_handler::DeviceHandle& device_handle) OVERRIDE; @@ -760,11 +747,12 @@ class ApplicationManagerImpl security_manager::SSLContext::HandshakeContext GetHandshakeContext( uint32_t key) const OVERRIDE FINAL; #endif // ENABLE_SECURITY - /** - * @ Add notification to collection - * - * @param ptr Reference to shared pointer that point on hmi notification - */ + + /** + * @ Add notification to collection + * + * @param ptr Reference to shared pointer that point on hmi notification + */ void addNotification(const CommandSharedPtr ptr); /** @@ -783,24 +771,8 @@ class ApplicationManagerImpl */ void updateRequestTimeout(uint32_t connection_key, uint32_t mobile_correlation_id, - uint32_t new_timeout_value); + uint32_t new_timeout_value) OVERRIDE; - /* - * @brief Retrieves application id associated whith correlation id - * - * @param correlation_id Correlation ID of the HMI request - * - * @return application id associated whith correlation id - */ - const uint32_t application_id(const int32_t correlation_id); - - /* - * @brief Sets application id correlation id - * - * @param correlation_id Correlation ID of the HMI request - * @param app_id Application ID - */ - void set_application_id(const int32_t correlation_id, const uint32_t app_id); /** * @brief AddPolicyObserver allows to subscribe needed component to events * from policy. @@ -823,7 +795,8 @@ class ApplicationManagerImpl * @return True if streaming is allowed, false in other case */ bool HMILevelAllowsStreaming( - uint32_t app_id, protocol_handler::ServiceType service_type) const; + uint32_t app_id, + protocol_handler::ServiceType service_type) const OVERRIDE; /** * @brief Checks if application can stream (streaming service is started and @@ -833,19 +806,19 @@ class ApplicationManagerImpl * @return True if streaming is allowed, false in other case */ bool CanAppStream(uint32_t app_id, - protocol_handler::ServiceType service_type) const; + protocol_handler::ServiceType service_type) const OVERRIDE; /** * @brief Ends opened navi services (audio/video) for application * @param app_id Application id */ - void EndNaviServices(uint32_t app_id); + void EndNaviServices(uint32_t app_id) OVERRIDE; /** - * @brief ForbidStreaming forbids the stream over the certain application. + * @brief ForbidStreaming forbid the stream over the certain application. * @param app_id the application's id which should stop streaming. */ - void ForbidStreaming(uint32_t app_id); + void ForbidStreaming(uint32_t app_id) OVERRIDE; /** * @brief Callback calls when application starts/stops data streaming @@ -855,7 +828,7 @@ class ApplicationManagerImpl */ void OnAppStreaming(uint32_t app_id, protocol_handler::ServiceType service_type, - bool state); + bool state) OVERRIDE; mobile_api::HMILevel::eType GetDefaultHmiLevel( ApplicationConstSharedPtr application) const; @@ -864,7 +837,7 @@ class ApplicationManagerImpl * Getter for resume_controller * @return Resume Controller */ - resumption::ResumeCtrl& resume_controller() { + resumption::ResumeCtrl& resume_controller() OVERRIDE{ return resume_ctrl_; } @@ -873,14 +846,14 @@ class ApplicationManagerImpl * * @return New grammar ID */ - uint32_t GenerateGrammarID(); + uint32_t GenerateGrammarID() OVERRIDE; /** * Generate new HMI application ID * * @return New HMI application ID */ - uint32_t GenerateNewHMIAppID(); + uint32_t GenerateNewHMIAppID()OVERRIDE; /** * @brief Parse smartObject and replace mobile app Id by HMI app ID @@ -911,7 +884,7 @@ class ApplicationManagerImpl mobile_apis::Result::eType SaveBinary(const std::vector<uint8_t>& binary_data, const std::string& file_path, const std::string& file_name, - const int64_t offset); + const int64_t offset) OVERRIDE; /** * @brief Get available app space @@ -923,7 +896,7 @@ class ApplicationManagerImpl /* * @brief returns true if HMI is cooperating */ - bool IsHMICooperating() const; + bool IsHMICooperating() const OVERRIDE; /** * @brief Method used to send default app tts globalProperties @@ -937,7 +910,7 @@ class ApplicationManagerImpl * @param app_id contains application which will * send TTS global properties after timeout */ - void AddAppToTTSGlobalPropertiesList(const uint32_t app_id); + void AddAppToTTSGlobalPropertiesList(const uint32_t app_id) OVERRIDE; /** * @brief method removes application @@ -945,7 +918,7 @@ class ApplicationManagerImpl * @param app_id contains application which will * send TTS global properties after timeout */ - void RemoveAppFromTTSGlobalPropertiesList(const uint32_t app_id); + void RemoveAppFromTTSGlobalPropertiesList(const uint32_t app_id) OVERRIDE; /** * @brief method adds application in FULL and LIMITED state @@ -961,14 +934,9 @@ class ApplicationManagerImpl */ void ResetPhoneCallAppList(); - /** - * Function used only by HMI request/response/notification base classes - * to change HMI app id to Mobile app id and vice versa. - * Dot use it inside Core - */ - ApplicationSharedPtr application_by_hmi_app(uint32_t hmi_app_id) const; // TODO(AOleynik): Temporary added, to fix build. Should be reworked. connection_handler::ConnectionHandler& connection_handler() const OVERRIDE; + protocol_handler::ProtocolHandler& protocol_handler() const OVERRIDE; virtual policy::PolicyHandlerInterface& GetPolicyHandler() OVERRIDE { return policy_handler_; @@ -988,7 +956,7 @@ class ApplicationManagerImpl mobile_apis::HMILevel::eType hmi_level, mobile_apis::FunctionID::eType function_id, const RPCParams& rpc_params, - CommandParametersPermissions* params_permissions = NULL); + CommandParametersPermissions* params_permissions = NULL) OVERRIDE; /* * @brief Function Should be called when Low Voltage is occured */ @@ -1005,12 +973,15 @@ class ApplicationManagerImpl * * @param connection_key the connection key ofthe required application * - * @param mobile_app_id application's mobile(policy) identifier. + * @param policy_app_id application's mobile(policy) identifier. * * @return true in case application is allowed to register, false otherwise. */ bool IsApplicationForbidden(uint32_t connection_key, - const std::string& mobile_app_id); + const std::string& policy_app_id) const OVERRIDE; + + policy::DeviceConsent GetUserConsentForDevice( + const std::string& device_id) const OVERRIDE; struct ApplicationsAppIdSorter { bool operator()(const ApplicationSharedPtr lhs, @@ -1019,97 +990,18 @@ class ApplicationManagerImpl } }; - struct ApplicationsMobileAppIdSorter { + struct ApplicationsPolicyAppIdSorter { bool operator()(const ApplicationSharedPtr lhs, const ApplicationSharedPtr rhs) { - if (lhs->mobile_app_id() == rhs->mobile_app_id()) { - return lhs->device() < rhs->device(); - } - return lhs->mobile_app_id() < rhs->mobile_app_id(); + return lhs->policy_app_id() < rhs->policy_app_id(); } }; // typedef for Applications list - typedef std::set<ApplicationSharedPtr, ApplicationsAppIdSorter> ApplictionSet; - - typedef std::multiset<ApplicationSharedPtr, ApplicationsMobileAppIdSorter> + typedef std::set<ApplicationSharedPtr, ApplicationsPolicyAppIdSorter> AppsWaitRegistrationSet; typedef std::set<std::string> ForbiddenApps; - // typedef for Applications list iterator - - DataAccessor<AppsWaitRegistrationSet> apps_waiting_for_registration() const; - ApplicationConstSharedPtr waiting_app(const uint32_t hmi_id) const; - - /** - * Class for thread-safe access to applications list - */ - class ApplicationListAccessor : public DataAccessor<ApplicationSet> { - public: - /** - * @brief ApplicationListAccessor class constructor - */ - ApplicationListAccessor() - : DataAccessor<ApplicationSet>( - ApplicationManagerImpl::instance()->applications_, - ApplicationManagerImpl::instance()->applications_list_lock_) {} - - ~ApplicationListAccessor(); - - /** - * @brief thread-safe getter for applications - * @return applications list - */ - const ApplicationSet& applications() const { - return GetData(); - } - - ApplicationSetConstIt begin() { - return applications().begin(); - } - - ApplicationSetConstIt end() { - return applications().end(); - } - - template <class UnaryPredicate> - ApplicationSharedPtr Find(UnaryPredicate finder) { - ApplicationSharedPtr result; - ApplicationSetConstIt it = std::find_if(begin(), end(), finder); - if (it != end()) { - result = *it; - } - return result; - } - - template <class UnaryPredicate> - std::vector<ApplicationSharedPtr> FindAll(UnaryPredicate finder) { - std::vector<ApplicationSharedPtr> result; - ApplicationSetConstIt it = std::find_if(begin(), end(), finder); - while (it != end()) { - result.push_back(*it); - it = std::find_if(++it, end(), finder); - } - return result; - } - - void Erase(ApplicationSharedPtr app_to_remove) { - ApplicationManagerImpl::instance()->applications_.erase(app_to_remove); - } - - void Insert(ApplicationSharedPtr app_to_insert) { - ApplicationManagerImpl::instance()->applications_.insert(app_to_insert); - } - - bool Empty() { - return ApplicationManagerImpl::instance()->applications_.empty(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(ApplicationListAccessor); - }; - - friend class ApplicationListAccessor; struct AppIdPredicate { uint32_t app_id_; @@ -1127,12 +1019,12 @@ class ApplicationManagerImpl } }; - struct MobileAppIdPredicate { + struct PolicyAppIdPredicate { std::string policy_app_id_; - MobileAppIdPredicate(const std::string& policy_app_id) + PolicyAppIdPredicate(const std::string& policy_app_id) : policy_app_id_(policy_app_id) {} bool operator()(const ApplicationSharedPtr app) const { - return app ? policy_app_id_ == app->mobile_app_id() : false; + return app ? policy_app_id_ == app->policy_app_id() : false; } }; @@ -1175,10 +1067,18 @@ class ApplicationManagerImpl } }; + struct GrammarIdPredicate { + uint32_t grammar_id_; + GrammarIdPredicate(uint32_t grammar_id) : grammar_id_(grammar_id) {} + bool operator()(const ApplicationSharedPtr app) const { + return app ? grammar_id_ == app->get_grammar_id() : false; + } + }; + /** * @brief Sends UpdateAppList notification to HMI */ - void SendUpdateAppList(); + void SendUpdateAppList() OVERRIDE; /** * @brief Marks applications received through QueryApps as should be @@ -1187,20 +1087,24 @@ class ApplicationManagerImpl * @param handle, device handle */ void MarkAppsGreyOut(const connection_handler::DeviceHandle handle, - bool is_greyed_out); + bool is_greyed_out) OVERRIDE; /** * @brief Checks, if apps list had been queried already from certain device * @param handle, Device handle * @return true, if list had been queried already, otherwise - false */ - bool IsAppsQueriedFrom(const connection_handler::DeviceHandle handle) const; + bool IsAppsQueriedFrom(const connection_handler::DeviceHandle handle) const OVERRIDE; - bool IsStopping() const { + bool IsStopping() const OVERRIDE { return is_stopping_; } - private: + StateController& state_controller() OVERRIDE; + const ApplicationManagerSettings& get_settings() const OVERRIDE; + virtual event_engine::EventDispatcher& event_dispatcher() OVERRIDE; + +private: /** * @brief PullLanguagesInfo allows to pull information about languages. * @@ -1213,8 +1117,6 @@ class ApplicationManagerImpl smart_objects::SmartObject& ttsName, smart_objects::SmartObject& vrSynonym); - ApplicationManagerImpl(); - /** * @brief Method transforms string to AppHMIType * @param str contains string AppHMIType @@ -1266,7 +1168,8 @@ class ApplicationManagerImpl template <typename ApplicationList> void PrepareApplicationListSO(ApplicationList app_list, - smart_objects::SmartObject& applications) { + smart_objects::SmartObject& applications, + ApplicationManager& app_mngr) { CREATE_LOGGERPTR_LOCAL(logger_, "ApplicationManager"); smart_objects::SmartArray* app_array = applications.asArray(); @@ -1282,7 +1185,7 @@ class ApplicationManagerImpl const protocol_handler::SessionObserver& session_observer = connection_handler().get_session_observer(); if (MessageHelper::CreateHMIApplicationStruct( - *it, session_observer, GetPolicyHandler(), &hmi_application)) { + *it, session_observer, GetPolicyHandler(), &hmi_application, app_mngr)) { applications[app_count++] = hmi_application; } else { LOG4CXX_DEBUG(logger_, "Can't CreateHMIApplicationStruct "); @@ -1294,8 +1197,6 @@ class ApplicationManagerImpl } } - void ClearTTSGlobalPropertiesList(); - void OnApplicationListUpdateTimer(); /** @@ -1328,22 +1229,21 @@ class ApplicationManagerImpl * 1st value - is video service opened or not * 2nd value - is audio service opened or not */ - typedef std::map<uint32_t, std::pair<bool, bool>> NaviServiceStatusMap; + typedef std::map<uint32_t, std::pair<bool, bool> > NaviServiceStatusMap; -typedef utils::SharedPtr<timer::Timer> TimerSPtr; /** * @brief GetHashedAppID allows to obtain unique application id as a string. * It concatenates device mac and application id to obtain unique id. * * @param connection_key connection key for which need to obtain device mac; * - * @param mobile_app_id mobile(policy) application id on particular device. + * @param policy_app_id mobile(policy) application id on particular device. * This parameter will be concatenated with device id. * * @return unique aplication identifier. */ std::string GetHashedAppID(uint32_t connection_key, - const std::string& mobile_app_id); + const std::string& policy_app_id) const; /** * @brief Removes suspended and stopped timers from timer pool @@ -1440,7 +1340,10 @@ typedef utils::SharedPtr<timer::Timer> TimerSPtr; void RemoveAppsWaitingForRegistration( const connection_handler::DeviceHandle handle); + void ClearTTSGlobalPropertiesList(); + private: + const ApplicationManagerSettings& settings_; /** * @brief List of applications */ @@ -1476,6 +1379,8 @@ typedef utils::SharedPtr<timer::Timer> TimerSPtr; bool is_vr_session_strated_; bool hmi_cooperating_; bool is_all_apps_allowed_; + + event_engine::EventDispatcherImpl event_dispatcher_; media_manager::MediaManager* media_manager_; hmi_message_handler::HMIMessageHandler* hmi_handler_; @@ -1522,8 +1427,8 @@ typedef utils::SharedPtr<timer::Timer> TimerSPtr; std::vector<TimerSPtr> timer_pool_; sync_primitives::Lock timer_pool_lock_; - sync_primitives::Lock stopping_flag_lock_; - StateController state_ctrl_; + sync_primitives::Lock stopping_application_mng_lock_; + StateControllerImpl state_ctrl_; #ifdef TELEMETRY_MONITOR AMTelemetryObserver* metric_observer_; @@ -1534,10 +1439,10 @@ typedef utils::SharedPtr<timer::Timer> TimerSPtr; Timer tts_global_properties_timer_; bool is_low_voltage_; + volatile bool is_stopping_; DISALLOW_COPY_AND_ASSIGN(ApplicationManagerImpl); - FRIEND_BASE_SINGLETON_CLASS(ApplicationManagerImpl); }; bool ApplicationManagerImpl::vr_session_started() const { diff --git a/src/components/application_manager/include/application_manager/commands/command.h b/src/components/application_manager/include/application_manager/commands/command.h index 238e0b71c7..4932fa1ddb 100644 --- a/src/components/application_manager/include/application_manager/commands/command.h +++ b/src/components/application_manager/include/application_manager/commands/command.h @@ -32,19 +32,14 @@ #ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_COMMAND_H_ #define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_COMMAND_H_ - -#include "utils/shared_ptr.h" +#include <stdint.h> #include "smart_objects/smart_object.h" -#include "application_manager/event_engine/event_observer.h" -#include "application_manager/smart_object_keys.h" +#include "utils/shared_ptr.h" namespace application_manager { -/** - * @brief SmartObject type - **/ - namespace smart_objects = NsSmartDeviceLink::NsSmartObjects; +class ApplicationManager; namespace commands { /** @@ -128,7 +123,6 @@ class Command { }; typedef smart_objects::SmartObjectSPtr MessageSharedPtr; - } // namespace commands } // namespace application_manager diff --git a/src/components/application_manager/include/application_manager/commands/command_impl.h b/src/components/application_manager/include/application_manager/commands/command_impl.h index 6cc8f82330..03f03a6a50 100644 --- a/src/components/application_manager/include/application_manager/commands/command_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_impl.h @@ -34,6 +34,9 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_COMMAND_IMPL_H_ #include "application_manager/commands/command.h" +#include "application_manager/event_engine/event_observer.h" +#include "application_manager/application_manager.h" +#include "application_manager/smart_object_keys.h" #include "utils/logger.h" namespace application_manager { @@ -49,7 +52,6 @@ struct CommandParametersPermissions { }; namespace commands { - /** * @brief Class is intended to encapsulate RPC as an object **/ @@ -60,7 +62,8 @@ class CommandImpl : public Command { * * @param message Incoming SmartObject message **/ - explicit CommandImpl(const MessageSharedPtr& message); + explicit CommandImpl(const MessageSharedPtr& message, + ApplicationManager& application_manager); /** * @brief CommandImpl class destructor @@ -125,17 +128,13 @@ class CommandImpl : public Command { * If request need to terminate itself, it should override this function false * @return allowed_to_terminate_ value */ - virtual bool AllowedToTerminate() { - return allowed_to_terminate_; - } + virtual bool AllowedToTerminate(); /** * @brief SetAllowedToTerminate set up allowed to terminate flag. * If true, request controller will terminate request on response */ - virtual void SetAllowedToTerminate(bool allowed) { - allowed_to_terminate_ = allowed; - } + virtual void SetAllowedToTerminate(bool allowed); // members static const int32_t hmi_protocol_type_; @@ -143,15 +142,32 @@ class CommandImpl : public Command { static const int32_t protocol_version_; protected: + /** + * @brief Parse smartObject and replace mobile app Id by HMI app ID + * + * @param message Smartobject to be parsed + */ + void ReplaceMobileByHMIAppId(smart_objects::SmartObject& message); + + /** + * @brief Parse smartObject and replace HMI app ID by mobile app Id + * + * @param message Smartobject to be parsed + */ + void ReplaceHMIByMobileAppId(smart_objects::SmartObject& message); + MessageSharedPtr message_; uint32_t default_timeout_; bool allowed_to_terminate_; + ApplicationManager& application_manager_; + #ifdef ENABLE_LOG static log4cxx::LoggerPtr logger_; #endif // ENABLE_LOG private: DISALLOW_COPY_AND_ASSIGN(CommandImpl); + }; } // namespace commands diff --git a/src/components/application_manager/include/application_manager/commands/command_notification_from_mobile_impl.h b/src/components/application_manager/include/application_manager/commands/command_notification_from_mobile_impl.h index 9f95a52850..ffe909f96a 100644 --- a/src/components/application_manager/include/application_manager/commands/command_notification_from_mobile_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_notification_from_mobile_impl.h @@ -47,7 +47,8 @@ namespace commands { class CommandNotificationFromMobileImpl : public CommandImpl { public: - explicit CommandNotificationFromMobileImpl(const MessageSharedPtr& message); + explicit CommandNotificationFromMobileImpl(const MessageSharedPtr& message, + ApplicationManager& application_manager); virtual ~CommandNotificationFromMobileImpl(); virtual bool Init(); virtual bool CleanUp(); diff --git a/src/components/application_manager/include/application_manager/commands/command_notification_impl.h b/src/components/application_manager/include/application_manager/commands/command_notification_impl.h index 7d0d11af89..db105dce1c 100644 --- a/src/components/application_manager/include/application_manager/commands/command_notification_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_notification_impl.h @@ -47,7 +47,8 @@ namespace commands { class CommandNotificationImpl : public CommandImpl { public: - explicit CommandNotificationImpl(const MessageSharedPtr& message); + explicit CommandNotificationImpl(const MessageSharedPtr& message, + ApplicationManager& application_manager); virtual ~CommandNotificationImpl(); virtual bool Init(); virtual bool CleanUp(); diff --git a/src/components/application_manager/include/application_manager/commands/command_request_impl.h b/src/components/application_manager/include/application_manager/commands/command_request_impl.h index 164871e1af..adba63e000 100644 --- a/src/components/application_manager/include/application_manager/commands/command_request_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_request_impl.h @@ -54,7 +54,8 @@ class CommandRequestImpl : public CommandImpl, public: enum RequestState { kAwaitingHMIResponse = 0, kTimedOut, kCompleted }; - explicit CommandRequestImpl(const MessageSharedPtr& message); + explicit CommandRequestImpl(const MessageSharedPtr& message, + ApplicationManager& application_manager); virtual ~CommandRequestImpl(); virtual bool CheckPermissions(); virtual bool Init(); diff --git a/src/components/application_manager/include/application_manager/commands/command_response_impl.h b/src/components/application_manager/include/application_manager/commands/command_response_impl.h index 0c93bf54d4..8c1e7f2efc 100644 --- a/src/components/application_manager/include/application_manager/commands/command_response_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_response_impl.h @@ -48,7 +48,8 @@ namespace commands { class CommandResponseImpl : public CommandImpl { public: - explicit CommandResponseImpl(const MessageSharedPtr& message); + explicit CommandResponseImpl(const MessageSharedPtr& message, + ApplicationManager& application_manager); virtual ~CommandResponseImpl(); virtual bool Init(); virtual bool CleanUp(); diff --git a/src/components/application_manager/include/application_manager/event_engine/event.h b/src/components/application_manager/include/application_manager/event_engine/event.h index 18c9a972e9..7e90227bd7 100644 --- a/src/components/application_manager/include/application_manager/event_engine/event.h +++ b/src/components/application_manager/include/application_manager/event_engine/event.h @@ -41,6 +41,8 @@ namespace application_manager { namespace event_engine { +class EventDispatcher; + namespace smart_objects = NsSmartDeviceLink::NsSmartObjects; class Event { @@ -65,7 +67,7 @@ class Event { * @brief Sends synchronously event to all subscribers. * */ - void raise(); + void raise(EventDispatcher& event_dispatcher); /* * @brief Provides event ID diff --git a/src/components/application_manager/include/application_manager/event_engine/event_dispatcher_impl.h b/src/components/application_manager/include/application_manager/event_engine/event_dispatcher_impl.h index e834889bff..0a58e329b3 100644 --- a/src/components/application_manager/include/application_manager/event_engine/event_dispatcher_impl.h +++ b/src/components/application_manager/include/application_manager/event_engine/event_dispatcher_impl.h @@ -37,7 +37,6 @@ #include <map> #include "utils/lock.h" -#include "utils/singleton.h" #include "application_manager/event_engine/event.h" #include "application_manager/event_engine/event_dispatcher.h" @@ -47,16 +46,33 @@ namespace event_engine { class EventObserver; -class EventDispatcherImpl : public EventDispatcher, - public utils::Singleton<EventDispatcherImpl> { +class EventDispatcherImpl : public EventDispatcher { public: + // Data types section + typedef std::vector<EventObserver*> ObserverVector; + typedef std::map<int32_t, ObserverVector> ObserversMap; + typedef std::map<Event::EventID, ObserversMap> EventObserverMap; + /* + * @brief Destructor + */ + virtual ~EventDispatcherImpl(); + + /* + * @brief Default constructor + */ + EventDispatcherImpl(); + +#ifdef BUILD_TESTS + EventObserverMap get_observers() const { return observers_event_; } + ObserverVector get_observers_list() const { return observers_; } +#endif // BUILD_TESTS /* * @brief Delivers the event to all subscribers * * @param event Received event */ - virtual void raise_event(const Event& event); + void raise_event(const Event& event) OVERRIDE; /* * @brief Subscribe the observer to event @@ -65,9 +81,9 @@ class EventDispatcherImpl : public EventDispatcher, * @param hmi_correlation_id The event HMI correlation ID * @param observer The observer to subscribe for event */ - virtual void add_observer(const Event::EventID& event_id, - int32_t hmi_correlation_id, - EventObserver* const observer); + void add_observer(const Event::EventID& event_id, + int32_t hmi_correlation_id, + EventObserver* const observer) OVERRIDE; /* * @brief Unsubscribes the observer from specific event @@ -75,29 +91,19 @@ class EventDispatcherImpl : public EventDispatcher, * @param event_id The event ID to unsubscribe from * @param observer The observer to be unsubscribed */ - virtual void remove_observer(const Event::EventID& event_id, - EventObserver* const observer); + void remove_observer(const Event::EventID& event_id, + EventObserver* const observer) OVERRIDE; /* * @brief Unsubscribes the observer from all events * * @param observer The observer to be unsubscribed */ - virtual void remove_observer(EventObserver* const observer); - - /* - * @brief Destructor - */ - virtual ~EventDispatcherImpl(); + void remove_observer(EventObserver* const observer) OVERRIDE; private: /* - * @brief Default constructor - */ - EventDispatcherImpl(); - - /* * @brief removes observer * when occurs unsubscribe from event * @param observer to be removed @@ -106,19 +112,12 @@ class EventDispatcherImpl : public EventDispatcher, DISALLOW_COPY_AND_ASSIGN(EventDispatcherImpl); - FRIEND_BASE_SINGLETON_CLASS(EventDispatcherImpl); - - // Data types section - typedef std::vector<EventObserver*> ObserverVector; - typedef std::map<int32_t, ObserverVector> ObserversMap; - typedef std::map<Event::EventID, ObserversMap> EventObserverMap; - + private: // Members section - sync_primitives::Lock state_lock_; - sync_primitives::Lock observer_lock_; - EventObserverMap observers_event_; - ObserverVector observers_; - + sync_primitives::Lock state_lock_; + sync_primitives::Lock observer_lock_; + EventObserverMap observers_event_; + ObserverVector observers_; }; } // namespace event_engine diff --git a/src/components/application_manager/include/application_manager/event_engine/event_observer.h b/src/components/application_manager/include/application_manager/event_engine/event_observer.h index 04e73e3d86..d11591b587 100644 --- a/src/components/application_manager/include/application_manager/event_engine/event_observer.h +++ b/src/components/application_manager/include/application_manager/event_engine/event_observer.h @@ -35,14 +35,14 @@ #include <string> #include "application_manager/event_engine/event.h" -#include "application_manager/event_engine/event_dispatcher_impl.h" namespace application_manager { namespace event_engine { -class EventObserver -{ +class EventDispatcher; +class EventObserver { public: + friend class EventDispatcher; // Typedef for possible Observer ID's from mobile_apis functionID enum typedef unsigned long ObserverID; @@ -51,7 +51,7 @@ class EventObserver * @brief Constructor * */ - EventObserver(); + EventObserver(EventDispatcher& event_dispatcher); /* * @brief Destructor @@ -73,7 +73,6 @@ class EventObserver virtual void on_event(const Event& event) = 0; protected: - /* * @brief Subscribe to an event * @@ -81,8 +80,8 @@ class EventObserver * @param hmi_correlation_id The event HMI correlation ID. * If param is omitted, it means subscription for HMI notification */ - void subscribe_on_event( - const Event::EventID& event_id, int32_t hmi_correlation_id = 0); + void subscribe_on_event(const Event::EventID& event_id, + int32_t hmi_correlation_id = 0); /* * @brief Unsubscribes the observer from specific event @@ -98,8 +97,8 @@ class EventObserver void unsubscribe_from_all_events(); private: - ObserverID id_; + EventDispatcher& event_dispatcher_; DISALLOW_COPY_AND_ASSIGN(EventObserver); }; diff --git a/src/components/application_manager/include/application_manager/hmi_capabilities.h b/src/components/application_manager/include/application_manager/hmi_capabilities.h index 85aaca0f4c..70f7987cf4 100644 --- a/src/components/application_manager/include/application_manager/hmi_capabilities.h +++ b/src/components/application_manager/include/application_manager/hmi_capabilities.h @@ -51,7 +51,7 @@ class LastState; namespace smart_objects = NsSmartDeviceLink::NsSmartObjects; namespace application_manager { -class ApplicationManagerImpl; +class ApplicationManager; class HMICapabilities { @@ -62,7 +62,7 @@ class HMICapabilities { * * @param app_mngr Application manager pointer */ - explicit HMICapabilities(ApplicationManagerImpl* const app_mngr); + explicit HMICapabilities(ApplicationManager& app_mngr); /* * @brief Class destructor @@ -477,7 +477,7 @@ class HMICapabilities { bool is_navigation_supported_; bool is_phone_call_supported_; - ApplicationManagerImpl* app_mngr_; + ApplicationManager& app_mngr_; HMILanguageHandler hmi_language_handler_; DISALLOW_COPY_AND_ASSIGN(HMICapabilities); diff --git a/src/components/application_manager/include/application_manager/hmi_command_factory.h b/src/components/application_manager/include/application_manager/hmi_command_factory.h index 89936e4ca6..0b37c54ea2 100644 --- a/src/components/application_manager/include/application_manager/hmi_command_factory.h +++ b/src/components/application_manager/include/application_manager/hmi_command_factory.h @@ -37,9 +37,7 @@ #include "utils/macro.h" namespace application_manager { - typedef utils::SharedPtr<commands::Command> CommandSharedPtr; - /** * @brief Factory class for command creation **/ @@ -51,7 +49,9 @@ class HMICommandFactory { * @param smartObject SmartObject shared pointer. * @return Pointer to created command object. **/ - static CommandSharedPtr CreateCommand(const commands::MessageSharedPtr& message); + static CommandSharedPtr CreateCommand( + const commands::MessageSharedPtr& message, + ApplicationManager& application_manager); private: HMICommandFactory(); diff --git a/src/components/application_manager/include/application_manager/hmi_language_handler.h b/src/components/application_manager/include/application_manager/hmi_language_handler.h index a16a8fdb0b..fe5d480c79 100644 --- a/src/components/application_manager/include/application_manager/hmi_language_handler.h +++ b/src/components/application_manager/include/application_manager/hmi_language_handler.h @@ -34,12 +34,15 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HMI_LANGUAGE_HANDLER_H_ #include "application_manager/event_engine/event_observer.h" +#include "utils/lock.h" #include "interfaces/HMI_API.h" namespace resumption { class LastState; } namespace application_manager { + +class ApplicationManager; /** * Class is used to handle edge case with slow HMI responses for current * languages. Main idea is to cache values within some persistent storage and @@ -63,7 +66,7 @@ public: /** * @brief Class constructor */ - HMILanguageHandler(); + HMILanguageHandler(ApplicationManager& application_manager); /** * @brief Sets language for interface @@ -174,6 +177,7 @@ private: */ bool is_tts_language_received_; resumption::LastState* last_state_; + ApplicationManager& application_manager_; }; } // namespace application_manager diff --git a/src/components/application_manager/include/application_manager/hmi_state.h b/src/components/application_manager/include/application_manager/hmi_state.h index fbcb5a4f29..ffdb183149 100644 --- a/src/components/application_manager/include/application_manager/hmi_state.h +++ b/src/components/application_manager/include/application_manager/hmi_state.h @@ -70,8 +70,8 @@ class HmiState { STATE_ID_EMBEDDED_NAVI }; - HmiState(uint32_t app_id, ApplicationManager* app_mngr); - HmiState(uint32_t app_id, ApplicationManager* app_mngr, StateID state_id); + HmiState(uint32_t app_id, const ApplicationManager& app_mngr); + HmiState(uint32_t app_id, const ApplicationManager& app_mngr, StateID state_id); virtual ~HmiState() {} @@ -166,7 +166,7 @@ class HmiState { protected: uint32_t app_id_; StateID state_id_; - ApplicationManager* app_mngr_; + const ApplicationManager& app_mngr_; HmiStatePtr parent_; mobile_apis::HMILevel::eType hmi_level_; mobile_apis::AudioStreamingState::eType audio_streaming_state_; @@ -203,9 +203,8 @@ class HmiState { */ class VRHmiState : public HmiState { public: - mobile_apis::AudioStreamingState::eType audio_streaming_state() - const OVERRIDE; - VRHmiState(uint32_t app_id, ApplicationManager* app_mngr); + virtual mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE; + VRHmiState(uint32_t app_id, const ApplicationManager& app_mngr); }; /** @@ -213,9 +212,8 @@ class VRHmiState : public HmiState { */ class TTSHmiState : public HmiState { public: - TTSHmiState(uint32_t app_id, ApplicationManager* app_mngr); - mobile_apis::AudioStreamingState::eType audio_streaming_state() - const OVERRIDE; + TTSHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + virtual mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE; }; /** @@ -224,18 +222,16 @@ class TTSHmiState : public HmiState { */ class NaviStreamingHmiState : public HmiState { public: - NaviStreamingHmiState(uint32_t app_id, ApplicationManager* app_mngr); - mobile_apis::AudioStreamingState::eType audio_streaming_state() - const OVERRIDE; + NaviStreamingHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE; }; /** - * @brief The PhoneCallHmiState class implements logic of PhoneCall temporary - * state + * @brief The PhoneCallHmiState class implements logic of PhoneCall temporary state */ class PhoneCallHmiState : public HmiState { public: - PhoneCallHmiState(uint32_t app_id, ApplicationManager* app_mngr); + PhoneCallHmiState(uint32_t app_id, const ApplicationManager& app_mngr); mobile_apis::HMILevel::eType hmi_level() const OVERRIDE; mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { @@ -249,7 +245,7 @@ class PhoneCallHmiState : public HmiState { */ class SafetyModeHmiState : public HmiState { public: - SafetyModeHmiState(uint32_t app_id, ApplicationManager* app_mngr); + SafetyModeHmiState(uint32_t app_id, const ApplicationManager& app_mngr); mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { return mobile_apis::AudioStreamingState::NOT_AUDIBLE; @@ -262,7 +258,7 @@ class SafetyModeHmiState : public HmiState { */ class DeactivateHMI : public HmiState { public: - DeactivateHMI(uint32_t app_id, ApplicationManager* app_mngr); + DeactivateHMI(uint32_t app_id, const ApplicationManager& app_mngr); mobile_apis::HMILevel::eType hmi_level() const OVERRIDE; mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { @@ -276,7 +272,7 @@ class DeactivateHMI : public HmiState { */ class AudioSource : public HmiState { public: - AudioSource(uint32_t app_id, ApplicationManager* app_mngr); + AudioSource(uint32_t app_id, const ApplicationManager& app_mngr); mobile_apis::HMILevel::eType hmi_level() const OVERRIDE; mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { @@ -290,7 +286,7 @@ class AudioSource : public HmiState { */ class EmbeddedNavi : public HmiState { public: - EmbeddedNavi(uint32_t app_id, ApplicationManager* app_mngr); + EmbeddedNavi(uint32_t app_id, const ApplicationManager& app_mngr); mobile_apis::HMILevel::eType hmi_level() const OVERRIDE; mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { 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 0cc7ed3dba..0b91bcf257 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -81,7 +81,9 @@ class MessageHelper { * (e.g. gps, odometer, fuel_level) */ static void CreateGetVehicleDataRequest( - uint32_t correlation_id, const std::vector<std::string>& params); + const uint32_t correlation_id, + const std::vector<std::string>& params, + ApplicationManager &app_mngr); /** * @brief Create mobile HashUpdateNotification @@ -89,45 +91,31 @@ class MessageHelper { static smart_objects::SmartObjectSPtr CreateHashUpdateNotification( const uint32_t app_id); - static smart_objects::SmartObjectSPtr GetHashUpdateNotification( - const uint32_t app_id); - /** * @brief Sends to mobile HashUpdateNotification */ - static void SendHashUpdateNotification(const uint32_t app_id); + static void SendHashUpdateNotification(const uint32_t app_id, ApplicationManager &app_mngr); /** - * @brief Sends OnAppInterfaceUnregistered notification to mobile - * - *@param connection_key Connection key - *@param reason Reason - * - **/ - static void SendOnAppInterfaceUnregisteredNotificationToMobile( - int32_t connection_key, - mobile_apis::AppInterfaceUnregisteredReason::eType reason); - - /** - * @brief Sends OnLanguageChange notification to application - * @param connection_key Connection key of application - */ - static void SendOnLanguageChangeToMobile(uint32_t connection_key); + * @brief Sends OnLanguageChange notification to application + * @param connection_key Connection key of application + */ + static void SendOnLanguageChangeToMobile(uint32_t connection_key); - /* - * @brief Retrieve vehicle data map for param name in mobile request - * to VehicleDataType - * - * @return VehicleData reference - */ - static const VehicleData& vehicle_data(); + /* + * @brief Retrieve vehicle data map for param name in mobile request + * to VehicleDataType + * + * @return VehicleData reference + */ + static const VehicleData& vehicle_data(); - /** - * @brief Converts HMI Result enum value to string - * @param hmi_result HMI Result enum value - * @return stringified value for enum if succedeed, otherwise - empty string - */ - static std::string HMIResultToString( + /** + * @brief Converts HMI Result enum value to string + * @param hmi_result HMI Result enum value + * @return stringified value for enum if succedeed, otherwise - empty string + */ + static std::string HMIResultToString( hmi_apis::Common_Result::eType hmi_result); /** @@ -200,7 +188,7 @@ class MessageHelper { static smart_objects::SmartObjectSPtr CreateBlockedByPoliciesResponse( mobile_apis::FunctionID::eType function_id, mobile_apis::Result::eType result, - uint32_t correlation_id, + const uint32_t correlation_id, uint32_t connection_key); /* @@ -210,12 +198,12 @@ class MessageHelper { * @param devices Devices list * */ - static smart_objects::SmartObjectSPtr CreateDeviceListSO( - const connection_handler::DeviceMap& devices, - const policy::PolicyHandlerInterface& policy_handler); + static smart_objects::SmartObjectSPtr CreateDeviceListSO(const connection_handler::DeviceMap& devices, + const policy::PolicyHandlerInterface& policy_handler, + ApplicationManager &app_mngr); static smart_objects::SmartObjectSPtr CreateModuleInfoSO( - uint32_t function_id); + uint32_t function_id, ApplicationManager& app_mngr); static smart_objects::SmartObjectSPtr CreateSetAppIcon( const std::string& path_to_icon, uint32_t app_id); @@ -223,64 +211,61 @@ class MessageHelper { /** * @brief Sends IVI subscription requests */ - static bool SendIVISubscribtions(const uint32_t app_id); + static bool SendIVISubscribtions(const uint32_t app_id, ApplicationManager &app_mngr); /** * @brief Returns IVI subscription requests */ - static smart_objects::SmartObjectList GetIVISubscriptionRequests( - ApplicationSharedPtr app); + static smart_objects::SmartObjectList GetIVISubscriptionRequests(ApplicationSharedPtr app, ApplicationManager& app_mngr); /** * @brief Sends button subscription notification */ static void SendOnButtonSubscriptionNotification( - const uint32_t app_id, - const hmi_apis::Common_ButtonName::eType button, - const bool is_subscribed); + const uint32_t app_id, + const hmi_apis::Common_ButtonName::eType button, + const bool is_subscribed, + ApplicationManager &app_mngr); /** * @brief Sends button subscription notifications for all buttons * that application is subscribed on */ - static void SendAllOnButtonSubscriptionNotificationsForApp( - ApplicationConstSharedPtr app); + static void SendAllOnButtonSubscriptionNotificationsForApp(ApplicationConstSharedPtr app, ApplicationManager &app_mngr); - static void SendAppDataToHMI(ApplicationConstSharedPtr app); - static void SendGlobalPropertiesToHMI(ApplicationConstSharedPtr app); + static void SendAppDataToHMI(ApplicationConstSharedPtr app, ApplicationManager& app_man); + static void SendGlobalPropertiesToHMI(ApplicationConstSharedPtr app, ApplicationManager &app_mngr); static smart_objects::SmartObjectList CreateGlobalPropertiesRequestsToHMI( - ApplicationConstSharedPtr app); + ApplicationConstSharedPtr app, const uint32_t correlation_id); static smart_objects::SmartObjectSPtr CreateAppVrHelp( ApplicationConstSharedPtr app); static smart_objects::SmartObjectList CreateShowRequestToHMI( - ApplicationConstSharedPtr app); - static void SendShowRequestToHMI(ApplicationConstSharedPtr app); - static void SendShowConstantTBTRequestToHMI(ApplicationConstSharedPtr app); - static void SendAddCommandRequestToHMI(ApplicationConstSharedPtr app); + ApplicationConstSharedPtr app, const uint32_t correlation_id); + static void SendShowRequestToHMI(ApplicationConstSharedPtr app, ApplicationManager &app_mngr); + static void SendShowConstantTBTRequestToHMI(ApplicationConstSharedPtr app, ApplicationManager& app_man); + static void SendAddCommandRequestToHMI(ApplicationConstSharedPtr app, ApplicationManager &app_man); static smart_objects::SmartObjectList CreateAddCommandRequestToHMI( - ApplicationConstSharedPtr app); + ApplicationConstSharedPtr app, ApplicationManager& app_mngr); static smart_objects::SmartObjectList - CreateAddVRCommandRequestFromChoiceToHMI(ApplicationConstSharedPtr app); + CreateAddVRCommandRequestFromChoiceToHMI(ApplicationConstSharedPtr app, + ApplicationManager& app_mngr); /** * @brief Sends UI_ChangeRegistration to HMI with list of AppHMIType * @param app applicaton instace */ - static void SendUIChangeRegistrationRequestToHMI( - ApplicationConstSharedPtr app); - static void SendChangeRegistrationRequestToHMI(ApplicationConstSharedPtr app); - static void SendAddVRCommandToHMI( - const uint32_t cmd_id, + static void SendUIChangeRegistrationRequestToHMI(ApplicationConstSharedPtr app, ApplicationManager &app_mngr); + static void SendChangeRegistrationRequestToHMI(ApplicationConstSharedPtr app, ApplicationManager &app_mngr); + static void SendAddVRCommandToHMI(uint32_t cmd_id, const smart_objects::SmartObject& vr_commands, - const uint32_t app_id); + const uint32_t app_id, ApplicationManager &app_mngr); - static smart_objects::SmartObjectSPtr CreateAddVRCommandToHMI( - const uint32_t cmd_id, + static smart_objects::SmartObjectSPtr CreateAddVRCommandToHMI(uint32_t cmd_id, const smart_objects::SmartObject& vr_commands, - const uint32_t app_id); + const uint32_t app_id, ApplicationManager &app_mngr); /* * @brief Create Common.HMIApplication struct application instance @@ -291,11 +276,10 @@ class MessageHelper { static bool CreateHMIApplicationStruct(ApplicationConstSharedPtr app, const protocol_handler::SessionObserver& session_observer, const policy::PolicyHandlerInterface &policy_handler, - smart_objects::SmartObject* output); + smart_objects::SmartObject* output, ApplicationManager &app_mngr); - static void SendAddSubMenuRequestToHMI(ApplicationConstSharedPtr app); - static smart_objects::SmartObjectList CreateAddSubMenuRequestToHMI( - ApplicationConstSharedPtr app); + static void SendAddSubMenuRequestToHMI(ApplicationConstSharedPtr app, ApplicationManager &app_mngr); + static smart_objects::SmartObjectList CreateAddSubMenuRequestToHMI(ApplicationConstSharedPtr app, const uint32_t correlation_id); /* * @brief Creates BasicCommunication.OnAppUnregistered notification @@ -303,30 +287,29 @@ class MessageHelper { * @param is_unexpected_disconnect * Indicates if connection was unexpectedly lost by TM or HB */ - static void SendOnAppUnregNotificationToHMI( - ApplicationConstSharedPtr app, bool is_unexpected_disconnect = false); + static void SendOnAppUnregNotificationToHMI(ApplicationConstSharedPtr app, bool is_unexpected_disconnect, ApplicationManager &app_mngr); static NsSmartDeviceLink::NsSmartObjects::SmartObjectSPtr GetBCActivateAppRequestToHMI(ApplicationConstSharedPtr app, const protocol_handler::SessionObserver& session_observer, - const policy::PolicyHandlerInterface &policy_handler, + const policy::PolicyHandlerInterface& policy_handler, hmi_apis::Common_HMILevel::eType level, - bool send_policy_priority); + bool send_policy_priority, ApplicationManager &app_mngr); - static void SendOnResumeAudioSourceToHMI(const uint32_t app_id); + static void SendOnResumeAudioSourceToHMI(const uint32_t app_id, ApplicationManager &app_mngr); /** * @brief Send SDL_ActivateApp response to HMI * @param permissions response parameters */ - static void SendSDLActivateAppResponse(policy::AppPermissions& permissions, - const uint32_t correlation_id); + static void SendSDLActivateAppResponse(policy::AppPermissions& permissions, uint32_t correlation_id, + ApplicationManager &app_mngr); /** * @brief Send OnSDLConsentNeeded to HMI for device data consent by user * @param device_info Device info, e.g. mac, handle, name */ - static void SendOnSDLConsentNeeded(const policy::DeviceParams& device_info); + static void SendOnSDLConsentNeeded(const policy::DeviceParams& device_info, ApplicationManager& app_man); /** * @brief Send request to SyncP process to read file and send @@ -336,17 +319,17 @@ class MessageHelper { * @param retries Seconds between retries */ static void SendPolicyUpdate(const std::string& file_path, - const int timeout, - const std::vector<int>& retries); + int timeout, + const std::vector<int>& retries, + ApplicationManager &app_mngr); /** * @brief Send GetUserFriendlyMessage response to HMI * @param msg Appopriate messages params * @param correlation_id Correlation id of request */ - static void SendGetUserFriendlyMessageResponse( - const std::vector<policy::UserFriendlyMessage>& msg, - const uint32_t correlation_id); + static void SendGetUserFriendlyMessageResponse(const std::vector<policy::UserFriendlyMessage>& msg, + uint32_t correlation_id, ApplicationManager &app_mngr); /** * @brief Send GetListOfPermissions response to HMI @@ -355,7 +338,8 @@ class MessageHelper { */ static void SendGetListOfPermissionsResponse( const std::vector<policy::FunctionalGroupPermission>& permissions, - const uint32_t correlation_id); + uint32_t correlation_id, + ApplicationManager& app_mngr); /* * @brief Sends notification to HMI to start video streaming @@ -363,7 +347,7 @@ class MessageHelper { * @param connection_key Application connection key * */ - static void SendNaviStartStream(const int32_t app_id); + static void SendNaviStartStream(int32_t app_id, ApplicationManager &app_mngr); /* * @brief Sends notification to HMI to stop video streaming @@ -371,7 +355,7 @@ class MessageHelper { * @param connection_key Application connection key * */ - static void SendNaviStopStream(const int32_t app_id); + static void SendNaviStopStream(int32_t app_id, ApplicationManager &app_mngr); /* * @brief Send notification for Update of Policy Table @@ -381,13 +365,13 @@ class MessageHelper { * @param url If empty string, no URL is provided * @param timeout If -1 no timeout is provdied */ - static void SendPolicySnapshotNotification(const unsigned int connection_key, + static void SendPolicySnapshotNotification(uint32_t connection_key, const std::vector<uint8_t>& policy_data, - const std::string& url = ""); + const std::string& url, + ApplicationManager& app_mngr); - static void SendSystemRequestNotification( - const uint32_t connection_key, - NsSmartDeviceLink::NsSmartObjects::SmartObject*& content); + static void SendSystemRequestNotification(uint32_t connection_key, + NsSmartDeviceLink::NsSmartObjects::SmartObject& content, ApplicationManager &app_mngr); /** * @brief SendLaunchApp allows to send OnSystemRequest with LAUNCH_UP. @@ -400,21 +384,22 @@ class MessageHelper { */ static void SendLaunchApp(const uint32_t connection_key, const std::string& urlSchema, - const std::string& packageName); + const std::string& packageName, + ApplicationManager& app_man); /** * @brief Sends OnSystemRequest which queries remote apps list * @param connection_key application id, which is used for sending out */ - static void SendQueryApps(const uint32_t connection_key); + static void SendQueryApps(const uint32_t connection_key, + ApplicationManager& app_man); /* * @brief Send notification to mobile on application permissions update * @param connection_key Id of application to send message to * @param permissions updated permissions for application */ - static void SendOnPermissionsChangeNotification( - const uint32_t connection_key, const policy::Permissions& permissions); + static void SendOnPermissionsChangeNotification(uint32_t connection_key, const policy::Permissions& permissions, ApplicationManager &app_mngr); /* * @brief Send notification to HMI on application permissions update @@ -422,7 +407,7 @@ class MessageHelper { * @param permissions updated permissions for application */ static void SendOnAppPermissionsChangedNotification( - const uint32_t connection_key, const policy::AppPermissions& permissions); + uint32_t connection_key, const policy::AppPermissions& permissions, ApplicationManager& app_mngr); /** * @brief Send GetStatusUpdate response to HMI with current policy update @@ -431,7 +416,7 @@ class MessageHelper { * @param correlation_id Correlation id from request */ static void SendGetStatusUpdateResponse(const std::string& status, - const uint32_t correlation_id); + const uint32_t correlation_id, ApplicationManager &app_mngr); /** * @brief Send UpdateSDL response to HMI with policy update result @@ -439,18 +424,18 @@ class MessageHelper { * @param correlation_id Correlation id from request */ static void SendUpdateSDLResponse(const std::string& result, - const uint32_t correlation_id); + const uint32_t correlation_id, ApplicationManager &app_mngr); /** * @brief Send OnStatusUpdate to HMI on policy update status change * @param status Policy table update status */ - static void SendOnStatusUpdate(const std::string& status); + static void SendOnStatusUpdate(const std::string& status, ApplicationManager& app_mngr); /** * @brief Send GetSystemInfo request to HMI */ - static void SendGetSystemInfoRequest(); + static void SendGetSystemInfoRequest(ApplicationManager &app_mngr); /* * @brief Sends notification to HMI to start audio streaming @@ -458,7 +443,7 @@ class MessageHelper { * @param connection_key Application connection key * */ - static void SendAudioStartStream(const int32_t app_id); + static void SendAudioStartStream(int32_t app_id, ApplicationManager &app_mngr); /* * @brief Sends notification to HMI to stop audio streaming @@ -466,10 +451,10 @@ class MessageHelper { * @param connection_key Application connection key * */ - static void SendAudioStopStream(const int32_t connection_key); + static void SendAudioStopStream(int32_t connection_key, ApplicationManager &app_mngr); - static void SendOnDataStreaming(const protocol_handler::ServiceType service, - const bool available); + static void SendOnDataStreaming(protocol_handler::ServiceType service, + bool available, ApplicationManager &app_mngr); /* * @brief Sends notification to HMI to stop audioPathThru @@ -478,18 +463,18 @@ class MessageHelper { * * @return TRUE on SUCCES otherwise return FALSE */ - static bool SendStopAudioPathThru(); + static bool SendStopAudioPathThru(ApplicationManager &app_mngr); /** * @brief Sends UnsubscribeWayPoints request * @return true if UnSubscribedWayPoints is send otherwise false */ - static bool SendUnsubscribedWayPoints(); + static bool SendUnsubscribedWayPoints(ApplicationManager& app_mngr); static smart_objects::SmartObjectSPtr CreateNegativeResponse( uint32_t connection_key, int32_t function_id, - uint32_t correlation_id, + const uint32_t correlation_id, int32_t result_code); /* @@ -503,7 +488,9 @@ class MessageHelper { * */ static mobile_apis::Result::eType VerifyImage( - smart_objects::SmartObject& image, ApplicationConstSharedPtr app); + smart_objects::SmartObject& image, + ApplicationConstSharedPtr app, + ApplicationManager& app_mngr); /* * @brief Finds "Image" structure in request and verify image file presence @@ -517,10 +504,9 @@ class MessageHelper { * */ static mobile_apis::Result::eType VerifyImageFiles( - smart_objects::SmartObject& message, ApplicationConstSharedPtr app); + smart_objects::SmartObject& message, ApplicationConstSharedPtr app, ApplicationManager& app_mngr); - static mobile_apis::Result::eType VerifyImageVrHelpItems( - smart_objects::SmartObject& message, ApplicationConstSharedPtr app); + static mobile_apis::Result::eType VerifyImageVrHelpItems(smart_objects::SmartObject& message, ApplicationConstSharedPtr app, ApplicationManager &app_mngr); /** * @brief Checks string if it contains incorrect character \t\n \\t \\n @@ -534,7 +520,8 @@ class MessageHelper { static mobile_apis::Result::eType ProcessSoftButtons( smart_objects::SmartObject& message_params, ApplicationConstSharedPtr app, - const policy::PolicyHandlerInterface& policy_handler); + const policy::PolicyHandlerInterface& policy_handler, + ApplicationManager& app_mngr); /* * @brief subscribe application to softbutton @@ -558,7 +545,6 @@ class MessageHelper { } static const uint32_t GetPriorityCode(const std::string& priority); - /** * @brief Convert common language to string representation * @param language Common language @@ -610,7 +596,7 @@ class MessageHelper { * with empty helpPrompt array. */ static void SendTTSGlobalProperties( - ApplicationSharedPtr app, const bool default_help_prompt); + ApplicationSharedPtr app, const bool default_help_prompt, ApplicationManager& app_man); /** * @brief SendSetAppIcon allows to send SetAppIcon request. @@ -619,43 +605,45 @@ class MessageHelper { * * @param icon_path path to the icon. */ - static void SendSetAppIcon(const uint32_t app_id, const std::string& icon_path); - - /** - * @brief Sends DecryptCertificate request to HMI - * @param file_name path to file containing encrypted certificate - */ - static void SendDecryptCertificateToHMI(const std::string& file_name); + static void SendSetAppIcon(const uint32_t app_id, + const std::string& icon_path, + ApplicationManager& application_manager); static hmi_apis::Common_Language::eType CommonLanguageFromString( const std::string& language); + static smart_objects::SmartObjectSPtr + GetOnAppInterfaceUnregisteredNotificationToMobile( + int32_t connection_key, + mobile_api::AppInterfaceUnregisteredReason::eType reason); + private: - /** - * @brief Creates new request object and fill its header - * @return New request object - */ - static smart_objects::SmartObjectSPtr CreateRequestObject(); + /** + * @brief Creates new request object and fill its header + * @return New request object + */ + static smart_objects::SmartObjectSPtr CreateRequestObject(const uint32_t correlation_id); - /** - * @brief Allows to fill SO according to the current permissions. - * @param permissions application permissions. - * @param message which should be filled. - */ - static void FillAppRevokedPermissions( - const policy::AppPermissions& permissions, - smart_objects::SmartObject& message); + /** + * @brief Allows to fill SO according to the current permissions. + * @param permissions application permissions. + * @param message which should be filled. + */ + static void FillAppRevokedPermissions( + const policy::AppPermissions& permissions, + smart_objects::SmartObject& message); static smart_objects::SmartObjectSPtr CreateChangeRegistration( const int32_t function_id, const int32_t language, const uint32_t app_id, - const smart_objects::SmartObject* app_types = NULL); + const smart_objects::SmartObject* app_types, + ApplicationManager& app_mngr); - MessageHelper(); + MessageHelper(); - static const VehicleData vehicle_data_; - DISALLOW_COPY_AND_ASSIGN(MessageHelper); + static const VehicleData vehicle_data_; + DISALLOW_COPY_AND_ASSIGN(MessageHelper); }; } // namespace application_manager diff --git a/src/components/application_manager/include/application_manager/mobile_command_factory.h b/src/components/application_manager/include/application_manager/mobile_command_factory.h index 997e973828..f8097a83ef 100644 --- a/src/components/application_manager/include/application_manager/mobile_command_factory.h +++ b/src/components/application_manager/include/application_manager/mobile_command_factory.h @@ -52,8 +52,9 @@ class MobileCommandFactory { * @return Pointer to created command object. **/ static CommandSharedPtr CreateCommand( - const commands::MessageSharedPtr& message, - commands::Command::CommandOrigin origin); + const commands::MessageSharedPtr& message, + commands::Command::CommandOrigin origin, + ApplicationManager& application_manager); private: MobileCommandFactory(); diff --git a/src/components/application_manager/include/application_manager/request_controller.h b/src/components/application_manager/include/application_manager/request_controller.h index 1e713c11d1..259abc6c0f 100644 --- a/src/components/application_manager/include/application_manager/request_controller.h +++ b/src/components/application_manager/include/application_manager/request_controller.h @@ -48,6 +48,7 @@ #include "interfaces/HMI_API.h" #include "application_manager/request_info.h" +#include "application_manager/request_controller_settings.h" namespace application_manager { @@ -86,7 +87,7 @@ class RequestController { * @brief Class constructor * */ - RequestController(); + RequestController(const RequestControlerSettings& settings); /** * @brief Class destructor @@ -284,6 +285,7 @@ class RequestController { timer::Timer timer_; bool is_low_voltage_; + const RequestControlerSettings& settings_; DISALLOW_COPY_AND_ASSIGN(RequestController); }; diff --git a/src/components/application_manager/include/application_manager/state_context.h b/src/components/application_manager/include/application_manager/state_context.h deleted file mode 100644 index 4654eb38b6..0000000000 --- a/src/components/application_manager/include/application_manager/state_context.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2015, 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_INCLUDE_APPLICATION_MANAGER_STATE_CONTEXT_H_ -#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_STATE_CONTEXT_H_ - -#include <cstdint> - -namespace application_manager { -/** -* @brief The StateContext implement acessing to data, that is required by HmiState -*/ -class StateContext { - public: - - /** - * @brief is_navi_app check if app is navi - * @param app_id application id - * @return true if app is navi, otherwise return false - */ - bool is_navi_app(const uint32_t app_id) const; - - /** - * @brief is_meida_app check if app is is meida - * @param app_id application id - * @return @return true if meida_app, otherwise return false - */ - bool is_meida_app(const uint32_t app_id) const; - - /** - * @brief is_voice_comunication_app check if app is voice comunication - * @param app_id application id - * @return @return true if voice_comunication_app, otherwise return false - */ - bool is_voice_comunication_app(const uint32_t app_id) const; - - /** - * @brief is_attenuated_supported check if HMI support attenuated mode - * @return true if supported, otherwise return false - */ - bool is_attenuated_supported() const; -}; - -} -#endif // STATE_CONTEXT_H - diff --git a/src/components/application_manager/include/application_manager/state_controller.h b/src/components/application_manager/include/application_manager/state_controller_impl.h index a6cd06247d..e555d50b2f 100644 --- a/src/components/application_manager/include/application_manager/state_controller.h +++ b/src/components/application_manager/include/application_manager/state_controller_impl.h @@ -30,14 +30,15 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_STATE_CONTROLLER_H_ -#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_STATE_CONTROLLER_H_ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_STATE_CONTROLLER_IMPL_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_STATE_CONTROLLER_IMPL_H_ #include <list> #include "application_manager/hmi_state.h" #include "application_manager/application.h" #include "application_manager/application_manager.h" #include "event_engine/event_observer.h" +#include "application_manager/state_controller.h" #include "application_manager/message_helper.h" #include "interfaces/MOBILE_API.h" #include "utils/lock.h" @@ -45,9 +46,10 @@ namespace application_manager { -class StateController : public event_engine::EventObserver { +class StateControllerImpl : public event_engine::EventObserver, + public StateController { public: - explicit StateController(ApplicationManager* app_mngr); + explicit StateControllerImpl(ApplicationManager& app_mngr); /** * @brief SetRegularState setup regular hmi state, that will appear if @@ -55,53 +57,9 @@ class StateController : public event_engine::EventObserver { * @param app appication to setup regular State * @param state state of new regular state */ - template <bool SendActivateApp> - void SetRegularState(ApplicationSharedPtr app, HmiStatePtr state) { - CREATE_LOGGERPTR_LOCAL(logger_, "StateController"); - LOG4CXX_AUTO_TRACE(logger_); - if (!app) { - return; - } - DCHECK_OR_RETURN_VOID(state); - DCHECK_OR_RETURN_VOID(state->state_id() == HmiState::STATE_ID_REGULAR); - - if (state->hmi_level() == mobile_apis::HMILevel::INVALID_ENUM || - state->audio_streaming_state() == - mobile_apis::AudioStreamingState::INVALID_ENUM || - state->system_context() == mobile_apis::SystemContext::INVALID_ENUM) { - LOG4CXX_ERROR(logger_, "Get invalid state"); - return; - } - if (app->is_resuming() && !IsResumptionAllowed(app, state)) { - return; - } - - HmiStatePtr resolved_state = ResolveHmiState(app, state); - if (!resolved_state) { - state->set_state_id(HmiState::STATE_ID_POSTPONED); - app->SetPostponedState(state); - return; - } - hmi_apis::Common_HMILevel::eType hmi_level = - static_cast<hmi_apis::Common_HMILevel::eType>( - resolved_state->hmi_level()); - - const bool is_full_allowed = hmi_apis::Common_HMILevel::FULL == hmi_level; - - if (SendActivateApp && is_full_allowed) { - int64_t corr_id = SendBCActivateApp(app, hmi_level, true); - if (-1 != corr_id) { - subscribe_on_event(hmi_apis::FunctionID::BasicCommunication_ActivateApp, - corr_id); - waiting_for_activate[app->app_id()] = resolved_state; - return; - } - LOG4CXX_ERROR(logger_, "Unable to send BC.ActivateApp"); - return; - } - ApplyRegularState(app, resolved_state); - } + virtual void SetRegularState(ApplicationSharedPtr app, HmiStatePtr state, + const bool SendActivateApp); /** * @brief SetRegularState Change regular hmi level and audio state @@ -109,24 +67,12 @@ class StateController : public event_engine::EventObserver { * @param hmi_level of new regular state * @param audio_state of new regular state * @param SendActivateApp: if true, ActivateAppRequest will be sent on HMI */ - template <bool SendActivateApp> - void SetRegularState( + + virtual void SetRegularState( ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level, - const mobile_apis::AudioStreamingState::eType audio_state) { - if (!app) { - return; - } - HmiStatePtr prev_regular = app->RegularHmiState(); - DCHECK_OR_RETURN_VOID(prev_regular); - HmiStatePtr hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); - DCHECK_OR_RETURN_VOID(hmi_state); - hmi_state->set_hmi_level(hmi_level); - hmi_state->set_audio_streaming_state(audio_state); - hmi_state->set_system_context(prev_regular->system_context()); - SetRegularState<SendActivateApp>(app, hmi_state); - } + const mobile_apis::AudioStreamingState::eType audio_state, + const bool SendActivateApp); /** * @brief SetRegularState Change regular hmi level @@ -134,23 +80,9 @@ class StateController : public event_engine::EventObserver { * @param hmi_level of new regular state * @param SendActivateApp: if true, ActivateAppRequest will be sent on HMI */ - template <bool SendActivateApp> - void SetRegularState(ApplicationSharedPtr app, - const mobile_apis::HMILevel::eType hmi_level) { - using namespace mobile_apis; - using namespace helpers; - if (!app) { - return; - } - const HmiStatePtr hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); - - DCHECK_OR_RETURN_VOID(hmi_state); - hmi_state->set_hmi_level(hmi_level); - hmi_state->set_audio_streaming_state(CalcAudioState(app, hmi_level)); - hmi_state->set_system_context(SystemContext::SYSCTXT_MAIN); - SetRegularState<SendActivateApp>(app, hmi_state); - } + virtual void SetRegularState(ApplicationSharedPtr app, + const mobile_apis::HMILevel::eType hmi_level, + const bool SendActivateApp); /** * @brief SetRegularState Change regular hmi level, audio state and system @@ -160,24 +92,13 @@ class StateController : public event_engine::EventObserver { * @param audio_state of new regular state * @param system_context of new regular state * @param SendActivateApp: if true, ActivateAppRequest will be sent on HMI */ - template <bool SendActivateApp> - void SetRegularState( + + virtual void SetRegularState( ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level, const mobile_apis::AudioStreamingState::eType audio_state, - const mobile_apis::SystemContext::eType system_context) { - if (!app) { - return; - } - - HmiStatePtr hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); - DCHECK_OR_RETURN_VOID(hmi_state); - hmi_state->set_hmi_level(hmi_level); - hmi_state->set_audio_streaming_state(audio_state); - hmi_state->set_system_context(system_context); - SetRegularState<SendActivateApp>(app, hmi_state); - } + const mobile_apis::SystemContext::eType system_context, + const bool SendActivateApp); /** * @brief SetRegularState Sets regular state with new hmi level @@ -185,44 +106,17 @@ class StateController : public event_engine::EventObserver { * @param app appication to setup regular state * @param hmi_level new hmi level for application */ - void SetRegularState(ApplicationSharedPtr app, - const mobile_apis::HMILevel::eType hmi_level) { - if (!app) { - return; - } - HmiStatePtr prev_state = app->RegularHmiState(); - HmiStatePtr hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); - DCHECK_OR_RETURN_VOID(hmi_state); - hmi_state->set_hmi_level(hmi_level); - hmi_state->set_audio_streaming_state(CalcAudioState(app, hmi_level)); - hmi_state->set_system_context( - prev_state ? prev_state->system_context() - : mobile_apis::SystemContext::SYSCTXT_MAIN); - SetRegularState(app, hmi_state); - } + virtual void SetRegularState(ApplicationSharedPtr app, + const mobile_apis::HMILevel::eType hmi_level); /** * @brief SetRegularState Change regular audio state * @param app appication to setup regular State * @param audio_state of new regular state */ - void SetRegularState( + virtual void SetRegularState( ApplicationSharedPtr app, - const mobile_apis::AudioStreamingState::eType audio_state) { - if (!app) { - return; - } - HmiStatePtr prev_state = app->RegularHmiState(); - DCHECK_OR_RETURN_VOID(prev_state); - HmiStatePtr hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); - DCHECK_OR_RETURN_VOID(hmi_state); - hmi_state->set_hmi_level(prev_state->hmi_level()); - hmi_state->set_audio_streaming_state(audio_state); - hmi_state->set_system_context(prev_state->system_context()); - SetRegularState<false>(app, hmi_state); - } + const mobile_apis::AudioStreamingState::eType audio_state); /** * @brief SetRegularState Change regular system context @@ -231,38 +125,14 @@ class StateController : public event_engine::EventObserver { */ virtual void SetRegularState( ApplicationSharedPtr app, - const mobile_apis::SystemContext::eType system_context) { - if (!app) { - return; - } - HmiStatePtr prev_regular = app->RegularHmiState(); - DCHECK_OR_RETURN_VOID(prev_regular); - HmiStatePtr hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); - DCHECK_OR_RETURN_VOID(hmi_state); - hmi_state->set_hmi_level(prev_regular->hmi_level()); - hmi_state->set_audio_streaming_state( - CalcAudioState(app, prev_regular->hmi_level())); - hmi_state->set_system_context(system_context); - SetRegularState<false>(app, hmi_state); - } + const mobile_apis::SystemContext::eType system_context); /** * @brief SetRegularState Sets new regular state to application * @param app appication to setup regular state * @param state new hmi state for application */ - void SetRegularState(ApplicationSharedPtr app, HmiStatePtr state) { - if (!app) { - return; - } - DCHECK_OR_RETURN_VOID(state); - if (mobile_apis::HMILevel::HMI_FULL == state->hmi_level()) { - SetRegularState<true>(app, state); - } else { - SetRegularState<false>(app, state); - } - } + virtual void SetRegularState(ApplicationSharedPtr app, HmiStatePtr state); // EventObserver interface void on_event(const event_engine::Event& event); @@ -293,7 +163,7 @@ class StateController : public event_engine::EventObserver { * @param old_state state before change * @param new_state state after change */ - void OnStateChanged(ApplicationSharedPtr app, + virtual void OnStateChanged(ApplicationSharedPtr app, HmiStatePtr old_state, HmiStatePtr new_state); @@ -302,9 +172,7 @@ class StateController : public event_engine::EventObserver { * @return Returns TRUE if deactivate HMI state is active, otherwise returns * FALSE. */ - bool IsDeactivateHMIStateActive() const; - - bool IsStateActive(HmiState::StateID state_id) const; + virtual bool IsStateActive(HmiState::StateID state_id) const; private: int64_t SendBCActivateApp(ApplicationConstSharedPtr app, @@ -317,22 +185,22 @@ class StateController : public event_engine::EventObserver { struct HmiLevelConflictResolver { ApplicationSharedPtr applied_; HmiStatePtr state_; - StateController* state_ctrl_; + StateControllerImpl* state_ctrl_; HmiLevelConflictResolver(ApplicationSharedPtr app, HmiStatePtr state, - StateController* state_ctrl) + StateControllerImpl* state_ctrl) : applied_(app), state_(state), state_ctrl_(state_ctrl) {} void operator()(ApplicationSharedPtr to_resolve); }; template <typename UnaryFunction> void ForEachApplication(UnaryFunction func) const { - DataAccessor<ApplicationSet> accessor = app_mngr_->applications(); + DataAccessor<ApplicationSet> accessor = app_mngr_.applications(); ApplicationSet::iterator it = accessor.GetData().begin(); for (; it != accessor.GetData().end(); ++it) { ApplicationConstSharedPtr const_app = *it; if (const_app) { - func(app_mngr_->application(const_app->app_id())); + func(app_mngr_.application(const_app->app_id())); } } } @@ -430,13 +298,13 @@ class StateController : public event_engine::EventObserver { } /** - * @brief TempStateStarted add HMI State ID in StateController collection + * @brief TempStateStarted add HMI State ID in StateControllerImpl collection * @param ID state identifier */ void TempStateStarted(HmiState::StateID ID); /** - * @brief TempStateStopped remove HMI State ID from StateController collection + * @brief TempStateStopped remove HMI State ID from StateControllerImpl collection * @param ID state identifier */ void TempStateStopped(HmiState::StateID ID); @@ -541,7 +409,7 @@ class StateController : public event_engine::EventObserver { template <HmiState::StateID ID> void ApplyTempState() { ForEachApplication(std::bind1st( - std::mem_fun(&StateController::HMIStateStarted<ID>), this)); + std::mem_fun(&StateControllerImpl::HMIStateStarted<ID>), this)); TempStateStarted(ID); } @@ -551,17 +419,11 @@ class StateController : public event_engine::EventObserver { template <HmiState::StateID ID> void CancelTempState() { ForEachApplication(std::bind1st( - std::mem_fun(&StateController::HMIStateStopped<ID>), this)); + std::mem_fun(&StateControllerImpl::HMIStateStopped<ID>), this)); TempStateStopped(ID); } /** - * @brief SetAplicationManager setter got app_mngr - * @param app_mngr - */ - void SetAplicationManager(ApplicationManager* app_mngr); - - /** * @brief CreateHmiState creates Hmi state according to state_id * @param app_id application ID * @param state_id state id @@ -577,8 +439,9 @@ class StateController : public event_engine::EventObserver { StateIDList active_states_; mutable sync_primitives::Lock active_states_lock_; std::map<uint32_t, HmiStatePtr> waiting_for_activate; - ApplicationManager* app_mngr_; + ApplicationManager& app_mngr_; }; + } -#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_STATE_CONTROLLER_H_ +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_STATE_CONTROLLER_IMPL_H_ |