2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FNetWifi_WifiDirectSystemAdapter.h
20 * @brief This is the header file for the WifiDirectSystemAdapter class.
23 * This header file contains declarations of the WifiDirectSystemAdapter class.
26 #ifndef _FNET_WIFI_INTERNAL_WIFI_DIRECT_SYSTEM_ADAPTER_H_
27 #define _FNET_WIFI_INTERNAL_WIFI_DIRECT_SYSTEM_ADAPTER_H_
29 #include <unique_ptr.h>
30 #include <wifi-direct.h>
31 #include <FBaseObject.h>
32 #include <FNetWifiWifiTypes.h>
35 namespace Tizen { namespace Base { namespace Collection
38 } } } // Tizen::Base::Collection
40 namespace Tizen { namespace Net { namespace Wifi
42 class WifiDirectGroupInfo;
43 class WifiDirectDeviceInfo;
44 class WifiDirectGroupMember;
45 class _WifiDirectEvent;
46 class _WifiDirectDeviceImpl;
49 enum _WifiDirectSystemState
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
68 enum _WifiDirectSystemScanState
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
77 class _WifiDirectSystemAdapter
78 : public Tizen::Base::Object
81 struct _WifiDirectEventDeleter
83 template< typename Obj >
84 void operator ()(Obj* 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();
96 * @return The pointer to %_WifiDirectSystemAdapter
98 static _WifiDirectSystemAdapter* GetInstance(void);
101 * Gets the All Device Info List.
103 * @return The pointer to List containing all device info
105 Tizen::Base::Collection::IList* GetAllDeviceInfoN(void);
108 * @see WifiDirectDevice::Activate()
110 result Activate(void);
113 * @see WifiDirectDevice::Deactivate()
115 result Deactivate(void);
118 * @see WifiDirectDevice::GetGroupSettingInfoN()
120 WifiDirectGroupInfo* GetGroupSettingInfoN(void) const;
123 * @see WifiDirectDevice::GetLocalDeviceInfoN()
125 WifiDirectDeviceInfo* GetLocalDeviceInfoN(void) const;
128 * @see WifiDirectDevice::GetWpsConfigurationModePreference()
130 WifiWpsConfigurationMode GetWpsConfigurationModePreference(void) const;
133 * @see WifiDirectDevice::SetLocalDeviceName()
135 result SetLocalDeviceName(const Tizen::Base::String& name);
138 * @see WifiDirectDevice::SetWpsConfigurationModePreference()
140 result SetWpsConfigurationModePreference(WifiWpsConfigurationMode mode);
143 * @see WifiDirectDevice::CreateGroup()
145 result CreateGroup(const WifiDirectGroupInfo* pWifiDirectGroupInfo = null, const WifiDirectDeviceInfo* pWifiDirectRemoteDeviceInfo = null);
148 * @see WifiDirectDevice::CancelGroupCreation()
150 result CancelGroupCreation(void);
153 * @see WifiDirectDevice::Scan()
158 * @see WifiDirectDevice::CancelScan()
160 result CancelScan(void);
163 * @see WifiDirectDevice::Associate()
165 result Associate(const WifiDirectDeviceInfo& wifiDirectGroupOwnerDeviceInfo);
168 * @see WifiDirectDevice::GetWifiDirectMemberN()
170 WifiDirectGroupMember* GetWifiDirectMemberN(void);
173 * @see WifiDirectDevice::IsDiscoverable()
175 bool IsDiscoverable(void) const;
178 * @see WifiDirectDevice::IsActivated()
180 bool IsActivated(void) const;
183 * @see WifiDirectDevice::Connect()
185 result Connect(const WifiDirectDeviceInfo& peerDeviceInfo);
188 * @see WifiDirectDevice::CancelConnect()
190 result CancelConnect(void);
193 * @see WifiDirectDevice::CreateAutonomousGroup()
195 result CreateAutonomousGroup(void);
198 * @see WifiDirectDevice::SetGroupSettingInfo()
200 result SetGroupSettingInfo(const WifiDirectGroupInfo& groupSettingInfo);
203 * @see WifiDirectDevice::Disconnect()
204 * @see WifiDirectGroupOwner::Disconnect()
206 result Disconnect(const WifiDirectDeviceInfo& remoteDeviceInfo);
209 * @see WifiDirectDevice::LeaveGroup()
211 result LeaveGroup(void);
214 * @see WifiDirectDevice::GetGroupOwnerInfo()
216 WifiDirectDeviceInfo* GetGroupOwnerInfoN(void) const;
219 * @see WifiDirectDevice::GetGroupClientInfoListN()
221 Tizen::Base::Collection::IList* GetGroupClientInfoListN(void) const;
224 * @see WifiDirectDevice::GetOperatingChannel()
226 WifiRadioChannel GetOperatingChannel(void) const;
229 * @see WifiDirectGroupOwner::DestroyGroup()
231 result DestroyGroup(void);
234 * @see WifiDirectGroupOwner::GetAllGroupMemberInfoImplListN()
236 Tizen::Base::Collection::IList* GetAllGroupMemberInfoImplListN(void);
239 * @see WifiDirectGroupClient::Disassociate()
241 result Disassociate(void);
244 * Gets the type of the Wi-Fi Direct group member.
246 * @return The type of the Wi-Fi Direct group member
248 WifiDirectGroupMemberType GetCurrentMemberType(void) const;
251 * Called when the state of device is changed.
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
257 static void OnWifiDirectPowerChanged(int errorCode, wifi_direct_device_state_e deviceState, void* pUserData);
260 * Called when the state of discovery is changed.
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
266 static void OnWifiDirectScanCompleted(int errorCode, wifi_direct_discovery_state_e discoveryState, void* pUserData);
269 * Called when the state of connection is changed.
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
276 static void OnWifiDirectConnectionChanged(int errorCode, wifi_direct_connection_state_e connectionState, const char* pMacAddress, void* pUserData);
278 * Called when IP address of client is assigned when your device is group owner.
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
285 static void OnWifiDirectClientIpAssigned(const char* mac_address, const char* ip_address, const char* interface_address, void* user_data);
288 * Call back for each discovered device
290 * @param[in] pPeer Device Information
291 * @param[in] pUserData The user data passed from the callback registration function
293 static bool OnWifiDirectPeerFound(wifi_direct_discovered_peer_info_s* pPeer, void* pUserData);
296 * Call back for each Discovered device
298 * @param[in] pPeer Device Information
299 * @param[in] pUserData The user data passed from the callback registration function
301 static bool OnWifiDirectEachDiscoveredPeer(wifi_direct_discovered_peer_info_s* pPeer, void* pUserData);
304 * Call back for each connected device
306 * @param[in] pPeer Device Information
307 * @param[in] pUserData The user data passed from the callback registration function
309 static bool OnWifiDirectEachConnectedClient(wifi_direct_connected_peer_info_s* pPeer, void* pUserData);
312 * Call back for connected owner
314 * @param[in] pPeer Device Information
315 * @param[in] pUserData The user data passed from the callback registration function
317 static bool OnWifiDirectConnectedOwner(wifi_direct_connected_peer_info_s* pPeer, void* pUserData);
320 * Call back for each discovered device, for searching same device for create group
322 * @param[in] pPeer Device Information
323 * @param[in] pUserData The user data passed from the callback registration function
325 static bool OnWifiDirectFindSameDeviceName(wifi_direct_discovered_peer_info_s* pPeer, void* pUserData);
328 * Call back for each supported WPS mode
330 * @param[in] type WPS mode type
331 * @param[in] pUserData The user data passed from the callback registration function
333 static bool OnWifiDirectSupportedWpsMode(wifi_direct_wps_type_e type, void* pUserData);
338 * @param[in] listner object of _WifiDirectDeviceImpl
340 void AddListener(const _WifiDirectDeviceImpl& listner);
345 * @param[in] listner object of _WifiDirectDeviceImpl
347 void RemoveListener(const _WifiDirectDeviceImpl& listner);
350 * Called to notify the application with the result and related information for a request of group creation or group creation
353 * @param[in] peerMacAddress The peer mac address
354 * @param[in] r An error code
356 void OnWifiDirectGroupCreated(const Tizen::Base::String& peerMacAddress, result r);
359 * Called to notify the application that the connection to a Wi-Fi Direct group owner is completely established.
361 * @param[in] peerMacAddress The peer mac address
362 * @param[in] r An error code
364 void OnWifiDirectAssociationCompleted(const Tizen::Base::String& peerMacAddress, result r);
367 * Called to notify the application that a successful association has occurred with a client.
369 * @param[in] peerMacAddress The peer mac address
371 void OnWifiDirectClientAssociated(const Tizen::Base::String& peerMacAddress);
374 * Called to notify the application that a disassociation has occurred with a client.
376 * @param[in] peerMacAddress The peer mac address
378 void OnWifiDirectClientDisassociated(const Tizen::Base::String& peerMacAddress);
381 * Called to notify the application that a connection to a Wi-Fi Direct group owner has terminated.
383 * @param[in] reason The reason of association termination
384 * @param[in] r An error code
386 void OnWifiDirectAssociationTerminated(WifiDirectAssociationTerminationReason reason, result r);
389 * Called to notify the application that the Wi-Fi Direct group is destroyed.
391 * @param[in] r An error code
393 void OnWifiDirectGroupDestroyed(result r);
396 * Called to notify the application that Wi-Fi Direct connection has been established with the remove device.
398 * @param[in] peerMacAddress The peer mac address
399 * @param[in] r An error code
401 void OnWifiDirectConnected(const Tizen::Base::String& peerMacAddress, result r);
404 * Called to notify the application that the Wi-Fi Direct connection has been disconnected with peer device.
406 * @param[in] peerMacAddress The peer mac address
408 void OnWifiDirectDisconnected(const Tizen::Base::String& peerMacAddress, result r);
411 * Called to notify the application that an autonomous group is created.
413 * @param[in] r An error code
415 void OnWifiDirectAutonomousGroupCreated(result r);
418 * Called to notify the application that the local device is left from the group.
420 * @param[in] r An error code
422 void OnWifiDirectGroupLeft(result r);
426 * This default constructor is intentionally declared as private to implement the Singleton semantic.
429 _WifiDirectSystemAdapter(void);
432 * This destructor is intentionally declared as private to implement the Singleton semantic.
435 virtual ~_WifiDirectSystemAdapter(void);
438 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
440 _WifiDirectSystemAdapter(const _WifiDirectSystemAdapter& value);
443 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
445 _WifiDirectSystemAdapter& operator =(const _WifiDirectSystemAdapter& rhs);
448 * Initializes this instance of _WifiDirectSystemAdapter.
450 bool Construct(void);
453 * Adds connected peer to the end of the list.
455 * @param[in] pPeerInfo The peer device information
457 result AddPeerInfo(WifiDirectDeviceInfo* pPeerInfo);
460 * Removes disconnected peer.
462 * @param[in] pClientInfo Device Information
464 result RemovePeerInfo(WifiDirectDeviceInfo* pPeerInfo);
467 * Returns device information matching with mac address
469 * @param[in] macAddress mac address string to search in the list
471 WifiDirectDeviceInfo* GetPeerInfo(const Tizen::Base::String& macAddress);
474 * Returns char buffer of device state
476 * @return char buffer of device state
478 const char* GetStringOfDeviceState(void) const;
481 * Returns char buffer of scan state
483 * @return char buffer of scan state
485 const char* GetStringOfScanState(void) const;
488 * Returns String of all status
490 * @return String of all status
492 Tizen::Base::String GetStringOfAllCurrentState(void) const;
495 * Initializes current state of Wi-Fi Direct
497 * @return An error code
499 result InitializeCurrentState(void);
504 * @return An error code
506 result StartListenMode(void);
511 * @return An error code
513 result StopListenModeToScan(void);
518 * @return An error code
520 result StartDiscovery(void);
525 * @return An error code
527 result CancelDiscovery(void);
530 * Initializes the _WifiDirectSystemAdapter singletone instance.
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.
536 static void InitSingleton(void);
539 * Destorys instance of singleton class.
541 static void DestroySingleton(void);
544 * Gets the connected peer device info.
546 WifiDirectDeviceInfo* GetConnectedPeerDeviceInfoN(WifiDirectGroupMemberType peerMemberType, const Tizen::Base::String* pPeerMacAddress = null) const;
549 * Gets the list of connected peer device info.
551 Tizen::Base::Collection::IList* GetConnectedPeerDeviceInfoListN(WifiDirectGroupMemberType currentMemberType) const;
556 static _WifiDirectSystemAdapter* __pWifiDirectSystemAdapter;
557 std::unique_ptr< _WifiDirectEvent, _WifiDirectEventDeleter > __pWifiDirectEvent;
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;
569 friend class std::default_delete< _WifiDirectSystemAdapter >;
571 } } } // Tizen::Net::Wifi
574 #endif // _FNET_WIFI_INTERNAL_WIFI_DIRECT_SYSTEM_ADAPTER_H_