2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 FNetNetConnectionManager.cpp
20 * @brief This is the implementation for the %NetConnectionManager class.
23 #include <FNetNetConnectionInfo.h>
24 #include <FNetNetConnectionManager.h>
25 #include <FBaseSysLog.h>
26 #include <FSec_AccessController.h>
27 #include <FSys_SystemInfoImpl.h>
28 #include "FNet_NetConnectionManagerImpl.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Security;
33 using namespace Tizen::System;
35 namespace Tizen { namespace Net
38 NetConnectionManager::NetConnectionManager(void)
39 : __pNetConnectionManagerImpl(null)
43 NetConnectionManager::~NetConnectionManager(void)
48 NetConnectionManager::Construct(void)
52 SysAssertf(__pNetConnectionManagerImpl == null,
53 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
55 __pNetConnectionManagerImpl = _NetConnectionManagerImpl::GetInstance();
56 SysTryReturnResult(NID_NET, __pNetConnectionManagerImpl != null, E_SYSTEM,
57 "A system error has been occurred. Failed to initialize the network connection manager instance.");
63 NetConnectionManager::CreateNetConnectionN(NetAccountId netAccountId)
66 NetConnection* pConnection = null;
68 SysAssertf(__pNetConnectionManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
70 pConnection = __pNetConnectionManagerImpl->CreateNetConnectionN(netAccountId);
72 SysTryReturn(NID_NET, pConnection != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
78 NetConnectionManager::GetManagedNetConnectionN(void) const
81 ManagedNetConnection* pManagedConnection = null;
83 SysAssertf(__pNetConnectionManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
85 pManagedConnection = __pNetConnectionManagerImpl->GetManagedNetConnectionN();
87 SysTryReturn(NID_NET, pManagedConnection != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
89 return pManagedConnection;
93 NetConnectionManager::GetNetPreference(void) const
95 SysAssertf(__pNetConnectionManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
97 return __pNetConnectionManagerImpl->GetNetPreference();
101 NetConnectionManager::SetNetPreference(NetPreferenceType netPreference)
103 result r = E_SUCCESS;
105 r = _AccessController::CheckUserPrivilege(_PRV_NETWORK_CONNECTION);
106 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
107 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "The application is not permitted to call this method.");
110 if (netPreference == NET_WIFI_ONLY)
112 static const wchar_t _WIFI[] = L"http://tizen.org/feature/network.wifi";
114 bool isWifiSupported = false;
116 r = _SystemInfoImpl::GetSysInfo(_WIFI, isWifiSupported);
117 SysTryReturnResult(NID_NET, r == E_SUCCESS && isWifiSupported, E_UNSUPPORTED_OPERATION, "Wi-Fi is not supported.");
119 else if (netPreference == NET_PS_ONLY)
121 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
123 bool isTelephonySupported = false;
125 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
126 SysTryReturnResult(NID_NET, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
128 #endif // !_OSP_EMUL_
130 SysAssertf(__pNetConnectionManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
132 r = __pNetConnectionManagerImpl->SetNetPreference(netPreference);
133 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
139 NetConnectionManager::GetNetConnectionInfoN(NetAccountId netAccountId)
141 result r = E_SUCCESS;
142 NetConnectionInfo* pConnectionInfo = null;
144 pConnectionInfo = _NetConnectionManagerImpl::GetNetConnectionInfoN(netAccountId);
146 SysTryReturn(NID_NET, pConnectionInfo != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
148 return pConnectionInfo;
152 NetConnectionManager::GetAllNetConnectionInfoN(void)
154 result r = E_SUCCESS;
157 pList = _NetConnectionManagerImpl::GetAllNetConnectionInfoN();
159 SysTryReturn(NID_NET, pList != null, null, r, "[%s] Propagating.", GetErrorMessage(r));