diff options
Diffstat (limited to 'src/components/include')
58 files changed, 821 insertions, 925 deletions
diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index f6f06bd7cd..61095e388a 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -39,19 +39,17 @@ #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 +80,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 +98,6 @@ struct ApplicationsAppIdSorter { return lhs->app_id() < rhs->app_id(); } }; - struct ApplicationsPolicyAppIdSorter { bool operator()(const ApplicationSharedPtr lhs, const ApplicationSharedPtr rhs) { @@ -135,8 +138,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 +169,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 +185,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; @@ -251,7 +260,15 @@ class ApplicationManager { * **/ virtual void SendHMIStatusNotification( - const utils::SharedPtr<Application> app) = 0; + const std::shared_ptr<Application> app) = 0; + + /** + * @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 SendDriverDistractionState(ApplicationSharedPtr application) = 0; /** * DEPRECATED @@ -308,23 +325,24 @@ class ApplicationManager { */ 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 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) = 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 +398,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; @@ -431,10 +454,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; @@ -463,6 +486,8 @@ class ApplicationManager { virtual bool IsStopping() const = 0; + virtual bool IsLowVoltage() = 0; + virtual void RemoveAppFromTTSGlobalPropertiesList(const uint32_t app_id) = 0; virtual mobile_apis::Result::eType SaveBinary( @@ -613,6 +638,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,7 +697,7 @@ 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, @@ -690,9 +718,6 @@ class ApplicationManager { 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) diff --git a/src/components/include/application_manager/application_manager_settings.h b/src/components/include/application_manager/application_manager_settings.h index e745a831c6..8f9d7496c8 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, @@ -87,6 +89,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 d48c7307b9..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" @@ -53,7 +52,7 @@ 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: @@ -125,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( @@ -471,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 @@ -536,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/connection_handler/connection_handler.h b/src/components/include/connection_handler/connection_handler.h index 352f886aed..bfaacf5fc1 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,14 @@ 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; +} SessionTransports; +typedef std::map<uint8_t, SessionTransports> SessionConnectionMap; + /** * \class ConnectionHandler * \brief SmartDeviceLink ConnectionHandler interface class @@ -202,6 +211,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(). @@ -217,6 +263,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..2f4ee94449 100644 --- a/src/components/include/connection_handler/connection_handler_observer.h +++ b/src/components/include/connection_handler/connection_handler_observer.h @@ -157,6 +157,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..c023f3c7fc 100644 --- a/src/components/include/policy/policy_external/policy/policy_listener.h +++ b/src/components/include/policy/policy_external/policy/policy_listener.h @@ -137,7 +137,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 +172,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 7970d525c5..57f6d2f802 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -42,14 +42,11 @@ #include "policy/policy_listener.h" #include "policy/usage_statistics/statistics_manager.h" #include "policy/cache_manager_interface.h" - -#ifdef SDL_REMOTE_CONTROL #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: @@ -565,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 @@ -613,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_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 84d48a691e..ee0bae7118 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -42,14 +42,11 @@ #include "policy/policy_listener.h" #include "policy/usage_statistics/statistics_manager.h" #include "policy/cache_manager_interface.h" - -#ifdef SDL_REMOTE_CONTROL #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: @@ -543,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 @@ -592,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/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 1da8d61e52..bb79964b12 100644 --- a/src/components/include/protocol_handler/protocol_handler.h +++ b/src/components/include/protocol_handler/protocol_handler.h @@ -100,7 +100,15 @@ 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; diff --git a/src/components/include/protocol_handler/protocol_handler_settings.h b/src/components/include/protocol_handler/protocol_handler_settings.h index e1107cb2a9..c4f9bb6420 100644 --- a/src/components/include/protocol_handler/protocol_handler_settings.h +++ b/src/components/include/protocol_handler/protocol_handler_settings.h @@ -51,6 +51,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 7a5dcf287c..d50b1e694e 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_; @@ -71,7 +72,8 @@ struct SessionContext { * @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) @@ -81,6 +83,8 @@ struct SessionContext { /** * @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() @@ -91,13 +95,15 @@ 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) @@ -205,6 +211,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. diff --git a/src/components/include/protocol_handler/telemetry_observer.h b/src/components/include/protocol_handler/telemetry_observer.h index 533ad51d62..b2bf94de35 100644 --- a/src/components/include/protocol_handler/telemetry_observer.h +++ b/src/components/include/protocol_handler/telemetry_observer.h @@ -50,7 +50,7 @@ class PHTelemetryObserver { }; virtual void StartMessageProcess( uint32_t message_id, const date_time::TimeDuration& start_time) = 0; - virtual void EndMessageProcess(utils::SharedPtr<MessageMetric> m) = 0; + virtual void EndMessageProcess(std::shared_ptr<MessageMetric> m) = 0; virtual ~PHTelemetryObserver() {} }; } // protocol_handler 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/test/application_manager/mock_app_extension.h b/src/components/include/test/application_manager/mock_app_extension.h new file mode 100644 index 0000000000..eb8fcd51cf --- /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(NsSmartDeviceLink::NsSmartObjects::SmartObject& resumption_data)); + MOCK_METHOD1(ProcessResumption, + void(const NsSmartDeviceLink::NsSmartObjects::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 bc1c0d08d2..4a86c17f39 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,11 @@ 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)); + void(const std::shared_ptr<application_manager::Application> app)); + MOCK_METHOD1(SendDriverDistractionState, + void(application_manager::ApplicationSharedPtr app)); 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(application_manager::commands::MessageSharedPtr& message)); MOCK_CONST_METHOD1( GetDefaultHmiLevel, mobile_apis::HMILevel::eType( @@ -143,6 +133,9 @@ 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)); @@ -158,6 +151,12 @@ 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)); @@ -169,11 +168,10 @@ class MockApplicationManager : public application_manager::ApplicationManager { 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, @@ -182,6 +180,7 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_CONST_METHOD1(IsAppsQueriedFrom, bool(const connection_handler::DeviceHandle handle)); MOCK_CONST_METHOD0(IsStopping, bool()); + MOCK_METHOD0(IsLowVoltage, bool()); MOCK_METHOD1(RemoveAppFromTTSGlobalPropertiesList, void(const uint32_t app_id)); MOCK_METHOD4( @@ -234,6 +233,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)); @@ -311,14 +312,12 @@ 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&()); }; } // 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..735539156a 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 @@ -95,6 +95,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/policies/mock_policy_handler_interface.h b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h index dfd537c678..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)); @@ -239,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, @@ -270,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..ede08a9a4a 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 @@ -74,6 +74,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 02931114f0..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&)); 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 96e484acae..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)); 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 d216957eb0..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,7 +202,7 @@ 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()); 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 e0214934ee..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)); 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 e667911944..13c0264cb8 100644 --- a/src/components/include/test/protocol_handler/mock_protocol_handler.h +++ b/src/components/include/test/protocol_handler/mock_protocol_handler.h @@ -55,8 +55,9 @@ 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, 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..c0612ce137 100644 --- a/src/components/include/test/protocol_handler/mock_session_observer.h +++ b/src/components/include/test/protocol_handler/mock_session_observer.h @@ -76,6 +76,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 +95,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 6b24d5a919..82c42775fa 100644 --- a/src/components/include/test/protocol_handler/mock_telemetry_observer.h +++ b/src/components/include/test/protocol_handler/mock_telemetry_observer.h @@ -46,7 +46,7 @@ class MockPHTelemetryObserver : public PHTelemetryObserver { MOCK_METHOD2(StartMessageProcess, void(uint32_t message_id, const date_time::TimeDuration& start_time)); - MOCK_METHOD1(EndMessageProcess, void(utils::SharedPtr<MessageMetric> m)); + MOCK_METHOD1(EndMessageProcess, void(std::shared_ptr<MessageMetric> m)); }; } // namespace protocol_handler_test 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/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..8bba7ade8b 100644 --- a/src/components/include/transport_manager/transport_adapter/transport_adapter.h +++ b/src/components/include/transport_manager/transport_adapter/transport_adapter.h @@ -5,6 +5,9 @@ * Copyright (c) 2016, Ford Motor Company * All rights reserved. * + * Copyright (c) 2018 Xevo Inc. + * All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -16,7 +19,7 @@ * 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 + * Neither the name of the copyright holders nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,8 +44,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" @@ -70,6 +71,9 @@ enum DeviceType { 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 +90,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 +328,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..5d55960943 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 @@ -2,6 +2,9 @@ * Copyright (c) 2013, Ford Motor Company * All rights reserved. * + * Copyright (c) 2018 Xevo Inc. + * All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -13,7 +16,7 @@ * 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 + * Neither the name of the copyright holders nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -57,7 +60,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 { diff --git a/src/components/include/transport_manager/transport_manager_listener.h b/src/components/include/transport_manager/transport_manager_listener.h index d336eade45..0d02bfd8c7 100644 --- a/src/components/include/transport_manager/transport_manager_listener.h +++ b/src/components/include/transport_manager/transport_manager_listener.h @@ -2,6 +2,9 @@ * Copyright (c) 2014, Ford Motor Company * All rights reserved. * + * Copyright (c) 2018 Xevo Inc. + * All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -13,7 +16,7 @@ * 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 + * Neither the name of the copyright holders nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -33,6 +36,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 +197,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..a255256290 100644 --- a/src/components/include/transport_manager/transport_manager_listener_empty.h +++ b/src/components/include/transport_manager/transport_manager_listener_empty.h @@ -2,6 +2,9 @@ * Copyright (c) 2014, Ford Motor Company * All rights reserved. * + * Copyright (c) 2018 Xevo Inc. + * All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -13,7 +16,7 @@ * 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 + * Neither the name of the copyright holders nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -187,6 +190,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/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/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 { |