|
| 1 | +/* |
| 2 | + * \file Usbmuxd_client_listener.h |
| 3 | + * \brief UsbmuxdClientListener class header file. |
| 4 | + * |
| 5 | + * Copyright (c) 2013, Ford Motor Company |
| 6 | + * All rights reserved. |
| 7 | + * |
| 8 | + * Redistribution and use in source and binary forms, with or without |
| 9 | + * modification, are permitted provided that the following conditions are met: |
| 10 | + * |
| 11 | + * Redistributions of source code must retain the above copyright notice, this |
| 12 | + * list of conditions and the following disclaimer. |
| 13 | + * |
| 14 | + * Redistributions in binary form must reproduce the above copyright notice, |
| 15 | + * this list of conditions and the following |
| 16 | + * disclaimer in the documentation and/or other materials provided with the |
| 17 | + * distribution. |
| 18 | + * |
| 19 | + * Neither the name of the Ford Motor Company nor the names of its contributors |
| 20 | + * may be used to endorse or promote products derived from this software |
| 21 | + * without specific prior written permission. |
| 22 | + * |
| 23 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 24 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 25 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 26 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 27 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 28 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 29 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 30 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 31 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 32 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 33 | + * POSSIBILITY OF SUCH DAMAGE. |
| 34 | + */ |
| 35 | + |
| 36 | +#ifndef SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_USBMUXD_USBMUXD_CLIENT_LISTENER_H_ |
| 37 | +#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_USBMUXD_USBMUXD_CLIENT_LISTENER_H_ |
| 38 | + |
| 39 | +#include "utils/threads/thread_delegate.h" |
| 40 | +#include "transport_manager/transport_adapter/client_connection_listener.h" |
| 41 | + |
| 42 | +class Thread; |
| 43 | + |
| 44 | +namespace transport_manager { |
| 45 | +namespace transport_adapter { |
| 46 | + |
| 47 | +class TransportAdapterController; |
| 48 | + |
| 49 | +/** |
| 50 | + * @brief Listener of device adapter that use Usbmuxd transport. |
| 51 | + */ |
| 52 | +class UsbmuxdClientListener : public ClientConnectionListener { |
| 53 | + public: |
| 54 | + /** |
| 55 | + * @breaf Constructor. |
| 56 | + * |
| 57 | + * @param controller Pointer to the device adapter controller. |
| 58 | + * @param port Port No. |
| 59 | + * @param enable_keepalive If true enables Usbmuxd keepalive on accepted |
| 60 | + *connections |
| 61 | + */ |
| 62 | + UsbmuxdClientListener(TransportAdapterController* controller, |
| 63 | + uint16_t port, |
| 64 | + bool enable_keepalive); |
| 65 | + |
| 66 | + /** |
| 67 | + * @brief Destructor. |
| 68 | + */ |
| 69 | + virtual ~UsbmuxdClientListener(); |
| 70 | + |
| 71 | + /** |
| 72 | + * @brief Run Usbmuxd client listener. |
| 73 | + * |
| 74 | + * @return Error information about possible reason of starting Usbmuxd listener |
| 75 | + *listener failure. |
| 76 | + */ |
| 77 | + virtual TransportAdapter::Error Init(); |
| 78 | + |
| 79 | + /** |
| 80 | + * @brief Stop Usbmuxd client listener. |
| 81 | + */ |
| 82 | + virtual void Terminate(); |
| 83 | + |
| 84 | + /** |
| 85 | + * @brief Check initialization. |
| 86 | + * |
| 87 | + * @return True if initialized. |
| 88 | + * @return False if not initialized. |
| 89 | + */ |
| 90 | + virtual bool IsInitialised() const; |
| 91 | + |
| 92 | + /** |
| 93 | + * @brief |
| 94 | + * |
| 95 | + * @return Error information about possible reason of failure. |
| 96 | + */ |
| 97 | + virtual TransportAdapter::Error StartListening(); |
| 98 | + |
| 99 | + /** |
| 100 | + * @brief Terminate Usbmuxd client listener thread. |
| 101 | + */ |
| 102 | + virtual TransportAdapter::Error StopListening(); |
| 103 | + |
| 104 | +#ifdef BUILD_TESTS |
| 105 | + uint16_t port() const { |
| 106 | + return port_; |
| 107 | + } |
| 108 | + |
| 109 | + int get_socket() const { |
| 110 | + return socket_; |
| 111 | + } |
| 112 | + |
| 113 | + threads::Thread* thread() const { |
| 114 | + return thread_; |
| 115 | + } |
| 116 | +#endif // BUILD_TESTS |
| 117 | + |
| 118 | + private: |
| 119 | + const uint16_t port_; |
| 120 | + const bool enable_keepalive_; |
| 121 | + TransportAdapterController* controller_; |
| 122 | + threads::Thread* thread_; |
| 123 | + int socket_; |
| 124 | + bool thread_stop_requested_; |
| 125 | + |
| 126 | + void Loop(); |
| 127 | + void StopLoop(); |
| 128 | + |
| 129 | + class ListeningThreadDelegate : public threads::ThreadDelegate { |
| 130 | + public: |
| 131 | + explicit ListeningThreadDelegate(UsbmuxdClientListener* parent); |
| 132 | + virtual void threadMain(); |
| 133 | + void exitThreadMain(); |
| 134 | + |
| 135 | + private: |
| 136 | + UsbmuxdClientListener* parent_; |
| 137 | + }; |
| 138 | +}; |
| 139 | + |
| 140 | +} // namespace transport_adapter |
| 141 | +} // namespace transport_manager |
| 142 | + |
| 143 | +#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_Usbmuxd_Usbmuxd_CLIENT_LISTENER_H_ |
0 commit comments