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,
277 const char* pMacAddress, void* pUserData);
279 * Called when IP address of client is assigned when your device is group owner.
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
286 static void OnWifiDirectClientIpAssigned(const char *mac_address, const char *ip_address,
287 const char *interface_address, void *user_data);
290 * Call back for each discovered device
292 * @param[in] pPeer Device Information
293 * @param[in] pUserData The user data passed from the callback registration function
295 static bool OnWifiDirectPeerFound(wifi_direct_discovered_peer_info_s* pPeer, void* pUserData);
298 * Call back for each discovered device
300 * @param[in] pPeer Device Information
301 * @param[in] pUserData The user data passed from the callback registration function
303 static bool OnWifiDirectEachDiscoveredPeer(wifi_direct_discovered_peer_info_s* pPeer, void* pUserData);
306 * Call back for each connected device
308 * @param[in] pPeer Device Information
309 * @param[in] pUserData The user data passed from the callback registration function
311 static bool OnWifiDirectEachConnectedClient(wifi_direct_connected_peer_info_s* pPeer, void* pUserData);
314 * Call back for connected owner
316 * @param[in] pPeer Device Information
317 * @param[in] pUserData The user data passed from the callback registration function
319 static bool OnWifiDirectConnectedOwner(wifi_direct_connected_peer_info_s* pPeer, void* pUserData);
322 * Call back for each discovered device, for searching same device for create group
324 * @param[in] pPeer Device Information
325 * @param[in] pUserData The user data passed from the callback registration function
327 static bool OnWifiDirectFindSameDeviceName(wifi_direct_discovered_peer_info_s* pPeer, void* pUserData);
330 * Call back for each supported WPS mode
332 * @param[in] type WPS mode type
333 * @param[in] pUserData The user data passed from the callback registration function
335 static bool OnWifiDirectSupportedWpsMode(wifi_direct_wps_type_e type, void* pUserData);
340 * @param[in] listner object of _WifiDirectDeviceImpl
342 void AddListener(const _WifiDirectDeviceImpl& listner);
347 * @param[in] listner object of _WifiDirectDeviceImpl
349 void RemoveListener(const _WifiDirectDeviceImpl& listner);
352 * Called to notify the application with the result and related information for a request of group creation or group creation
355 * @param[in] peerMacAddress The peer mac address
356 * @param[in] r An error code
358 void OnWifiDirectGroupCreated(const Tizen::Base::String& peerMacAddress, result r);
361 * Called to notify the application that the connection to a Wi-Fi Direct group owner is completely established.
363 * @param[in] peerMacAddress The peer mac address
364 * @param[in] r An error code
366 void OnWifiDirectAssociationCompleted(const Tizen::Base::String& peerMacAddress, result r);
369 * Called to notify the application that a successful association has occurred with a client.
371 * @param[in] peerMacAddress The peer mac address
373 void OnWifiDirectClientAssociated(const Tizen::Base::String& peerMacAddress);
376 * Called to notify the application that a disassociation has occurred with a client.
378 * @param[in] peerMacAddress The peer mac address
380 void OnWifiDirectClientDisassociated(const Tizen::Base::String& peerMacAddress);
383 * Called to notify the application that a connection to a Wi-Fi Direct group owner has terminated.
385 * @param[in] reason The reason of association termination
386 * @param[in] r An error code
388 void OnWifiDirectAssociationTerminated(WifiDirectAssociationTerminationReason reason, result r);
391 * Called to notify the application that the Wi-Fi Direct group is destroyed.
393 * @param[in] r An error code
395 void OnWifiDirectGroupDestroyed(result r);
398 * Called to notify the application that Wi-Fi Direct connection has been established with the remove device.
400 * @param[in] peerMacAddress The peer mac address
401 * @param[in] r An error code
403 void OnWifiDirectConnected(const Tizen::Base::String& peerMacAddress, result r);
406 * Called to notify the application that the Wi-Fi Direct connection has been disconnected with peer device.
408 * @param[in] peerMacAddress The peer mac address
410 void OnWifiDirectDisconnected(const Tizen::Base::String& peerMacAddress, result r);
413 * Called to notify the application that an autonomous group is created.
415 * @param[in] r An error code
417 void OnWifiDirectAutonomousGroupCreated(result r);
420 * Called to notify the application that the local device is left from the group.
422 * @param[in] r An error code
424 void OnWifiDirectGroupLeft(result r);
428 * This default constructor is intentionally declared as private to implement the Singleton semantic.
431 _WifiDirectSystemAdapter(void);
434 * This destructor is intentionally declared as private to implement the Singleton semantic.
437 virtual ~_WifiDirectSystemAdapter(void);
440 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
442 _WifiDirectSystemAdapter(const _WifiDirectSystemAdapter& value);
445 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
447 _WifiDirectSystemAdapter& operator =(const _WifiDirectSystemAdapter& rhs);
450 * Initializes this instance of _WifiDirectSystemAdapter.
452 bool Construct(void);
455 * Adds connected peer to the end of the list.
457 * @param[in] pPeerInfo The peer device information
459 result AddPeerInfo(WifiDirectDeviceInfo* pPeerInfo);
462 * Removes disconnected peer.
464 * @param[in] pClientInfo Device Information
466 result RemovePeerInfo(WifiDirectDeviceInfo* pPeerInfo);
469 * Returns device information matching with mac address
471 * @param[in] macAddress mac address string to search in the list
473 WifiDirectDeviceInfo* GetPeerInfo(const Tizen::Base::String& macAddress);
476 * Returns char buffer of device state
478 * @return char buffer of device state
480 const char* GetStringOfDeviceState(void) const;
483 * Returns char buffer of scan state
485 * @return char buffer of scan state
487 const char* GetStringOfScanState(void) const;
490 * Returns String of all status
492 * @return String of all status
494 Tizen::Base::String GetStringOfAllCurrentState(void) const;
497 * Initializes current state of Wi-Fi Direct
499 * @return An error code
501 result InitializeCurrentState(void);
506 * @return An error code
508 result StartListenMode(void);
513 * @return An error code
515 result StopListenModeToScan(void);
520 * @return An error code
522 result StartDiscovery(void);
527 * @return An error code
529 result CancelDiscovery(void);
532 * Initializes the _WifiDirectSystemAdapter singletone instance.
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.
538 static void InitSingleton(void);
541 * Destorys instance of singleton class.
543 static void DestroySingleton(void);
546 * Gets the connected peer device info.
548 WifiDirectDeviceInfo* GetConnectedPeerDeviceInfoN(WifiDirectGroupMemberType peerMemberType, const Tizen::Base::String* pPeerMacAddress = null) const;
553 static _WifiDirectSystemAdapter* __pWifiDirectSystemAdapter;
554 std::unique_ptr<_WifiDirectEvent,_WifiDirectEventDeleter> __pWifiDirectEvent;
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>;
566 } } } // Tizen::Net::Wifi
569 #endif // _FNET_WIFI_INTERNAL_WIFI_DIRECT_SYSTEM_ADAPTER_H_