Modified to return an exception(E_INVALID_STATE) when you try to connect to a speicif...
[framework/osp/net.git] / src / inc / FNetWifi_WifiSystemAdapter.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  * @file    FNetWifi_WifiSystemAdapter.h
19  * @brief   This is the header file for the _WifiSystemAdapter class.
20  * @version 2.1
21  *
22  * This header file contains declarations of the _WifiSystemAdapter class.
23  */
24 #ifndef _FNET_WIFI_INTERNAL_WIFI_SYSTEM_ADAPTER_H_
25 #define _FNET_WIFI_INTERNAL_WIFI_SYSTEM_ADAPTER_H_
26
27 #include <unique_ptr.h>
28 #include <wifi.h>
29 #include <FOspConfig.h>
30 #include <FBaseObject.h>
31 #include <FNetWifiWifiTypes.h>
32
33 namespace Tizen { namespace Net { namespace Wifi
34 {
35
36 class WifiBssInfo;
37 class _WifiManagerImpl;
38 class _IWifiManagerEventListener;
39
40 class _OSP_EXPORT_ _WifiSystemAdapter :
41         public Tizen::Base::Object
42 {
43
44 public:
45     /**
46      * Register an instance of _IWifiManagerEventListener interface.
47      *
48      * @return      An error code
49      * @param[in]   listener            The instance of _IWifiManagerEventListener to be registered
50      * @param[in]   isHighPriority      Set to @c true to register with the high priority, @n
51      *                                  else @c false
52      * @exception   E_SUCCESS           The method is successful.
53      * @exception   E_OUT_OF_MEMORY     The memory is insufficient.
54      */
55         result RegisterManagerEventListener(_IWifiManagerEventListener& listener);
56
57     /**
58      * Unregister an instance of _IBluetoothManagerEventListener interface.
59      *
60      * @return      An error code
61      * @param[in]   listener            The instance of _IWifiManagerEventListener to be unregistered
62      * @exception   E_SUCCESS           The method is successful.
63      * @exception   E_OBJ_NOT_FOUND     The input instance is not registered.
64      */
65     result UnregisterManagerEventListener(_IWifiManagerEventListener& listener);
66
67     /**
68      * Activates the local Wifi device.
69      *
70      * @return      An error code
71      * @exception   E_SUCCESS           The activation was successful.
72      * @exception   E_FAILURE           Failed to activate.
73      * @exception   E_SYSTEM            A system error occurred.
74      */
75     result Activate(void);
76
77     /**
78      * Deactivates the local Wifi device.
79      *
80      * @return      An error code
81      * @exception   E_SUCCESS           The deactivation was successful.
82      * @exception   E_FAILURE           Failed to deactivate.
83      * @exception   E_SYSTEM            A system error occurred.
84      */
85     result Deactivate(void);
86
87     /**
88      * Gets the MAC address of the Wifi device.
89      * @return      The MAC address in the form '00-00-00-00-00-00'
90      */
91     Tizen::Base::String GetMacAddress(void) const;
92
93     /**
94      * Checks whether the local device is activated.
95      * @return      @c true, if the local device is activated @n
96      *              @c false, otherwise
97      */
98     bool IsActivated(void) const;
99
100     /**
101      * Checks whether the local device is connected with a remote STA.
102      * @return      @c true, if the local device is connected with a remote STA @n
103      *              @c false, otherwise
104      */
105     bool IsConnected(void) const;
106
107     /**
108      * Checks whether the local device is already connected with a specific remote STA.
109      *
110      * @return      @c true, if the local device is already connected with a specific remote STA @n
111      *              @c false, otherwise
112      * @param[in]   pApHandle        a handle of access point
113      *
114      */
115     bool IsConnected(wifi_ap_h pApHandle) const;
116
117     /**
118      * Requests a scan for nearby BSS with both infrastructure and independent mode.
119      *
120      * @return      An error code
121      * @exception   E_SUCCESS           The method was successful.
122      * @exception   E_FAILURE           The method failed.
123      * @remarks     Only active scan - i.e. probing for APs in the range - is supported.
124      * @see         IWifiManagerEventListener::OnWifiScanCompleted()
125      */
126     result Scan(void);
127
128     /**
129      * Establishes a connection to a specific access point - only BSS with infrastructure mode.
130      *
131      * @return      An error code
132      * @param[in]   targetApInfo        A BSS information that represents target access point.
133      * @exception   E_SUCCESS           The method was successful.
134      * @exception   E_FAILURE           The method failed.
135      * @exception   E_INVALID_ARG       A specified input parameter is invalid. E.g. BSS type is independent mode.
136      * @remarks     If a connection to other access point is already established, it will be disconnected and the new connection
137      *              of this method will be established.
138      * @see         IWifiManagerEventListener::OnWifiConnected()
139      */
140     result Connect(const WifiBssInfo& targetApInfo);
141
142     /**
143      * Gets the state of current Wi-Fi connection.
144      *
145      * @return      The state of the current Wi-Fi connection
146      */
147     WifiConnectionState GetConnectionState(void) const;
148
149     /**
150      * Gets the information of current Wi-Fi connection target which the local device is connecting or connected with.
151      *
152      * @return      A pointer to the WifiBssInfo instance representing the information of current Wi-Fi connection target
153      *              else @c null if GetConnectionState() is WIFI_CONNECTION_STATE_NOT_CONNECTED
154      */
155     WifiBssInfo* GetConnectionTargetInfoN(void) const;
156
157     /**
158      * Gets a list of the latest search results which the underlying Wi-Fi system scan periodically on background.
159      *
160      * @return      An IList containing WifiBssInfo of existing Wi-Fi connections if successful, @n
161      *              else @c null
162      */
163     Tizen::Base::Collection::IList* GetSystemScanResultN(void) const;
164
165     /**
166      * Called when the device state is changed.
167      *
168      * @param[in]   state               Device status
169      * @param[in]   pUserData           The user data passed from the callback registration function
170      */
171     static void OnWifiDeviceStateChanged(wifi_device_state_e state, void* pUserData);
172
173     /**
174      * Called when the connection state is changed.
175      *
176      * @param[in]   state               Connection status
177      * @param[in]   pApHandle           A handle of access point
178      * @param[in]   pUserData           The user data passed from the callback registration function
179      */
180     static void OnWifiConnectionStateChanged(wifi_connection_state_e state, wifi_ap_h pApHandle, void* pUserData);
181     
182     /**
183      * Called when each access point is found.
184      *
185      * @param[in]   pApHandle          A handle of access point
186      * @param[in]   pUserData          The user data passed from the callback registration function
187      */
188     static bool OnWifiEachAccessPointFound(wifi_ap_h pApHandle, void* pUserData);
189
190     /**
191      * Called when each access point is checked.
192      *
193      * @param[in]   pApHandle           A handle of access point
194      * @param[in]   pUserData           The user data passed from the callback registration function
195      */
196     static bool OnWifiEachAccessPointChecked(wifi_ap_h pApHandle, void* pUserData);
197
198     /**
199      * Called when Wifi is activated.
200      *
201      * @param[in]   errorCode           Error code
202      * @param[in]   pUserData           The user data passed from the callback registration function
203      */
204     static void OnWifiActivated(wifi_error_e errorCode, void* pUserData);
205
206     /**
207      * Called when Wifi is dectivated.
208      *
209      * @param[in]   errorCode           Error code
210      * @param[in]   pUserData           The user data passed from the callback registration function
211      */
212     static void OnWifiDeactivated(wifi_error_e errorCode, void* pUserData);
213
214     /**
215      * Called when the local device is connected with Wifi access point.
216      *
217      * @param[in]   errorCode           Error code
218      * @param[in]   pUserData           The user data passed from the callback registration function
219      */
220     static void OnWifiConnected(wifi_error_e errorCode, void* pUserData);
221
222     /**
223      * Called when the scan process is completed.
224      *
225      * @param[in]   errorCode           Error code
226      * @param[in]   pUserData           The user data passed from the callback registration function
227      */
228     static void OnWifiScanCompleted(wifi_error_e errorCode, void* pUserData);
229     
230     /**
231      * Called when the rssi value is changed.
232      *
233      * @param[in]   rssiLevel           Rssi level
234      * @param[in]   pUserData           The user data passed from the callback registration function
235      */
236     static void OnWifiRssiLevelChanged(wifi_rssi_level_e rssiLevel, void* pUserData);
237
238     /**
239      * Called when the background scan result is updated.
240      *
241      * @param[in]   errorCode           Error code
242      * @param[in]   pUserData           The user data passed from the callback registration function
243      */
244     static void OnWifiBackgroundScanResultUpdated(wifi_error_e errorCode, void* pUserData);
245
246     /**
247      * Get the singleton insatnce of _WifiSystemAdapter.
248      *
249      * @return      The pointer to _WifiSystemAdapter
250      */
251     static _WifiSystemAdapter* GetInstance(void);
252
253 private:
254     /**
255      * This default constructor is intentionally declared as private to implement the Singleton semantic.
256      *
257      * @remarks     After creating an instance of this class, you must explicitly call
258      *              the construction method to initialize the instance.
259      * @see Construct()
260      */
261     _WifiSystemAdapter(void);
262
263     /**
264      * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
265      *
266      * @param[in]   rhs                 An instance of %_WifiSystemAdapter
267      */
268     _WifiSystemAdapter(const _WifiSystemAdapter& rhs);
269
270     /**
271      * This destructor is intentionally declared as private to implement the Singleton semantic.
272      *
273      */
274     virtual ~_WifiSystemAdapter(void);
275
276     /**
277      * Initializes the _WifiSystemAdapter instance and adds the listener instance.
278      *
279      * @return      An error code
280      * @exception   E_SUCCESS           The initialization was successful.
281      * @exception   E_SYSTEM            A system error occurred.
282      */
283     result Construct();
284
285     /**
286      * Initializes the _WifiSystemAdapter singletone instance.
287      *
288      * @exception   E_SUCCESS           The initialization was successful.
289      * @exception   E_SYSTEM            A system error occurred.
290      * @exception   E_OUT_OF_MEMORY     The memory is insufficient.     
291      */
292     static void InitSingleton(void);
293
294     /**
295      * Destorys instance of singleton class.
296      *
297      */
298     static void DestroySingleton(void);
299     
300     /**
301      * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
302      *
303      * @param[in] rhs An instance of %_WifiSystemAdapter
304      */
305     _WifiSystemAdapter& operator=(const _WifiSystemAdapter& rhs);
306
307 private:
308     Tizen::Base::Collection::LinkedListT<_IWifiManagerEventListener*> __mgrEvtListenerList;
309     WifiBssInfo* __pBssInfo;
310
311 friend class std::default_delete<_WifiSystemAdapter>;
312
313 }; // _WifiSystemAdapter
314
315 } } } // Tizen::Net::Wifi
316
317 #endif // _FNET_WIFI_INTERNAL_WIFI_SYSTEM_ADAPTER_H_