diff options
author | Justin Dickow <jjdickow@gmail.com> | 2014-10-20 17:44:41 -0400 |
---|---|---|
committer | Justin Dickow <jjdickow@gmail.com> | 2014-10-20 17:44:41 -0400 |
commit | 34e7256493ff0e6594029b9857d7e2aa31f5dbeb (patch) | |
tree | 367306b507c52d3af211533810adbc22004e0192 /src/components/include/transport_manager | |
parent | 2eef966e9b5fd4d94dd98820095eb765e200c64b (diff) | |
download | sdl_core-34e7256493ff0e6594029b9857d7e2aa31f5dbeb.tar.gz |
SDL 3.8!
Signed-off-by: Justin Dickow <jjdickow@gmail.com>
Diffstat (limited to 'src/components/include/transport_manager')
9 files changed, 1415 insertions, 0 deletions
diff --git a/src/components/include/transport_manager/common.h b/src/components/include/transport_manager/common.h new file mode 100644 index 0000000000..c1fc51dc8a --- /dev/null +++ b/src/components/include/transport_manager/common.h @@ -0,0 +1,94 @@ +/* + * 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_TRANSPORT_MANAGER_COMMON_H_ +#define SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_COMMON_H_ + +#include <vector> +#include <string> + +/** + * @brief - transport_manager namespace + */ +namespace transport_manager { + +/** + * @enum Transport manager states. + */ +enum { + E_SUCCESS = 0, + E_TM_IS_NOT_INITIALIZED, + E_INVALID_HANDLE, + E_CONNECTION_IS_TO_SHUTDOWN, + E_CONNECTION_EXISTS, + E_ADAPTER_EXISTS, + E_ADAPTERS_FAIL, + E_INTERNAL_ERROR +}; + +/** + * @brief Type definition for variable that hold handle of device. + */ +typedef unsigned int DeviceHandle; + +/** + * @brief Type definition for variable that hold connection unique identifier. + */ +typedef unsigned int ConnectionUID; + +/** + * @brief Type definition for variable that hold connection type. + */ +typedef std::string ConnectionType; + +/** + * @brief Type definition for variable that hold device unique identifier. + */ +typedef std::string DeviceUID; + +/** + * @brief Type definition of container(vector) that holds device unique + * identifiers. + */ +typedef std::vector<DeviceUID> DeviceList; + +/** + * @brief Type definition for variable that hold handle of application. + */ +typedef int ApplicationHandle; + +/** + * @brief Type definition for vector that contain ApplicationHandle variables. + */ +typedef std::vector<ApplicationHandle> ApplicationList; +} // namespace transport_manager +#endif // SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_COMMON_H_ diff --git a/src/components/include/transport_manager/error.h b/src/components/include/transport_manager/error.h new file mode 100644 index 0000000000..7e2349eac2 --- /dev/null +++ b/src/components/include/transport_manager/error.h @@ -0,0 +1,146 @@ +/* + * 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_TRANSPORT_MANAGER_ERROR_H_ +#define SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_ERROR_H_ + +#include <string> +#include <utils/shared_ptr.h> + +namespace transport_manager { + +/** + * @brief Class that hold information about error. + */ +class BaseError { + public: + /** + * @brief Constructor. + */ + BaseError() {} + + /** + * @brief Constructor. + * + * @param desc Description of error. + */ + explicit BaseError(const std::string& desc) : description_(desc) {} + + /** + * @brief Constructor. + * + * @param other Error class. + */ + BaseError(const BaseError& other) : description_(other.description_) {} + + /** + * @brief Destructor. + */ + virtual ~BaseError() {} + + /** + * @brief Return description of error. + * + * @return string with description of error. + */ + virtual const std::string& text() const { + return description_; + } + + private: + std::string description_; +}; +typedef utils::SharedPtr<BaseError> BaseErrorPtr; + +/** + * @brief Error that originates during device search. + */ +class SearchDeviceError : public BaseError { +}; + +/** + * @brief Error that originates during connection. + */ +class ConnectError : public BaseError { +}; + +/** + * @brief Error that originates during disconnection. + */ +class DisconnectError : public BaseError { +}; + +/** + * @brief Error that originates during device disconnection. + */ +class DisconnectDeviceError : public BaseError { +}; + +/** + * @brief Error that originates during data receive.. + */ +class DataReceiveError : public BaseError { +}; + +/** + * @brief Error that originates during data send. + */ +class DataSendError : public BaseError { + public: + /** + * @brief Constructor. + */ + DataSendError() : BaseError() {} + + /** + * @brief Constructor. + * + * @param Error description. + */ + explicit DataSendError(const std::string& desc) : BaseError(desc) {} +}; + +/** + * @brief Error that originates during data sending timeout. + */ +class DataSendTimeoutError : public DataSendError { +}; + + +/** + * @brief Error that originates during communication. + */ +class CommunicationError : public BaseError { +}; + +} // namespace transport_manager +#endif // SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_ERROR_H_ diff --git a/src/components/include/transport_manager/info.h b/src/components/include/transport_manager/info.h new file mode 100644 index 0000000000..66e9df97a3 --- /dev/null +++ b/src/components/include/transport_manager/info.h @@ -0,0 +1,163 @@ +/* + * \file info.h + * \brief Information classes header file. + * + * 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_TRANSPORT_MANAGER_INFO_H_ +#define SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_INFO_H_ + +#include <string> +#include "transport_manager/common.h" + +/** + * @brief transport_manager name space + */ +namespace transport_manager { + +/** + * @brief Base information class. + */ +class Info { + protected: + /** + * @brief Variable that hold name. + */ + std::string name_; + + public: + /** + * @brief Constructor. + */ + Info() {} + + /** + * @brief Constructor + * + * @param name Info class object name. + */ + explicit Info(std::string name) + : name_(name) { + } + + /** + * @brief Return string with name. + */ + std::string name() const { + return name_; + } + + /** + * @brief Destructor. + */ + virtual ~Info() {} +}; + +/** + * @brief Hold information about device. + */ +class DeviceInfo : public Info { + protected: + /** + * @brief Variable that hold MAC address of device. + */ + std::string mac_address_; + + /** + * @brief Variable that hold handle of device. + */ + DeviceHandle device_handle_; + + /** + * @brief The connection type used by device. + */ + ConnectionType connection_type_; + + public: + /** + * @brief Constructor. + * + * @param device_handle Handle of device. + * @param mac_address MAC address of device. + * @param name Name of device. + */ + DeviceInfo(DeviceHandle device_handle, std::string mac_address, + std::string name, const ConnectionType& connection_type) + : Info(name), + mac_address_(mac_address), + device_handle_(device_handle), + connection_type_(connection_type) { + } + + /** + * @brief Return mac_address. + */ + std::string mac_address() const { + return mac_address_; + } + + /** + * @brief Return device_handle field. + */ + DeviceHandle device_handle() const { + return device_handle_; + } + + /** + * @brief Return connection_type_. + * @return + */ + ConnectionType connection_type() const { + return connection_type_; + } + + /** + * @brief Overloaded operator "==". + */ + friend bool operator ==(const DeviceInfo& first, const DeviceInfo& second); + + // Needed for std::set container + bool operator <(const DeviceInfo& than) const { + return device_handle_ < than.device_handle_; + } +}; + +/** + * @brief Assign fields of one DeviceInfo class to another. + */ +inline bool operator ==(const DeviceInfo& first, const DeviceInfo& second) { + return first.name_ == second.name_ + && first.mac_address_ == second.mac_address_ + && first.device_handle_ == second.device_handle_; +} +} // namespace transport_manager +#endif // SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_INFO_H_ diff --git a/src/components/include/transport_manager/transport_adapter/device.h b/src/components/include/transport_manager/transport_adapter/device.h new file mode 100644 index 0000000000..78d3b44958 --- /dev/null +++ b/src/components/include/transport_manager/transport_adapter/device.h @@ -0,0 +1,125 @@ +/* + * 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_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_DEVICE_H_ +#define SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_DEVICE_H_ + +#include <string> +#include <vector> + +#include "transport_manager/common.h" +#include "utils/shared_ptr.h" + +namespace transport_manager { +namespace transport_adapter { + +/** + * @brief Internal class describing device. + **/ +class Device { + public: + /** + * @brief Constructor. + * + * @param name User-friendly device name. + * @param unique_device_id device unique identifier. + **/ + Device(const std::string& name, const DeviceUID& unique_device_id) + : name_(name), + unique_device_id_(unique_device_id), + keep_on_disconnect_(false) {} + /** + * @brief Destructor. + **/ + virtual ~Device() {} + + /** + * @brief Compare devices. + * + * This method checks whether two SDevice structures + * refer to the same device. + * + * @param other_Ddvice Device to compare with. + * + * @return true if devices are equal, false otherwise. + **/ + virtual bool IsSameAs(const Device* other_device) const = 0; + + virtual ApplicationList GetApplicationList() const = 0; + + inline const DeviceUID& unique_device_id() const { + return unique_device_id_; + } + + /** + * @brief Return name of device. + */ + inline const std::string& name() const { + return name_; + } + + /** + * @brief Get @link keep_on_disconnect_ @endlink value + */ + inline bool keep_on_disconnect() const { + return keep_on_disconnect_; + } + + /** + * @brief Set @link keep_on_disconnect_ @endlink value + * @param keep_on_disconnect new value + */ + inline void set_keep_on_disconnect(bool keep_on_disconnect) { + keep_on_disconnect_ = keep_on_disconnect; + } + + private: + /** + * @brief Device user-friendly name. + **/ + std::string name_; + + /** + * @brief Unique device identifier across all devices. + **/ + DeviceUID unique_device_id_; + + /** + * @brief If true, device will remain in list even if all its connections finished. + **/ + bool keep_on_disconnect_; +}; +typedef utils::SharedPtr<Device> DeviceSptr; +typedef std::vector<DeviceSptr> DeviceVector; +} // namespace transport_adapter +} // namespace transport_manager +#endif // SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_DEVICE_H_ diff --git a/src/components/include/transport_manager/transport_adapter/transport_adapter.h b/src/components/include/transport_manager/transport_adapter/transport_adapter.h new file mode 100644 index 0000000000..eb4bb88f53 --- /dev/null +++ b/src/components/include/transport_manager/transport_adapter/transport_adapter.h @@ -0,0 +1,267 @@ +/** + * \file transport_adapter.h + * \brief TransportAdapter class header file. + * + * 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_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_TRANSPORT_ADAPTER_H_ +#define SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_TRANSPORT_ADAPTER_H_ + +#include <string> +#include <vector> +#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" +#include "protocol/common.h" + +namespace transport_manager { + +class TMMetricObserver; + +namespace transport_adapter { + +class TransportAdapterListener; + +// TODO(EZamakhov): cahnge to DeviceUID +typedef std::string DeviceType; +/** + * @brief Type definition of container(map) that holds device unique + *identifier(key value) and smart pointer to the device(mapped value). + **/ +typedef std::map<DeviceUID, DeviceSptr> DeviceMap; +/** + * @brief Type definition for container(list) that holds pointers to device + * adapter listeners + */ +typedef std::list<TransportAdapterListener*> TransportAdapterListenerList; + +class TransportAdapter { + public: + /** + * @enum Available types of errors. + */ + enum Error { + OK, + FAIL, + NOT_SUPPORTED, + ALREADY_EXISTS, + BAD_STATE, + BAD_PARAM + }; + + public: + /** + * @brief Destructor. + */ + virtual ~TransportAdapter() {} + + /** + * @brief + */ + virtual DeviceType GetDeviceType() const = 0; + + /** + * @brief Allows to obtain connection type used by device. + * @return connection type. + */ + virtual ConnectionType GetConnectionType() const = 0; + + /* TODO + virtual Error LoadState(TransportAdapterState* state) = 0; + virtual void SaveState(TransportAdapterState* state) = 0; + */ + + /** + * @brief Check initialization. + * + * @return true if initialized. + * @return false if not initialized. + */ + virtual bool IsInitialised() const = 0; + + /** + * @brief Run device adapter. + * + * Called from transport manager to start device adapter. + * + * @return Error information about possible reason of failure. + **/ + virtual Error Init() = 0; + + /** + * @brief Add listener to the container(list) of device adapter listeners. + * + * @param listener Pointer to the device adapter listener. + */ + virtual void AddListener(TransportAdapterListener* listener) = 0; + + /** + * @brief Notify that device scanner is available. + * + * @return true - available, false - not available. + */ + virtual bool IsSearchDevicesSupported() const = 0; + + /** + * @brief Start scanning for new devices. + * + * List of new devices will be supplied in onDeviceListUpdated callback. + * + * @return Error information about possible reason of failure. + **/ + virtual Error SearchDevices() = 0; + + /** + * @brief Notify that server connection factory is available. + * + * @return true - available, false - not available. + */ + virtual bool IsServerOriginatedConnectSupported() const = 0; + + /** + * @brief Connect to the specified application discovered on device. + * + * @param device_handle Handle of device to connect to. + * @param app_handle Handle of application to connect to. + * + * @return Error information about possible reason of failure. + **/ + virtual Error Connect(const DeviceUID& device_handle, + const ApplicationHandle& app_handle) = 0; + + /** + * @brief Connect to all applications discovered on device + * @param device_handle Handle of device + * @return Error information about connecting applications on device + */ + virtual Error ConnectDevice(const DeviceUID& device_handle) = 0; + + /** + * @brief Notify that listener of client connection is available. + * + * @return true - available, false - not available. + */ + virtual bool IsClientOriginatedConnectSupported() const = 0; + + /** + * @brief Start client listener. + * + * @return Error information about possible reason of failure. + */ + virtual Error StartClientListening() = 0; + + /** + * @brief Stop client listener. + * + * @return Error information about possible reason of failure. + */ + virtual Error StopClientListening() = 0; + + /** + * @brief Disconnect from specified session. + * + * @param device_handle Handle of device to Disconnect from. + * @param app_handle Handle of application. + * + * @return Error information about possible reason of disconnection from the + *device failure. + **/ + virtual Error Disconnect(const DeviceUID& device_handle, + const ApplicationHandle& app_handle) = 0; + + /** + * @brief Disconnect from all sessions on specified device. + * + * @param device_handle Device handle to Disconnect. + * + * @return Error information about possible reason of disconnecting from + *device failure + **/ + virtual Error DisconnectDevice(const DeviceUID& device_handle) = 0; + + /** + * @brief Send frame. + * + * @param device_handle Device unique identifier. + * @param app_handle Handle of application. + * @param data Smart pointer to the raw message. + * + * @return Error information about possible reason of sending data failure. + **/ + virtual Error SendData(const DeviceUID& device_handle, + const ApplicationHandle& app_handle, + const RawMessagePtr data) = 0; + + /** + * @brief Create container(vector) of device unique identifiers. + * + * @return container(vector) of device unique identifiers. + */ + virtual DeviceList GetDeviceList() const = 0; + + /** + * @brief Get container(vector) of application unique identifiers that + *available at specified device. + * + * @param device_handle Device unique identifier. + * + * @return Container(vector) that holds application unique identifiers. + */ + virtual ApplicationList GetApplicationList(const DeviceUID& device_handle) + const = 0; + + /** + * @brief Return name of device. + * + * @param device_id device unique identifier. + * + * @return string. + */ + virtual std::string DeviceName(const DeviceUID& device_id) const = 0; + +#ifdef TIME_TESTER + /** + * @brief Return Time metric observer + * + * @param return pointer to Time metric observer + */ + virtual TMMetricObserver* GetTimeMetricObserver() = 0; +#endif // TIME_TESTER +}; +} // namespace transport_adapter +} // namespace transport_manager +#endif // SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_TRANSPORT_ADAPTER_H_ 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 new file mode 100644 index 0000000000..d343ccc357 --- /dev/null +++ b/src/components/include/transport_manager/transport_adapter/transport_adapter_event.h @@ -0,0 +1,92 @@ +/* + * 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_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_TRANSPORT_ADAPTER_EVENT_H_ +#define SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_TRANSPORT_ADAPTER_EVENT_H_ + +#include "transport_manager/common.h" +#include "transport_manager/transport_adapter/transport_adapter.h" +#include "protocol/common.h" + +namespace transport_manager { + +class TransportAdapterEvent { + public: + /** + * @brief Constructor. + * + * @param type Event type. + * @param transport_adapter Transport adapter + * @param device_handle Handle of device. + * @param application_id Handle of application. + * @param data Smart pointer to the raw message. + * @param error Error class that contains details of this error situation. + */ + TransportAdapterEvent(int type, + transport_adapter::TransportAdapter* adapter, + const DeviceUID& device_handle, + const ApplicationHandle& application_id, + RawMessagePtr data, BaseErrorPtr error) + : event_type(type), + application_id(application_id), + device_uid(device_handle), + transport_adapter(adapter), + event_data(data), + event_error(error) { + } + /** + * @brief Value that describe event type. + */ + int event_type; + /** + * @brief Handle of application + */ + ApplicationHandle application_id; + /** + * @brief Device unique identifier. + */ + DeviceUID device_uid; + /** + * @brief Transport adapter. + */ + transport_adapter::TransportAdapter* transport_adapter; + /** + * @brief Smart pointer to the raw message + */ + RawMessagePtr event_data; + /** + * @brief Pointer to the class that contain details of error. + */ + BaseErrorPtr event_error; +}; +} // namespace transport_manager +#endif // SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_TRANSPORT_ADAPTER_EVENT_H_ diff --git a/src/components/include/transport_manager/transport_manager.h b/src/components/include/transport_manager/transport_manager.h new file mode 100644 index 0000000000..149dede001 --- /dev/null +++ b/src/components/include/transport_manager/transport_manager.h @@ -0,0 +1,166 @@ +/* + * 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_TRANSPORT_MANAGER_TRANSPORT_MANAGER_H_ +#define SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_H_ + +#include "transport_manager/common.h" +#include "transport_manager/transport_manager_listener.h" +#include "transport_manager/transport_adapter/transport_adapter_event.h" +#include "protocol/common.h" + +namespace transport_manager { + +class TransportAdapterEvent; + +/** + * @brief Interface of transport manager. + **/ +class TransportManager { + public: + /** + * @brief Destructor. + **/ + virtual ~TransportManager() {} + + /** + * @brief Initialize transport manager. + * @return Error code. + */ + virtual int Init() = 0; + + /** + * @brief Start scanning for new devices. + * + * @return Code error. + **/ + virtual int SearchDevices() = 0; + + /** + * @brief Connect to all applications discovered on device. + * + * @param device_id Handle of device to connect to. + * + * @return Code error. + **/ + virtual int ConnectDevice(const DeviceHandle& device_id) = 0; + + /** + * @brief Disconnect from all applications connected on device. + * + * @param device_id Handle of device to Disconnect from. + * + * @return Code error. + **/ + virtual int DisconnectDevice(const DeviceHandle& device_id) = 0; + + /** + * @brief Disconnect from applications connected on device by connection + *unique identifier. + * + * @param connection Connection unique identifier. + * + * @return Code error. + **/ + virtual int Disconnect(const ConnectionUID& connection_id) = 0; + + /** + * @brief Disconnect and clear all unprocessed data. + * + * @param connection Connection unique identifier. + */ + virtual int DisconnectForce(const ConnectionUID& connection_id) = 0; + + /** + * @brief Post new message in queue for massages destined to device. + * + * @param message Smart pointer to the raw massage. + * + * @return Code error. + **/ + virtual int SendMessageToDevice(const RawMessagePtr message) = 0; + + /** + * @brief Post event in the event queue. + * + * @param event Current event information. + * + * @return Code error. + **/ + virtual int ReceiveEventFromDevice(const TransportAdapterEvent& event) = 0; + + /** + * @brief Add transport adapter. + * + * @param transport_adapter Transport adapter + * + * @return Error code. + **/ + virtual int AddTransportAdapter( + transport_adapter::TransportAdapter* transport_adapter) = 0; + + /** + * @brief Post listener to the container of transport manager listeners. + * + * @param listener Pointer to the transport manager listener. + * + * @return Code error. + **/ + virtual int AddEventListener(TransportManagerListener* listener) = 0; + + /** + * @brief Stop work finally. No new events guaranteed after method finish. + * + * @return Error code. + **/ + virtual int Stop() = 0; + + /** + * @brief Remove device from the container that hold devices. + * + * @param device Handle of device. + * + * @return Code error. + **/ + virtual int RemoveDevice(const DeviceHandle& device_handle) = 0; + + /** + * @brief Turns on or off visibility of SDL to mobile devices + * when visibility is ON (on_off = true) mobile devices are able to connect + * otherwise ((on_off = false)) SDL is not visible from outside + * + * @return Code error. + */ + virtual int Visibility(const bool& on_off) const = 0; +}; +} // namespace transport_manager +#endif // SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_H_ diff --git a/src/components/include/transport_manager/transport_manager_listener.h b/src/components/include/transport_manager/transport_manager_listener.h new file mode 100644 index 0000000000..c36c0cb2f1 --- /dev/null +++ b/src/components/include/transport_manager/transport_manager_listener.h @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2014, 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_TRANSPORT_MANAGER_TRANSPORT_MANAGER_LISTENER_H_ +#define SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_LISTENER_H_ + +#include <vector> +#include "transport_manager/common.h" +#include "transport_manager/info.h" +#include "transport_manager/error.h" +#include "protocol/common.h" + +namespace transport_manager { + +class TransportManagerListener { + public: + /** + * @brief Destructor. + */ + virtual ~TransportManagerListener() { + } + + /** + * @brief Reaction to the event, when the list of devices is updated. + * + * @param Container that holds information about devices. + */ + virtual void OnDeviceListUpdated(const std::vector<DeviceInfo>&) = 0; + + /** + * @brief Reaction to "Find new applications" request + */ + virtual void OnFindNewApplicationsRequest() = 0; + + /** + * @brief Reaction to the event, when the device is found. + * + * @param device_info Variable that hold information about device. + */ + virtual void OnDeviceFound(const DeviceInfo& device_info) = 0; + virtual void OnDeviceAdded(const DeviceInfo& device_info) = 0; + virtual void OnDeviceRemoved(const DeviceInfo& device_info) = 0; + + /** + * @brief Reaction to the event, when scanning of devices is finished. + */ + virtual void OnScanDevicesFinished() = 0; + + /** + * @brief Reaction to the event, when scanning of devices is failed. + * + * @param error Error information about possible reason of scanning of devices failure. + */ + virtual void OnScanDevicesFailed(const SearchDeviceError& error) = 0; + + /** + * @brief Reaction to the event, when connection is established. + * + * @param devcie_info Variable that hold information about device. + * @param connection_id connection unique identifier. + */ + virtual void OnConnectionEstablished(const DeviceInfo& device_info, + const ConnectionUID& connection_id) = 0; + + /** + * @brief Reaction to the event, when connection to the device is failed. + * + * @param device_info Variable that hold information about device. + * @param error Error information about possible reason of connect failure. + */ + virtual void OnConnectionFailed(const DeviceInfo& device_info, + const ConnectError& error) = 0; + + /** + * @brief Reaction to the event, when connection is closed. + * + * @param connection_id Connection unique identifier. + */ + virtual void OnConnectionClosed(ConnectionUID connection_id) = 0; + + /** + * @brief Called when connection is closed unexpectedly, i.e. disconnect was not requested + * + * @param connection_id Connection ID. + * @param error Error information. + */ + virtual void OnUnexpectedDisconnect(ConnectionUID connection_id, + const CommunicationError& error) = 0; + + /** + * @brief Reaction to the event, when connection close is failed. + * + * @param connection_id Connection unique identifier. + * @param error Error information about possible reason of failure. + */ + virtual void OnConnectionClosedFailure(ConnectionUID connection_id, + const DisconnectError& error) = 0; + + /** + * \brief Inform about losing connection with device. + * \param device Handle of device. + * \param error Error information about possible reason of loosing connection. + */ + virtual void OnDeviceConnectionLost(const DeviceHandle& device, + const DisconnectDeviceError& error) = 0; + + /** + * \brief Inform about failure during DisconnectDevice procedure of transport manager. + * \param device Handle of device. + * \param error Error information about possible reason of disconnecting failure. + */ + virtual void OnDisconnectFailed(const DeviceHandle& device, + const DisconnectDeviceError& error) = 0; + /** + * @brief Notifies about recieving message from TM. + * + * @param message Recieved message + **/ + virtual void OnTMMessageReceived(const RawMessagePtr message) = 0; + + /** + * @brief Reaction to the event, when receiving of massage for transport manager is failed. + * + * @param connection_id connection unique identifier. + * @param error Error information about possible reason of failure. + */ + virtual void OnTMMessageReceiveFailed(ConnectionUID connection_id, + const DataReceiveError& error) = 0; + + /** + * @brief Reaction to the event, when transport manager sent a massage. + */ + virtual void OnTMMessageSend(const RawMessagePtr message) = 0; + + /** + * @brief Reaction to the event, when sending of massage by transport manager is failed. + * + * @param error Error information about possible reason of failure. + * @param message Smart pointer to the raw massage. + */ + virtual void OnTMMessageSendFailed(const DataSendError& error, + const RawMessagePtr message) = 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 new file mode 100644 index 0000000000..2b3149bb54 --- /dev/null +++ b/src/components/include/transport_manager/transport_manager_listener_empty.h @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2014, 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_TRANSPORT_MANAGER_TRANSPORT_MANAGER_LISTENER_EMPTY_H_ +#define SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_LISTENER_EMPTY_H_ + +#include <vector> + +#include "transport_manager/transport_manager_listener.h" +#include "protocol/common.h" + +namespace transport_manager { + +/** + * @brief Empty implementation class for transport manager listener. + */ +class TransportManagerListenerEmpty : public TransportManagerListener { + public: + /** + * @Destructor. + */ + virtual ~TransportManagerListenerEmpty() {} + + /** + * @brief Reaction to the event, when the list of devices is updated. + * + * @param Container that holds information about devices. + */ + virtual void OnDeviceListUpdated(const std::vector<DeviceInfo>&) { + } + + virtual void OnFindNewApplicationsRequest() { + } + + /** + * @brief Reaction to the event, when the device is found. + * + * @param device_info Variable that hold information about device. + */ + virtual void OnDeviceFound(const DeviceInfo& device_info) { + } + virtual void OnDeviceAdded(const DeviceInfo& device_info) { + } + virtual void OnDeviceRemoved(const DeviceInfo& device_info) { + } + + /** + * @brief Reaction to the event, when scanning of devices is finished. + */ + virtual void OnScanDevicesFinished() { + } + + /** + * @brief Reaction to the event, when scanning of devices is failed. + * + * @param error Error information about possible reason of scanning of devices failure. + */ + virtual void OnScanDevicesFailed(const SearchDeviceError& error) { + } + + /** + * @brief Reaction to the event, when connection is established. + * + * @param devcie_info Variable that hold information about device. + * @param connection_id connection unique identifier. + */ + virtual void OnConnectionEstablished(const DeviceInfo& device_info, + const ConnectionUID& connection_id) { + } + + /** + * @brief Reaction to the event, when connection to the device is failed. + * + * @param device_info Variable that hold information about device. + * @param error Error information about possible reason of connect failure. + */ + virtual void OnConnectionFailed(const DeviceInfo& device_info, + const ConnectError& error) { + } + + /** + * @brief Reaction to the event, when connection is closed. + * + * @param connection_id Connection unique identifier. + */ + virtual void OnConnectionClosed(ConnectionUID connection_id) { + } + + virtual void OnUnexpectedDisconnect(ConnectionUID connection_id, + const CommunicationError& error) { + } + + /** + * @brief Reaction to the event, when connection close is failed. + * + * @param connection_id Connection unique identifier. + * @param error Error information about possible reason of failure. + */ + virtual void OnConnectionClosedFailure(ConnectionUID connection_id, + const DisconnectError& error) { + } + + /** + * @brief Reaction to the event, when connection with the device is lost. + * + * @param device Handle of device. + * @param error Error information about possible reason of lost connection. + */ + virtual void OnDeviceConnectionLost(const DeviceHandle& device, + const DisconnectDeviceError& error) { + } + + /** + * @brief Reaction to the event, when Disconnect is failed. + * + * @param device Handle of device. + * @param error Error information about possible reason of Disconnect failure. + */ + virtual void OnDisconnectFailed(const DeviceHandle& device, + const DisconnectDeviceError& error) { + } + + /** + * @brief Reaction to the event, when transport manager received a massage. + * + * @param message Smart pointer to the raw massage. + * @param connection_id Connection unique identifier. + */ + virtual void OnTMMessageReceived(const RawMessagePtr message) { + } + + /** + * @brief Reaction to the event, when receiving of massage for transport manager is failed. + * + * @param connection_id connection unique identifier. + * @param error Error information about possible reason of failure. + */ + virtual void OnTMMessageReceiveFailed(ConnectionUID connection_id, + const DataReceiveError& error) { + } + + /** + * @brief Reaction to the event, when transport manager sent a massage. + */ + virtual void OnTMMessageSend(const RawMessagePtr message) { + } + + /** + * @brief Reaction to the event, when sending of massage by transport manager is failed. + * + * @param error Error information about possible reason of failure. + * @param message Smart pointer to the raw massage. + */ + virtual void OnTMMessageSendFailed(const DataSendError& error, + const RawMessagePtr message) { + } +}; +} // namespace transport_manager +#endif // SRC_COMPONENTS_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_MANAGER_LISTENER_EMPTY_H_ |