transport_manager
[profile/ivi/smartdevicelink.git] / src / components / transport_manager / include / transport_manager / transport_adapter / transport_adapter_listener_impl.h
1 /**
2  * \file transport_adapter_listener_impl.h
3  * \brief TransportAdapterListenerImpl 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_TRANSPORT_ADAPTER_TRANSPORT_ADAPTER_LISTENER_IMPL_H_
37 #define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_TRANSPORT_ADAPTER_LISTENER_IMPL_H_
38
39 #include "transport_manager/common.h"
40 #include "transport_manager/transport_adapter/transport_adapter_listener.h"
41 #include "transport_manager/transport_adapter/transport_adapter.h"
42
43 using transport_manager::transport_adapter::TransportAdapter;
44
45 namespace transport_manager {
46
47 class TransportManagerImpl;
48
49 /**
50  * @brief Implementation of TransportAdapterListener class.
51  */
52 class TransportAdapterListenerImpl
53     : public transport_adapter::TransportAdapterListener {
54  public:
55   /**
56    * @enum Available types of events.
57    */
58   enum EventTypeEnum {
59     ON_SEARCH_DONE = 0,
60     ON_SEARCH_FAIL,
61     ON_DEVICE_LIST_UPDATED,
62     ON_APPLICATION_LIST_UPDATED,
63     ON_CONNECT_DONE,
64     ON_CONNECT_FAIL,
65     ON_DISCONNECT_DONE,
66     ON_DISCONNECT_FAIL,
67     ON_SEND_DONE,
68     ON_SEND_FAIL,
69     ON_RECEIVED_DONE,
70     ON_RECEIVED_FAIL,
71     ON_COMMUNICATION_ERROR,
72     ON_UNEXPECTED_DISCONNECT
73   };
74
75   /**
76    * @brief Constructor.
77    *
78    * @param manager Pointer to the transport manager implementation class.
79    * @param adapter Pointer to the transport adapter associated with listener.
80    */
81   TransportAdapterListenerImpl(TransportManagerImpl* manager,
82                                TransportAdapter* adapter);
83
84   /**
85    * @brief Dectructor.
86    */
87   virtual ~TransportAdapterListenerImpl();
88
89   /**
90    * @brief Search specified device adapter in the container of shared pointers
91    *to device adapters to be sure it is available,
92    * launch event ON_SEARCH_DONE in transport manager.
93    *
94    * @param adapter Pointer to the device adapter.
95    */
96   virtual void OnSearchDeviceDone(const TransportAdapter* adapter);
97
98   /**
99    * @brief Search specified device adapter in the container of shared pointers
100    *to device adapters to be sure it is available, create search device error,
101    * launch event ON_SEARCH_FAIL in transport manager.
102    *
103    * @param adapter Pointer to the device adapter.
104    * @param error Error class with information about possible reason of search
105    *device failure.
106    */
107   virtual void OnSearchDeviceFailed(const TransportAdapter* adapter,
108                                     const SearchDeviceError& error);
109
110   /**
111    * @brief Passes notification to TransportManagerImpl
112    *
113    * @param adapter Transport adapter that sent notification
114    */
115   virtual void OnDeviceListUpdated(const TransportAdapter* adapter);
116
117
118   /**
119    * @brief Reaction on event, when new applications are started on device
120    * and SDL found this application
121    *
122    * @param adapter Current transport adapter
123    * @param device_handle Unique ID of device with new application list
124    */
125
126   virtual void OnApplicationListUpdated(const TransportAdapter* adapter,
127                                         const DeviceUID& device_handle);
128
129   /**
130    * @brief Search specified device adapter in the container of shared pointers
131    *to device adapters to be sure it is available,
132    * launch event ON_CONNECT_DONE in transport manager.
133    *
134    * @param device_adater Pointer to the device adapter.
135    * @param device_handle Device unique identifier.
136    * @param app_id Handle of application.
137    */
138   virtual void OnConnectDone(const TransportAdapter* adapter,
139                              const DeviceUID& device_handle,
140                              const ApplicationHandle& app_id);
141
142   /**
143    * @brief Search specified device adapter in the container of shared pointers
144    *to device adapters to be sure it is available,
145    * launch event ON_CONNECT_FAIL in transport manager.
146    *
147    * @param adapter Pointer to the device adapter.
148    * @param device Device unique identifier.
149    * @param app_id Handle of application.
150    * @param error Error class with information about possible reason of connect
151    *failure.
152    */
153   virtual void OnConnectFailed(const TransportAdapter* adapter,
154                                const DeviceUID& device,
155                                const ApplicationHandle& app_id,
156                                const ConnectError& error);
157
158   /**
159    * @brief
160    *
161    * @param adapter Pointer to the device adapter.
162    * @param device_handle Device unique identifier.
163    * @param app_handle Handle of application.
164    */
165   virtual void OnConnectRequested(const TransportAdapter* adapter,
166                                   const DeviceUID& device_handle,
167                                   const ApplicationHandle& app_handle);
168
169   /**
170    * @brief Search specified device adapter in the container of shared pointers
171    *to device adapters to be sure it is available,
172    * launch event ON_UNEXPECTED_DISCONNECT in transport manager.
173    *
174    * @param adapter Pointer to the device adapter.
175    * @param device Device unique identifier.
176    * @param app_id Handle of application.
177    * @param error Error class with information about possible reason of
178    *unexpected Disconnect.
179    */
180   virtual void OnUnexpectedDisconnect(const TransportAdapter* adapter,
181                                       const DeviceUID& device,
182                                       const ApplicationHandle& app_id,
183                                       const CommunicationError& error);
184
185   /**
186    * @brief Search specified device adapter in the container of shared pointers
187    *to device adapters to be sure it is available,
188    * launch event ON_DISCONNECT_DONE in transport manager.
189    *
190    * @param adapter Pointer to the device adapter.
191    * @param devcie_id Device unique identifier.
192    * @param app_id Handle of application.
193    */
194   virtual void OnDisconnectDone(const TransportAdapter* adapter,
195                                 const DeviceUID& device_id,
196                                 const ApplicationHandle& app_id);
197
198   /**
199    * @brief Search specified device adapter in the container of shared pointers
200    *to device adapters to be sure it is available, create Disconnect error,
201    * launch event ON_DISCONNECT_FAIL in transport manager.
202    *
203    * @param adapter Pointer to the device adapter.
204    * @param device Device unique identifier.
205    * @param app_id Handle of application.
206    * @param error Error class with information about possible reason of
207    *Disconnect failure.
208    */
209   virtual void OnDisconnectFailed(const TransportAdapter* adapter,
210                                   const DeviceUID& device,
211                                   const ApplicationHandle& app_id,
212                                   const DisconnectError& error);
213
214   /**
215    * @brief
216    *
217    * @param adapter Pointer to the device adapter.
218    * @param devic Device unique identifier.
219    */
220   virtual void OnDisconnectDeviceDone(const TransportAdapter* adapter,
221                                       const DeviceUID& device);
222
223   /**
224    * @brief
225    *
226    * @param adapter Pointer to the device adapter.
227    * @param device Device unique identifier.
228    * @param error Error class with information about possible reason of
229    *Disconnect from device failure.
230    */
231   virtual void OnDisconnectDeviceFailed(const TransportAdapter* adapter,
232                                         const DeviceUID& device,
233                                         const DisconnectDeviceError& error);
234
235   /**
236    * @brief Search specified device adapter in the container of shared pointers
237    *to device adapters to be sure it is available, create error,
238    * launch event ON_RECEIVED_DONE in transport manager.
239    *
240    * @param adapter Pointer to the device adapter.
241    * @param devcie Device unique identifier.
242    * @param app_id Handle of application.
243    * @param data_container Smart pointer to the raw message.
244    */
245   virtual void OnDataReceiveDone(const TransportAdapter* adapter,
246                                  const DeviceUID& device,
247                                  const ApplicationHandle& app_id,
248                                  const RawMessageSptr data_container);
249
250   /**
251    * @brief Search specified device adapter in the container of shared pointers
252    *to device adapters to be sure it is available, create data receive error,
253    * launch event ON_RECEIVED_DONE in transport manager.
254    *
255    * @param adapter Pointer to the device adapter.
256    * @param device Device unique identifier.
257    * @param app_id Handle of application.
258    * @param error Error class with information about possible reason of data
259    *receive failure.
260    */
261   virtual void OnDataReceiveFailed(const TransportAdapter* adapter,
262                                    const DeviceUID& device,
263                                    const ApplicationHandle& app_id,
264                                    const DataReceiveError& error);
265
266   /**
267    * @brief Search specified device adapter in the container of shared pointers
268    *to device adapters to be sure it is available, create error,
269    * launch event ON_SEND_DONE in transport manager.
270    *
271    * @param adapter Pointer to the device adapter.
272    * @param device Device unique identifier.
273    * @param app_id Handle of application.
274    * @param data_container Smart pointer to the raw message.
275    */
276   virtual void OnDataSendDone(const TransportAdapter* adapter,
277                               const DeviceUID& device,
278                               const ApplicationHandle& app_id,
279                               const RawMessageSptr data_container);
280
281   /**
282    * @brief Search specified device adapter in the container of shared pointers
283    * to device adapters to be sure it is available, create data send error,
284    * launch event ON_SEND_FAIL in transport manager.
285    */
286   virtual void OnDataSendFailed(const TransportAdapter* adapter,
287                                 const DeviceUID& device,
288                                 const ApplicationHandle& app_id,
289                                 const RawMessageSptr data_container,
290                                 const DataSendError& error);
291
292   /**
293    * @brief Search specified device adapter in the container of shared pointers
294    *to device adapters to be sure it is available, create error,
295    * launch event ON_COMMUNICATION_ERROR in transport manager.
296    *
297    * @param adapter Pointer to the device adapter.
298    * @param device Device unique identifier.
299    * @param app_id Handle of application.
300    */
301   virtual void OnCommunicationError(const TransportAdapter* adapter,
302                                     const DeviceUID& device,
303                                     const ApplicationHandle& app_id);
304
305  private:
306   TransportManagerImpl* transport_manager_impl_;
307   TransportAdapter* transport_adapter_;
308 };
309 }  // namespace transport_manager
310
311 #endif  // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_transport_adapter_transport_adapter_LISTENER_IMPL_H