merge with master
[framework/osp/net.git] / src / wifi / FNetWifi_WifiDirectSystemAdapter.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file    FNetWifi_WifiDirectSystemAdapter.h
20  * @brief   This is the header file for the WifiDirectSystemAdapter class.
21  * @version 2.1
22  *
23  * This header file contains declarations of the WifiDirectSystemAdapter class.
24  */
25
26 #ifndef _FNET_WIFI_INTERNAL_WIFI_DIRECT_SYSTEM_ADAPTER_H_
27 #define _FNET_WIFI_INTERNAL_WIFI_DIRECT_SYSTEM_ADAPTER_H_
28
29 #include <unique_ptr.h>
30 #include <wifi-direct.h>
31 #include <FBaseObject.h>
32 #include <FNetWifiWifiTypes.h>
33
34
35 namespace Tizen { namespace Base { namespace Collection
36 {
37 class IList;
38 } } } // Tizen::Base::Collection
39
40 namespace Tizen { namespace Net { namespace Wifi
41 {
42 class WifiDirectGroupInfo;
43 class WifiDirectDeviceInfo;
44 class WifiDirectGroupMember;
45 class _WifiDirectEvent;
46 class _WifiDirectDeviceImpl;
47 class _WifiIpcProxy;
48
49     enum _WifiDirectSystemState
50     {
51         WIFI_DIRECT_SYSTEM_DEACTIVATED,
52         WIFI_DIRECT_SYSTEM_ACTIVATING,
53         WIFI_DIRECT_SYSTEM_DEACTIVATING,
54         WIFI_DIRECT_SYSTEM_ACTIVATED,
55         WIFI_DIRECT_SYSTEM_AUTONOMOUS_GROUP_CREATING,
56         WIFI_DIRECT_SYSTEM_GROUP_CREATING,
57         WIFI_DIRECT_SYSTEM_GROUP_CANCELING,
58         WIFI_DIRECT_SYSTEM_CONNECTING,
59         WIFI_DIRECT_SYSTEM_CONNECT_CANCELLING,
60         WIFI_DIRECT_SYSTEM_ASSOCIATING,
61         WIFI_DIRECT_SYSTEM_OWNER,
62         WIFI_DIRECT_SYSTEM_DESTROYING,
63         WIFI_DIRECT_SYSTEM_LEAVING,
64         WIFI_DIRECT_SYSTEM_CLIENT,
65         WIFI_DIRECT_SYSTEM_DISCONNECTING
66     };
67
68     enum _WifiDirectSystemScanState
69     {
70         WIFI_DIRECT_SYSTEM_SCAN_IDLE,
71         WIFI_DIRECT_SYSTEM_SCAN_LISTEN,
72         WIFI_DIRECT_SYSTEM_SCAN_LISTEN_CANCELING_TO_SCAN,
73         WIFI_DIRECT_SYSTEM_SCAN_SCANNING,
74         WIFI_DIRECT_SYSTEM_SCAN_CANCELLING
75      };
76
77 class _WifiDirectSystemAdapter
78     : public Tizen::Base::Object
79 {
80 public:
81     struct _WifiDirectEventDeleter
82     {
83         template <typename Obj>
84         void operator()(Obj* object)
85         {
86             delete object;
87             wifi_direct_unset_connection_state_changed_cb();
88             wifi_direct_unset_discovery_state_changed_cb();
89             wifi_direct_unset_connection_state_changed_cb();
90         }
91     };
92
93     /**
94      * Gets the instance.
95      *
96      * @return  The pointer to %_WifiDirectSystemAdapter
97      */
98     static _WifiDirectSystemAdapter* GetInstance(void);
99
100     /**
101      * Gets the All Device Info List.
102      *
103      * @return  The pointer to List containing all device info
104      */
105     Tizen::Base::Collection::IList* GetAllDeviceInfoN(void);
106
107     /**
108      * @see WifiDirectDevice::Activate()
109      */
110     result Activate(void);
111
112     /**
113      * @see WifiDirectDevice::Deactivate()
114      */
115     result Deactivate(void);
116     
117     /**
118      * @see WifiDirectDevice::GetGroupSettingInfoN()
119      */
120     WifiDirectGroupInfo* GetGroupSettingInfoN(void) const;
121     
122     /**
123      * @see WifiDirectDevice::GetLocalDeviceInfoN()
124      */    
125     WifiDirectDeviceInfo* GetLocalDeviceInfoN(void) const;
126
127     /**
128      * @see WifiDirectDevice::GetWpsConfigurationModePreference()
129      */
130     WifiWpsConfigurationMode GetWpsConfigurationModePreference(void) const;
131
132     /**
133      * @see WifiDirectDevice::SetLocalDeviceName()
134      */
135     result SetLocalDeviceName(const Tizen::Base::String &name);
136
137     /**
138      * @see WifiDirectDevice::SetWpsConfigurationModePreference()
139      */    
140     result SetWpsConfigurationModePreference(WifiWpsConfigurationMode mode);
141
142     /**
143      * @see WifiDirectDevice::CreateGroup()
144      */  
145     result CreateGroup(const WifiDirectGroupInfo *pWifiDirectGroupInfo = null, const WifiDirectDeviceInfo *pWifiDirectRemoteDeviceInfo = null);
146
147     /**
148      * @see WifiDirectDevice::CancelGroupCreation()
149      */      
150     result CancelGroupCreation(void);
151
152     /**
153      * @see WifiDirectDevice::Scan()
154      */  
155     result Scan(void);
156
157     /**
158      * @see WifiDirectDevice::CancelScan()
159      */  
160     result CancelScan(void);
161
162     /**
163      * @see WifiDirectDevice::Associate()
164      */  
165     result Associate(const WifiDirectDeviceInfo &wifiDirectGroupOwnerDeviceInfo);
166
167     /**
168      * @see WifiDirectDevice::GetWifiDirectMemberN()
169      */  
170     WifiDirectGroupMember* GetWifiDirectMemberN(void);
171
172     /**
173      * @see WifiDirectDevice::IsDiscoverable()
174      */  
175     bool IsDiscoverable(void) const;
176
177     /**
178      * @see WifiDirectDevice::IsActivated()
179      */
180     bool IsActivated(void) const;
181
182     /**
183      * @see WifiDirectDevice::Connect()
184      */
185     result Connect(const WifiDirectDeviceInfo& peerDeviceInfo);
186
187     /**
188      * @see WifiDirectDevice::CancelConnect()
189      */
190     result CancelConnect(void);
191
192     /**
193      * @see WifiDirectDevice::CreateAutonomousGroup()
194      */
195     result CreateAutonomousGroup(void);
196
197     /**
198      * @see WifiDirectDevice::SetGroupSettingInfo()
199      */
200     result SetGroupSettingInfo(const WifiDirectGroupInfo& groupSettingInfo);
201
202     /**
203      * @see WifiDirectDevice::Disconnect()
204      * @see WifiDirectGroupOwner::Disconnect()
205      */
206     result Disconnect(const WifiDirectDeviceInfo& remoteDeviceInfo);
207
208     /**
209      * @see WifiDirectDevice::LeaveGroup()
210      */
211     result LeaveGroup(void);
212
213     /**
214      * @see WifiDirectDevice::GetGroupOwnerInfo()
215      */
216     WifiDirectDeviceInfo* GetGroupOwnerInfoN(void) const;
217
218     /**
219      * @see WifiDirectDevice::GetGroupClientInfoListN()
220      */
221     Tizen::Base::Collection::IList* GetGroupClientInfoListN(void) const;
222
223     /**
224      * @see WifiDirectDevice::GetOperatingChannel()
225      */
226     WifiRadioChannel GetOperatingChannel(void) const;
227
228     /**
229      * @see WifiDirectGroupOwner::DestroyGroup()
230      */  
231     result DestroyGroup(void);
232     
233     /**
234      * @see WifiDirectGroupOwner::GetAllGroupMemberInfoImplListN()
235      */     
236     Tizen::Base::Collection::IList* GetAllGroupMemberInfoImplListN(void);
237
238     /**
239      * @see WifiDirectGroupClient::Disassociate()
240      */ 
241     result Disassociate(void);
242
243     /**
244      * Gets the type of the Wi-Fi Direct group member.
245      *
246      * @return The type of the Wi-Fi Direct group member
247      */
248     WifiDirectGroupMemberType GetCurrentMemberType(void) const;
249
250     /**
251      * Called when the state of device is changed.
252      *
253      * @param[in]   errorCode   Any Error occured on power change
254      * @param[in]   deviceState Device Status
255      * @param[in]   pUserData   The user data passed from the callback registration function
256      */
257     static void OnWifiDirectPowerChanged(int errorCode, wifi_direct_device_state_e deviceState, void* pUserData);
258
259     /**
260      * Called when the state of discovery is changed.
261      *
262      * @param[in]   errorCode       Any Error occured during scan process
263      * @param[in]   discoveryState  Discovery status
264      * @param[in]   pUserData       The user data passed from the callback registration function
265      */
266     static void OnWifiDirectScanCompleted(int errorCode, wifi_direct_discovery_state_e discoveryState, void* pUserData);
267
268     /**
269      * Called when the state of connection is changed.
270      *
271      * @param[in]   errorCode       Any Error occured during connection process
272      * @param[in]   connectionState Connection status
273      * @param[in]   pMacAddress     Mac Address
274      * @param[in]   pUserData       The user data passed from the callback registration function
275      */
276     static void OnWifiDirectConnectionChanged(int errorCode, wifi_direct_connection_state_e connectionState,
277                                                 const char* pMacAddress, void* pUserData);
278     /**
279      * Called when IP address of client is assigned when your device is group owner.
280      *
281      * @param[in]   errorCode       Any Error occured during connection process
282      * @param[in]   connectionState Connection status
283      * @param[in]   pMacAddress     Mac Address
284      * @param[in]   pUserData       The user data passed from the callback registration function
285      */
286     static void OnWifiDirectClientIpAssigned(const char *mac_address, const char *ip_address,
287                                              const char *interface_address, void *user_data);
288
289     /**
290      * Call back for each discovered device
291      *
292      * @param[in]   pPeer       Device Information
293      * @param[in]   pUserData   The user data passed from the callback registration function
294      */
295     static bool OnWifiDirectPeerFound(wifi_direct_discovered_peer_info_s* pPeer, void* pUserData);
296
297     /**
298      * Call back for each discovered device
299      *
300      * @param[in]   pPeer       Device Information
301      * @param[in]   pUserData   The user data passed from the callback registration function
302      */
303     static bool OnWifiDirectEachDiscoveredPeer(wifi_direct_discovered_peer_info_s* pPeer, void* pUserData);
304
305     /**
306      * Call back for each connected device
307      *
308      * @param[in]   pPeer       Device Information
309      * @param[in]   pUserData   The user data passed from the callback registration function
310      */
311     static bool OnWifiDirectEachConnectedClient(wifi_direct_connected_peer_info_s* pPeer, void* pUserData);
312     
313     /**
314      * Call back for connected owner
315      *
316      * @param[in]   pPeer       Device Information
317      * @param[in]   pUserData   The user data passed from the callback registration function
318      */
319     static bool OnWifiDirectConnectedOwner(wifi_direct_connected_peer_info_s* pPeer, void* pUserData);
320
321     /**
322      * Call back for each discovered device, for searching same device for create group
323      *
324      * @param[in]   pPeer       Device Information
325      * @param[in]   pUserData   The user data passed from the callback registration function
326      */
327     static bool OnWifiDirectFindSameDeviceName(wifi_direct_discovered_peer_info_s* pPeer, void* pUserData);
328
329     /**
330      * Call back for each supported WPS mode
331      *
332      * @param[in]   type        WPS mode type
333      * @param[in]   pUserData   The user data passed from the callback registration function
334      */    
335     static bool OnWifiDirectSupportedWpsMode(wifi_direct_wps_type_e type, void* pUserData);
336
337     /**
338      * Adds Listner
339      *
340      * @param[in]   listner     object of _WifiDirectDeviceImpl
341      */
342     void AddListener(const _WifiDirectDeviceImpl& listner);
343
344     /**
345      * Removes Listner
346      *
347      * @param[in]   listner     object of _WifiDirectDeviceImpl
348      */
349     void RemoveListener(const _WifiDirectDeviceImpl& listner);
350
351     /**
352      * Called to notify the application with the result and related information for a request of group creation or group creation
353      * cancellation.
354      *
355      * @param[in]   peerMacAddress  The peer mac address
356      * @param[in]   r               An error code
357      */
358     void OnWifiDirectGroupCreated(const Tizen::Base::String& peerMacAddress, result r);
359
360     /**
361      * Called to notify the application that the connection to a Wi-Fi Direct group owner is completely established.
362      *
363      * @param[in]   peerMacAddress  The peer mac address
364      * @param[in]   r               An error code
365      */
366     void OnWifiDirectAssociationCompleted(const Tizen::Base::String& peerMacAddress, result r);
367
368     /**
369      * Called to notify the application that a successful association has occurred with a client.
370      *
371      * @param[in]   peerMacAddress  The peer mac address
372      */
373     void OnWifiDirectClientAssociated(const Tizen::Base::String& peerMacAddress);
374
375     /**
376      * Called to notify the application that a disassociation has occurred with a client.
377      *
378      * @param[in]   peerMacAddress  The peer mac address
379      */
380     void OnWifiDirectClientDisassociated(const Tizen::Base::String& peerMacAddress);
381
382     /**
383      * Called to notify the application that a connection to a Wi-Fi Direct group owner has terminated.
384      *
385      * @param[in]   reason  The reason of association termination
386      * @param[in]   r       An error code
387      */
388     void OnWifiDirectAssociationTerminated(WifiDirectAssociationTerminationReason reason, result r);
389
390     /**
391      * Called to notify the application that the Wi-Fi Direct group is destroyed.
392      *
393      * @param[in]   r   An error code
394      */
395     void OnWifiDirectGroupDestroyed(result r);
396
397     /**
398      * Called to notify the application that Wi-Fi Direct connection has been established with the remove device.
399      *
400      * @param[in]   peerMacAddress  The peer mac address
401      * @param[in]   r               An error code
402      */
403     void OnWifiDirectConnected(const Tizen::Base::String& peerMacAddress, result r);
404
405     /**
406      * Called to notify the application that the Wi-Fi Direct connection has been disconnected with peer device.
407      *
408      * @param[in]   peerMacAddress  The peer mac address
409      */
410     void OnWifiDirectDisconnected(const Tizen::Base::String& peerMacAddress, result r);
411
412     /**
413      * Called to notify the application that an autonomous group is created.
414      *
415      * @param[in]   r   An error code
416      */
417     void OnWifiDirectAutonomousGroupCreated(result r);
418
419     /**
420      * Called to notify the application that the local device is left from the group.
421      *
422      * @param[in]   r   An error code
423      */
424     void OnWifiDirectGroupLeft(result r);
425
426 private:
427     /**
428      * This default constructor is intentionally declared as private to implement the Singleton semantic.
429      *
430      */
431     _WifiDirectSystemAdapter(void);
432
433     /**
434      * This destructor is intentionally declared as private to implement the Singleton semantic.
435      *
436      */
437     virtual ~_WifiDirectSystemAdapter(void);
438
439     /**
440      * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
441      */
442     _WifiDirectSystemAdapter(const _WifiDirectSystemAdapter& value);
443
444     /**
445      * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
446      */
447     _WifiDirectSystemAdapter& operator =(const _WifiDirectSystemAdapter& rhs);
448
449     /**
450      * Initializes this instance of _WifiDirectSystemAdapter.
451      */
452     bool Construct(void);
453     
454     /**
455      * Adds connected peer to the end of the list.
456      *
457      * @param[in]   pPeerInfo  The peer device information
458      */
459     result AddPeerInfo(WifiDirectDeviceInfo* pPeerInfo);
460
461     /**
462      * Removes disconnected peer.
463      *
464      * @param[in]   pClientInfo  Device Information
465      */
466     result RemovePeerInfo(WifiDirectDeviceInfo* pPeerInfo);
467
468     /**
469      * Returns device information matching with mac address
470      *
471      * @param[in]   macAddress  mac address string to search in the list
472      */
473     WifiDirectDeviceInfo* GetPeerInfo(const Tizen::Base::String& macAddress);
474
475     /**
476      * Returns char buffer of device state
477      *
478      * @return   char buffer of device state
479      */
480     const char* GetStringOfDeviceState(void) const;
481
482     /**
483      * Returns char buffer of scan state
484      *
485      * @return   char buffer of scan state
486      */  
487     const char* GetStringOfScanState(void) const;
488
489     /**
490      * Returns String of all status
491      *
492      * @return   String of all status
493      */      
494     Tizen::Base::String GetStringOfAllCurrentState(void) const;
495     
496     /**
497      * Initializes current state of Wi-Fi Direct
498      *
499      * @return   An error code
500      */
501     result InitializeCurrentState(void);
502
503     /**
504      * Starts listen mode
505      *
506      * @return   An error code
507      */
508     result StartListenMode(void);
509
510     /**
511      * Stops listen mode
512      *
513      * @return   An error code
514      */
515     result StopListenModeToScan(void);
516
517     /**
518      * Starts discovery
519      *
520      * @return   An error code
521      */
522     result StartDiscovery(void);
523
524     /**
525      * Cancels discovery
526      *
527      * @return   An error code
528      */
529     result CancelDiscovery(void);
530
531     /**
532      * Initializes the _WifiDirectSystemAdapter singletone instance.
533      *
534      * @exception   E_SUCCESS           The initialization was successful.
535      * @exception   E_SYSTEM            A system error occurred.
536      * @exception   E_OUT_OF_MEMORY     The memory is insufficient.     
537      */
538     static void InitSingleton(void);
539
540     /**
541      * Destorys instance of singleton class.
542      */
543     static void DestroySingleton(void);
544     
545     /**
546      * Gets the connected peer device info.
547      */
548     WifiDirectDeviceInfo* GetConnectedPeerDeviceInfoN(WifiDirectGroupMemberType peerMemberType, const Tizen::Base::String* pPeerMacAddress = null) const;
549
550
551
552 private:
553     static _WifiDirectSystemAdapter* __pWifiDirectSystemAdapter;
554     std::unique_ptr<_WifiDirectEvent,_WifiDirectEventDeleter> __pWifiDirectEvent;
555
556     Tizen::Base::String __remoteMacAddress;
557     Tizen::Base::String __remoteDeviceName;
558     Tizen::Base::Collection::IList* __pScanResult;
559     _WifiDirectSystemState __currentState;
560     _WifiDirectSystemScanState __currentScanState;
561     Tizen::Base::Collection::ArrayList __connectedPeerList;
562     Tizen::Base::Collection::ArrayList __discoveredPeerList;
563     _WifiIpcProxy* __pWifiServiceProxy;
564     friend class std::default_delete<_WifiDirectSystemAdapter>;
565 };
566 } } } // Tizen::Net::Wifi
567
568
569 #endif // _FNET_WIFI_INTERNAL_WIFI_DIRECT_SYSTEM_ADAPTER_H_