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 FNetWifiWifiManager.cpp
20 * @brief This is the implementation file for the WifiManager Class.
23 * This file contains the implementation of the WifiManager Class.
26 #include <unique_ptr.h>
27 #include <FBaseSysLog.h>
28 #include <FNetWifiWifiBssInfo.h>
29 #include <FNetWifiWifiManager.h>
30 #include <FSec_AccessController.h>
31 #include "FSys_SystemInfoImpl.h"
32 #include "FNetWifi_WifiManagerImpl.h"
34 static const wchar_t* _WIFI_FEATURE_INFO_KEY = L"http://tizen.org/feature/network.wifi";
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Runtime;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::Security;
41 using namespace Tizen::System;
43 namespace Tizen { namespace Net { namespace Wifi {
45 WifiManager::WifiManager(void)
46 :__pWifiManagerImpl(null)
50 WifiManager::~WifiManager(void)
52 delete __pWifiManagerImpl;
56 WifiManager::Construct(IWifiManagerEventListener& listener)
60 bool isWifiSupported = false;
61 r = _SystemInfoImpl::GetSysInfo(_WIFI_FEATURE_INFO_KEY, isWifiSupported);
63 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS && isWifiSupported == true, E_UNSUPPORTED_OPERATION, "Wi-Fi is not supported.");
65 SysAssertf(__pWifiManagerImpl == null,
66 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
68 unique_ptr<_WifiManagerImpl> pWifiManagerImpl(new (std::nothrow) _WifiManagerImpl());
69 SysTryReturnResult(NID_NET_WIFI, pWifiManagerImpl, E_OUT_OF_MEMORY, "Memory allocation failed.");
71 r = pWifiManagerImpl->Construct(listener);
73 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating.");
74 __pWifiManagerImpl = pWifiManagerImpl.release();
80 WifiManager::Activate(void) const
84 r = _AccessController::CheckUserPrivilege(_PRV_WIFI_ADMIN);
85 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
87 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
89 r = __pWifiManagerImpl->Activate();
90 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating.");
96 WifiManager::Deactivate(void) const
100 r = _AccessController::CheckUserPrivilege(_PRV_WIFI_ADMIN);
101 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
103 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
105 r = __pWifiManagerImpl->Deactivate();
106 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating.");
112 WifiManager::GetPowerStatus(void) const
114 WifiPowerStatus wifiPowerStatus = WIFI_POWER_STATUS_OFF;
116 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
118 wifiPowerStatus = __pWifiManagerImpl->GetPowerStatus();
120 return wifiPowerStatus;
124 WifiManager::GetMacAddress(void) const
126 String macAddress(L"");
128 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
130 macAddress = __pWifiManagerImpl->GetMacAddress();
136 WifiManager::IsActivated(void) const
138 bool isActivated = false;
140 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
142 isActivated = __pWifiManagerImpl->IsActivated();
148 WifiManager::IsConnected(void) const
150 bool isConnected = false;
152 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
154 isConnected = __pWifiManagerImpl->IsConnected();
160 WifiManager::Scan(void)
162 result r = E_SUCCESS;
164 r = _AccessController::CheckUserPrivilege(_PRV_WIFI_READ);
165 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
167 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
169 r = __pWifiManagerImpl->Scan();
170 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating.");
176 WifiManager::Connect(const WifiBssInfo& targetApInfo)
178 result r = E_SUCCESS;
180 r = _AccessController::CheckUserPrivilege(_PRV_WIFI_ADMIN);
181 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
183 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
185 r = __pWifiManagerImpl->Connect(targetApInfo);
186 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating.");
192 WifiManager::SetWifiSystemScanMode(WifiSystemScanMode mode)
194 result r = E_SUCCESS;
196 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
198 // Privilege check will be done by Impl class
199 r = __pWifiManagerImpl->SetWifiSystemScanMode(mode);
200 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating.");
206 WifiManager::AddSystemMonitoringEventListener(IWifiSystemMonitoringEventListener& listener)
208 result r = E_SUCCESS;
210 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
212 // Privilege check will be done by Impl class
213 r = __pWifiManagerImpl->AddSystemMonitoringEventListener(listener);
214 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating.");
220 WifiManager::RemoveSystemMonitoringEventListener(IWifiSystemMonitoringEventListener& listener)
222 result r = E_SUCCESS;
224 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
226 // Privilege check will be done by Impl class
227 r = __pWifiManagerImpl->RemoveSystemMonitoringEventListener(listener);
228 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating.");
234 WifiManager::GetConnectionState(void) const
236 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
238 return __pWifiManagerImpl->GetConnectionState();
242 WifiManager::GetConnectionTargetInfoN(void) const
244 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
246 return __pWifiManagerImpl->GetConnectionTargetInfoN();
250 WifiManager::UpdateBssInfo(const WifiBssInfo& bssInfo)
252 result r = E_SUCCESS;
254 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
256 // Privilege check will be done by Impl class
257 r = __pWifiManagerImpl->UpdateBssInfo(bssInfo);
258 SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating.");
263 Tizen::Base::Collection::IList*
264 WifiManager::GetSystemScanResultN(void) const
266 SysAssertf(__pWifiManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
268 return __pWifiManagerImpl->GetSystemScanResultN();
271 } } } // Tizen::Net::Wifi