Initialize Tizen 2.3
[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, const char* pMacAddress, void* pUserData);
277         /**
278          * Called when IP address of client is assigned when your device is group owner.
279          *
280          * @param[in]   errorCode       Any Error occured during connection process
281          * @param[in]   connectionState Connection status
282          * @param[in]   pMacAddress     Mac Address
283          * @param[in]   pUserData       The user data passed from the callback registration function
284          */
285         static void OnWifiDirectClientIpAssigned(const char* mac_address, const char* ip_address, const char* interface_address, void* user_data);
286
287         /**
288      * Call back for each discovered device
289      *
290      * @param[in]   pPeer       Device Information
291      * @param[in]   pUserData   The user data passed from the callback registration function
292      */
293     static bool OnWifiDirectPeerFound(wifi_direct_discovered_peer_info_s* pPeer, void* pUserData);
294
295         /**
296          * Call back for each Discovered device
297          *
298          * @param[in]   pPeer       Device Information
299          * @param[in]   pUserData   The user data passed from the callback registration function
300          */
301         static bool OnWifiDirectEachDiscoveredPeer(wifi_direct_discovered_peer_info_s* pPeer, void* pUserData);
302
303         /**
304          * Call back for each connected device
305          *
306          * @param[in]   pPeer       Device Information
307          * @param[in]   pUserData   The user data passed from the callback registration function
308          */
309         static bool OnWifiDirectEachConnectedClient(wifi_direct_connected_peer_info_s* pPeer, void* pUserData);
310
311         /**
312          * Call back for connected owner
313          *
314          * @param[in]   pPeer       Device Information
315          * @param[in]   pUserData   The user data passed from the callback registration function
316          */
317         static bool OnWifiDirectConnectedOwner(wifi_direct_connected_peer_info_s* pPeer, void* pUserData);
318
319         /**
320          * Call back for each discovered device, for searching same device for create group
321          *
322          * @param[in]   pPeer       Device Information
323          * @param[in]   pUserData   The user data passed from the callback registration function
324          */
325         static bool OnWifiDirectFindSameDeviceName(wifi_direct_discovered_peer_info_s* pPeer, void* pUserData);
326
327         /**
328          * Call back for each supported WPS mode
329          *
330          * @param[in]   type        WPS mode type
331          * @param[in]   pUserData   The user data passed from the callback registration function
332          */
333         static bool OnWifiDirectSupportedWpsMode(wifi_direct_wps_type_e type, void* pUserData);
334
335         /**
336          * Adds Listner
337          *
338          * @param[in]   listner     object of _WifiDirectDeviceImpl
339          */
340         void AddListener(const _WifiDirectDeviceImpl& listner);
341
342         /**
343          * Removes Listner
344          *
345          * @param[in]   listner     object of _WifiDirectDeviceImpl
346          */
347         void RemoveListener(const _WifiDirectDeviceImpl& listner);
348
349         /**
350          * Called to notify the application with the result and related information for a request of group creation or group creation
351          * cancellation.
352          *
353          * @param[in]   peerMacAddress  The peer mac address
354          * @param[in]   r               An error code
355          */
356         void OnWifiDirectGroupCreated(const Tizen::Base::String& peerMacAddress, result r);
357
358         /**
359          * Called to notify the application that the connection to a Wi-Fi Direct group owner is completely established.
360          *
361          * @param[in]   peerMacAddress  The peer mac address
362          * @param[in]   r               An error code
363          */
364         void OnWifiDirectAssociationCompleted(const Tizen::Base::String& peerMacAddress, result r);
365
366         /**
367          * Called to notify the application that a successful association has occurred with a client.
368          *
369          * @param[in]   peerMacAddress  The peer mac address
370          */
371         void OnWifiDirectClientAssociated(const Tizen::Base::String& peerMacAddress);
372
373         /**
374          * Called to notify the application that a disassociation has occurred with a client.
375          *
376          * @param[in]   peerMacAddress  The peer mac address
377          */
378         void OnWifiDirectClientDisassociated(const Tizen::Base::String& peerMacAddress);
379
380         /**
381          * Called to notify the application that a connection to a Wi-Fi Direct group owner has terminated.
382          *
383          * @param[in]   reason  The reason of association termination
384          * @param[in]   r       An error code
385          */
386         void OnWifiDirectAssociationTerminated(WifiDirectAssociationTerminationReason reason, result r);
387
388         /**
389          * Called to notify the application that the Wi-Fi Direct group is destroyed.
390          *
391          * @param[in]   r   An error code
392          */
393         void OnWifiDirectGroupDestroyed(result r);
394
395         /**
396          * Called to notify the application that Wi-Fi Direct connection has been established with the remove device.
397          *
398          * @param[in]   peerMacAddress  The peer mac address
399          * @param[in]   r               An error code
400          */
401         void OnWifiDirectConnected(const Tizen::Base::String& peerMacAddress, result r);
402
403         /**
404          * Called to notify the application that the Wi-Fi Direct connection has been disconnected with peer device.
405          *
406          * @param[in]   peerMacAddress  The peer mac address
407          */
408         void OnWifiDirectDisconnected(const Tizen::Base::String& peerMacAddress, result r);
409
410         /**
411          * Called to notify the application that an autonomous group is created.
412          *
413          * @param[in]   r   An error code
414          */
415         void OnWifiDirectAutonomousGroupCreated(result r);
416
417         /**
418          * Called to notify the application that the local device is left from the group.
419          *
420          * @param[in]   r   An error code
421          */
422         void OnWifiDirectGroupLeft(result r);
423
424 private:
425         /**
426          * This default constructor is intentionally declared as private to implement the Singleton semantic.
427          *
428          */
429         _WifiDirectSystemAdapter(void);
430
431         /**
432          * This destructor is intentionally declared as private to implement the Singleton semantic.
433          *
434          */
435         virtual ~_WifiDirectSystemAdapter(void);
436
437         /**
438          * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
439          */
440         _WifiDirectSystemAdapter(const _WifiDirectSystemAdapter& value);
441
442         /**
443          * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
444          */
445         _WifiDirectSystemAdapter& operator =(const _WifiDirectSystemAdapter& rhs);
446
447         /**
448          * Initializes this instance of _WifiDirectSystemAdapter.
449          */
450         bool Construct(void);
451
452         /**
453          * Adds connected peer to the end of the list.
454          *
455          * @param[in]   pPeerInfo  The peer device information
456          */
457         result AddPeerInfo(WifiDirectDeviceInfo* pPeerInfo);
458
459         /**
460          * Removes disconnected peer.
461          *
462          * @param[in]   pClientInfo  Device Information
463          */
464         result RemovePeerInfo(WifiDirectDeviceInfo* pPeerInfo);
465
466         /**
467          * Returns device information matching with mac address
468          *
469          * @param[in]   macAddress  mac address string to search in the list
470          */
471         WifiDirectDeviceInfo* GetPeerInfo(const Tizen::Base::String& macAddress);
472
473         /**
474          * Returns char buffer of device state
475          *
476          * @return   char buffer of device state
477          */
478         const char* GetStringOfDeviceState(void) const;
479
480         /**
481          * Returns char buffer of scan state
482          *
483          * @return   char buffer of scan state
484          */
485         const char* GetStringOfScanState(void) const;
486
487         /**
488          * Returns String of all status
489          *
490          * @return   String of all status
491          */
492         Tizen::Base::String GetStringOfAllCurrentState(void) const;
493
494         /**
495          * Initializes current state of Wi-Fi Direct
496          *
497          * @return   An error code
498          */
499         result InitializeCurrentState(void);
500
501         /**
502          * Starts listen mode
503          *
504          * @return   An error code
505          */
506         result StartListenMode(void);
507
508         /**
509          * Stops listen mode
510          *
511          * @return   An error code
512          */
513         result StopListenModeToScan(void);
514
515         /**
516          * Starts discovery
517          *
518          * @return   An error code
519          */
520         result StartDiscovery(void);
521
522         /**
523          * Cancels discovery
524          *
525          * @return   An error code
526          */
527         result CancelDiscovery(void);
528
529         /**
530          * Initializes the _WifiDirectSystemAdapter singletone instance.
531          *
532          * @exception   E_SUCCESS           The initialization was successful.
533          * @exception   E_SYSTEM            A system error occurred.
534          * @exception   E_OUT_OF_MEMORY     The memory is insufficient.
535          */
536         static void InitSingleton(void);
537
538         /**
539          * Destorys instance of singleton class.
540          */
541         static void DestroySingleton(void);
542
543         /**
544          * Gets the connected peer device info.
545          */
546         WifiDirectDeviceInfo* GetConnectedPeerDeviceInfoN(WifiDirectGroupMemberType peerMemberType, const Tizen::Base::String* pPeerMacAddress = null) const;
547
548         /**
549          * Gets the list of connected peer device info.
550          */
551         Tizen::Base::Collection::IList* GetConnectedPeerDeviceInfoListN(WifiDirectGroupMemberType currentMemberType) const;
552
553
554
555 private:
556         static _WifiDirectSystemAdapter* __pWifiDirectSystemAdapter;
557         std::unique_ptr< _WifiDirectEvent, _WifiDirectEventDeleter > __pWifiDirectEvent;
558
559         Tizen::Base::String __remoteMacAddress;
560         Tizen::Base::String __remoteDeviceName;
561         Tizen::Base::Collection::IList* __pScanResult;
562         _WifiDirectSystemState __currentState;
563         _WifiDirectSystemScanState __currentScanState;
564         Tizen::Base::Collection::ArrayList __connectedPeerList;
565         Tizen::Base::Collection::ArrayList __discoveredPeerList;
566         _WifiIpcProxy* __pWifiServiceProxy;
567         std::unique_ptr< char[] >__pConnectionRequestMac;
568
569         friend class std::default_delete< _WifiDirectSystemAdapter >;
570 };
571 } } } // Tizen::Net::Wifi
572
573
574 #endif // _FNET_WIFI_INTERNAL_WIFI_DIRECT_SYSTEM_ADAPTER_H_