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.
18 * @file FTelNetworkManager.cpp
19 * @brief This is the implementation file for NetworkManager class.
22 #include <FTelNetworkManager.h>
23 #include <FBaseSysLog.h>
24 #include <FTelITelephonyNetworkEventListener.h>
25 #include <FTelITelephonyNetworkSettingListener.h>
26 #include <FSec_AccessController.h>
27 #include <FSys_SystemInfoImpl.h>
28 #include "FTel_NetworkManagerImpl.h"
30 using namespace Tizen::Security;
31 using namespace Tizen::System;
33 namespace Tizen { namespace Telephony
35 NetworkManager::NetworkManager(void)
36 : __pNetworkManagerImpl(null)
41 NetworkManager::~NetworkManager(void)
43 delete __pNetworkManagerImpl;
47 NetworkManager::Construct(ITelephonyNetworkEventListener* pListener)
49 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
51 SysAssertf(__pNetworkManagerImpl == null,
52 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
55 bool isTelephonySupported = false;
57 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
58 SysTryReturnResult(NID_TEL, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
60 __pNetworkManagerImpl = new (std::nothrow) _NetworkManagerImpl();
61 SysTryReturnResult(NID_TEL, __pNetworkManagerImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
63 r = __pNetworkManagerImpl->Construct(pListener);
67 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
68 delete __pNetworkManagerImpl;
69 __pNetworkManagerImpl = null;
76 NetworkManager::GetNetworkStatus(NetworkStatus& networkStatus) const
78 SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
82 r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
83 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
85 r = __pNetworkManagerImpl->GetNetworkStatus(networkStatus);
86 SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
92 NetworkManager::GetNetworkInfo(NetworkInfo& networkInfo) const
94 SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
98 r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
99 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
102 r = __pNetworkManagerImpl->GetNetworkInfo(networkInfo);
103 SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
111 NetworkManager::SetNetworkSettingListener(ITelephonyNetworkSettingListener* pListener)
113 SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
115 result r = __pNetworkManagerImpl->SetNetworkSettingListener(pListener);
117 if (r == E_PRIVILEGE_DENIED)
119 SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
121 else if( r != E_SUCCESS)
123 SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
130 NetworkManager::GetNetworkSelectionMode(void)
132 SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
134 result r = __pNetworkManagerImpl->GetNetworkSelectionMode();
136 if (r == E_PRIVILEGE_DENIED)
138 SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
140 else if( r != E_SUCCESS)
142 SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
150 NetworkManager::SelectNetwork(const NetworkInfo& networkInfo)
152 SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
154 result r = __pNetworkManagerImpl->SelectNetwork(networkInfo);
156 if (r == E_PRIVILEGE_DENIED)
158 SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
160 else if( r != E_SUCCESS)
162 SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
170 NetworkManager::SelectNetwork(void)
172 SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
174 result r = __pNetworkManagerImpl->SelectNetwork();
176 if (r == E_PRIVILEGE_DENIED)
178 SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
180 else if( r != E_SUCCESS)
182 SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
190 NetworkManager::SearchNetwork(void)
192 SysAssertf(__pNetworkManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
194 result r = __pNetworkManagerImpl->SearchNetwork();
196 if (r == E_PRIVILEGE_DENIED)
198 SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
200 else if( r != E_SUCCESS)
202 SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
208 }} // Tizen::Telephony