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 FNet_NetStatisticsImpl.cpp
19 * @brief This is the implementation for the FNet_NetStatisticsImpl class.
22 #include <net_connection.h>
23 #include <FNetNetTypes.h>
24 #include <FNetNetStatistics.h>
25 #include <FBaseSysLog.h>
26 #include "FNet_NetTypes.h"
27 #include "FNet_NetStatisticsImpl.h"
28 #include "FNet_NetIpcProxy.h"
30 using namespace Tizen::Base;
32 namespace Tizen { namespace Net
35 _NetStatisticsImpl::_NetStatisticsImpl(void)
36 : __isConstructed(false)
40 _NetStatisticsImpl::~_NetStatisticsImpl(void)
45 _NetStatisticsImpl::Construct()
48 int ret = CONNECTION_ERROR_NONE;
49 connection_h connectionHandle = null;
51 SysAssertf(!__isConstructed,
52 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
54 ret = connection_create(&connectionHandle);
55 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
56 "A system error has been occurred. The return value from connection_create() is %d", GetErrorMessage(E_SYSTEM), ret);
58 __pConnectionHandle.reset(connectionHandle);
59 __isConstructed = true;
65 _NetStatisticsImpl::GetNetStatisticsInfo(NetBearerType operationMode, NetStatisticsInfoType netStatType) const
67 int err = CONNECTION_ERROR_NONE;
68 long long returnVal = INVALID_HANDLE;
72 SysAssertf(__isConstructed, "Not yet constructed. Construct() should be called before use.");
74 SysTryReturn(NID_NET, (operationMode == NET_BEARER_WIFI || operationMode == NET_BEARER_PS), INVALID_HANDLE, E_INVALID_ARG,
75 "[%s] Invalid argument is used. operationMode=%d", GetErrorMessage(E_INVALID_ARG), operationMode);
77 //get net statistics info based on type
81 case NET_STAT_RCVD_SIZE:
82 if (operationMode == NET_BEARER_PS)
84 err = connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &returnVal);
85 SysLog(NID_NET, "Bearer type: NET_BEARER_PS, Statistics type: NET_STAT_RCVD_SIZE, Value returned: %d", returnVal);
87 else if (operationMode == NET_BEARER_WIFI)
89 err = connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &returnVal);
90 SysLog(NID_NET, "Bearer type: NET_BEARER_WIFI, Statistics type: NET_STAT_RCVD_SIZE, Value returned: %d", returnVal);
94 // should not reach here.
95 SysLog(NID_NET, "_NetStatisticsImpl::GetNetStatisticsInfo invalid mode: %d", operationMode);
96 SysTryReturn(NID_NET, false, INVALID_HANDLE, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
101 case NET_STAT_SENT_SIZE:
102 if (operationMode == NET_BEARER_PS)
104 err = connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &returnVal);
105 SysLog(NID_NET, "Bearer type: NET_BEARER_PS, Statistics type: NET_STAT_SENT_SIZE, Value returned: %d", returnVal);
107 else if (operationMode == NET_BEARER_WIFI)
109 err = connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &returnVal);
110 SysLog(NID_NET, "Bearer type: NET_BEARER_WIFI, Statistics type :NET_STAT_SENT_SIZE, Value returned: %d", returnVal);
114 // should not reach here.
115 SysLog(NID_NET, "_NetStatisticsImpl::GetNetStatisticsInfo invalid mode: %d", operationMode);
116 SysTryReturn(NID_NET, false, INVALID_HANDLE, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
121 case NET_STAT_TOTAL_RCVD_SIZE:
122 if (operationMode == NET_BEARER_PS)
124 err = connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &returnVal);
125 SysLog(NID_NET, "Bearer type: NET_BEARER_PS, Statistics type: NET_STAT_TOTAL_RCVD_SIZE, Value returned: %d", returnVal);
127 else if (operationMode == NET_BEARER_WIFI)
129 err = connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &returnVal);
130 SysLog(NID_NET, "Bearer type: NET_BEARER_WIFI, Statistics type: NET_STAT_TOTAL_RCVD_SIZE, Value returned: %d", returnVal);
134 // should not reach here.
135 SysLog(NID_NET, "_NetStatisticsImpl::GetNetStatisticsInfo invalid mode: %d", operationMode);
136 SysTryReturn(NID_NET, false, INVALID_HANDLE, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
141 case NET_STAT_TOTAL_SENT_SIZE:
142 if (operationMode == NET_BEARER_PS)
144 err = connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &returnVal);
145 SysLog(NID_NET, "Bearer type: NET_BEARER_PS, Statistics type: NET_STAT_TOTAL_SENT_SIZE, Value returned: %d", returnVal);
147 else if (operationMode == NET_BEARER_WIFI)
149 err = connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &returnVal);
150 SysLog(NID_NET, "Bearer type: NET_BEARER_WIFI, Statistics type: NET_STAT_TOTAL_SENT_SIZE, Value returned: %d", returnVal);
154 // should not reach here.
155 SysLog(NID_NET, "_NetStatisticsImpl::GetNetStatisticsInfo invalid mode: %d", operationMode);
156 SysTryReturn(NID_NET, false, INVALID_HANDLE, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
162 SysTryReturn(NID_NET, false, INVALID_HANDLE, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
167 // make sure u catch error
168 SysLog(NID_NET, "_NetStatisticsImpl::GetNetStatisticsInfo err code: %d", err);
169 SysTryReturn(NID_NET, err == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
170 "[%s] A system error has been occurred. Operation failed .", GetErrorMessage(E_SYSTEM));
176 _NetStatisticsImpl::Reset(NetBearerType operationMode, NetStatisticsInfoType netStatType)
178 SysAssertf(__isConstructed, "Not yet constructed. Construct() should be called before use.");
180 result r = E_SUCCESS;
182 _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
183 SysTryReturnResult(NID_NET, pProxy != null, E_SYSTEM,
184 "A system error has been occurred. Failed to get an IPC proxy.");
186 r = pProxy->ResetNetStatistics(operationMode, netStatType);
187 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
193 _NetStatisticsImpl::ResetAll(NetBearerType operationMode)
195 SysAssertf(__isConstructed, "Not yet constructed. Construct() should be called before use.");
197 result r = E_SUCCESS;
199 _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
200 SysTryReturnResult(NID_NET, pProxy != null, E_SYSTEM,
201 "A system error has been occurred. Failed to get an IPC proxy.");
203 r = pProxy->ResetAllNetStatistics(operationMode);
204 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
210 _NetStatisticsImpl::GetInstance(NetStatistics& netStatistics)
212 return netStatistics.__pNetStatisticsImpl;
215 const _NetStatisticsImpl*
216 _NetStatisticsImpl::GetInstance(const NetStatistics& netStatistics)
218 return netStatistics.__pNetStatisticsImpl;