diff options
Diffstat (limited to 'src/components/include')
79 files changed, 1434 insertions, 1253 deletions
diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index c7a50199b1..e6e5c89f45 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -33,25 +33,24 @@ #ifndef SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ #define SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ +#include <ctime> #include <string> #include <vector> #include <set> #include "application_manager/application.h" #include "application_manager/hmi_capabilities.h" #include "application_manager/commands/command.h" +#include "application_manager/command_factory.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" #include "application_manager/hmi_interfaces.h" #include "policy/policy_types.h" -#ifdef SDL_REMOTE_CONTROL -#include "functional_module/plugin_manager.h" -#endif - +#include "application_manager/plugin_manager/rpc_plugin_manager.h" namespace resumption { class LastState; } @@ -82,6 +81,12 @@ namespace application_manager { namespace event_engine { class EventDispatcher; } +namespace rpc_service { +class RPCService; +} +namespace rpc_handler { +class RPCHandler; +} class Application; class StateControllerImpl; @@ -94,7 +99,6 @@ struct ApplicationsAppIdSorter { return lhs->app_id() < rhs->app_id(); } }; - struct ApplicationsPolicyAppIdSorter { bool operator()(const ApplicationSharedPtr lhs, const ApplicationSharedPtr rhs) { @@ -135,8 +139,15 @@ class ApplicationManager { virtual void set_hmi_message_handler( hmi_message_handler::HMIMessageHandler* handler) = 0; + + /** + * @brief set_protocol_handler + * @param handler + * set protocol handler + */ virtual void set_protocol_handler( protocol_handler::ProtocolHandler* handler) = 0; + virtual void set_connection_handler( connection_handler::ConnectionHandler* handler) = 0; @@ -159,7 +170,6 @@ class ApplicationManager { virtual AppSharedPtrs applications_by_button(uint32_t button) = 0; virtual AppSharedPtrs applications_with_navi() = 0; -#ifdef SDL_REMOTE_CONTROL /** * @brief application find application by device and policy identifier * @param device_id device id @@ -176,12 +186,12 @@ class ApplicationManager { virtual std::vector<std::string> devices( const std::string& policy_app_id) const = 0; - virtual void SendPostMessageToMobile(const MessagePtr& message) = 0; + virtual plugin_manager::RPCPluginManager& GetPluginManager() = 0; - virtual void SendPostMessageToHMI(const MessagePtr& message) = 0; - - virtual functional_modules::PluginManager& GetPluginManager() = 0; -#endif // SDL_REMOTE_CONTROL +#ifdef BUILD_TESTS + virtual void SetPluginManager( + std::unique_ptr<plugin_manager::RPCPluginManager>& plugin_manager) = 0; +#endif virtual std::vector<ApplicationSharedPtr> applications_with_mobile_projection() = 0; @@ -230,6 +240,18 @@ class ApplicationManager { */ virtual void set_application_id(const int32_t correlation_id, const uint32_t app_id) = 0; + /** + * @brief get_current_audio_source + * @return current audio source + */ + virtual uint32_t get_current_audio_source() const = 0; + + /** + * @brief set_current_audio_source + * @param source + * set current audio source + */ + virtual void set_current_audio_source(const uint32_t source) = 0; /** * @brief OnHMILevelChanged the callback that allows SDL to react when @@ -251,30 +273,15 @@ class ApplicationManager { * **/ virtual void SendHMIStatusNotification( - const utils::SharedPtr<Application> app) = 0; - - /** - * DEPRECATED - * @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; - - /** - * DEPRECATED - * @brief Subscribe Application for way points - * @param Application AppID - */ - virtual void SubscribeAppForWayPoints(const uint32_t app_id) = 0; + const std::shared_ptr<Application> app) = 0; /** - * DEPRECATED - * @brief Unsubscribe Application for way points - * @param Application AppID + * @brief Checks if driver distraction state is valid, creates message + * which is sent to the application if allowed, otherwise it is added + * to a list of postponed messages. + * @param application contains registered application. */ - virtual void UnsubscribeAppFromWayPoints(const uint32_t app_id) = 0; + virtual void SendDriverDistractionState(ApplicationSharedPtr application) = 0; /** * @brief Checks if Application is subscribed for way points @@ -306,25 +313,27 @@ class ApplicationManager { * @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; - - virtual void SendMessageToHMI(const commands::MessageSharedPtr message) = 0; + virtual const std::set<uint32_t> GetAppsSubscribedForWayPoints() const = 0; virtual void RemoveHMIFakeParameters( - application_manager::MessagePtr& message) = 0; - - virtual bool ManageHMICommand(const commands::MessageSharedPtr message) = 0; - virtual bool ManageMobileCommand(const commands::MessageSharedPtr message, - commands::Command::CommandOrigin origin) = 0; - - virtual MessageValidationResult ValidateMessageBySchema( - const Message& message) = 0; + application_manager::commands::MessageSharedPtr& message, + const hmi_apis::FunctionID::eType& function_id) = 0; virtual mobile_api::HMILevel::eType GetDefaultHmiLevel( ApplicationConstSharedPtr application) const = 0; + + /** + * @brief Checks if required transport for resumption is available + * + * The required transport can be configured through smartDeviceLink.ini file. + * + * @param application an instance of the app to check + * @return true if the app is connected through one of the required + * transports, false otherwise + */ + virtual bool CheckResumptionRequiredTransportAvailable( + ApplicationConstSharedPtr application) const = 0; + /** * @brief hmi_capabilities return capabilities of hmi * @return capabilities of hmi @@ -380,6 +389,11 @@ class ApplicationManager { virtual policy::PolicyHandlerInterface& GetPolicyHandler() = 0; virtual const policy::PolicyHandlerInterface& GetPolicyHandler() const = 0; + virtual rpc_service::RPCService& GetRPCService() const = 0; + virtual rpc_handler::RPCHandler& GetRPCHandler() const = 0; + virtual bool is_stopping() const = 0; + virtual bool is_audio_pass_thru_active() const = 0; + virtual uint32_t GetNextHMICorrelationID() = 0; virtual uint32_t GenerateNewHMIAppID() = 0; @@ -389,12 +403,10 @@ class ApplicationManager { */ virtual void EndNaviServices(uint32_t app_id) = 0; - /* @brief Starts audio passthru process - * @deprecated Use BeginAudioPassThru(uint32_t app_id) instead - * - * @return true on success, false if passthru is already in process + /** + * @brief returns true if low voltage state is active */ - DEPRECATED virtual bool BeginAudioPassThrough() = 0; + virtual bool IsLowVoltage() const = 0; /** * @brief Starts AudioPassThru process by given application @@ -403,14 +415,6 @@ class ApplicationManager { */ virtual bool BeginAudioPassThru(uint32_t app_id) = 0; - /* - * @brief Finishes already started audio passthru process - * @deprecated Use EndAudioPassThru(uint32_t app_id) instead - * - * @return true on success, false if passthru is not active - */ - DEPRECATED virtual bool EndAudioPassThrough() = 0; - /** * @brief Finishes already started AudioPassThru process by given application * @param app_id ID of the application which started the process @@ -431,10 +435,10 @@ class ApplicationManager { * @param vehicle_info Enum value of type of vehicle data * @param new value (for integer values currently) of vehicle data */ - virtual AppSharedPtrs IviInfoUpdated( - mobile_apis::VehicleDataType::eType vehicle_info, int value) = 0; + virtual void IviInfoUpdated(mobile_apis::VehicleDataType::eType vehicle_info, + int value) = 0; - virtual ApplicationSharedPtr RegisterApplication(const utils::SharedPtr< + virtual ApplicationSharedPtr RegisterApplication(const std::shared_ptr< smart_objects::SmartObject>& request_for_registration) = 0; virtual void SendUpdateAppList() = 0; @@ -469,7 +473,7 @@ class ApplicationManager { const std::vector<uint8_t>& binary_data, const std::string& file_path, const std::string& file_name, - const int64_t offset) = 0; + const uint64_t offset) = 0; /* * @brief Sets SDL access to all mobile apps * @@ -613,6 +617,9 @@ class ApplicationManager { virtual app_launch::AppLaunchCtrl& app_launch_ctrl() = 0; + virtual protocol_handler::MajorProtocolVersion SupportedSDLVersion() + const = 0; + /* * @brief Converts connection string transport type representation * to HMI Common_TransportType @@ -669,30 +676,13 @@ class ApplicationManager { * @return new regular HMI state */ virtual HmiStatePtr CreateRegularState( - utils::SharedPtr<Application> app, + std::shared_ptr<Application> app, mobile_apis::HMILevel::eType hmi_level, mobile_apis::AudioStreamingState::eType audio_state, + mobile_apis::VideoStreamingState::eType video_state, mobile_apis::SystemContext::eType system_context) const = 0; /** - * DEPRECATED - * @brief CreateRegularState create regular HMI state for application - * @param app_id Application 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) * @param app_id Application id @@ -723,6 +713,9 @@ class ApplicationManager { std::vector<std::string>& rejected_params) = 0; virtual const ApplicationManagerSettings& get_settings() const = 0; + // Extract the app ID to use internally based on the UseFullAppID .ini setting + virtual std::string GetCorrectMobileIDFromMessage( + const commands::MessageSharedPtr& message) const = 0; virtual event_engine::EventDispatcher& event_dispatcher() = 0; @@ -730,6 +723,10 @@ class ApplicationManager { virtual void OnTimerSendTTSGlobalProperties() = 0; virtual void OnLowVoltage() = 0; virtual void OnWakeUp() = 0; + + virtual bool IsSOStructValid( + const hmi_apis::StructIdentifiers::eType struct_id, + const smart_objects::SmartObject& display_capabilities) = 0; }; } // namespace application_manager diff --git a/src/components/include/application_manager/application_manager_settings.h b/src/components/include/application_manager/application_manager_settings.h index e745a831c6..8fdca4125f 100644 --- a/src/components/include/application_manager/application_manager_settings.h +++ b/src/components/include/application_manager/application_manager_settings.h @@ -38,6 +38,8 @@ #include <stdint.h> #include <string> +#include <map> +#include <vector> namespace application_manager { class ApplicationManagerSettings : public RequestControlerSettings, @@ -48,6 +50,8 @@ class ApplicationManagerSettings : public RequestControlerSettings, virtual const std::pair<uint32_t, int32_t>& read_did_frequency() const = 0; virtual const std::pair<uint32_t, int32_t>& get_vehicle_data_frequency() const = 0; + virtual const std::pair<uint32_t, int32_t>& + get_interior_vehicle_data_frequency() const = 0; virtual uint32_t hash_string_size() const = 0; virtual const uint32_t& app_dir_quota() const = 0; virtual uint32_t stop_streaming_timeout() const = 0; @@ -80,6 +84,7 @@ class ApplicationManagerSettings : public RequestControlerSettings, virtual const std::string& video_stream_file() const = 0; virtual const std::string& audio_stream_file() const = 0; + virtual bool use_full_app_id() const = 0; virtual bool use_db_for_resumption() const = 0; virtual const uint32_t& app_resumption_save_persistent_data_timeout() const = 0; @@ -87,6 +92,13 @@ class ApplicationManagerSettings : public RequestControlerSettings, virtual const uint32_t& app_resuming_timeout() const = 0; virtual uint16_t attempts_to_open_resumption_db() const = 0; virtual uint16_t open_attempt_timeout_ms_resumption_db() const = 0; + virtual const std::map<std::string, std::vector<std::string> >& + transport_required_for_resumption_map() const = 0; + virtual const std::string& navigation_lowbandwidth_resumption_level() + const = 0; + virtual const std::string& projection_lowbandwidth_resumption_level() + const = 0; + virtual const std::string& media_lowbandwidth_resumption_level() const = 0; virtual void set_config_file_name(const std::string& fileName) = 0; virtual const std::pair<uint32_t, int32_t>& start_stream_retry_amount() const = 0; diff --git a/src/components/include/application_manager/policies/policy_handler_interface.h b/src/components/include/application_manager/policies/policy_handler_interface.h index f0859ece38..ee9274ead7 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -40,7 +40,6 @@ #include <queue> #include "interfaces/MOBILE_API.h" #include "application_manager/policies/policy_handler_observer.h" -#include "application_manager/core_service.h" #include "application_manager/application.h" #include "policy/usage_statistics/statistics_manager.h" #include "utils/custom_string.h" @@ -49,10 +48,11 @@ #include "smart_objects/smart_object.h" #include "policy/policy_types.h" #include "policy/policy_table/types.h" +#include "policy/cache_manager_interface.h" using namespace ::rpc::policy_table_interface_base; namespace policy { -typedef utils::SharedPtr<utils::Callable> StatusNotifier; +typedef std::shared_ptr<utils::Callable> StatusNotifier; class PolicyHandlerInterface { public: @@ -124,7 +124,7 @@ class PolicyHandlerInterface { virtual void add_listener(PolicyHandlerObserver* listener) = 0; virtual void remove_listener(PolicyHandlerObserver* listener) = 0; - virtual utils::SharedPtr<usage_statistics::StatisticsManager> + virtual std::shared_ptr<usage_statistics::StatisticsManager> GetStatisticManager() const = 0; virtual void SendOnAppPermissionsChanged( @@ -391,6 +391,32 @@ class PolicyHandlerInterface { mobile_apis::RequestType::eType type) const = 0; /** + * @brief Checks if certain request subtype is allowed for application + * @param policy_app_id Unique applicaion id + * @param request_subtype Request subtype + * @return true, if allowed, otherwise - false + */ + virtual bool IsRequestSubTypeAllowed( + const std::string& policy_app_id, + const std::string& request_subtype) const = 0; + + /** + * @brief Gets application request types state + * @param policy_app_id Unique application id + * @return request types state + */ + virtual RequestType::State GetAppRequestTypeState( + const std::string& policy_app_id) const = 0; + + /** + * @brief Gets application request subtypes state + * @param policy_app_id Unique application id + * @return request subtypes state + */ + virtual RequestSubType::State GetAppRequestSubTypeState( + const std::string& policy_app_id) const = 0; + + /** * @brief Gets application request types * @param policy_app_id Unique application id * @return request types @@ -399,6 +425,14 @@ class PolicyHandlerInterface { const std::string& policy_app_id) const = 0; /** + * @brief Gets application request subtypes + * @param policy_app_id Unique application id + * @return app request subtypes + */ + virtual const std::vector<std::string> GetAppRequestSubTypes( + const std::string& policy_app_id) const = 0; + + /** * @brief Gets vehicle information * @return Structure with vehicle information */ @@ -436,7 +470,6 @@ class PolicyHandlerInterface { virtual void OnDeviceSwitching(const std::string& device_id_from, const std::string& device_id_to) = 0; -#ifdef SDL_REMOTE_CONTROL /** * @brief Sets HMI default type for specified application * @param application_id ID application @@ -501,7 +534,6 @@ class PolicyHandlerInterface { */ virtual bool GetModuleTypes(const std::string& policy_app_id, std::vector<std::string>* modules) const = 0; -#endif // SDL_REMOTE_CONTROL private: /** diff --git a/src/components/include/application_manager/rpc_handler.h b/src/components/include/application_manager/rpc_handler.h new file mode 100644 index 0000000000..9b6428f32d --- /dev/null +++ b/src/components/include/application_manager/rpc_handler.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_RPC_HANDLER_H +#define SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_RPC_HANDLER_H + +#include "protocol_handler/protocol_observer.h" +#include "hmi_message_handler/hmi_message_handler.h" + +#ifdef TELEMETRY_MONITOR +#include "application_manager/telemetry_observer.h" +#endif // TELEMETRY_MONITOR + +namespace application_manager { +namespace rpc_handler { + +class RPCHandler + : public hmi_message_handler::HMIMessageObserver, + public protocol_handler::ProtocolObserver +#ifdef TELEMETRY_MONITOR + , + public telemetry_monitor::TelemetryObservable<AMTelemetryObserver> +#endif // TELEMETRY_MONITOR + { + public: + virtual ~RPCHandler() {} +}; + +} // namespace rpc_handler +} // namespace application_manager +#endif // SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_RPC_HANDLER_H diff --git a/src/components/include/application_manager/rpc_service.h b/src/components/include/application_manager/rpc_service.h new file mode 100644 index 0000000000..79b4007f71 --- /dev/null +++ b/src/components/include/application_manager/rpc_service.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_RPC_SERVICE_H +#define SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_RPC_SERVICE_H + +#include "application_manager/commands/command.h" +#include "application_manager/message.h" +#include "protocol_handler/protocol_handler.h" +#include "hmi_message_handler/hmi_message_handler.h" + +namespace application_manager { +namespace rpc_service { + +class RPCService { + public: + virtual ~RPCService() {} + + /** + * @brief ManageMobileCommand convert message to mobile command and execute it + * @param message pointer to received message + * @param origin origin of command + * @return true if command is executed, otherwise return false + */ + virtual bool ManageMobileCommand(const commands::MessageSharedPtr message, + commands::Command::CommandSource source) = 0; + /** + * @brief ManageHMICommand convert message to HMI command and execute it + * @param message pointer to received message + * @return true if command is executed, otherwise return false + */ + virtual bool ManageHMICommand(const commands::MessageSharedPtr message) = 0; + + /** + * @brief SendMessageToMobile Put message to the queue to be sent to mobile. + * @param message pointer to message to send + * @param final_message if true - connection to mobile will be closed + * after processing this message + */ + virtual void SendMessageToMobile(const commands::MessageSharedPtr message, + bool final_message = false) = 0; + /** + * @brief SendMessageToHMI Put message to the queue to be sent to HMI. + * @param message pointer to message to send + */ + virtual void SendMessageToHMI(const commands::MessageSharedPtr message) = 0; + + /** + * @brief set_protocol_handler + * @param handler + * set protocol handler + */ + virtual void set_protocol_handler( + protocol_handler::ProtocolHandler* handler) = 0; + virtual void set_hmi_message_handler( + hmi_message_handler::HMIMessageHandler* handler) = 0; +}; +} // namespace rpc_service +} // namespace application_manager + +#endif // SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_RPC_SERVICE_H diff --git a/src/components/include/application_manager/state_controller.h b/src/components/include/application_manager/state_controller.h index 2fe0492b42..8f608488e9 100644 --- a/src/components/include/application_manager/state_controller.h +++ b/src/components/include/application_manager/state_controller.h @@ -49,6 +49,7 @@ class StateController { ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level, const mobile_apis::AudioStreamingState::eType audio_state, + const mobile_apis::VideoStreamingState::eType video_state, const bool SendActivateApp) = 0; virtual void SetRegularState(ApplicationSharedPtr app, @@ -58,6 +59,7 @@ class StateController { ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level, const mobile_apis::AudioStreamingState::eType audio_state, + const mobile_apis::VideoStreamingState::eType video_state, const mobile_apis::SystemContext::eType system_context, const bool SendActivateApp) = 0; @@ -67,7 +69,8 @@ class StateController { virtual void SetRegularState( ApplicationSharedPtr app, - const mobile_apis::AudioStreamingState::eType audio_state) = 0; + const mobile_apis::AudioStreamingState::eType audio_state, + const mobile_apis::VideoStreamingState::eType video_state) = 0; virtual void SetRegularState( ApplicationSharedPtr app, @@ -82,9 +85,17 @@ class StateController { virtual int64_t SendBCActivateApp(ApplicationConstSharedPtr app, hmi_apis::Common_HMILevel::eType level, bool send_policy_priority) = 0; + /** + * @brief OnVideoStreamingStarted process video streaming started + * @param app projection or navigation application starting streaming + */ + virtual void OnVideoStreamingStarted(ApplicationConstSharedPtr app) = 0; - virtual void OnNaviStreamingStarted() = 0; - virtual void OnNaviStreamingStopped() = 0; + /** + * @brief OnVideoStreamingStopped process video streaming stopped + * @param app projection or navigation application stopping streaming + */ + virtual void OnVideoStreamingStopped(ApplicationConstSharedPtr app) = 0; virtual void OnStateChanged(ApplicationSharedPtr app, HmiStatePtr old_state, HmiStatePtr new_state) = 0; diff --git a/src/components/include/connection_handler/connection_handler.h b/src/components/include/connection_handler/connection_handler.h index 1fcf5e4477..a50760b547 100644 --- a/src/components/include/connection_handler/connection_handler.h +++ b/src/components/include/connection_handler/connection_handler.h @@ -40,6 +40,7 @@ #include "connection_handler/connection.h" #include "connection_handler/devices_discovery_starter.h" #include "utils/macro.h" +#include "utils/data_accessor.h" /** * \namespace connection_handler @@ -51,6 +52,15 @@ enum CloseSessionReason { kCommon = 0, kFlood, kMalformed, kUnauthorizedApp }; class ConnectionHandlerObserver; +// The SessionConnectionMap keeps track of the primary and secondary transports +// associated with a session ID +typedef struct { + transport_manager::ConnectionUID primary_transport; + transport_manager::ConnectionUID secondary_transport; + std::vector<protocol_handler::ServiceType> secondary_transport_services; +} SessionTransports; +typedef std::map<uint8_t, SessionTransports> SessionConnectionMap; + /** * \class ConnectionHandler * \brief SmartDeviceLink ConnectionHandler interface class @@ -183,21 +193,6 @@ class ConnectionHandler { connection_handler::DeviceHandle* device_id) const = 0; /** - * DEPRECATED - * \brief information about given Connection Key. - * \param key Unique key used by other components as session identifier - * \param app_id Returned: ApplicationID - * \param sessions_list Returned: List of session keys - * \param device_id Returned: DeviceID - * \return int32_t -1 in case of error or 0 in case of success - */ - DEPRECATED virtual int32_t GetDataOnSessionKey( - uint32_t key, - uint32_t* app_id, - std::list<int32_t>* sessions_list, - uint32_t* device_id) const = 0; - - /** * @brief GetConnectedDevicesMAC allows to obtain MAC adresses for all * currently connected devices. * @@ -217,6 +212,43 @@ class ConnectionHandler { virtual DevicesDiscoveryStarter& get_device_discovery_starter() = 0; /** + * \brief Add a session. This is meant to be called from Connection class. + * \param primary_transport_id the primary connection ID to associate with the + * newly created session + * \return new session id, or 0 if failed + **/ + virtual uint32_t AddSession( + const transport_manager::ConnectionUID primary_transport_id) = 0; + + /** + * \brief Remove a session. This is meant to be called from Connection class. + * \param session_id ID of the session to remove + * \return true if successful, false otherwise + **/ + virtual bool RemoveSession(uint8_t session_id) = 0; + + virtual DataAccessor<SessionConnectionMap> session_connection_map() = 0; + + /** + * \brief Associate a secondary transport ID with a session + * \param session_id the session ID + * \param connection_id the new secondary connection ID to associate with the + * session + * \return the SessionTransports (newly) associated with the session + **/ + virtual SessionTransports SetSecondaryTransportID( + uint8_t session_id, + transport_manager::ConnectionUID secondary_transport_id) = 0; + + /** + * \brief Retrieve the session transports associated with a session + * \param session_id the session ID + * \return the SessionTransports associated with the session + **/ + virtual const SessionTransports GetSessionTransports( + uint8_t session_id) const = 0; + + /** * \brief Invoked when observer's OnServiceStartedCallback is completed * \param session_key the key of started session passed to * OnServiceStartedCallback(). @@ -232,6 +264,28 @@ class ConnectionHandler { bool result, std::vector<std::string>& rejected_params) = 0; + /** + * \brief Called when secondary transport with given session ID is established + * \param primary_connection_handle Set to identifier of primary connection + * \param secondary_connection_handle Identifier of secondary connection + * \param session_id session ID taken from Register Secondary Transport frame + * \return true if successful + **/ + virtual bool OnSecondaryTransportStarted( + transport_manager::ConnectionUID& primary_connection_handle, + const transport_manager::ConnectionUID secondary_connection_handle, + const uint8_t session_id) = 0; + + /** + * \brief Called when secondary transport shuts down + * \param primary_connection_handle Identifier of primary connection + * \param secondary_connection_handle Identifier of secondary connection + * transport + **/ + virtual void OnSecondaryTransportEnded( + const transport_manager::ConnectionUID primary_connection_handle, + const transport_manager::ConnectionUID secondary_connection_handle) = 0; + protected: /** * \brief Destructor diff --git a/src/components/include/connection_handler/connection_handler_observer.h b/src/components/include/connection_handler/connection_handler_observer.h index b4c04c17c9..154a2a8e34 100644 --- a/src/components/include/connection_handler/connection_handler_observer.h +++ b/src/components/include/connection_handler/connection_handler_observer.h @@ -86,19 +86,6 @@ class ConnectionHandlerObserver { /** * \brief Callback function used by connection_handler * when Mobile Application initiates start of new service. - * \param deviceHandle Device identifier within which session has to be - * started. - * \param sessionKey Key of started session. - * \param type Established service type - */ - virtual bool OnServiceStartedCallback( - const connection_handler::DeviceHandle& device_handle, - const int32_t& session_key, - const protocol_handler::ServiceType& type) = 0; - - /** - * \brief Callback function used by connection_handler - * when Mobile Application initiates start of new service. * Result must be notified through NotifyServiceStartedResult(). * \param deviceHandle Device identifier within which session has to be * started. @@ -157,6 +144,23 @@ class ConnectionHandlerObserver { virtual security_manager::SSLContext::HandshakeContext GetHandshakeContext( uint32_t key) const = 0; #endif // ENABLE_SECURITY + + /** + * \brief Called when secondary transport for a particular app is started. + * \param device_handle Device identifier on which the secondary transport is + * started. + * \param session_key session ID representing the app + */ + virtual void OnSecondaryTransportStartedCallback( + const connection_handler::DeviceHandle device_handle, + const int32_t session_key) = 0; + + /** + * \brief Called when secondary transport for a particular app is terminated. + * \param session_key session ID representing the app + */ + virtual void OnSecondaryTransportEndedCallback(const int32_t session_key) = 0; + protected: /** * \brief Destructor diff --git a/src/components/include/hmi_message_handler/hmi_message_observer.h b/src/components/include/hmi_message_handler/hmi_message_observer.h index 0676615b53..e7ba2619ee 100644 --- a/src/components/include/hmi_message_handler/hmi_message_observer.h +++ b/src/components/include/hmi_message_handler/hmi_message_observer.h @@ -33,8 +33,6 @@ #ifndef SRC_COMPONENTS_INCLUDE_HMI_MESSAGE_HANDLER_HMI_MESSAGE_OBSERVER_H_ #define SRC_COMPONENTS_INCLUDE_HMI_MESSAGE_HANDLER_HMI_MESSAGE_OBSERVER_H_ -#include "utils/shared_ptr.h" - namespace application_manager { class Message; } @@ -45,9 +43,9 @@ class HMIMessageObserver { public: virtual ~HMIMessageObserver() {} virtual void OnMessageReceived( - utils::SharedPtr<application_manager::Message> message) = 0; + std::shared_ptr<application_manager::Message> message) = 0; virtual void OnErrorSending( - utils::SharedPtr<application_manager::Message> message) = 0; + std::shared_ptr<application_manager::Message> message) = 0; }; } diff --git a/src/components/include/hmi_message_handler/hmi_message_sender.h b/src/components/include/hmi_message_handler/hmi_message_sender.h index 91c20a1986..3f70f78a97 100644 --- a/src/components/include/hmi_message_handler/hmi_message_sender.h +++ b/src/components/include/hmi_message_handler/hmi_message_sender.h @@ -36,7 +36,7 @@ #include "application_manager/message.h" namespace hmi_message_handler { -typedef utils::SharedPtr<application_manager::Message> MessageSharedPointer; +typedef std::shared_ptr<application_manager::Message> MessageSharedPointer; class HMIMessageSender { public: diff --git a/src/components/include/policy/policy_external/policy/policy_listener.h b/src/components/include/policy/policy_external/policy/policy_listener.h index e850a3fa2b..c446c87d1b 100644 --- a/src/components/include/policy/policy_external/policy/policy_listener.h +++ b/src/components/include/policy/policy_external/policy/policy_listener.h @@ -52,13 +52,6 @@ class PolicyListener { const Permissions& permissions) = 0; virtual void OnPendingPermissionChange(const std::string& policy_app_id) = 0; virtual void OnUpdateStatusChanged(const std::string&) = 0; - - /** - * Gets device ID - * @param policy_app_id - * @return device ID - * @deprecated see std::vector<std::string> GetDevicesIds(const std::string&) - */ virtual std::string OnCurrentDeviceIdUpdateRequired( const std::string& policy_app_id) = 0; virtual void OnSystemInfoUpdateRequired() = 0; @@ -137,7 +130,6 @@ class PolicyListener { virtual void GetRegisteredLinks( std::map<std::string, std::string>& out_links) const = 0; -#ifdef SDL_REMOTE_CONTROL /** * Gets devices ids by policy application id * @param policy_app_id @@ -173,8 +165,6 @@ class PolicyListener { virtual void OnUpdateHMIStatus(const std::string& device_id, const std::string& policy_app_id, const std::string& hmi_level) = 0; - -#endif // SDL_REMOTE_CONTROL }; } // namespace policy #endif // SRC_COMPONENTS_INCLUDE_POLICY_POLICY_EXTERNAL_POLICY_POLICY_LISTENER_H_ diff --git a/src/components/include/policy/policy_external/policy/policy_manager.h b/src/components/include/policy/policy_external/policy/policy_manager.h index 24905671fa..57f6d2f802 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -41,14 +41,12 @@ #include "policy/policy_table/types.h" #include "policy/policy_listener.h" #include "policy/usage_statistics/statistics_manager.h" - -#ifdef SDL_REMOTE_CONTROL +#include "policy/cache_manager_interface.h" #include "policy/access_remote.h" -#endif // SDL_REMOTE_CONTROL namespace policy { class PolicySettings; -typedef utils::SharedPtr<utils::Callable> StatusNotifier; +typedef std::shared_ptr<utils::Callable> StatusNotifier; class PolicyManager : public usage_statistics::StatisticsManager { public: @@ -487,6 +485,22 @@ class PolicyManager : public usage_statistics::StatisticsManager { const std::string& device_id_to) = 0; /** + * @brief Get state of request types for given application + * @param policy_app_id Unique application id + * @return request type state + */ + virtual RequestType::State GetAppRequestTypesState( + const std::string& policy_app_id) const = 0; + + /** + * @brief Get state of request subtypes for given application + * @param policy_app_id Unique application id + * @return request subtype state + */ + virtual RequestSubType::State GetAppRequestSubTypesState( + const std::string& policy_app_id) const = 0; + + /** * @brief Gets request types for application * @param policy_app_id Unique application id * @return request types of application @@ -495,6 +509,14 @@ class PolicyManager : public usage_statistics::StatisticsManager { const std::string policy_app_id) const = 0; /** + * @brief Gets request subtypes for application + * @param policy_app_id Unique application id + * @return request subtypes of application + */ + virtual const std::vector<std::string> GetAppRequestSubTypes( + const std::string& policy_app_id) const = 0; + + /** * @brief Get information about vehicle * @return vehicle information */ @@ -540,7 +562,6 @@ class PolicyManager : public usage_statistics::StatisticsManager { */ virtual AppIdURL GetNextUpdateUrl(const EndpointUrls& urls) = 0; -#ifdef SDL_REMOTE_CONTROL /** * @brief Assigns new HMI types for specified application * @param application_id Unique application id @@ -588,8 +609,7 @@ class PolicyManager : public usage_statistics::StatisticsManager { * @param access_remote pointer to new access_remote instance */ virtual void set_access_remote( - utils::SharedPtr<AccessRemote> access_remote) = 0; -#endif // SDL_REMOTE_CONTROL + std::shared_ptr<AccessRemote> access_remote) = 0; /** * @brief Checks if there is existing URL in the EndpointUrls vector with diff --git a/src/components/include/policy/policy_external/policy/policy_settings.h b/src/components/include/policy/policy_external/policy/policy_settings.h index def9fca05a..7eca5129ad 100644 --- a/src/components/include/policy/policy_external/policy/policy_settings.h +++ b/src/components/include/policy/policy_external/policy/policy_settings.h @@ -31,6 +31,8 @@ class PolicySettings { */ virtual const std::string& policies_snapshot_file_name() const = 0; + virtual bool use_full_app_id() const = 0; + /** * @brief Returns system files folder path */ diff --git a/src/components/include/policy/policy_regular/policy/policy_listener.h b/src/components/include/policy/policy_regular/policy/policy_listener.h index e8de37d5de..3f6f555bcc 100644 --- a/src/components/include/policy/policy_regular/policy/policy_listener.h +++ b/src/components/include/policy/policy_regular/policy/policy_listener.h @@ -112,7 +112,6 @@ class PolicyListener { */ virtual void OnCertificateUpdated(const std::string& certificate_data) = 0; -#ifdef SDL_REMOTE_CONTROL /** * Gets devices ids by policy application id * @param policy_app_id @@ -148,8 +147,6 @@ class PolicyListener { virtual void OnUpdateHMIStatus(const std::string& device_id, const std::string& policy_app_id, const std::string& hmi_level) = 0; - -#endif // SDL_REMOTE_CONTROL }; } // namespace policy #endif // SRC_COMPONENTS_INCLUDE_POLICY_POLICY_REGULAR_POLICY_POLICY_LISTENER_H_ diff --git a/src/components/include/policy/policy_regular/policy/policy_manager.h b/src/components/include/policy/policy_regular/policy/policy_manager.h index 3e90cfc094..ee0bae7118 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -41,13 +41,12 @@ #include "policy/policy_table/types.h" #include "policy/policy_listener.h" #include "policy/usage_statistics/statistics_manager.h" -#ifdef SDL_REMOTE_CONTROL +#include "policy/cache_manager_interface.h" #include "policy/access_remote.h" -#endif // SDL_REMOTE_CONTROL namespace policy { class PolicySettings; -typedef utils::SharedPtr<utils::Callable> StatusNotifier; +typedef std::shared_ptr<utils::Callable> StatusNotifier; class PolicyManager : public usage_statistics::StatisticsManager { public: @@ -466,6 +465,22 @@ class PolicyManager : public usage_statistics::StatisticsManager { virtual void OnAppsSearchCompleted(const bool trigger_ptu) = 0; /** + * @brief Get state of request types for given application + * @param policy_app_id Unique application id + * @return request type state + */ + virtual RequestType::State GetAppRequestTypesState( + const std::string& policy_app_id) const = 0; + + /** + * @brief Get state of request subtypes for given application + * @param policy_app_id Unique application id + * @return request subtype state + */ + virtual RequestSubType::State GetAppRequestSubTypesState( + const std::string& policy_app_id) const = 0; + + /** * @brief Gets request types for application * @param policy_app_id Unique application id * @return request types of application @@ -474,6 +489,14 @@ class PolicyManager : public usage_statistics::StatisticsManager { const std::string policy_app_id) const = 0; /** + * @brief Gets request subtypes for application + * @param policy_app_id Unique application id + * @return request subtypes of application + */ + virtual const std::vector<std::string> GetAppRequestSubTypes( + const std::string& policy_app_id) const = 0; + + /** * @brief Get information about vehicle * @return vehicle information */ @@ -517,7 +540,7 @@ class PolicyManager : public usage_statistics::StatisticsManager { * urls vector */ virtual AppIdURL GetNextUpdateUrl(const EndpointUrls& urls) = 0; -#ifdef SDL_REMOTE_CONTROL + /** * @brief Assigns new HMI types for specified application * @param application_id Unique application id @@ -566,8 +589,7 @@ class PolicyManager : public usage_statistics::StatisticsManager { * @param access_remote pointer to new access_remote instance */ virtual void set_access_remote( - utils::SharedPtr<AccessRemote> access_remote) = 0; -#endif // SDL_REMOTE_CONTROL + std::shared_ptr<AccessRemote> access_remote) = 0; /** * @brief Checks if there is existing URL in the EndpointUrls vector with diff --git a/src/components/include/policy/policy_regular/policy/policy_settings.h b/src/components/include/policy/policy_regular/policy/policy_settings.h index def9fca05a..35a2d54c3a 100644 --- a/src/components/include/policy/policy_regular/policy/policy_settings.h +++ b/src/components/include/policy/policy_regular/policy/policy_settings.h @@ -36,6 +36,8 @@ class PolicySettings { */ virtual const std::string& system_files_path() const = 0; + virtual bool use_full_app_id() const = 0; + virtual ~PolicySettings() {} }; } // namespace policy diff --git a/src/components/include/protocol/bson_object_keys.h b/src/components/include/protocol/bson_object_keys.h index 6f80aeec2b..56bd5cebd6 100644 --- a/src/components/include/protocol/bson_object_keys.h +++ b/src/components/include/protocol/bson_object_keys.h @@ -42,6 +42,12 @@ extern const char* height; extern const char* width; extern const char* video_protocol; extern const char* video_codec; +extern const char* secondary_transports; +extern const char* audio_service_transports; +extern const char* video_service_transports; +extern const char* tcp_ip_address; +extern const char* tcp_port; +extern const char* reason; } // namespace strings diff --git a/src/components/include/protocol/common.h b/src/components/include/protocol/common.h index 00d57a9bf5..1c95020a96 100644 --- a/src/components/include/protocol/common.h +++ b/src/components/include/protocol/common.h @@ -167,6 +167,22 @@ enum { */ FRAME_DATA_END_SERVICE_NACK = 0x06, /** + *\brief Register Secondary Transport frame + */ + FRAME_DATA_REGISTER_SECONDARY_TRANSPORT = 0x07, + /** + *\brief Register Secondary Transport acknowledgement frame + */ + FRAME_DATA_REGISTER_SECONDARY_TRANSPORT_ACK = 0x08, + /** + *\brief Register Secondary Transport not acknowledgement frame + */ + FRAME_DATA_REGISTER_SECONDARY_TRANSPORT_NACK = 0x09, + /** + *\brief Transport Event Update frame + */ + FRAME_DATA_TRANSPORT_EVENT_UPDATE = 0xFD, + /** *\brief Service data ACK frame */ FRAME_DATA_SERVICE_DATA_ACK = 0xFE, diff --git a/src/components/include/protocol/raw_message.h b/src/components/include/protocol/raw_message.h index 99cb73ce67..5171d42593 100644 --- a/src/components/include/protocol/raw_message.h +++ b/src/components/include/protocol/raw_message.h @@ -33,7 +33,7 @@ #define SRC_COMPONENTS_INCLUDE_PROTOCOL_RAW_MESSAGE_H_ #include "utils/macro.h" -#include "utils/shared_ptr.h" +#include <memory> #include "protocol/service_type.h" #include "protocol/message_priority.h" @@ -114,6 +114,6 @@ class RawMessage { bool waiting_; DISALLOW_COPY_AND_ASSIGN(RawMessage); }; -typedef utils::SharedPtr<RawMessage> RawMessagePtr; +typedef std::shared_ptr<RawMessage> RawMessagePtr; } // namespace protocol_handler #endif // SRC_COMPONENTS_INCLUDE_PROTOCOL_RAW_MESSAGE_H_ diff --git a/src/components/include/protocol_handler/protocol_handler.h b/src/components/include/protocol_handler/protocol_handler.h index 6aafd7d53f..d65902030b 100644 --- a/src/components/include/protocol_handler/protocol_handler.h +++ b/src/components/include/protocol_handler/protocol_handler.h @@ -100,9 +100,23 @@ class ProtocolHandler { */ virtual void SendEndSession(int32_t connection_id, uint8_t session_id) = 0; - virtual void SendEndService(int32_t connection_id, + /** + * \brief Sends ending session to mobile application + * \param primary_connection_id Identifier of connection within which + * service exists + * \param connection_id Identifier of the actual transport for the service + * \param session_id ID of session to be ended + */ + virtual void SendEndService(int32_t primary_connection_id, + int32_t connection_id, uint8_t session_id, uint8_t service_type) = 0; + + /** + * \brief Called to notify all handsheke handlers about handshake failure. + */ + virtual void NotifyOnFailedHandshake() = 0; + /** * \brief Protocol handler settings getter * \return pointer to protocol handler settings class @@ -111,27 +125,6 @@ class ProtocolHandler { virtual SessionObserver& get_session_observer() = 0; /** - * \brief Called by connection handler to notify the result of - * OnSessionStartedCallback(). - * \param connection_id Identifier of connection within which session exists - * \param session_id session ID passed to OnSessionStartedCallback() - * \param generated_session_id Generated session ID, will be 0 if session is - * not started - * \param hash_id Generated Hash ID - * \param protection whether the service will be protected - * \param rejected_params list of parameters' name that are rejected. - * Only valid when generated_session_id is 0. Note, even if - * generated_session_id is 0, the list may be empty. - */ - DEPRECATED virtual void NotifySessionStartedResult( - int32_t connection_id, - uint8_t session_id, - uint8_t generated_session_id, - uint32_t hash_id, - bool protection, - std::vector<std::string>& rejected_params) = 0; - - /** * @brief Called by connection handler to notify the context of * OnSessionStartedCallback(). * @param context reference to structure with started session data diff --git a/src/components/include/protocol_handler/protocol_handler_settings.h b/src/components/include/protocol_handler/protocol_handler_settings.h index e1107cb2a9..62a24df32c 100644 --- a/src/components/include/protocol_handler/protocol_handler_settings.h +++ b/src/components/include/protocol_handler/protocol_handler_settings.h @@ -34,12 +34,6 @@ class ProtocolHandlerSettings { */ virtual uint16_t max_supported_protocol_version() const = 0; - /* - * @brief Returns true, if SDL 4.0 is enabled - * @deprecated Use max_supported_protocol_version instead - */ - DEPRECATED virtual bool enable_protocol_4() const = 0; - virtual uint32_t multiframe_waiting_timeout() const = 0; #ifdef ENABLE_SECURITY /** @@ -51,6 +45,28 @@ class ProtocolHandlerSettings { */ virtual const std::vector<int>& force_unprotected_service() const = 0; #endif // ENABLE_SECURITY + + /** + * @brief Returns true multiple transports is enabled + */ + virtual const bool multiple_transports_enabled() const = 0; + + /** + * @brief Returns list of secondary transports available + * for the named primary transport + */ + virtual const std::vector<std::string>& secondary_transports_for_bluetooth() + const = 0; + virtual const std::vector<std::string>& secondary_transports_for_usb() + const = 0; + virtual const std::vector<std::string>& secondary_transports_for_wifi() + const = 0; + + /** + * @brief Returns list of allowed transports for the named service + */ + virtual const std::vector<std::string>& audio_service_transports() const = 0; + virtual const std::vector<std::string>& video_service_transports() const = 0; }; } // namespace protocol_handler #endif // SRC_COMPONENTS_INCLUDE_PROTOCOL_HANDLER_PROTOCOL_HANDLER_SETTINGS_H_ diff --git a/src/components/include/protocol_handler/session_observer.h b/src/components/include/protocol_handler/session_observer.h index 3482c6569c..e71557fecf 100644 --- a/src/components/include/protocol_handler/session_observer.h +++ b/src/components/include/protocol_handler/session_observer.h @@ -59,6 +59,7 @@ enum { HASH_ID_NOT_SUPPORTED = 0, HASH_ID_WRONG = 0xFFFF0000 }; * @brief Struct with data containing attributes of starting session **/ struct SessionContext { + transport_manager::ConnectionUID primary_connection_id_; transport_manager::ConnectionUID connection_id_; uint8_t initial_session_id_; uint8_t new_session_id_; @@ -66,23 +67,24 @@ struct SessionContext { uint32_t hash_id_; bool is_protected_; bool is_new_service_; - bool is_ptu_required_; /** * @brief Constructor */ SessionContext() - : connection_id_(0) + : primary_connection_id_(0) + , connection_id_(0) , initial_session_id_(0) , new_session_id_(0) , service_type_(protocol_handler::kInvalidServiceType) , hash_id_(0) , is_protected_(false) - , is_new_service_(false) - , is_ptu_required_(false) {} + , is_new_service_(false) {} /** * @brief Constructor + * @param primary_connection_id Connection identifier of the primary + * connection in which the session is started * @param connection_id_ Connection identifier within which session is * started. * @param session_id Session ID specified to OnSessionStartedCallback() @@ -93,20 +95,21 @@ struct SessionContext { * @param is_protected Whether service will be protected * @param is_new_service Whether service was already established **/ - SessionContext(transport_manager::ConnectionUID connection_id, + SessionContext(transport_manager::ConnectionUID primary_connection_id, + transport_manager::ConnectionUID connection_id, uint8_t session_id, uint8_t new_session_id, protocol_handler::ServiceType service_type, uint32_t hash_id, const bool is_protected) - : connection_id_(connection_id) + : primary_connection_id_(primary_connection_id) + , connection_id_(connection_id) , initial_session_id_(session_id) , new_session_id_(new_session_id) , service_type_(service_type) , hash_id_(hash_id) , is_protected_(is_protected) - , is_new_service_(false) - , is_ptu_required_(false) {} + , is_new_service_(false) {} }; /** @@ -122,26 +125,6 @@ class SessionObserver { /** * \brief Callback function used by ProtocolHandler * when Mobile Application initiates start of new session. - * \param connection_handle Connection identifier within which session - * has to be started. - * \param sessionId Identifier of the session to be start - * \param service_type Type of service - * \param protocol_version Version of protocol - * \param is_protected would be service protected - * \param hash_id pointer for session hash identifier, uint32_t* hash_id - * \return uint32_t Id (number) of new session if successful, otherwise 0. - * \deprecated - */ - DEPRECATED virtual uint32_t OnSessionStartedCallback( - const transport_manager::ConnectionUID connection_handle, - const uint8_t sessionId, - const protocol_handler::ServiceType& service_type, - const bool is_protected, - uint32_t* hash_id) = 0; - - /** - * \brief Callback function used by ProtocolHandler - * when Mobile Application initiates start of new session. * Result must be notified through NotifySessionStartedContext(). * \param connection_handle Connection identifier within which session * has to be started. @@ -164,24 +147,6 @@ class SessionObserver { * \param connection_handle Connection identifier within which session exists * \param sessionId Identifier of the session to be ended * \param hashCode Hash used only in second version of SmartDeviceLink - * protocol. - * If not equal to hash assigned to session on start then operation fails. - * \param service_type Type of service - * \return uint32_t 0 if operation fails, session key otherwise - * \deprecated - */ - DEPRECATED virtual uint32_t OnSessionEndedCallback( - const transport_manager::ConnectionUID connection_handle, - const uint8_t sessionId, - const uint32_t& hashCode, - const protocol_handler::ServiceType& service_type) = 0; - - /** - * \brief Callback function used by ProtocolHandler - * when Mobile Application initiates session ending. - * \param connection_handle Connection identifier within which session exists - * \param sessionId Identifier of the session to be ended - * \param hashCode Hash used only in second version of SmartDeviceLink * protocol. (Set to HASH_ID_WRONG if the hash is incorrect) * If not equal to hash assigned to session on start then operation fails. * \param service_type Type of service @@ -208,6 +173,24 @@ class SessionObserver { virtual void OnMalformedMessageCallback(const uint32_t& connection_key) = 0; /** + * @brief Converts connection handle to transport type string used in + * smartDeviceLink.ini file, e.g. "TCP_WIFI" + * @param connection_handle A connection identifier + * @return string representation of the transport of the device + */ + virtual const std::string TransportTypeProfileStringFromConnHandle( + transport_manager::ConnectionUID connection_handle) const = 0; + + /** + * @brief Converts device handle to transport type string used in + * smartDeviceLink.ini file, e.g. "TCP_WIFI" + * @param device_handle A device handle + * @return string representation of the transport of the device + */ + virtual const std::string TransportTypeProfileStringFromDeviceHandle( + transport_manager::DeviceHandle device_handle) const = 0; + + /** * \brief Creates unique identifier of session (can be used as hash) * from given connection identifier * within which session exists and session number. @@ -231,20 +214,6 @@ class SessionObserver { uint8_t* sessionId) const = 0; /** - * DEPRECATED - * \brief information about given Connection Key. - * \param key Unique key used by other components as session identifier - * \param app_id Returned: ApplicationID - * \param sessions_list Returned: List of session keys - * \param device_id Returned: DeviceID - * \return int32_t -1 in case of error or 0 in case of success - */ - virtual int32_t GetDataOnSessionKey(uint32_t key, - uint32_t* app_id, - std::list<int32_t>* sessions_list, - uint32_t* device_id) const = 0; - - /** * \brief information about given Connection Key. * \param key Unique key used by other components as session identifier * \param app_id Returned: ApplicationID diff --git a/src/components/include/protocol_handler/telemetry_observer.h b/src/components/include/protocol_handler/telemetry_observer.h index a76fbce717..b2bf94de35 100644 --- a/src/components/include/protocol_handler/telemetry_observer.h +++ b/src/components/include/protocol_handler/telemetry_observer.h @@ -45,12 +45,12 @@ class PHTelemetryObserver { RawMessagePtr raw_msg; uint32_t message_id; uint8_t connection_key; - TimevalStruct begin; - TimevalStruct end; + date_time::TimeDuration begin; + date_time::TimeDuration end; }; - virtual void StartMessageProcess(uint32_t message_id, - const TimevalStruct& start_time) = 0; - virtual void EndMessageProcess(utils::SharedPtr<MessageMetric> m) = 0; + virtual void StartMessageProcess( + uint32_t message_id, const date_time::TimeDuration& start_time) = 0; + virtual void EndMessageProcess(std::shared_ptr<MessageMetric> m) = 0; virtual ~PHTelemetryObserver() {} }; } // protocol_handler diff --git a/src/components/include/security_manager/crypto_manager.h b/src/components/include/security_manager/crypto_manager.h index 18c06ffe06..486b6da64f 100644 --- a/src/components/include/security_manager/crypto_manager.h +++ b/src/components/include/security_manager/crypto_manager.h @@ -33,6 +33,7 @@ #ifndef SRC_COMPONENTS_INCLUDE_SECURITY_MANAGER_CRYPTO_MANAGER_H_ #define SRC_COMPONENTS_INCLUDE_SECURITY_MANAGER_CRYPTO_MANAGER_H_ +#include <time.h> #include "application_manager/policies/policy_handler_observer.h" #include "security_manager/security_manager_settings.h" @@ -65,8 +66,16 @@ class CryptoManager : public policy::PolicyHandlerObserver { virtual bool OnCertificateUpdated(const std::string& data) = 0; virtual void ReleaseSSLContext(SSLContext* context) = 0; virtual std::string LastError() const = 0; - - virtual bool IsCertificateUpdateRequired() const = 0; + /** + * @brief IsCertificateUpdateRequired checks if certificate update is needed + * @param system_time - time with which certificate expiration time + * should be compared + * @param certificates_time - certificate expiration time + * @return True if certificate expired and need to be updated + * otherwise False + */ + virtual bool IsCertificateUpdateRequired( + const time_t system_time, const time_t certificates_time) const = 0; /** * \brief Crypto manager settings getter * \return pointer to crypto manager settings class diff --git a/src/components/include/security_manager/security_manager.h b/src/components/include/security_manager/security_manager.h index 8f772f6a13..61ba43c74f 100644 --- a/src/components/include/security_manager/security_manager.h +++ b/src/components/include/security_manager/security_manager.h @@ -41,6 +41,7 @@ #include "protocol_handler/session_observer.h" #include "security_manager/security_manager_listener.h" +#include "application_manager/policies/policy_handler_observer.h" namespace security_manager { @@ -50,7 +51,8 @@ class CryptoManager; * protocol_handler::ProtocolObserver * and provide interface for handling Security queries from mobile side */ -class SecurityManager : public protocol_handler::ProtocolObserver { +class SecurityManager : public protocol_handler::ProtocolObserver, + public policy::PolicyHandlerObserver { public: /** * \brief InternalErrors is 1 byte identifier of internal error @@ -70,6 +72,10 @@ class SecurityManager : public protocol_handler::ProtocolObserver { ERROR_INTERNAL = 0xFF, ERROR_UNKNOWN_INTERNAL_ERROR = 0xFE // error value for testing }; + + // SSL context creation strategy + enum ContextCreationStrategy { kUseExisting = 0, kForceRecreation }; + /** * \brief Sets pointer for Connection Handler layer for managing sessions * \param session_observer pointer to object of the class implementing @@ -114,13 +120,15 @@ class SecurityManager : public protocol_handler::ProtocolObserver { } /** - * \brief Create new SSLContext for connection or return exists + * @brief Create new SSLContext for connection or return exists * Do not notify listeners, send security error on occure - * \param connection_key Unique key used by other components as session + * @param connection_key Unique key used by other components as session * identifier + * @param cc_strategy - SSL context creation strategy * @return new \c SSLContext or \c NULL on any error */ - virtual SSLContext* CreateSSLContext(const uint32_t& connection_key) = 0; + virtual SSLContext* CreateSSLContext(const uint32_t& connection_key, + ContextCreationStrategy cc_strategy) = 0; /** * \brief Start handshake as SSL client @@ -128,10 +136,26 @@ class SecurityManager : public protocol_handler::ProtocolObserver { virtual void StartHandshake(uint32_t connection_key) = 0; /** + * @brief PostponeHandshake allows to postpone handshake. It notifies + * cryptomanager that certificate should be updated and adds specified + * connection key to the list of the certificate awaiting connections. + * @param connection_key the identifier for connection to postpone handshake. + */ + virtual void PostponeHandshake(const uint32_t connection_key) = 0; + + /** * @brief Check whether certificate should be updated + * @param connection_key the connection identifier to check certificate for. * @return true if certificate should be updated otherwise false */ - virtual bool IsCertificateUpdateRequired() = 0; + virtual bool IsCertificateUpdateRequired(const uint32_t connection_key) = 0; + + /** + * @brief Checks whether system time ready notification + * was received from hmi + * @return true if received otherwise false + */ + virtual bool IsSystemTimeProviderReady() const = 0; /** * @brief Notify all listeners that certificate update required @@ -140,6 +164,11 @@ class SecurityManager : public protocol_handler::ProtocolObserver { virtual void NotifyOnCertificateUpdateRequired() = 0; /** + * @brief Notify all listeners that handshake was failed + */ + virtual void NotifyListenersOnHandshakeFailed() = 0; + + /** * @brief Check if policy certificate data is empty * @return true if policy certificate data is empty otherwise false */ @@ -150,6 +179,18 @@ class SecurityManager : public protocol_handler::ProtocolObserver { */ virtual void AddListener(SecurityManagerListener* const listener) = 0; virtual void RemoveListener(SecurityManagerListener* const listener) = 0; + + /** + * @brief OnCertificateUpdated allows to obtain notification when certificate + * has been updated with policy table update. Pass this certificate to crypto + * manager for further processing. Also process postopnes handshake for the + * certain connection key. + * + * @param data the certificates content. + * + * @return always true. + */ + virtual bool OnCertificateUpdated(const std::string& data) = 0; }; } // namespace security_manager #endif // SRC_COMPONENTS_INCLUDE_SECURITY_MANAGER_SECURITY_MANAGER_H_ diff --git a/src/components/include/security_manager/security_manager_listener.h b/src/components/include/security_manager/security_manager_listener.h index aeb3334a56..00a4c68134 100644 --- a/src/components/include/security_manager/security_manager_listener.h +++ b/src/components/include/security_manager/security_manager_listener.h @@ -47,6 +47,13 @@ class SecurityManagerListener { */ virtual bool OnHandshakeDone(uint32_t connection_key, SSLContext::HandshakeResult result) = 0; + + /** + * @brief Notification about handshake failure + * @return true on success notification handling or false otherwise + */ + virtual bool OnHandshakeFailed() = 0; + /** * @brief Notify listeners that certificate update is required. */ diff --git a/src/components/include/security_manager/security_manager_settings.h b/src/components/include/security_manager/security_manager_settings.h index c6b97f85cc..0bbe0f4f96 100644 --- a/src/components/include/security_manager/security_manager_settings.h +++ b/src/components/include/security_manager/security_manager_settings.h @@ -33,12 +33,16 @@ #ifndef SRC_COMPONENTS_INCLUDE_SECURITY_MANAGER_SECURITY_MANAGER_SETTINGS_H_ #define SRC_COMPONENTS_INCLUDE_SECURITY_MANAGER_SECURITY_MANAGER_SETTINGS_H_ +#include <stddef.h> +#include <string> +#include <vector> + namespace security_manager { enum Mode { CLIENT, SERVER }; -enum Protocol { SSLv3, TLSv1, TLSv1_1, TLSv1_2 }; +enum Protocol { SSLv3, TLSv1, TLSv1_1, TLSv1_2, DTLSv1 }; /** - * \class ConnectionHandlerSettings - * \brief Interface for connection handler component settings. + * \class CryptoManagerSettings + * \brief Interface for crypto manager component settings. */ class CryptoManagerSettings { public: @@ -50,8 +54,12 @@ class CryptoManagerSettings { virtual const std::string& certificate_data() const = 0; virtual const std::string& ciphers_list() const = 0; virtual const std::string& ca_cert_path() const = 0; + virtual const std::string& module_cert_path() const = 0; + virtual const std::string& module_key_path() const = 0; virtual size_t update_before_hours() const = 0; virtual size_t maximum_payload_size() const = 0; + virtual const std::vector<int>& force_protected_service() const = 0; + virtual const std::vector<int>& force_unprotected_service() const = 0; }; } // namespace security_manager diff --git a/src/components/include/security_manager/security_query.h b/src/components/include/security_manager/security_query.h index cdad1c746c..8aa5b60853 100644 --- a/src/components/include/security_manager/security_query.h +++ b/src/components/include/security_manager/security_query.h @@ -37,7 +37,7 @@ #include <cstddef> #include <vector> #include <string> -#include "utils/shared_ptr.h" +#include <memory> namespace security_manager { /** @@ -189,6 +189,6 @@ class SecurityQuery { /** *\brief SmartPointer wrapper */ -typedef utils::SharedPtr<SecurityQuery> SecurityQueryPtr; +typedef std::shared_ptr<SecurityQuery> SecurityQueryPtr; } // namespace security_manager #endif // SRC_COMPONENTS_INCLUDE_SECURITY_MANAGER_SECURITY_QUERY_H_ diff --git a/src/components/include/security_manager/ssl_context.h b/src/components/include/security_manager/ssl_context.h index 86997edbd9..7d52c72abe 100644 --- a/src/components/include/security_manager/ssl_context.h +++ b/src/components/include/security_manager/ssl_context.h @@ -77,14 +77,16 @@ class SSLContext { }; struct HandshakeContext { - HandshakeContext() : expected_sn(""), expected_cn("") {} + HandshakeContext() + : expected_sn(""), expected_cn(""), system_time(time(NULL)) {} HandshakeContext(const custom_str::CustomString& exp_sn, const custom_str::CustomString& exp_cn) - : expected_sn(exp_sn), expected_cn(exp_cn) {} + : expected_sn(exp_sn), expected_cn(exp_cn), system_time(time(NULL)) {} custom_str::CustomString expected_sn; custom_str::CustomString expected_cn; + time_t system_time; }; virtual HandshakeResult StartHandshake(const uint8_t** const out_data, @@ -103,6 +105,14 @@ class SSLContext { size_t* out_data_size) = 0; virtual bool IsInitCompleted() const = 0; virtual bool IsHandshakePending() const = 0; + /** + * @brief GetCertificateDueDate gets certificate expiration date + * @param due_date - certificate expiration time to be received + * @return True if certificate expiration date received + * otherwise False + */ + virtual bool GetCertificateDueDate(time_t& due_date) const = 0; + virtual bool HasCertificate() const = 0; virtual size_t get_max_block_size(size_t mtu) const = 0; virtual std::string LastError() const = 0; diff --git a/src/components/include/test/application_manager/mock_app_extension.h b/src/components/include/test/application_manager/mock_app_extension.h new file mode 100644 index 0000000000..5898bc9b72 --- /dev/null +++ b/src/components/include/test/application_manager/mock_app_extension.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_APP_EXTENSION_H_ +#define SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_APP_EXTENSION_H_ + +#include "gmock/gmock.h" +#include "application_manager/app_extension.h" + +namespace test { +namespace components { +namespace application_manager_test { + +namespace { +static unsigned MockAppExtensionUID = 123; +} // namespace + +class MockAppExtension : public application_manager::AppExtension { + public: + MockAppExtension() : AppExtension(MockAppExtensionUID) {} + MOCK_METHOD1(SaveResumptionData, + void(ns_smart_device_link::ns_smart_objects::SmartObject& + resumption_data)); + MOCK_METHOD1(ProcessResumption, + void(const ns_smart_device_link::ns_smart_objects::SmartObject& + resumption_data)); +}; + +} // namespace application_manager_test +} // namespace components +} // namespace test + +#endif // SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_APP_EXTENSION_H_ diff --git a/src/components/include/test/application_manager/mock_application_manager.h b/src/components/include/test/application_manager/mock_application_manager.h index 452a1e6c39..7f5f17a93d 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -35,6 +35,7 @@ #include <string> #include <vector> +#include <memory> #include "gmock/gmock.h" @@ -51,10 +52,13 @@ #include "application_manager/event_engine/event_dispatcher.h" #include "application_manager/state_controller.h" #include "smart_objects/smart_object.h" +#include "application_manager/plugin_manager/rpc_plugin_manager.h" +#include "application_manager/command_factory.h" namespace test { namespace components { namespace application_manager_test { +using application_manager::plugin_manager::RPCPluginManager; class MockApplicationManager : public application_manager::ApplicationManager { public: @@ -74,22 +78,18 @@ class MockApplicationManager : public application_manager::ApplicationManager { application, application_manager::ApplicationSharedPtr(uint32_t app_id)); MOCK_CONST_METHOD0(active_application, application_manager::ApplicationSharedPtr()); - -#ifdef SDL_REMOTE_CONTROL MOCK_CONST_METHOD2(application, application_manager::ApplicationSharedPtr( const std::string& device_id, const std::string& policy_app_id)); MOCK_METHOD2(ChangeAppsHMILevel, void(uint32_t app_id, mobile_apis::HMILevel::eType level)); - MOCK_METHOD0(GetPluginManager, functional_modules::PluginManager&()); MOCK_CONST_METHOD1( devices, std::vector<std::string>(const std::string& policy_app_id)); - MOCK_METHOD1(SendPostMessageToMobile, - void(const application_manager::MessagePtr& message)); - MOCK_METHOD1(SendPostMessageToHMI, - void(const application_manager::MessagePtr& message)); -#endif // SDL_REMOTE_CONTROL + MOCK_METHOD0(GetPluginManager, RPCPluginManager&()); + + MOCK_METHOD1(SetPluginManager, + void(std::unique_ptr<RPCPluginManager>& plugin_manager)); MOCK_CONST_METHOD1( application_by_hmi_app, @@ -121,21 +121,12 @@ class MockApplicationManager : public application_manager::ApplicationManager { mobile_apis::HMILevel::eType to)); MOCK_METHOD1( SendHMIStatusNotification, - void(const utils::SharedPtr<application_manager::Application> app)); - MOCK_METHOD2(SendMessageToMobile, - void(application_manager::commands::MessageSharedPtr, bool)); - MOCK_METHOD1( - SendMessageToHMI, - void(const application_manager::commands::MessageSharedPtr message)); - MOCK_METHOD1(RemoveHMIFakeParameters, - void(application_manager::MessagePtr& message)); - MOCK_METHOD1( - ManageHMICommand, - bool(const application_manager::commands::MessageSharedPtr message)); - MOCK_METHOD2( - ManageMobileCommand, - bool(const application_manager::commands::MessageSharedPtr message, - application_manager::commands::Command::CommandOrigin origin)); + void(const std::shared_ptr<application_manager::Application> app)); + MOCK_METHOD1(SendDriverDistractionState, + void(application_manager::ApplicationSharedPtr app)); + MOCK_METHOD2(RemoveHMIFakeParameters, + void(application_manager::commands::MessageSharedPtr& message, + const hmi_apis::FunctionID::eType& function_id)); MOCK_CONST_METHOD1( GetDefaultHmiLevel, mobile_apis::HMILevel::eType( @@ -143,10 +134,14 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_METHOD0(hmi_capabilities, application_manager::HMICapabilities&()); MOCK_CONST_METHOD0(hmi_capabilities, const application_manager::HMICapabilities&()); + MOCK_CONST_METHOD1( + CheckResumptionRequiredTransportAvailable, + bool(application_manager::ApplicationConstSharedPtr application)); MOCK_METHOD2(ProcessQueryApp, void(const smart_objects::SmartObject& sm_object, const uint32_t connection_key)); MOCK_CONST_METHOD0(is_attenuated_supported, bool()); + MOCK_CONST_METHOD0(IsLowVoltage, bool()); MOCK_CONST_METHOD1(IsAppTypeExistsInFullOrLimited, bool(application_manager::ApplicationConstSharedPtr app)); MOCK_METHOD1(OnApplicationRegistered, @@ -158,22 +153,25 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_CONST_METHOD0(protocol_handler, protocol_handler::ProtocolHandler&()); MOCK_METHOD0(GetPolicyHandler, policy::PolicyHandlerInterface&()); MOCK_CONST_METHOD0(GetPolicyHandler, const policy::PolicyHandlerInterface&()); + MOCK_CONST_METHOD0(GetRPCService, + application_manager::rpc_service::RPCService&()); + MOCK_CONST_METHOD0(GetRPCHandler, + application_manager::rpc_handler::RPCHandler&()); + MOCK_CONST_METHOD0(is_stopping, bool()); + MOCK_CONST_METHOD0(is_audio_pass_thru_active, bool()); MOCK_METHOD0(GetNextHMICorrelationID, uint32_t()); MOCK_METHOD0(GenerateNewHMIAppID, uint32_t()); MOCK_METHOD1(EndNaviServices, void(uint32_t app_id)); - DEPRECATED MOCK_METHOD0(BeginAudioPassThrough, bool()); MOCK_METHOD1(BeginAudioPassThru, bool(uint32_t app_id)); - DEPRECATED MOCK_METHOD0(EndAudioPassThrough, bool()); MOCK_METHOD1(EndAudioPassThru, bool(uint32_t app_id)); MOCK_METHOD1(ConnectToDevice, void(const std::string& device_mac)); MOCK_METHOD0(OnHMIStartedCooperation, void()); MOCK_CONST_METHOD0(IsHMICooperating, bool()); MOCK_METHOD2(IviInfoUpdated, - std::vector<application_manager::ApplicationSharedPtr>( - mobile_apis::VehicleDataType::eType vehicle_info, - int value)); + void(mobile_apis::VehicleDataType::eType vehicle_info, + int value)); MOCK_METHOD1(RegisterApplication, - application_manager::ApplicationSharedPtr(const utils::SharedPtr< + application_manager::ApplicationSharedPtr(const std::shared_ptr< smart_objects::SmartObject>& request_for_registration)); MOCK_METHOD0(SendUpdateAppList, void()); MOCK_METHOD2(MarkAppsGreyOut, @@ -189,7 +187,7 @@ class MockApplicationManager : public application_manager::ApplicationManager { mobile_apis::Result::eType(const std::vector<uint8_t>& binary_data, const std::string& file_path, const std::string& file_name, - const int64_t offset)); + const uint64_t offset)); MOCK_METHOD1(SetAllAppsAllowed, void(const bool allowed)); MOCK_METHOD1( set_driver_distraction_state, @@ -234,6 +232,8 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_METHOD0(resume_controller, resumption::ResumeCtrl&()); MOCK_METHOD0(hmi_interfaces, application_manager::HmiInterfaces&()); MOCK_METHOD0(app_launch_ctrl, app_launch::AppLaunchCtrl&()); + MOCK_CONST_METHOD0(SupportedSDLVersion, + protocol_handler::MajorProtocolVersion()); MOCK_METHOD1( GetDeviceTransportType, hmi_apis::Common_TransportType::eType(const std::string& transport_type)); @@ -248,19 +248,13 @@ class MockApplicationManager : public application_manager::ApplicationManager { void(uint32_t app_id, protocol_handler::ServiceType service_type, bool state)); - MOCK_CONST_METHOD4(CreateRegularState, + MOCK_CONST_METHOD5(CreateRegularState, application_manager::HmiStatePtr( application_manager::ApplicationSharedPtr app, mobile_apis::HMILevel::eType hmi_level, mobile_apis::AudioStreamingState::eType audio_state, + mobile_apis::VideoStreamingState::eType video_state, mobile_apis::SystemContext::eType system_context)); - DEPRECATED MOCK_CONST_METHOD4( - CreateRegularState, - application_manager::HmiStatePtr( - uint32_t app_id, - mobile_apis::HMILevel::eType hmi_level, - mobile_apis::AudioStreamingState::eType audio_state, - mobile_apis::SystemContext::eType system_context)); MOCK_METHOD2(SendAudioPassThroughNotification, void(uint32_t session_key, std::vector<uint8_t>& binary_data)); @@ -270,13 +264,16 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_METHOD1(ForbidStreaming, void(uint32_t app_id)); MOCK_CONST_METHOD0(get_settings, const application_manager::ApplicationManagerSettings&()); + MOCK_CONST_METHOD1( + GetCorrectMobileIDFromMessage, + std::string( + const application_manager::commands::MessageSharedPtr& message)); MOCK_METHOD0(event_dispatcher, application_manager::event_engine::EventDispatcher&()); - DEPRECATED MOCK_CONST_METHOD1(IsAppSubscribedForWayPoints, - bool(const uint32_t)); - DEPRECATED MOCK_METHOD1(SubscribeAppForWayPoints, void(const uint32_t)); - DEPRECATED MOCK_METHOD1(UnsubscribeAppFromWayPoints, void(const uint32_t)); + MOCK_METHOD2(IsSOStructValid, + bool(const hmi_apis::StructIdentifiers::eType struct_id, + const smart_objects::SmartObject& display_capabilities)); MOCK_CONST_METHOD1(IsAppSubscribedForWayPoints, bool(application_manager::ApplicationSharedPtr)); MOCK_METHOD1(SubscribeAppForWayPoints, @@ -284,7 +281,7 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_METHOD1(UnsubscribeAppFromWayPoints, void(application_manager::ApplicationSharedPtr)); MOCK_CONST_METHOD0(IsAnyAppSubscribedForWayPoints, bool()); - MOCK_CONST_METHOD0(GetAppsSubscribedForWayPoints, const std::set<int32_t>()); + MOCK_CONST_METHOD0(GetAppsSubscribedForWayPoints, const std::set<uint32_t>()); MOCK_CONST_METHOD1( WaitingApplicationByID, application_manager::ApplicationConstSharedPtr(const uint32_t)); @@ -306,14 +303,14 @@ class MockApplicationManager : public application_manager::ApplicationManager { protocol_handler::ServiceType service_type, bool result, std::vector<std::string>& rejected_params)); - MOCK_METHOD1(ValidateMessageBySchema, - application_manager::MessageValidationResult( - const application_manager::Message& message)); MOCK_METHOD2(ProcessReconnection, void(application_manager::ApplicationSharedPtr application, const uint32_t connection_key)); MOCK_CONST_METHOD1(IsAppInReconnectMode, bool(const std::string& policy_app_id)); + MOCK_CONST_METHOD0(GetCommandFactory, application_manager::CommandFactory&()); + MOCK_CONST_METHOD0(get_current_audio_source, uint32_t()); + MOCK_METHOD1(set_current_audio_source, void(const uint32_t)); }; } // namespace application_manager_test diff --git a/src/components/include/test/application_manager/mock_application_manager_settings.h b/src/components/include/test/application_manager/mock_application_manager_settings.h index 25cf994566..cfabf41b91 100644 --- a/src/components/include/test/application_manager/mock_application_manager_settings.h +++ b/src/components/include/test/application_manager/mock_application_manager_settings.h @@ -55,6 +55,8 @@ class MockApplicationManagerSettings // typedef for the return type. MOCK_CONST_METHOD0(get_vehicle_data_frequency, const std::pair<uint32_t, int32_t>&()); + MOCK_CONST_METHOD0(get_interior_vehicle_data_frequency, + const std::pair<uint32_t, int32_t>&()); MOCK_CONST_METHOD0(hash_string_size, uint32_t()); MOCK_CONST_METHOD0(app_storage_folder, const std::string&()); MOCK_CONST_METHOD0(app_info_storage, const std::string&()); @@ -87,6 +89,7 @@ class MockApplicationManagerSettings MOCK_CONST_METHOD0(named_audio_pipe_path, const std::string&()); MOCK_CONST_METHOD0(video_stream_file, const std::string&()); MOCK_CONST_METHOD0(audio_stream_file, const std::string&()); + MOCK_CONST_METHOD0(use_full_app_id, bool()); MOCK_CONST_METHOD0(use_db_for_resumption, bool()); MOCK_CONST_METHOD0(app_resumption_save_persistent_data_timeout, const uint32_t&()); @@ -95,6 +98,13 @@ class MockApplicationManagerSettings MOCK_CONST_METHOD0(app_resuming_timeout, const uint32_t&()); MOCK_CONST_METHOD0(attempts_to_open_resumption_db, uint16_t()); MOCK_CONST_METHOD0(open_attempt_timeout_ms_resumption_db, uint16_t()); + MOCK_CONST_METHOD0(transport_required_for_resumption_map, + std::map<std::string, std::vector<std::string> >&()); + MOCK_CONST_METHOD0(navigation_lowbandwidth_resumption_level, + const std::string&()); + MOCK_CONST_METHOD0(projection_lowbandwidth_resumption_level, + const std::string&()); + MOCK_CONST_METHOD0(media_lowbandwidth_resumption_level, const std::string&()); MOCK_METHOD1(set_config_file_name, void(const std::string& fileName)); // The following line won't really compile, as the return // type has multiple template arguments. To fix it, use a diff --git a/src/components/include/test/application_manager/mock_rpc_plugin.h b/src/components/include/test/application_manager/mock_rpc_plugin.h new file mode 100644 index 0000000000..1f7dd8951b --- /dev/null +++ b/src/components/include/test/application_manager/mock_rpc_plugin.h @@ -0,0 +1,30 @@ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_PLUGIN_MANAGER_MOCK_RPC_PLUGIN_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_PLUGIN_MANAGER_MOCK_RPC_PLUGIN_H + +#include "gmock/gmock.h" +#include "application_manager/plugin_manager/rpc_plugin.h" + +namespace application_manager { +class CommandFactory; +namespace plugin_manager { + +class MockRPCPlugin : public RPCPlugin { + public: + MOCK_METHOD4(Init, + bool(ApplicationManager& app_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler)); + MOCK_METHOD2(IsAbleToProcess, + bool(const int32_t function_id, + const commands::Command::CommandSource message_source)); + MOCK_METHOD0(PluginName, std::string()); + MOCK_METHOD0(GetCommandFactory, CommandFactory&()); + MOCK_METHOD1(OnPolicyEvent, void(PolicyEvent event)); + MOCK_METHOD2(OnApplicationEvent, + void(ApplicationEvent event, + application_manager::ApplicationSharedPtr application)); +}; +} // namespace plugin_manager +} // namespace application_manager +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_PLUGIN_MANAGER_MOCK_RPC_PLUGIN_H diff --git a/src/components/include/test/application_manager/mock_rpc_plugin_manager.h b/src/components/include/test/application_manager/mock_rpc_plugin_manager.h new file mode 100644 index 0000000000..74763f00d6 --- /dev/null +++ b/src/components/include/test/application_manager/mock_rpc_plugin_manager.h @@ -0,0 +1,24 @@ +#ifndef SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_RPC_PLUGIN_MANAGER_H_ +#define SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_RPC_PLUGIN_MANAGER_H_ +#include <string> + +#include "gmock/gmock.h" +#include "application_manager/plugin_manager/rpc_plugin_manager.h" + +namespace application_manager { +namespace plugin_manager { + +class MockRPCPluginManager : public RPCPluginManager { + public: + MOCK_METHOD1(LoadPlugins, uint32_t(const std::string& plugins_path)); + MOCK_METHOD0(GetPlugins, std::vector<RPCPluginPtr>&()); + MOCK_METHOD2(FindPluginToProcess, + utils::Optional<RPCPlugin>( + const int32_t function_id, + const commands::Command::CommandSource message_source)); + MOCK_METHOD1(ForEachPlugin, void(std::function<void(RPCPlugin&)> functor)); +}; + +} // namespace plugin_manager +} // namespace application_manager +#endif // SRC_COMPONENTS_INCLUDE_TEST_APPLICATION_MANAGER_MOCK_RPC_PLUGIN_MANAGER_H_ diff --git a/src/components/include/test/application_manager/mock_rpc_service.h b/src/components/include/test/application_manager/mock_rpc_service.h new file mode 100644 index 0000000000..4eddbbe257 --- /dev/null +++ b/src/components/include/test/application_manager/mock_rpc_service.h @@ -0,0 +1,34 @@ +#ifndef MOCK_RPC_SERVICE_H +#define MOCK_RPC_SERVICE_H + +#include "gmock/gmock.h" +#include "application_manager/rpc_service.h" + +namespace test { +namespace components { +namespace application_manager_test { + +class MockRPCService : public application_manager::rpc_service::RPCService { + public: + MOCK_METHOD1( + ManageHMICommand, + bool(const application_manager::commands::MessageSharedPtr message)); + MOCK_METHOD2( + ManageMobileCommand, + bool(const application_manager::commands::MessageSharedPtr message, + application_manager::commands::Command::CommandSource origin)); + MOCK_METHOD2(SendMessageToMobile, + void(application_manager::commands::MessageSharedPtr, bool)); + MOCK_METHOD1( + SendMessageToHMI, + void(const application_manager::commands::MessageSharedPtr message)); + MOCK_METHOD1(set_protocol_handler, + void(protocol_handler::ProtocolHandler* handler)); + MOCK_METHOD1(set_hmi_message_handler, + void(hmi_message_handler::HMIMessageHandler* handler)); +}; +} +} +} + +#endif // MOCK_RPC_SERVICE_H diff --git a/src/components/include/test/application_manager/mock_state_controller.h b/src/components/include/test/application_manager/mock_state_controller.h index 9f8d94599b..0165180a0a 100644 --- a/src/components/include/test/application_manager/mock_state_controller.h +++ b/src/components/include/test/application_manager/mock_state_controller.h @@ -51,27 +51,30 @@ class MockStateController : public am::StateController { void(am::ApplicationSharedPtr app, am::HmiStatePtr state, const bool SendActivateApp)); - MOCK_METHOD4(SetRegularState, + MOCK_METHOD5(SetRegularState, void(am::ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level, const mobile_apis::AudioStreamingState::eType audio_state, + const mobile_apis::VideoStreamingState::eType video_state, const bool SendActivateApp)); MOCK_METHOD3(SetRegularState, void(am::ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level, const bool SendActivateApp)); - MOCK_METHOD5(SetRegularState, + MOCK_METHOD6(SetRegularState, void(am::ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level, const mobile_apis::AudioStreamingState::eType audio_state, + const mobile_apis::VideoStreamingState::eType video_state, const mobile_apis::SystemContext::eType system_context, const bool SendActivateApp)); MOCK_METHOD2(SetRegularState, void(am::ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level)); - MOCK_METHOD2(SetRegularState, + MOCK_METHOD3(SetRegularState, void(am::ApplicationSharedPtr app, - const mobile_apis::AudioStreamingState::eType audio_state)); + const mobile_apis::AudioStreamingState::eType audio_state, + const mobile_apis::VideoStreamingState::eType video_state)); MOCK_METHOD2(SetRegularState, void(am::ApplicationSharedPtr app, const mobile_apis::SystemContext::eType system_context)); @@ -84,8 +87,10 @@ class MockStateController : public am::StateController { int64_t(am::ApplicationConstSharedPtr app, hmi_apis::Common_HMILevel::eType level, bool send_policy_priority)); - MOCK_METHOD0(OnNaviStreamingStarted, void()); - MOCK_METHOD0(OnNaviStreamingStopped, void()); + MOCK_METHOD1(OnVideoStreamingStarted, + void(am::ApplicationConstSharedPtr app)); + MOCK_METHOD1(OnVideoStreamingStopped, + void(am::ApplicationConstSharedPtr app)); MOCK_METHOD3(OnStateChanged, void(am::ApplicationSharedPtr app, am::HmiStatePtr old_state, diff --git a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h index 931fd6cfb4..cb47147074 100644 --- a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h +++ b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h @@ -112,7 +112,7 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { MOCK_METHOD1(add_listener, void(policy::PolicyHandlerObserver* listener)); MOCK_METHOD1(remove_listener, void(policy::PolicyHandlerObserver* listener)); MOCK_CONST_METHOD0(GetStatisticManager, - utils::SharedPtr<usage_statistics::StatisticsManager>()); + std::shared_ptr<usage_statistics::StatisticsManager>()); MOCK_CONST_METHOD2(CheckSystemAction, bool(mobile_apis::SystemAction::eType system_action, const std::string& policy_app_id)); @@ -197,6 +197,18 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { MOCK_CONST_METHOD2(IsRequestTypeAllowed, bool(const std::string& policy_app_id, mobile_apis::RequestType::eType type)); + MOCK_CONST_METHOD2(IsRequestSubTypeAllowed, + bool(const std::string& policy_app_id, + const std::string& request_subtype)); + MOCK_CONST_METHOD1( + GetAppRequestTypeState, + policy::RequestType::State(const std::string& policy_app_id)); + MOCK_CONST_METHOD1( + GetAppRequestSubTypeState, + policy::RequestSubType::State(const std::string& policy_app_id)); + MOCK_CONST_METHOD1( + GetAppRequestSubTypes, + const std::vector<std::string>(const std::string& policy_app_id)); MOCK_CONST_METHOD1( GetAppRequestTypes, const std::vector<std::string>(const std::string& policy_app_id)); @@ -227,7 +239,6 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { void(const std::string& service_type, policy::EndpointUrls& end_points)); -#ifdef SDL_REMOTE_CONTROL MOCK_METHOD3(OnUpdateHMILevel, void(const std::string& device_id, const std::string& policy_app_id, @@ -258,7 +269,6 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { MOCK_METHOD2(OnDeviceSwitching, void(const std::string& device_id_from, const std::string& device_id_to)); -#endif // SDL_REMOTE_CONTROL private: #ifdef EXTERNAL_PROPRIETARY_MODE diff --git a/src/components/include/test/connection_handler/mock_connection_handler.h b/src/components/include/test/connection_handler/mock_connection_handler.h index f1416c999e..2de3a0f9a7 100644 --- a/src/components/include/test/connection_handler/mock_connection_handler.h +++ b/src/components/include/test/connection_handler/mock_connection_handler.h @@ -51,6 +51,7 @@ using connection_handler::ConnectionHandle; using connection_handler::DeviceHandle; using connection_handler::CloseSessionReason; using connection_handler::DevicesDiscoveryStarter; +using connection_handler::SessionTransports; class MockConnectionHandler : public connection_handler::ConnectionHandler { public: @@ -84,13 +85,6 @@ class MockConnectionHandler : public connection_handler::ConnectionHandler { void(uint32_t connection_key, uint8_t session_id)); MOCK_METHOD2(BindProtocolVersionWithSession, void(uint32_t connection_key, uint8_t protocol_version)); - - // DEPRECATED - MOCK_CONST_METHOD4(GetDataOnSessionKey, - int32_t(uint32_t key, - uint32_t* app_id, - std::list<int32_t>* sessions_list, - uint32_t* device_id)); MOCK_CONST_METHOD4(GetDataOnSessionKey, int32_t(uint32_t key, uint32_t* app_id, @@ -103,10 +97,31 @@ class MockConnectionHandler : public connection_handler::ConnectionHandler { MOCK_METHOD0(get_device_discovery_starter, DevicesDiscoveryStarter&()); MOCK_CONST_METHOD1(GetConnectedDevicesMAC, void(std::vector<std::string>& macs)); + MOCK_METHOD1( + AddSession, + uint32_t(const transport_manager::ConnectionUID primary_transport_id)); + MOCK_METHOD1(RemoveSession, bool(uint8_t session_id)); + MOCK_METHOD0(session_connection_map, + DataAccessor<connection_handler::SessionConnectionMap>()); + MOCK_METHOD2(SetSecondaryTransportID, + SessionTransports( + uint8_t session_id, + transport_manager::ConnectionUID secondary_transport_id)); + MOCK_CONST_METHOD1(GetSessionTransports, + const SessionTransports(uint8_t session_id)); MOCK_METHOD3(NotifyServiceStartedResult, void(uint32_t session_key, bool result, std::vector<std::string>& rejected_params)); + MOCK_METHOD3( + OnSecondaryTransportStarted, + bool(transport_manager::ConnectionUID& primary_connection_handle, + const transport_manager::ConnectionUID secondary_connection_handle, + const uint8_t session_id)); + MOCK_METHOD2( + OnSecondaryTransportEnded, + void(const transport_manager::ConnectionUID primary_connection_handle, + const transport_manager::ConnectionUID secondary_connection_handle)); }; } // namespace connection_handler_test diff --git a/src/components/include/test/connection_handler/mock_connection_handler_observer.h b/src/components/include/test/connection_handler/mock_connection_handler_observer.h index a96498028d..a9e4349bec 100644 --- a/src/components/include/test/connection_handler/mock_connection_handler_observer.h +++ b/src/components/include/test/connection_handler/mock_connection_handler_observer.h @@ -48,11 +48,6 @@ class MockConnectionHandlerObserver MOCK_METHOD0(OnFindNewApplicationsRequest, void()); MOCK_METHOD1(RemoveDevice, void(const connection_handler::DeviceHandle& device_handle)); - DEPRECATED MOCK_METHOD3( - OnServiceStartedCallback, - bool(const connection_handler::DeviceHandle& device_handle, - const int32_t& session_key, - const protocol_handler::ServiceType& type)); MOCK_METHOD4(OnServiceStartedCallback, void(const connection_handler::DeviceHandle& device_handle, const int32_t& session_key, @@ -74,6 +69,11 @@ class MockConnectionHandlerObserver const connection_handler::Device& device_to)); MOCK_METHOD1(OnDeviceSwitchingFinish, void(const std::string& device_uid)); MOCK_CONST_METHOD1(CheckAppIsNavi, bool(const uint32_t app_id)); + MOCK_METHOD2(OnSecondaryTransportStartedCallback, + void(const connection_handler::DeviceHandle device_handle, + const int32_t session_key)); + MOCK_METHOD1(OnSecondaryTransportEndedCallback, + void(const int32_t session_key)); }; } // namespace connection_handler_test diff --git a/src/components/include/test/hmi_message_handler/mock_hmi_message_observer.h b/src/components/include/test/hmi_message_handler/mock_hmi_message_observer.h index 859d164231..17ec69ccf8 100644 --- a/src/components/include/test/hmi_message_handler/mock_hmi_message_observer.h +++ b/src/components/include/test/hmi_message_handler/mock_hmi_message_observer.h @@ -45,9 +45,9 @@ class MockHMIMessageObserver : public hmi_message_handler::HMIMessageObserver, public utils::Singleton<MockHMIMessageObserver> { public: MOCK_METHOD1(OnMessageReceived, - void(utils::SharedPtr<application_manager::Message> message)); + void(std::shared_ptr<application_manager::Message> message)); MOCK_METHOD1(OnErrorSending, - void(utils::SharedPtr<application_manager::Message> message)); + void(std::shared_ptr<application_manager::Message> message)); virtual ~MockHMIMessageObserver() {} }; diff --git a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h index 5aa92446b6..a4d50d7cc2 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h @@ -106,7 +106,7 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_METHOD2(Init, bool(const std::string& file_name, const PolicySettings* settings)); - MOCK_METHOD0(GenerateSnapshot, utils::SharedPtr<policy_table::Table>()); + MOCK_METHOD0(GenerateSnapshot, std::shared_ptr<policy_table::Table>()); MOCK_METHOD1(ApplyUpdate, bool(const policy_table::Table& update_pt)); MOCK_METHOD1(Save, bool(const policy_table::Table& table)); MOCK_CONST_METHOD0(UpdateRequired, bool()); @@ -231,7 +231,7 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { bool(const std::string& device_id, const std::string& policy_app_id, policy::Permissions& permission)); - MOCK_CONST_METHOD0(GetPT, utils::SharedPtr<policy_table::Table>()); + MOCK_CONST_METHOD0(GetPT, std::shared_ptr<policy_table::Table>()); MOCK_CONST_METHOD0(GetMetaInfo, const MetaInfo()); MOCK_CONST_METHOD0(GetCertificate, std::string()); MOCK_METHOD1(SetDecryptedCertificate, void(const std::string&)); @@ -250,6 +250,13 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_METHOD2(OnDeviceSwitching, void(const std::string& device_id_from, const std::string& device_id_to)); + MOCK_CONST_METHOD2(GetAppRequestSubTypes, + void(const std::string& policy_app_id, + std::vector<std::string>& request_subtypes)); + MOCK_CONST_METHOD1(GetAppRequestTypesState, + RequestType::State(const std::string& policy_app_id)); + MOCK_CONST_METHOD1(GetAppRequestSubTypesState, + RequestSubType::State(const std::string& policy_app_id)); }; } // namespace policy_test diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h b/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h index ad2f1fd56c..1f570d8699 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h @@ -92,7 +92,6 @@ class MockPolicyListener : public ::policy::PolicyListener { const std::string& hmi_level)); MOCK_CONST_METHOD1(GetRegisteredLinks, void(std::map<std::string, std::string>&)); -#ifdef SDL_REMOTE_CONTROL MOCK_METHOD1(OnRemoteAllowedChanged, void(bool new_consent)); MOCK_METHOD2(OnRemoteAppPermissionsChanged, void(const std::string& device_id, @@ -101,7 +100,6 @@ class MockPolicyListener : public ::policy::PolicyListener { void(const std::string& device_id, const std::string& policy_app_id, const std::string& hmi_level)); -#endif // SDL_REMOTE_CONTROL }; } // namespace policy_test diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h index 9e487da4ba..aeabf8fdcb 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h @@ -112,7 +112,7 @@ class MockPolicyManager : public PolicyManager { const policy::DeviceInfo& device_info)); MOCK_METHOD2(SetUserConsentForApp, void(const policy::PermissionConsent& permissions, - const NotificationMode mode)); + const policy::PolicyManager::NotificationMode mode)); MOCK_CONST_METHOD2(GetDefaultHmi, bool(const std::string& policy_app_id, std::string* default_hmi)); @@ -148,7 +148,6 @@ class MockPolicyManager : public PolicyManager { StatusNotifier( const std::string& application_id, const rpc::policy_table_interface_base::AppHmiTypes& hmi_types)); -#ifdef SDL_REMOTE_CONTROL MOCK_METHOD2(SetDefaultHmiTypes, void(const std::string& application_id, const std::vector<int>& hmi_types)); @@ -164,8 +163,7 @@ class MockPolicyManager : public PolicyManager { bool(const std::string& policy_app_id, std::vector<std::string>* modules)); MOCK_METHOD1(set_access_remote, - void(utils::SharedPtr<AccessRemote> access_remote)); -#endif // SDL_REMOTE_CONTROL + void(std::shared_ptr<AccessRemote> access_remote)); MOCK_METHOD0(CleanupUnpairedDevices, bool()); MOCK_CONST_METHOD1(CanAppKeepContext, bool(const std::string& app_id)); @@ -218,6 +216,13 @@ class MockPolicyManager : public PolicyManager { MOCK_METHOD2(OnDeviceSwitching, void(const std::string& device_id_from, const std::string& device_id_to)); + MOCK_CONST_METHOD1( + GetAppRequestSubTypes, + const std::vector<std::string>(const std::string& policy_app_id)); + MOCK_CONST_METHOD1(GetAppRequestTypesState, + RequestType::State(const std::string& policy_app_id)); + MOCK_CONST_METHOD1(GetAppRequestSubTypesState, + RequestSubType::State(const std::string& policy_app_id)); }; } // namespace policy_manager_test } // namespace components diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_settings.h b/src/components/include/test/policy/policy_external/policy/mock_policy_settings.h index eafc1df4fe..fe051aaae0 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_settings.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_settings.h @@ -49,6 +49,7 @@ class MockPolicySettings : public ::policy::PolicySettings { MOCK_CONST_METHOD0(open_attempt_timeout_ms, uint16_t()); MOCK_CONST_METHOD0(policies_snapshot_file_name, const std::string&()); MOCK_CONST_METHOD0(system_files_path, const std::string&()); + MOCK_CONST_METHOD0(use_full_app_id, bool()); }; } // namespace policy_test diff --git a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h index ed3a5088c1..440000dbff 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h @@ -84,7 +84,7 @@ class MockCacheManagerInterface : public CacheManagerInterface { MOCK_METHOD2(Init, bool(const std::string& file_name, const PolicySettings* settings)); - MOCK_METHOD0(GenerateSnapshot, utils::SharedPtr<policy_table::Table>()); + MOCK_METHOD0(GenerateSnapshot, std::shared_ptr<policy_table::Table>()); MOCK_METHOD1(ApplyUpdate, bool(const policy_table::Table& update_pt)); MOCK_METHOD1(Save, bool(const policy_table::Table& table)); MOCK_CONST_METHOD0(UpdateRequired, bool()); @@ -202,11 +202,10 @@ class MockCacheManagerInterface : public CacheManagerInterface { bool(const std::string& device_id, const std::string& policy_app_id, policy::Permissions& permission)); - MOCK_CONST_METHOD0(pt, utils::SharedPtr<policy_table::Table>()); + MOCK_CONST_METHOD0(pt, std::shared_ptr<policy_table::Table>()); MOCK_METHOD1(GetHMITypes, const policy_table::AppHMITypes*(const std::string& app_id)); MOCK_CONST_METHOD0(GetCertificate, std::string()); - MOCK_METHOD1(SetDecryptedCertificate, void(const std::string&)); MOCK_METHOD1(GetGroups, const policy_table::Strings&(const PTString& app_id)); MOCK_CONST_METHOD2(AppHasHMIType, bool(const std::string& application_id, @@ -214,6 +213,13 @@ class MockCacheManagerInterface : public CacheManagerInterface { MOCK_METHOD2(OnDeviceSwitching, void(const std::string& device_id_from, const std::string& device_id_to)); + MOCK_CONST_METHOD2(GetAppRequestSubTypes, + void(const std::string& policy_app_id, + std::vector<std::string>& request_subtypes)); + MOCK_CONST_METHOD1(GetAppRequestTypesState, + RequestType::State(const std::string& policy_app_id)); + MOCK_CONST_METHOD1(GetAppRequestSubTypesState, + RequestSubType::State(const std::string& policy_app_id)); }; } // namespace policy_test diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h index d98a0279d7..3b0c1a925e 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h @@ -85,7 +85,6 @@ class MockPolicyListener : public ::policy::PolicyListener { std::vector<std::string>(const std::string& policy_app_id)); MOCK_CONST_METHOD1(GetRegisteredLinks, void(std::map<std::string, std::string>&)); -#ifdef SDL_REMOTE_CONTROL MOCK_METHOD1(OnRemoteAllowedChanged, void(bool new_consent)); MOCK_METHOD2(OnRemoteAppPermissionsChanged, void(const std::string& device_id, @@ -94,7 +93,6 @@ class MockPolicyListener : public ::policy::PolicyListener { void(const std::string& device_id, const std::string& policy_app_id, const std::string& hmi_level)); -#endif // SDL_REMOTE_CONTROL }; } // namespace policy_test diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h index 82012b83c7..0e06e9c1a3 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h @@ -147,7 +147,6 @@ class MockPolicyManager : public PolicyManager { StatusNotifier( const std::string& application_id, const rpc::policy_table_interface_base::AppHmiTypes& hmi_types)); -#ifdef SDL_REMOTE_CONTROL MOCK_METHOD2(SetDefaultHmiTypes, void(const std::string& application_id, const std::vector<int>& hmi_types)); @@ -163,8 +162,7 @@ class MockPolicyManager : public PolicyManager { bool(const std::string& policy_app_id, std::vector<std::string>* modules)); MOCK_METHOD1(set_access_remote, - void(utils::SharedPtr<AccessRemote> access_remote)); -#endif // SDL_REMOTE_CONTROL + void(std::shared_ptr<AccessRemote> access_remote)); MOCK_METHOD0(CleanupUnpairedDevices, bool()); MOCK_CONST_METHOD1(CanAppKeepContext, bool(const std::string& app_id)); MOCK_CONST_METHOD1(CanAppStealFocus, bool(const std::string& app_id)); @@ -186,7 +184,6 @@ class MockPolicyManager : public PolicyManager { MOCK_CONST_METHOD0(GetMetaInfo, const policy::MetaInfo()); MOCK_CONST_METHOD0(RetrieveCertificate, std::string()); MOCK_CONST_METHOD0(HasCertificate, bool()); - MOCK_METHOD1(SetDecryptedCertificate, void(const std::string&)); MOCK_METHOD0(ExceededIgnitionCycles, bool()); MOCK_METHOD0(ExceededDays, bool()); MOCK_METHOD0(StartPTExchange, void()); @@ -226,6 +223,14 @@ class MockPolicyManager : public PolicyManager { MOCK_METHOD2(OnDeviceSwitching, void(const std::string& device_id_from, const std::string& device_id_to)); + + MOCK_CONST_METHOD1( + GetAppRequestSubTypes, + const std::vector<std::string>(const std::string& policy_app_id)); + MOCK_CONST_METHOD1(GetAppRequestTypesState, + RequestType::State(const std::string& policy_app_id)); + MOCK_CONST_METHOD1(GetAppRequestSubTypesState, + RequestSubType::State(const std::string& policy_app_id)); }; } // namespace policy_manager_test diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_settings.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_settings.h index 438e697c51..6e0acae33c 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_policy_settings.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_settings.h @@ -49,6 +49,7 @@ class MockPolicySettings : public ::policy::PolicySettings { MOCK_CONST_METHOD0(open_attempt_timeout_ms, uint16_t()); MOCK_CONST_METHOD0(policies_snapshot_file_name, const std::string&()); MOCK_CONST_METHOD0(system_files_path, const std::string&()); + MOCK_CONST_METHOD0(use_full_app_id, bool()); }; } // namespace policy_test diff --git a/src/components/include/test/protocol_handler/mock_protocol_handler.h b/src/components/include/test/protocol_handler/mock_protocol_handler.h index 79c2188cdf..f6db0c7097 100644 --- a/src/components/include/test/protocol_handler/mock_protocol_handler.h +++ b/src/components/include/test/protocol_handler/mock_protocol_handler.h @@ -55,23 +55,18 @@ class MockProtocolHandler : public ::protocol_handler::ProtocolHandler { void(uint32_t connection_key, int32_t number_of_frames)); MOCK_METHOD2(SendHeartBeat, void(int32_t connection_id, uint8_t session_id)); MOCK_METHOD2(SendEndSession, void(int32_t connection_id, uint8_t session_id)); - MOCK_METHOD3(SendEndService, - void(int32_t connection_id, + MOCK_METHOD4(SendEndService, + void(int32_t primary_connection_id, + int32_t connection_id, uint8_t session_id, uint8_t service_type)); MOCK_CONST_METHOD0(get_settings, const ::protocol_handler::ProtocolHandlerSettings&()); MOCK_METHOD0(get_session_observer, protocol_handler::SessionObserver&()); - DEPRECATED MOCK_METHOD6(NotifySessionStartedResult, - void(int32_t connection_id, - uint8_t session_id, - uint8_t generated_session_id, - uint32_t hash_id, - bool protection, - std::vector<std::string>& rejected_params)); MOCK_METHOD2(NotifySessionStarted, void(const ::protocol_handler::SessionContext& context, std::vector<std::string>& rejected_params)); + MOCK_METHOD0(NotifyOnFailedHandshake, void()); }; } // namespace protocol_handler_test } // namespace components diff --git a/src/components/include/test/protocol_handler/mock_protocol_handler_settings.h b/src/components/include/test/protocol_handler/mock_protocol_handler_settings.h index 8ddeded889..2ed9c47e9d 100644 --- a/src/components/include/test/protocol_handler/mock_protocol_handler_settings.h +++ b/src/components/include/test/protocol_handler/mock_protocol_handler_settings.h @@ -60,6 +60,17 @@ class MockProtocolHandlerSettings MOCK_CONST_METHOD0(force_protected_service, const std::vector<int>&()); MOCK_CONST_METHOD0(force_unprotected_service, const std::vector<int>&()); #endif + MOCK_CONST_METHOD0(multiple_transports_enabled, const bool()); + MOCK_CONST_METHOD0(secondary_transports_for_bluetooth, + const std::vector<std::string>&()); + MOCK_CONST_METHOD0(secondary_transports_for_usb, + const std::vector<std::string>&()); + MOCK_CONST_METHOD0(secondary_transports_for_wifi, + const std::vector<std::string>&()); + MOCK_CONST_METHOD0(audio_service_transports, + const std::vector<std::string>&()); + MOCK_CONST_METHOD0(video_service_transports, + const std::vector<std::string>&()); }; } // namespace protocol_handler_test diff --git a/src/components/include/test/protocol_handler/mock_session_observer.h b/src/components/include/test/protocol_handler/mock_session_observer.h index ae32f35948..0d74b15f64 100644 --- a/src/components/include/test/protocol_handler/mock_session_observer.h +++ b/src/components/include/test/protocol_handler/mock_session_observer.h @@ -47,13 +47,6 @@ namespace protocol_handler_test { */ class MockSessionObserver : public ::protocol_handler::SessionObserver { public: - DEPRECATED MOCK_METHOD5( - OnSessionStartedCallback, - uint32_t(const transport_manager::ConnectionUID connection_handle, - const uint8_t sessionId, - const protocol_handler::ServiceType& service_type, - const bool is_protected, - uint32_t* hash_id)); MOCK_METHOD5(OnSessionStartedCallback, void(const transport_manager::ConnectionUID connection_handle, const uint8_t sessionId, @@ -76,6 +69,12 @@ class MockSessionObserver : public ::protocol_handler::SessionObserver { void(const uint32_t& connection_key)); MOCK_METHOD1(OnMalformedMessageCallback, void(const uint32_t& connection_key)); + MOCK_CONST_METHOD1( + TransportTypeProfileStringFromConnHandle, + const std::string(transport_manager::ConnectionUID connection_handle)); + MOCK_CONST_METHOD1( + TransportTypeProfileStringFromDeviceHandle, + const std::string(transport_manager::DeviceHandle device_handle)); MOCK_CONST_METHOD2( KeyFromPair, uint32_t(transport_manager::ConnectionUID connection_handle, @@ -89,11 +88,6 @@ class MockSessionObserver : public ::protocol_handler::SessionObserver { uint32_t* app_id, std::list<int32_t>* sessions_list, transport_manager::DeviceHandle* device_id)); - DEPRECATED MOCK_CONST_METHOD4(GetDataOnSessionKey, - int32_t(uint32_t key, - uint32_t* app_id, - std::list<int32_t>* sessions_list, - uint32_t* device_id)); MOCK_CONST_METHOD5(GetDataOnDeviceID, int32_t(transport_manager::DeviceHandle device_handle, diff --git a/src/components/include/test/protocol_handler/mock_telemetry_observer.h b/src/components/include/test/protocol_handler/mock_telemetry_observer.h index 1c87de4d5a..82c42775fa 100644 --- a/src/components/include/test/protocol_handler/mock_telemetry_observer.h +++ b/src/components/include/test/protocol_handler/mock_telemetry_observer.h @@ -44,8 +44,9 @@ namespace protocol_handler_test { class MockPHTelemetryObserver : public PHTelemetryObserver { public: MOCK_METHOD2(StartMessageProcess, - void(uint32_t message_id, const TimevalStruct& start_time)); - MOCK_METHOD1(EndMessageProcess, void(utils::SharedPtr<MessageMetric> m)); + void(uint32_t message_id, + const date_time::TimeDuration& start_time)); + MOCK_METHOD1(EndMessageProcess, void(std::shared_ptr<MessageMetric> m)); }; } // namespace protocol_handler_test diff --git a/src/components/include/test/security_manager/mock_crypto_manager.h b/src/components/include/test/security_manager/mock_crypto_manager.h index 55c364bd89..61ec5183e4 100644 --- a/src/components/include/test/security_manager/mock_crypto_manager.h +++ b/src/components/include/test/security_manager/mock_crypto_manager.h @@ -52,7 +52,9 @@ class MockCryptoManager : public ::security_manager::CryptoManager { MOCK_METHOD0(CreateSSLContext, ::security_manager::SSLContext*()); MOCK_METHOD1(ReleaseSSLContext, void(::security_manager::SSLContext*)); MOCK_CONST_METHOD0(LastError, std::string()); - MOCK_CONST_METHOD0(IsCertificateUpdateRequired, bool()); + MOCK_CONST_METHOD2(IsCertificateUpdateRequired, + bool(const time_t system_time, + const time_t certificates_time)); }; } // namespace security_manager_test } // namespace components diff --git a/src/components/include/test/security_manager/mock_security_manager.h b/src/components/include/test/security_manager/mock_security_manager.h index 11890cb071..b2c2e3bf17 100644 --- a/src/components/include/test/security_manager/mock_security_manager.h +++ b/src/components/include/test/security_manager/mock_security_manager.h @@ -54,8 +54,9 @@ class MockSecurityManager : public ::security_manager::SecurityManager { MOCK_METHOD4( SendInternalError, void(const uint32_t, const uint8_t&, const std::string&, const uint32_t)); - MOCK_METHOD1(CreateSSLContext, - ::security_manager::SSLContext*(const uint32_t&)); + MOCK_METHOD2(CreateSSLContext, + ::security_manager::SSLContext*(const uint32_t&, + ContextCreationStrategy)); MOCK_METHOD1(StartHandshake, void(uint32_t)); MOCK_METHOD1(AddListener, void(::security_manager::SecurityManagerListener*)); MOCK_METHOD1(RemoveListener, @@ -65,9 +66,13 @@ class MockSecurityManager : public ::security_manager::SecurityManager { void(const ::protocol_handler::RawMessagePtr)); MOCK_METHOD1(OnMobileMessageSent, void(const ::protocol_handler::RawMessagePtr)); - MOCK_METHOD0(IsCertificateUpdateRequired, bool()); + MOCK_METHOD1(IsCertificateUpdateRequired, bool(const uint32_t)); MOCK_METHOD0(NotifyOnCertificateUpdateRequired, void()); + MOCK_METHOD0(NotifyListenersOnHandshakeFailed, void()); MOCK_METHOD0(IsPolicyCertificateDataEmpty, bool()); + MOCK_METHOD1(OnCertificateUpdated, bool(const std::string&)); + MOCK_METHOD1(PostponeHandshake, void(const uint32_t)); + MOCK_CONST_METHOD0(IsSystemTimeProviderReady, bool()); }; /* diff --git a/src/components/include/test/security_manager/mock_security_manager_listener.h b/src/components/include/test/security_manager/mock_security_manager_listener.h index a06762a09d..7a7714d299 100644 --- a/src/components/include/test/security_manager/mock_security_manager_listener.h +++ b/src/components/include/test/security_manager/mock_security_manager_listener.h @@ -49,6 +49,7 @@ class MockSecurityManagerListener ::security_manager::SSLContext::HandshakeResult result)); MOCK_METHOD0(OnCertificateUpdateRequired, void()); MOCK_CONST_METHOD1(GetPolicyCertificateData, bool(std::string& data)); + MOCK_METHOD0(OnHandshakeFailed, bool()); }; } // namespace security_manager_test } // namespace components diff --git a/src/components/include/test/security_manager/mock_security_manager_settings.h b/src/components/include/test/security_manager/mock_security_manager_settings.h index 6ac194ced4..b1c869cd1b 100644 --- a/src/components/include/test/security_manager/mock_security_manager_settings.h +++ b/src/components/include/test/security_manager/mock_security_manager_settings.h @@ -50,8 +50,12 @@ class MockCryptoManagerSettings MOCK_CONST_METHOD0(certificate_data, const std::string&()); MOCK_CONST_METHOD0(ciphers_list, const std::string&()); MOCK_CONST_METHOD0(ca_cert_path, const std::string&()); + MOCK_CONST_METHOD0(module_cert_path, const std::string&()); + MOCK_CONST_METHOD0(module_key_path, const std::string&()); MOCK_CONST_METHOD0(update_before_hours, size_t()); MOCK_CONST_METHOD0(maximum_payload_size, size_t()); + MOCK_CONST_METHOD0(force_protected_service, const std::vector<int>&()); + MOCK_CONST_METHOD0(force_unprotected_service, const std::vector<int>&()); }; } // namespace security_manager_test diff --git a/src/components/include/test/security_manager/mock_ssl_context.h b/src/components/include/test/security_manager/mock_ssl_context.h index 6b6a26a226..02198d1d22 100644 --- a/src/components/include/test/security_manager/mock_ssl_context.h +++ b/src/components/include/test/security_manager/mock_ssl_context.h @@ -68,6 +68,8 @@ class MockSSLContext : public ::security_manager::SSLContext { MOCK_CONST_METHOD0(LastError, std::string()); MOCK_METHOD0(ResetConnection, void()); MOCK_METHOD1(SetHandshakeContext, void(const HandshakeContext& hsh_ctx)); + MOCK_CONST_METHOD0(HasCertificate, bool()); + MOCK_CONST_METHOD1(GetCertificateDueDate, bool(time_t& due_date)); }; } // namespace security_manager_test } // namespace components diff --git a/src/components/include/test/transport_manager/mock_transport_manager_listener.h b/src/components/include/test/transport_manager/mock_transport_manager_listener.h index f4c4fdcf68..133dabe732 100644 --- a/src/components/include/test/transport_manager/mock_transport_manager_listener.h +++ b/src/components/include/test/transport_manager/mock_transport_manager_listener.h @@ -85,6 +85,8 @@ class MockTransportManagerListener : public TransportManagerListener { void(const DeviceUID& device_uid_from, const DeviceUID& device_uid_to)); MOCK_METHOD1(OnDeviceSwitchingFinish, void(const DeviceUID& device_uid)); + MOCK_METHOD1(OnTransportConfigUpdated, + void(const std::map<std::string, std::string>& configs)); }; } // namespace transport_manager_test diff --git a/src/components/include/test/transport_manager/mock_transport_manager_settings.h b/src/components/include/test/transport_manager/mock_transport_manager_settings.h index 88112df003..3e7c8f36f7 100644 --- a/src/components/include/test/transport_manager/mock_transport_manager_settings.h +++ b/src/components/include/test/transport_manager/mock_transport_manager_settings.h @@ -61,6 +61,8 @@ class MockTransportManagerSettings MOCK_CONST_METHOD0(iap_hub_connection_wait_timeout, uint32_t()); MOCK_CONST_METHOD0(app_transport_change_timer, uint32_t()); MOCK_CONST_METHOD0(app_transport_change_timer_addition, uint32_t()); + MOCK_CONST_METHOD0(transport_manager_tcp_adapter_network_interface, + std::string&()); }; } // namespace transport_manager_test diff --git a/src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h b/src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h index c37c41d4f8..eff0abdcd3 100644 --- a/src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h +++ b/src/components/include/test/transport_manager/transport_adapter/mock_transport_adapter.h @@ -103,6 +103,8 @@ class MockTransportAdapter void(const ::transport_manager::DeviceUID& device_handle)); MOCK_CONST_METHOD0(GetSwitchableDevices, transport_manager::SwitchableDevices()); + MOCK_CONST_METHOD0(GetTransportConfiguration, + transport_manager::transport_adapter::TransportConfig()); #ifdef TELEMETRY_MONITOR MOCK_METHOD0(GetTelemetryObserver, ::transport_manager::TMTelemetryObserver*()); diff --git a/src/components/include/test/utils/mock_system_time_handler.h b/src/components/include/test/utils/mock_system_time_handler.h new file mode 100644 index 0000000000..7bb2a7f0a5 --- /dev/null +++ b/src/components/include/test/utils/mock_system_time_handler.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_INCLUDE_TEST_SECURITY_MANAGER_MOCK_SYSTEM_TIME_HANDLER_H +#define SRC_COMPONENTS_INCLUDE_TEST_SECURITY_MANAGER_MOCK_SYSTEM_TIME_HANDLER_H + +#include "gmock/gmock.h" +#include "utils/system_time_handler.h" + +namespace test { +namespace components { +namespace security_manager_test { + +class MockSystemTimeHandler : public ::utils::SystemTimeHandler { + public: + MockSystemTimeHandler() {} + MOCK_METHOD0(QuerySystemTime, void()); + MOCK_METHOD1(SubscribeOnSystemTime, + void(utils::SystemTimeListener* listener)); + MOCK_METHOD1(UnsubscribeFromSystemTime, + void(utils::SystemTimeListener* listener)); + MOCK_METHOD0(GetUTCTime, time_t()); + MOCK_CONST_METHOD0(system_time_can_be_received, bool()); + ~MockSystemTimeHandler() {} + + private: + void DoSubscribe(utils::SystemTimeListener*) {} + void DoSystemTimeQuery() {} + void DoUnsubscribe(utils::SystemTimeListener* listener) {} + bool utc_time_can_be_received() const { + return true; + } + time_t FetchSystemTime() { + return 0; + } +}; +} // namespace security_manager_test +} // namespace components +} // namespace test +#endif // SRC_COMPONENTS_INCLUDE_TEST_SECURITY_MANAGER_MOCK_SYSTEM_TIME_HANDLER_H diff --git a/src/components/include/transport_manager/error.h b/src/components/include/transport_manager/error.h index 022ddf0e38..ba357dd54b 100644 --- a/src/components/include/transport_manager/error.h +++ b/src/components/include/transport_manager/error.h @@ -34,7 +34,7 @@ #define SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_ERROR_H_ #include <string> -#include <utils/shared_ptr.h> +#include <memory> namespace transport_manager { @@ -79,7 +79,7 @@ class BaseError { private: std::string description_; }; -typedef utils::SharedPtr<BaseError> BaseErrorPtr; +typedef std::shared_ptr<BaseError> BaseErrorPtr; /** * @brief Error that originates during device search. diff --git a/src/components/include/transport_manager/transport_adapter/device.h b/src/components/include/transport_manager/transport_adapter/device.h index 148e715050..1ac1424477 100644 --- a/src/components/include/transport_manager/transport_adapter/device.h +++ b/src/components/include/transport_manager/transport_adapter/device.h @@ -35,9 +35,10 @@ #include <string> #include <vector> +#include <memory> #include "transport_manager/common.h" -#include "utils/shared_ptr.h" + #include "utils/macro.h" namespace transport_manager { @@ -160,7 +161,7 @@ class Device { **/ bool keep_on_disconnect_; }; -typedef utils::SharedPtr<Device> DeviceSptr; +typedef std::shared_ptr<Device> DeviceSptr; typedef std::vector<DeviceSptr> DeviceVector; } // namespace transport_adapter } // namespace transport_manager diff --git a/src/components/include/transport_manager/transport_adapter/transport_adapter.h b/src/components/include/transport_manager/transport_adapter/transport_adapter.h index 7f6d347535..ebbf7dae28 100644 --- a/src/components/include/transport_manager/transport_adapter/transport_adapter.h +++ b/src/components/include/transport_manager/transport_adapter/transport_adapter.h @@ -41,8 +41,6 @@ #include <list> #include <map> -#include "utils/shared_ptr.h" - #include "transport_manager/transport_adapter/device.h" #include "transport_manager/common.h" #include "transport_manager/error.h" @@ -59,17 +57,16 @@ class TransportAdapterListener; /** * @brief The DeviceType enum defines types based on available transport * adapters - * @deprecated PASA_AOA, PASA_BLUETOOTH, MME */ enum DeviceType { AOA, - PASA_AOA, BLUETOOTH, - PASA_BLUETOOTH, - MME, IOS_BT, IOS_USB, TCP, + IOS_USB_HOST_MODE, + IOS_USB_DEVICE_MODE, + IOS_CARPLAY_WIRELESS, // running on iAP over Carplay wireless transport UNKNOWN }; @@ -86,6 +83,18 @@ typedef std::map<DeviceUID, DeviceSptr> DeviceMap; */ typedef std::list<TransportAdapterListener*> TransportAdapterListenerList; +/** + * @brief Type definition for transport's configuration information + */ +typedef std::map<std::string, std::string> TransportConfig; + +/** + * @brief TransportConfig keys + */ +extern const char* tc_enabled; +extern const char* tc_tcp_port; +extern const char* tc_tcp_ip_address; + class TransportAdapter { public: /** @@ -312,6 +321,12 @@ class TransportAdapter { virtual void DeviceSwitched(const DeviceUID& device_handle) = 0; virtual SwitchableDevices GetSwitchableDevices() const = 0; + + /** + * @brief Returns the transport's configuration information + */ + virtual TransportConfig GetTransportConfiguration() const = 0; + #ifdef TELEMETRY_MONITOR /** * @brief Return Time metric observer diff --git a/src/components/include/transport_manager/transport_adapter/transport_adapter_event.h b/src/components/include/transport_manager/transport_adapter/transport_adapter_event.h index 18f4ccb2d1..fd1d693067 100644 --- a/src/components/include/transport_manager/transport_adapter/transport_adapter_event.h +++ b/src/components/include/transport_manager/transport_adapter/transport_adapter_event.h @@ -57,7 +57,8 @@ enum class EventTypeEnum { ON_RECEIVED_FAIL, ON_COMMUNICATION_ERROR, ON_UNEXPECTED_DISCONNECT, - ON_TRANSPORT_SWITCH_REQUESTED + ON_TRANSPORT_SWITCH_REQUESTED, + ON_TRANSPORT_CONFIG_UPDATED }; class TransportAdapterEvent { @@ -87,30 +88,6 @@ class TransportAdapterEvent { , event_error(error) {} /** - * DEPRECATED - * @brief Constructor. - * - * @param type Event type. - * @param transport_adapter Transport adapter - * @param device_handle Handle of device. - * @param application_id Handle of application. - * @param data Smart pointer to the raw message. - * @param error Error class that contains details of this error situation. - */ - TransportAdapterEvent(int type, - transport_adapter::TransportAdapter* adapter, - const DeviceUID& device_handle, - const ApplicationHandle& application_id, - ::protocol_handler::RawMessagePtr data, - BaseErrorPtr error) - : event_type(static_cast<EventTypeEnum>(type)) - , application_id(application_id) - , device_uid(device_handle) - , transport_adapter(adapter) - , event_data(data) - , event_error(error) {} - - /** * @brief Value that describe event type. */ EventTypeEnum event_type; diff --git a/src/components/include/transport_manager/transport_manager_listener.h b/src/components/include/transport_manager/transport_manager_listener.h index d336eade45..6c3f6e2eaa 100644 --- a/src/components/include/transport_manager/transport_manager_listener.h +++ b/src/components/include/transport_manager/transport_manager_listener.h @@ -33,6 +33,7 @@ #ifndef SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_LISTENER_H_ #define SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_LISTENER_H_ +#include <map> #include <vector> #include "transport_manager/common.h" #include "transport_manager/info.h" @@ -193,6 +194,14 @@ class TransportManagerListener { virtual void OnTMMessageSendFailed( const DataSendError& error, const ::protocol_handler::RawMessagePtr message) = 0; + + /** + * @brief Notifies that configuration of a transport has been updated. + * + * @param configs pairs of key and value that represent configuration. + */ + virtual void OnTransportConfigUpdated( + const std::map<std::string, std::string>& configs) = 0; }; } // namespace transport_manager #endif // SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_LISTENER_H_ diff --git a/src/components/include/transport_manager/transport_manager_listener_empty.h b/src/components/include/transport_manager/transport_manager_listener_empty.h index ca6c573a06..08b2b77c30 100644 --- a/src/components/include/transport_manager/transport_manager_listener_empty.h +++ b/src/components/include/transport_manager/transport_manager_listener_empty.h @@ -187,6 +187,14 @@ class TransportManagerListenerEmpty : public TransportManagerListener { void OnTMMessageSendFailed( const DataSendError& error, const ::protocol_handler::RawMessagePtr message) OVERRIDE {} + + /** + * @brief Notifies that configuration of a transport has been updated. + * + * @param configs pairs of key and value that represent configuration. + */ + void OnTransportConfigUpdated( + const std::map<std::string, std::string>& configs) OVERRIDE {} }; } // namespace transport_manager #endif // SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_LISTENER_EMPTY_H_ diff --git a/src/components/include/transport_manager/transport_manager_settings.h b/src/components/include/transport_manager/transport_manager_settings.h index feb3fa2c02..3912bbe747 100644 --- a/src/components/include/transport_manager/transport_manager_settings.h +++ b/src/components/include/transport_manager/transport_manager_settings.h @@ -63,6 +63,12 @@ class TransportManagerSettings : public TransportManagerMMESettings { * the transport change timeout value. */ virtual uint32_t app_transport_change_timer_addition() const = 0; + + /** + * @brief Returns the network interface name for TCP transport adapter + */ + virtual const std::string& transport_manager_tcp_adapter_network_interface() + const = 0; }; } // namespace transport_manager #endif // SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_SETTINGS_H_ diff --git a/src/components/include/utils/atomic_object.h b/src/components/include/utils/atomic_object.h deleted file mode 100644 index 257fcfbe3a..0000000000 --- a/src/components/include/utils/atomic_object.h +++ /dev/null @@ -1,112 +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_INCLUDE_UTILS_ATOMIC_OBJECT_H_ -#define SRC_COMPONENTS_INCLUDE_UTILS_ATOMIC_OBJECT_H_ - -#include "utils/rwlock.h" -#include "utils/conditional_variable.h" -#include "utils/macro.h" - -namespace sync_primitives { - -/** - * @brief Allows to safely change stored value from different threads. - * - * The usage example: - * - * threads::Atomic<int> i; - * - * i = 5; // here SDL is able to guarantee that this value will be safely - * // assigned even in multi threaded environment. - */ -template <typename T> -class Atomic { - public: - /** - * @brief Atomic allows to construct atomic object. - * The operation is not atomic. - * - * @param value the value to initialize object with. - */ - Atomic(const T& value) : value_(value) {} - - /** - * @brief operator = thread safe setter for stored value. - * - * @param val value to assign. - * - * @return mofified value. - */ - T& operator=(const T& val) { - sync_primitives::AutoWriteLock lock(rw_lock_); - value_ = val; - return value_; - } - - /** - * @brief operator T thread safe getter - * - * return stored value. - */ - operator T() const { - sync_primitives::AutoReadLock lock(rw_lock_); - return value_; - } - - /** - * @brief operator T thread safe getter - * - * return stored value. - */ - template <typename U> - operator U() const { - sync_primitives::AutoReadLock lock(rw_lock_); - return static_cast<U>(value_); - } - - private: - T value_; - mutable sync_primitives::RWLock rw_lock_; -}; - -typedef Atomic<int> atomic_int; -typedef Atomic<int32_t> atomic_int32; -typedef Atomic<uint32_t> atomic_uint32; -typedef Atomic<int64_t> atomic_int64; -typedef Atomic<uint64_t> atomic_uint64; -typedef Atomic<size_t> atomic_size_t; -typedef Atomic<bool> atomic_bool; - -} // namespace sync_primitives - -#endif // SRC_COMPONENTS_INCLUDE_UTILS_ATOMIC_OBJECT_H_ diff --git a/src/components/include/utils/conditional_variable.h b/src/components/include/utils/conditional_variable.h index f54a22e993..a29f255dbf 100644 --- a/src/components/include/utils/conditional_variable.h +++ b/src/components/include/utils/conditional_variable.h @@ -32,24 +32,13 @@ #ifndef SRC_COMPONENTS_INCLUDE_UTILS_CONDITIONAL_VARIABLE_H_ #define SRC_COMPONENTS_INCLUDE_UTILS_CONDITIONAL_VARIABLE_H_ -#if defined(OS_POSIX) -#include <pthread.h> -#else -#error Please implement conditional variable for your OS -#endif #include <stdint.h> +#include <boost/thread/condition_variable.hpp> +#include "utils/lock.h" #include "utils/macro.h" namespace sync_primitives { -class AutoLock; -class Lock; - -namespace impl { -#if defined(OS_POSIX) -typedef pthread_cond_t PlatformConditionalVariable; -#endif -} // namespace impl /* * Conditional variable wrapper @@ -82,11 +71,11 @@ class ConditionalVariable { // Wait forever or up to milliseconds time limit bool Wait(AutoLock& auto_lock); - bool Wait(Lock& lock); + bool Wait(BaseLock& lock); WaitStatus WaitFor(AutoLock& auto_lock, uint32_t milliseconds); private: - impl::PlatformConditionalVariable cond_var_; + boost::condition_variable_any cond_var_; private: DISALLOW_COPY_AND_ASSIGN(ConditionalVariable); diff --git a/src/components/include/utils/data_accessor.h b/src/components/include/utils/data_accessor.h index 9be28a638b..1be7c3ab53 100644 --- a/src/components/include/utils/data_accessor.h +++ b/src/components/include/utils/data_accessor.h @@ -33,17 +33,15 @@ #define SRC_COMPONENTS_INCLUDE_UTILS_DATA_ACCESSOR_H_ #include "utils/lock.h" -#include "utils/shared_ptr.h" -// This class is for thread-safe access to data +// This class is for thread-safe const access to data template <class T> class DataAccessor { public: - DataAccessor(const T& data, const sync_primitives::Lock& lock) - : data_(data) - , lock_(const_cast<sync_primitives::Lock&>(lock)) - , counter_(new uint32_t(0)) { - lock_.Acquire(); + DataAccessor(const T& data, + const std::shared_ptr<sync_primitives::BaseLock>& lock) + : data_(data), lock_(lock), counter_(new uint32_t(0)) { + lock_->Acquire(); } DataAccessor(const DataAccessor<T>& other) @@ -53,7 +51,7 @@ class DataAccessor { ~DataAccessor() { if (0 == *counter_) { - lock_.Release(); + lock_->Release(); } else { --(*counter_); } @@ -65,8 +63,9 @@ class DataAccessor { private: void* operator new(size_t size); const T& data_; - sync_primitives::Lock& lock_; - utils::SharedPtr<uint32_t> counter_; + // Require that the lock lives at least as long as the DataAccessor + const std::shared_ptr<sync_primitives::BaseLock> lock_; + std::shared_ptr<uint32_t> counter_; }; #endif // SRC_COMPONENTS_INCLUDE_UTILS_DATA_ACCESSOR_H_ diff --git a/src/components/include/utils/date_time.h b/src/components/include/utils/date_time.h index f8f8e3d6ce..17b4fafe38 100644 --- a/src/components/include/utils/date_time.h +++ b/src/components/include/utils/date_time.h @@ -32,69 +32,70 @@ #ifndef SRC_COMPONENTS_INCLUDE_UTILS_DATE_TIME_H_ #define SRC_COMPONENTS_INCLUDE_UTILS_DATE_TIME_H_ -#if defined(OS_POSIX) -#include <sys/time.h> -typedef struct timeval TimevalStruct; -#endif #include <stdint.h> +#include "boost/date_time/posix_time/posix_time_duration.hpp" namespace date_time { +// skip boost namespacing for all this +// NOTE that it's called posix_time for its functionality, not for any +// platform-dependence +typedef boost::posix_time::time_duration TimeDuration; +// Capture from boost's namespaces +using boost::posix_time::microseconds; +using boost::posix_time::milliseconds; +using boost::posix_time::seconds; + enum TimeCompare { LESS, EQUAL, GREATER }; -class DateTime { - public: - static const int32_t MILLISECONDS_IN_SECOND = 1000; - static const int32_t MICROSECONDS_IN_MILLISECOND = 1000; - static const int32_t NANOSECONDS_IN_MICROSECOND = 1000; - static const int32_t SECONDS_IN_HOUR = 3600; - static const int32_t MICROSECONDS_IN_SECOND = - MILLISECONDS_IN_SECOND * MICROSECONDS_IN_MILLISECOND; - static const int32_t NANOSECONDS_IN_MILLISECOND = - MICROSECONDS_IN_MILLISECOND * NANOSECONDS_IN_MICROSECOND; +// public defines for external usage +const int32_t MILLISECONDS_IN_SECOND = 1000; +const int32_t MICROSECONDS_IN_MILLISECOND = 1000; +const int32_t NANOSECONDS_IN_MICROSECOND = 1000; +const int32_t SECONDS_IN_HOUR = 3600; +const int32_t MICROSECONDS_IN_SECOND = + MILLISECONDS_IN_SECOND * MICROSECONDS_IN_MILLISECOND; +const int32_t NANOSECONDS_IN_MILLISECOND = + MICROSECONDS_IN_MILLISECOND * NANOSECONDS_IN_MICROSECOND; + +TimeDuration getCurrentTime(); - static TimevalStruct getCurrentTime(); +// empty duration +TimeDuration TimeDurationZero(); - // return SECONDS count - static int64_t getSecs(const TimevalStruct& time); +// return SECONDS count +int64_t getSecs(const TimeDuration& t); - // return MILLISECONDS count - static int64_t getmSecs(const TimevalStruct& time); - // return MICROSECONDS count - static int64_t getuSecs(const TimevalStruct& time); +// return MILLISECONDS count +int64_t getmSecs(const TimeDuration& t); +// return MICROSECONDS count +int64_t getuSecs(const TimeDuration& t); - // return MILLISECONDS count between sinceTime value and current time - static int64_t calculateTimeSpan(const TimevalStruct& sinceTime); +// get just the MILLISECONDS count (< 1000) +int64_t get_just_mSecs(const TimeDuration& t); - // return MILLISECONDS count between time1 and time2 - static int64_t calculateTimeDiff(const TimevalStruct& time1, - const TimevalStruct& time2); +// get just the MICROSECONDS count (< 1000) +int64_t get_just_uSecs(const TimeDuration& t); - /** - * @brief Adds milliseconds to time struct - * @param time contains time struct - * @param milliseconds contains value which need to - * add to time struct - **/ - static void AddMilliseconds(TimevalStruct& time, uint32_t milliseconds); +// return MILLISECONDS count between sinceTime value and current time +int64_t calculateTimeSpan(const TimeDuration& sinceTime); - static TimevalStruct Sub(const TimevalStruct& time1, - const TimevalStruct& time2); +// return MILLISECONDS count between time1 and time2 +int64_t calculateTimeDiff(const TimeDuration& time1, const TimeDuration& time2); - static TimeCompare compareTime(const TimevalStruct& time1, - const TimevalStruct& time2); +/** + * @brief Adds milliseconds to time struct + * @param time contains time struct + * @param milliseconds contains value which need to + * add to time struct + **/ +void AddMilliseconds(TimeDuration& time, uint32_t milliseconds); - static bool Greater(const TimevalStruct& time1, const TimevalStruct& time2); - static bool Less(const TimevalStruct& time1, const TimevalStruct& time2); - static bool Equal(const TimevalStruct& time1, const TimevalStruct& time2); +TimeCompare compareTime(const TimeDuration& time1, const TimeDuration& time2); - private: - static TimevalStruct ConvertionUsecs(const TimevalStruct& time); -}; +bool Greater(const TimeDuration& time1, const TimeDuration& time2); +bool Less(const TimeDuration& time1, const TimeDuration& time2); +bool Equal(const TimeDuration& time1, const TimeDuration& time2); } // namespace date_time -bool operator<(const TimevalStruct& time1, const TimevalStruct& time2); -bool operator==(const TimevalStruct& time1, const TimevalStruct& time2); -const TimevalStruct operator-(const TimevalStruct& time1, - const TimevalStruct& time2); #endif // SRC_COMPONENTS_INCLUDE_UTILS_DATE_TIME_H_ diff --git a/src/components/include/utils/lock.h b/src/components/include/utils/lock.h index e615a58f9d..bfa1ef1770 100644 --- a/src/components/include/utils/lock.h +++ b/src/components/include/utils/lock.h @@ -32,24 +32,18 @@ #ifndef SRC_COMPONENTS_INCLUDE_UTILS_LOCK_H_ #define SRC_COMPONENTS_INCLUDE_UTILS_LOCK_H_ -#if defined(OS_POSIX) -#include <pthread.h> -#include <sched.h> -#else -#error Please implement lock for your OS -#endif #include <stdint.h> -#include "utils/macro.h" +#include <boost/thread/mutex.hpp> +#include <boost/thread/recursive_mutex.hpp> +#include <iostream> +#include <memory> #include "utils/atomic.h" +#include "utils/macro.h" #include "utils/memory_barrier.h" -namespace sync_primitives { +using boost::system::error_code; -namespace impl { -#if defined(OS_POSIX) -typedef pthread_mutex_t PlatformMutex; -#endif -} // namespace impl +namespace sync_primitives { class SpinMutex { public: @@ -78,71 +72,98 @@ class SpinMutex { volatile unsigned int state_; }; -/* Platform-indepenednt NON-RECURSIVE lock (mutex) wrapper - Please use AutoLock to ackquire and (automatically) release it - It eases balancing of multple lock taking/releasing and makes it - Impossible to forget to release the lock: - ... - ConcurentlyAccessedData data_; - sync_primitives::Lock data_lock_; - ... - { - sync_primitives::AutoLock auto_lock(data_lock_); - data_.ReadOrWriteData(); - } // lock is automatically released here -*/ -class Lock { +/* Abstract base class that allows AutoLock to handle both recursive and + * non-recursive locks + */ +class BaseLock { public: - Lock(); - Lock(bool is_recursive); - ~Lock(); - + BaseLock() {} + virtual ~BaseLock() {} // Ackquire the lock. Must be called only once on a thread. // Please consider using AutoLock to capture it. - void Acquire(); + virtual void Acquire() = 0; // Release the lock. Must be called only once on a thread after lock. // was acquired. Please consider using AutoLock to automatically release // the lock - void Release(); + virtual void Release() = 0; // Try if lock can be captured and lock it if it was possible. // If it captured, lock must be manually released calling to Release // when protected resource access was finished. // @returns wether lock was captured. - bool Try(); + virtual bool Try() = 0; - private: - impl::PlatformMutex mutex_; + protected: + // Ensures safety in locking + virtual void AssertTakenAndMarkFree() = 0; + virtual void AssertFreeAndMarkTaken() = 0; + + friend class ConditionalVariable; +}; + +/* + * Platform-indepenednt NON-RECURSIVE lock (mutex) wrapper + */ +class Lock : public BaseLock { + public: + Lock(); + ~Lock(); + + virtual void Acquire(); + + virtual void Release(); -#ifndef NDEBUG + virtual bool Try(); + + private: /** - * @brief Basic debugging aid, a flag that signals wether this lock is - * currently taken - * Allows detection of abandoned and recursively captured mutexes - */ + * @brief Basic debugging aid, a flag that signals wether this lock is + * currently taken + * Allows detection of abandoned and recursively captured mutexes + */ uint32_t lock_taken_; + virtual void AssertTakenAndMarkFree(); + virtual void AssertFreeAndMarkTaken(); + boost::mutex mutex_; + DISALLOW_COPY_AND_ASSIGN(Lock); + friend class ConditionalVariable; +}; - /** - * @brief Describe if mutex is recurcive or not - */ - bool is_mutex_recursive_; +/* + * Platform-indepenednt RECURSIVE lock (mutex) wrapper + */ +class RecursiveLock : public BaseLock { + public: + RecursiveLock(); + ~RecursiveLock(); + + virtual void Acquire(); - void AssertFreeAndMarkTaken(); - void AssertTakenAndMarkFree(); -#else - void AssertFreeAndMarkTaken() {} - void AssertTakenAndMarkFree() {} -#endif + virtual void Release(); - void Init(bool is_recursive); + virtual bool Try(); + private: + /** + * @brief Basic debugging aid, a flag that signals wether this lock is + * currently taken + * Allows detection of abandoned and recursively captured mutexes + */ + uint32_t lock_taken_; + virtual void AssertTakenAndMarkFree(); + virtual void AssertFreeAndMarkTaken(); + boost::recursive_mutex mutex_; + DISALLOW_COPY_AND_ASSIGN(RecursiveLock); friend class ConditionalVariable; - DISALLOW_COPY_AND_ASSIGN(Lock); }; // This class is used to automatically acquire and release the a lock class AutoLock { public: - explicit AutoLock(Lock& lock) : lock_(lock) { + explicit AutoLock(const std::shared_ptr<BaseLock>& lock) : lock_(*lock) { + lock_.Acquire(); + } + explicit AutoLock(BaseLock& lock) : lock_(lock) { + // std::cerr << "lock is at " << &lock << std::endl; lock_.Acquire(); } ~AutoLock() { @@ -150,21 +171,35 @@ class AutoLock { } private: - Lock& GetLock() { + BaseLock& GetLock() { return lock_; } - Lock& lock_; + BaseLock& lock_; private: friend class AutoUnlock; friend class ConditionalVariable; DISALLOW_COPY_AND_ASSIGN(AutoLock); }; - +/* Please use AutoLock to acquire and (automatically) release it + * It eases balancing of multple lock taking/releasing and makes it + * Impossible to forget to release the lock: + * ... + * ConcurentlyAccessedData data_; + * sync_primitives::Lock data_lock_; + * ... + * { + * sync_primitives::AutoLock auto_lock(data_lock_); + * data_.ReadOrWriteData(); + * } // lock is automatically released here + */ // This class is used to temporarly unlock autolocked lock class AutoUnlock { public: - explicit AutoUnlock(Lock& lock) : lock_(lock) { + explicit AutoUnlock(const std::shared_ptr<BaseLock>& lock) : lock_(*lock) { + lock_.Release(); + } + explicit AutoUnlock(BaseLock& lock) : lock_(lock) { lock_.Release(); } explicit AutoUnlock(AutoLock& lock) : lock_(lock.GetLock()) { @@ -175,7 +210,7 @@ class AutoUnlock { } private: - Lock& lock_; + BaseLock& lock_; private: DISALLOW_COPY_AND_ASSIGN(AutoUnlock); diff --git a/src/components/include/utils/make_shared.h b/src/components/include/utils/make_shared.h deleted file mode 100644 index 9d40d646a6..0000000000 --- a/src/components/include/utils/make_shared.h +++ /dev/null @@ -1,191 +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_INCLUDE_UTILS_MAKE_SHARED_H_ -#define SRC_COMPONENTS_INCLUDE_UTILS_MAKE_SHARED_H_ - -#include <new> -/** - * @brief The functions set below allows to create shared pointer in a safe way. - * There are up to 5 parameters could be passed as the constructor parameters. - * - * @example - * struct A { - * A(int){} - * A(int, double) {} - * A(int, double, std::string) {} - * } - * SharedPtr<A> shared1(MakeShared<A>(5); - * SharedPtr<A> shared2(MakeShared<A>(5, 5.5); - * SharedPtr<A> shared3(MakeShared<A>(5, 5.5, std::string("MyStr")); - * - * The profit in using MakeShared instead of simple allocation with operator new - *is evident. - * Firstly it allows us to centralize allocation place, secondly it allows us to - *use - * safe operator new overloading (no throwable one). - */ -namespace utils { -template <typename T> -class SharedPtr; - -namespace { -template <typename T> -SharedPtr<T> Initialize(T* object) { - return object == NULL ? SharedPtr<T>() : SharedPtr<T>(object); -} -} - -template <typename T> -SharedPtr<T> MakeShared() { - T* t = new (std::nothrow) T; - return Initialize(t); -} - -template <typename T, typename Arg1> -SharedPtr<T> MakeShared(Arg1& arg1) { - T* t = new (std::nothrow) T(arg1); - return Initialize(t); -} - -template <typename T, typename Arg1, typename Arg2> -SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2) { - T* t = new (std::nothrow) T(arg1, arg2); - return Initialize(t); -} - -template <typename T, typename Arg1, typename Arg2, typename Arg3> -SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2, Arg3& arg3) { - T* t = new (std::nothrow) T(arg1, arg2, arg3); - return Initialize(t); -} - -template <typename T, - typename Arg1, - typename Arg2, - typename Arg3, - typename Arg4> -SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2, Arg3& arg3, Arg4& arg4) { - T* t = new (std::nothrow) T(arg1, arg2, arg3, arg4); - return Initialize(t); -} - -template <typename T, - typename Arg1, - typename Arg2, - typename Arg3, - typename Arg4, - typename Arg5> -SharedPtr<T> MakeShared( - Arg1& arg1, Arg2& arg2, Arg3& arg3, Arg4& arg4, Arg5& arg5) { - T* t = new (std::nothrow) T(arg1, arg2, arg3, arg4, arg5); - return Initialize(t); -} - -template <typename T, - typename Arg1, - typename Arg2, - typename Arg3, - typename Arg4, - typename Arg5, - typename Arg6> -SharedPtr<T> MakeShared( - Arg1& arg1, Arg2& arg2, Arg3& arg3, Arg4& arg4, Arg5& arg5, Arg6& arg6) { - T* t = new (std::nothrow) T(arg1, arg2, arg3, arg4, arg5, arg6); - return Initialize(t); -} - -template <typename T, typename Arg1> -SharedPtr<T> MakeShared(const Arg1& arg1) { - T* t = new (std::nothrow) T(arg1); - return Initialize(t); -} - -template <typename T, typename Arg1, typename Arg2> -SharedPtr<T> MakeShared(const Arg1& arg1, const Arg2& arg2) { - T* t = new (std::nothrow) T(arg1, arg2); - return Initialize(t); -} - -template <typename T, typename Arg1, typename Arg2, typename Arg3> -SharedPtr<T> MakeShared(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) { - T* t = new (std::nothrow) T(arg1, arg2, arg3); - return Initialize(t); -} - -template <typename T, - typename Arg1, - typename Arg2, - typename Arg3, - typename Arg4> -SharedPtr<T> MakeShared(const Arg1& arg1, - const Arg2& arg2, - const Arg3& arg3, - const Arg4& arg4) { - T* t = new (std::nothrow) T(arg1, arg2, arg3, arg4); - return Initialize(t); -} - -template <typename T, - typename Arg1, - typename Arg2, - typename Arg3, - typename Arg4, - typename Arg5> -SharedPtr<T> MakeShared(const Arg1& arg1, - const Arg2& arg2, - const Arg3& arg3, - const Arg4& arg4, - const Arg5& arg5) { - T* t = new (std::nothrow) T(arg1, arg2, arg3, arg4, arg5); - return Initialize(t); -} - -template <typename T, - typename Arg1, - typename Arg2, - typename Arg3, - typename Arg4, - typename Arg5, - typename Arg6> -SharedPtr<T> MakeShared(const Arg1& arg1, - const Arg2& arg2, - const Arg3& arg3, - const Arg4& arg4, - const Arg5& arg5, - const Arg6& arg6) { - T* t = new (std::nothrow) T(arg1, arg2, arg3, arg4, arg5, arg6); - return Initialize(t); -} - -} // namespace utils; -#endif // SRC_COMPONENTS_INCLUDE_UTILS_MAKE_SHARED_H_ diff --git a/src/components/include/utils/messagemeter.h b/src/components/include/utils/messagemeter.h index 42b658ad6b..1148a65b57 100644 --- a/src/components/include/utils/messagemeter.h +++ b/src/components/include/utils/messagemeter.h @@ -34,8 +34,8 @@ #define SRC_COMPONENTS_INCLUDE_UTILS_MESSAGEMETER_H_ #include <cstddef> -#include <set> #include <map> +#include <set> #include "utils/date_time.h" namespace utils { @@ -82,20 +82,19 @@ class MessageMeter { void ClearIdentifiers(); void set_time_range(const size_t time_range_msecs); - void set_time_range(const TimevalStruct& time_range); - TimevalStruct time_range() const; + void set_time_range(const date_time::TimeDuration& time_range); + date_time::TimeDuration time_range() const; private: - TimevalStruct time_range_; - typedef std::multiset<TimevalStruct> Timings; + date_time::TimeDuration time_range_; + typedef std::multiset<date_time::TimeDuration> Timings; typedef std::map<Id, Timings> TimingMap; TimingMap timing_map_; }; template <class Id> -MessageMeter<Id>::MessageMeter() - : time_range_(TimevalStruct{0, 0}) { - time_range_.tv_sec = 1; +MessageMeter<Id>::MessageMeter() { + time_range_ = date_time::seconds(1); } template <class Id> @@ -106,7 +105,7 @@ size_t MessageMeter<Id>::TrackMessage(const Id& id) { template <class Id> size_t MessageMeter<Id>::TrackMessages(const Id& id, const size_t count) { Timings& timings = timing_map_[id]; - const TimevalStruct current_time = date_time::DateTime::getCurrentTime(); + const date_time::TimeDuration current_time = date_time::getCurrentTime(); for (size_t i = 0; i < count; ++i) { // Adding to the end is amortized constant timings.insert(timings.end(), current_time); @@ -124,8 +123,8 @@ size_t MessageMeter<Id>::Frequency(const Id& id) { if (timings.empty()) { return 0u; } - const TimevalStruct actual_begin_time = date_time::DateTime::Sub( - date_time::DateTime::getCurrentTime(), time_range_); + const date_time::TimeDuration actual_begin_time = + (date_time::getCurrentTime() - time_range_); timings.erase(timings.begin(), timings.upper_bound(actual_begin_time)); return timings.size(); } @@ -142,21 +141,15 @@ void MessageMeter<Id>::ClearIdentifiers() { template <class Id> void MessageMeter<Id>::set_time_range(const size_t time_range_msecs) { - // TODO(EZamakhov): move to date_time::DateTime - const size_t secs = - time_range_msecs / date_time::DateTime::MILLISECONDS_IN_SECOND; - time_range_.tv_sec = secs; - const size_t mSecs = - time_range_msecs % date_time::DateTime::MILLISECONDS_IN_SECOND; - time_range_.tv_usec = - mSecs * date_time::DateTime::MICROSECONDS_IN_MILLISECOND; + time_range_ = date_time::milliseconds(time_range_msecs); } template <class Id> -void MessageMeter<Id>::set_time_range(const TimevalStruct& time_range) { +void MessageMeter<Id>::set_time_range( + const date_time::TimeDuration& time_range) { time_range_ = time_range; } template <class Id> -TimevalStruct MessageMeter<Id>::time_range() const { +date_time::TimeDuration MessageMeter<Id>::time_range() const { return time_range_; } } // namespace utils diff --git a/src/components/include/utils/semantic_version.h b/src/components/include/utils/semantic_version.h new file mode 100644 index 0000000000..5fe7ce1deb --- /dev/null +++ b/src/components/include/utils/semantic_version.h @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2018, Livio + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the 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_INCLUDE_UTILS_SEMANTIC_VERSION_H_ +#define SRC_COMPONENTS_INCLUDE_UTILS_SEMANTIC_VERSION_H_ + +#include <string> +namespace utils { + +struct SemanticVersion { + SemanticVersion(uint16_t major = 0, uint16_t minor = 0, uint16_t patch = 0) { + major_version_ = major; + minor_version_ = minor; + patch_version_ = patch; + } + + SemanticVersion(const SemanticVersion& other) { + major_version_ = other.major_version_; + minor_version_ = other.minor_version_; + patch_version_ = other.patch_version_; + } + + SemanticVersion(const std::string& versionString) + : major_version_(0), minor_version_(0), patch_version_(0) { + unsigned int major_int, minor_int, patch_int; + int readElements = sscanf( + versionString.c_str(), "%u.%u.%u", &major_int, &minor_int, &patch_int); + if (readElements != 3) { + // LOG4CXX_WARN(logger_, + // "Error while parsing version string: " << versionString); + } else { + major_version_ = static_cast<uint8_t>(major_int); + minor_version_ = static_cast<uint8_t>(minor_int); + patch_version_ = static_cast<uint8_t>(patch_int); + } + } + + static inline int16_t cmp(const SemanticVersion& version1, + const SemanticVersion& version2) { + int16_t diff = + static_cast<int16_t>(version1.major_version_ - version2.major_version_); + if (diff == 0) { + diff = static_cast<int16_t>(version1.minor_version_ - + version2.minor_version_); + if (diff == 0) { + diff = static_cast<int16_t>(version1.patch_version_ - + version2.patch_version_); + } + } + return diff; + } + + bool operator==(const SemanticVersion& other) const { + return SemanticVersion::cmp(*this, other) == 0; + } + bool operator<(const SemanticVersion& other) const { + return SemanticVersion::cmp(*this, other) < 0; + } + bool operator>(const SemanticVersion& other) const { + return SemanticVersion::cmp(*this, other) > 0; + } + bool operator<=(const SemanticVersion& other) const { + return SemanticVersion::cmp(*this, other) <= 0; + } + bool operator>=(const SemanticVersion& other) const { + return SemanticVersion::cmp(*this, other) >= 0; + } + static inline SemanticVersion* min(SemanticVersion& version1, + SemanticVersion& version2) { + return (version1 < version2) ? &version1 : &version2; + } + + const std::string toString() const { + std::string result = ""; + result += std::to_string(major_version_); + result += "."; + result += std::to_string(minor_version_); + result += "."; + result += std::to_string(patch_version_); + return result; + } + + bool isValid() const { + return major_version_ > 0 || minor_version_ > 0 || patch_version_ > 0; + } + + uint16_t major_version_ = 0; + uint16_t minor_version_ = 0; + uint16_t patch_version_ = 0; +}; + +extern const SemanticVersion base_rpc_version; +extern const SemanticVersion rpc_version_5; +} + +#endif // SRC_COMPONENTS_INCLUDE_UTILS_CALLABLE_H
\ No newline at end of file diff --git a/src/components/include/utils/shared_ptr.h b/src/components/include/utils/shared_ptr.h deleted file mode 100644 index 064bb36b4a..0000000000 --- a/src/components/include/utils/shared_ptr.h +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright (c) 2013, 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_INCLUDE_UTILS_SHARED_PTR_H_ -#define SRC_COMPONENTS_INCLUDE_UTILS_SHARED_PTR_H_ - -#include <assert.h> -#include <stddef.h> -#include <stdint.h> - -#include "utils/macro.h" -#include "utils/atomic.h" - -namespace utils { - -/** - * @brief Shared pointer. - * - * Pointer to an object with reference counting. - * Object will be automatically deallocated when last shared - * pointer is destroyed. - * - * @tparam ObjectType Type of wrapped object. - **/ -template <typename ObjectType> -class SharedPtr { - static void DummyDeleter(ObjectType* object_to_delete) { - delete object_to_delete; - } - - public: - // std smart pointer compatibility - typedef ObjectType element_type; - typedef void (*Deleter)(ObjectType*); - /** - * @brief Constructor. - * - * Initialize shared pointer with wrapped object. - * Reference counter will be initialized to 1. - * - * @param Object Wrapped object. - **/ - SharedPtr(ObjectType* Object); - - SharedPtr(ObjectType* Object, Deleter deleter) - : mObject(Object) - , mReferenceCounter(new uint32_t(1)) - , deleter_(deleter) {} - - SharedPtr(); - - /** - * @brief Copy constructor. - * - * Initialize shared pointer with another shared pointer. - * Reference counter will be incremented. - * - * @param Other Other shared pointer. - **/ - SharedPtr(const SharedPtr<ObjectType>& Other); - - /** - * @brief Copy constructor. - * - * Initialize shared pointer with another shared pointer. - * Reference counter will be incremented. - * - * @tparam OtherObjectType Type of other object pointer. This - * allows creating a shared pointer to an - * intstance of a base class from a shared - * pointer to an instance of a class - * inherited from this base class. - * If OtherObjectType is not implicitly - * convertible to ObjectType it will - * cause a compile error. - * - * @param Other Other shared pointer. - **/ - template <typename OtherObjectType> - SharedPtr(const SharedPtr<OtherObjectType>& Other); - - /** - * @brief Destructor. - * - * Decrement reference counter and destroy wrapped object - * if reference counter reaches zero. - **/ - ~SharedPtr(); - - /** - * @brief Assignment operator. - * - * Drop reference to currently referenced object and add - * reference to assigned object. - * - * @param Other Shared pointer to an object - * that must be referenced. - * - * @return Reference to this shared pointer. - **/ - SharedPtr<ObjectType>& operator=(const SharedPtr<ObjectType>& Other); - - bool operator==(const SharedPtr<ObjectType>& Other) const; - - bool operator<(const SharedPtr<ObjectType>& other) const; - - /** - * @brief Assignment operator. - * - * Drop reference to currently referenced object and add - * reference to assigned object. - * - * @tparam OtherObjectType Type of other object pointer. This - * allows creating a shared pointer to an - * intstance of a base class from a shared - * pointer to an instance of a class - * inherited from this base class. - * If OtherObjectType is not implicitly - * convertible to ObjectType it will - * cause a compile error. - * - * @param Other Shared pointer to an object - * that must be referenced. - * - * @return Reference to this shared pointer. - **/ - template <typename OtherObjectType> - SharedPtr<ObjectType>& operator=(const SharedPtr<OtherObjectType>& Other); - - template <typename OtherObjectType> - static SharedPtr<OtherObjectType> static_pointer_cast( - const SharedPtr<ObjectType>& pointer); - - template <typename OtherObjectType> - static SharedPtr<OtherObjectType> dynamic_pointer_cast( - const SharedPtr<ObjectType>& pointer); - - /** - * @brief Member access operator. - * - * @return Wrapped object. - **/ - ObjectType* operator->() const; - - ObjectType& operator*() const; - operator bool() const; - void reset(); - void reset(ObjectType* other); - ObjectType* get() const; - -#ifdef BUILD_TESTS - inline const uint32_t* get_ReferenceCounter() const { - return mReferenceCounter; - } -#endif // BUILD_TESTS - - /** - * @return true if mObject not NULL - */ - bool valid() const; - - private: - void reset_impl(ObjectType* other); - - // TSharedPtr needs access to other TSharedPtr private members - // for shared pointers type casts. - template <typename OtherObjectType> - friend class SharedPtr; - - /** - * @brief Drop reference to wrapped object. - * - * If reference counter reaches zero object and its reference - * counter will be deallocated. - **/ - void dropReference(); - - /** - * @brief Wrapped object. - **/ - ObjectType* mObject; - - /** - * @brief Pointer to reference counter. - **/ - uint32_t* mReferenceCounter; - - Deleter deleter_; - void release(); -}; - -template <typename ObjectType> -inline utils::SharedPtr<ObjectType>::SharedPtr(ObjectType* Object) - : mObject(NULL) - , mReferenceCounter(new uint32_t(1)) - , deleter_(DummyDeleter) { - DCHECK(Object != NULL); - mObject = Object; -} - -template <typename ObjectType> -inline utils::SharedPtr<ObjectType>::SharedPtr() - : mObject(0), mReferenceCounter(0), deleter_(DummyDeleter) {} - -template <typename ObjectType> -inline utils::SharedPtr<ObjectType>::SharedPtr( - const SharedPtr<ObjectType>& Other) - : mObject(0), mReferenceCounter(0), deleter_(DummyDeleter) { - *this = Other; -} - -template <typename ObjectType> -template <typename OtherObjectType> -inline utils::SharedPtr<ObjectType>::SharedPtr( - const SharedPtr<OtherObjectType>& Other) - : mObject(0), mReferenceCounter(0), deleter_(DummyDeleter) { - *this = Other; -} - -template <typename ObjectType> -inline utils::SharedPtr<ObjectType>::~SharedPtr() { - dropReference(); -} - -template <typename ObjectType> -inline utils::SharedPtr<ObjectType>& utils::SharedPtr<ObjectType>::operator=( - const SharedPtr<ObjectType>& Other) { - return operator=<ObjectType>(Other); -} - -template <typename ObjectType> -inline bool utils::SharedPtr<ObjectType>::operator==( - const SharedPtr<ObjectType>& Other) const { - return (mObject == Other.mObject); -} - -template <typename ObjectType> -inline bool utils::SharedPtr<ObjectType>::operator<( - const SharedPtr<ObjectType>& other) const { - return (mObject < other.mObject); -} - -template <typename ObjectType> -template <typename OtherObjectType> -inline utils::SharedPtr<ObjectType>& utils::SharedPtr<ObjectType>::operator=( - const SharedPtr<OtherObjectType>& Other) { - dropReference(); - - mObject = Other.mObject; - mReferenceCounter = Other.mReferenceCounter; - - if (0 != mReferenceCounter) { - atomic_post_inc(mReferenceCounter); - } - - return *this; -} - -template <typename ObjectType> -template <typename OtherObjectType> -utils::SharedPtr<OtherObjectType> utils::SharedPtr< - ObjectType>::static_pointer_cast(const SharedPtr<ObjectType>& pointer) { - SharedPtr<OtherObjectType> casted_pointer; - casted_pointer.mObject = static_cast<OtherObjectType*>(pointer.mObject); - casted_pointer.mReferenceCounter = pointer.mReferenceCounter; - - if (0 != casted_pointer.mReferenceCounter) { - atomic_post_inc(casted_pointer.mReferenceCounter); - } - - return casted_pointer; -} - -template <typename ObjectType> -template <typename OtherObjectType> -utils::SharedPtr<OtherObjectType> utils::SharedPtr< - ObjectType>::dynamic_pointer_cast(const SharedPtr<ObjectType>& pointer) { - SharedPtr<OtherObjectType> casted_pointer; - casted_pointer.mObject = dynamic_cast<OtherObjectType*>(pointer.mObject); - if (NULL != casted_pointer.mObject) { - casted_pointer.mReferenceCounter = pointer.mReferenceCounter; - - if (0 != casted_pointer.mReferenceCounter) { - atomic_post_inc(casted_pointer.mReferenceCounter); - } - } - - return casted_pointer; -} - -template <typename ObjectType> -ObjectType* utils::SharedPtr<ObjectType>::operator->() const { - DCHECK(mObject); - return mObject; -} - -template <typename ObjectType> -ObjectType& utils::SharedPtr<ObjectType>::operator*() const { - DCHECK(mObject); - return *mObject; -} - -template <typename ObjectType> -utils::SharedPtr<ObjectType>::operator bool() const { - return valid(); -} - -template <typename ObjectType> -void utils::SharedPtr<ObjectType>::reset() { - reset_impl(0); -} - -template <typename ObjectType> -void utils::SharedPtr<ObjectType>::reset(ObjectType* other) { - DCHECK(other != NULL); - reset_impl(other); -} - -template <typename ObjectType> -void SharedPtr<ObjectType>::release() { - deleter_(mObject); - mObject = 0; - - delete mReferenceCounter; - mReferenceCounter = 0; -} - -template <typename ObjectType> -void utils::SharedPtr<ObjectType>::reset_impl(ObjectType* other) { - dropReference(); - mObject = other; - mReferenceCounter = new uint32_t(1); -} - -template <typename ObjectType> -inline void SharedPtr<ObjectType>::dropReference() { - if (0 != mReferenceCounter) { - if (1 == atomic_post_dec(mReferenceCounter)) { - release(); - } - } -} - -template <typename ObjectType> -ObjectType* SharedPtr<ObjectType>::get() const { - return mObject; -} - -template <typename ObjectType> -inline bool SharedPtr<ObjectType>::valid() const { - if (mReferenceCounter && (0 < *mReferenceCounter)) { - return (mObject != NULL); - } - return false; -} - -} // namespace utils - -#endif // SRC_COMPONENTS_INCLUDE_UTILS_SHARED_PTR_H_ - -// vim: set ts=2 sw=2 et: diff --git a/src/components/include/utils/threads/message_loop_thread.h b/src/components/include/utils/threads/message_loop_thread.h index 15023f02dd..add7fc38b8 100644 --- a/src/components/include/utils/threads/message_loop_thread.h +++ b/src/components/include/utils/threads/message_loop_thread.h @@ -40,7 +40,7 @@ #include "utils/macro.h" #include "utils/message_queue.h" #include "utils/threads/thread.h" -#include "utils/shared_ptr.h" + #include "utils/lock.h" namespace threads { diff --git a/src/components/include/utils/typed_enum_print.h b/src/components/include/utils/typed_enum_print.h new file mode 100644 index 0000000000..e2b903c948 --- /dev/null +++ b/src/components/include/utils/typed_enum_print.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_INCLUDE_UTILS_TYPED_ENUM_PRINT_H_ +#define SRC_COMPONENTS_INCLUDE_UTILS_TYPED_ENUM_PRINT_H_ + +#include <type_traits> +#include <ostream> + +namespace utils { + +// Generic overloaded operator "<<" to be able to send enum class values to +// std::ostream +template <typename T> +std::ostream& operator<<( + typename std::enable_if<std::is_enum<T>::value, std::ostream>::type& stream, + const T& e) { + return stream << static_cast<int>(e); +} + +} // namespace utils + +#endif // SRC_COMPONENTS_INCLUDE_UTILS_TYPED_ENUM_PRINT_H_ |