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 FNetNetStatistics.cpp
19 * @brief This is the implementation for the FNetNetStatistics class.
22 #include <unique_ptr.h>
23 #include <FNetNetTypes.h>
24 #include <FNetNetStatistics.h>
25 #include <FNet_NetTypes.h>
26 #include <FBaseSysLog.h>
27 #include <FSec_AccessController.h>
28 #include <FSys_SystemInfoImpl.h>
29 #include "FNet_NetStatisticsImpl.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Security;
34 using namespace Tizen::System;
36 namespace Tizen { namespace Net
39 NetStatistics::NetStatistics(void)
40 : __pNetStatisticsImpl(null)
45 NetStatistics::Construct(void)
49 SysAssertf(__pNetStatisticsImpl == null,
50 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
52 unique_ptr<_NetStatisticsImpl> pNetStatisticsImpl(new (std::nothrow) _NetStatisticsImpl());
53 SysTryReturnResult(NID_NET, pNetStatisticsImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
55 r = pNetStatisticsImpl->Construct();
56 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
58 __pNetStatisticsImpl = pNetStatisticsImpl.release();
63 NetStatistics::~NetStatistics(void)
65 delete __pNetStatisticsImpl;
66 __pNetStatisticsImpl = null;
70 NetStatistics::GetNetStatisticsInfo(NetBearerType operationMode, NetStatisticsInfoType netStatType) const
73 long long ret = INVALID_HANDLE;
77 r = _AccessController::CheckUserPrivilege(_PRV_NETWORK_STATISTICS_READ, _PRV_NETWORK_STATISTICS);
78 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY);
79 SysTryReturn(NID_NET, r == E_SUCCESS, INVALID_HANDLE, r,
80 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r));
83 if (operationMode == NET_BEARER_WIFI)
85 static const wchar_t _WIFI[] = L"http://tizen.org/feature/network.wifi";
87 bool isWifiSupported = false;
89 r = _SystemInfoImpl::GetSysInfo(_WIFI, isWifiSupported);
90 SysTryReturn(NID_NET, r == E_SUCCESS && isWifiSupported, INVALID_HANDLE, E_UNSUPPORTED_OPERATION,
91 "[%s] Wi-Fi is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
93 else if (operationMode == NET_BEARER_PS)
95 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
97 bool isTelephonySupported = false;
99 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
100 SysTryReturn(NID_NET, r == E_SUCCESS && isTelephonySupported, INVALID_HANDLE, E_UNSUPPORTED_OPERATION,
101 "[%s] Telephony is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
103 #endif // !_OSP_EMUL_
105 SysAssertf(__pNetStatisticsImpl != null, "Not yet constructed. Construct() should be called before use.");
107 ret = __pNetStatisticsImpl->GetNetStatisticsInfo(operationMode, netStatType);
109 SysTryReturn(NID_NET, r == E_SUCCESS, ret, r, "[%s] Propagating.", GetErrorMessage(r));
115 NetStatistics::Reset(NetBearerType operationMode, NetStatisticsInfoType netStatType)
117 result r = E_SUCCESS;
119 SysAssertf(__pNetStatisticsImpl != null, "Not yet constructed. Construct() should be called before use.");
122 if (operationMode == NET_BEARER_WIFI)
124 static const wchar_t _WIFI[] = L"http://tizen.org/feature/network.wifi";
126 bool isWifiSupported = false;
128 r = _SystemInfoImpl::GetSysInfo(_WIFI, isWifiSupported);
129 SysTryReturnResult(NID_NET, r == E_SUCCESS && isWifiSupported, E_UNSUPPORTED_OPERATION, "Wi-Fi is not supported.");
131 else if (operationMode == NET_BEARER_PS)
133 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
135 bool isTelephonySupported = false;
137 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
138 SysTryReturnResult(NID_NET, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
140 #endif // !_OSP_EMUL_
142 r = __pNetStatisticsImpl->Reset(operationMode, netStatType);
143 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
149 NetStatistics::ResetAll(NetBearerType operationMode)
151 result r = E_SUCCESS;
153 SysAssertf(__pNetStatisticsImpl != null, "Not yet constructed. Construct() should be called before use.");
156 if (operationMode == NET_BEARER_WIFI)
158 static const wchar_t _WIFI[] = L"http://tizen.org/feature/network.wifi";
160 bool isWifiSupported = false;
162 r = _SystemInfoImpl::GetSysInfo(_WIFI, isWifiSupported);
163 SysTryReturnResult(NID_NET, r == E_SUCCESS && isWifiSupported, E_UNSUPPORTED_OPERATION, "Wi-Fi is not supported.");
165 else if (operationMode == NET_BEARER_PS)
167 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
169 bool isTelephonySupported = false;
171 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
172 SysTryReturnResult(NID_NET, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
174 #endif // !_OSP_EMUL_
176 r = __pNetStatisticsImpl->ResetAll(operationMode);
177 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");