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()
49 SysAssertf(!__isConstructed,
50 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
52 __isConstructed = true;
58 _NetStatisticsImpl::GetNetStatisticsInfo(NetBearerType operationMode, NetStatisticsInfoType netStatType) const
60 int err = CONNECTION_ERROR_NONE;
61 long long returnVal = INVALID_HANDLE;
65 SysAssertf(__isConstructed, "Not yet constructed. Construct() should be called before use.");
67 SysTryReturn(NID_NET, (operationMode == NET_BEARER_WIFI || operationMode == NET_BEARER_PS), INVALID_HANDLE, E_INVALID_ARG,
68 "[%s] Invalid argument is used. operationMode=%d", GetErrorMessage(E_INVALID_ARG), operationMode);
70 //get net statistics info based on type
74 case NET_STAT_RCVD_SIZE:
75 if (operationMode == NET_BEARER_PS)
77 err = connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &returnVal);
78 SysLog(NID_NET, "Bearer type: NET_BEARER_PS, Statistics type: NET_STAT_RCVD_SIZE, Value returned: %d", returnVal);
80 else if (operationMode == NET_BEARER_WIFI)
82 err = connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &returnVal);
83 SysLog(NID_NET, "Bearer type: NET_BEARER_WIFI, Statistics type: NET_STAT_RCVD_SIZE, Value returned: %d", returnVal);
87 // should not reach here.
88 SysLog(NID_NET, "_NetStatisticsImpl::GetNetStatisticsInfo invalid mode: %d", operationMode);
89 SysTryReturn(NID_NET, false, INVALID_HANDLE, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
94 case NET_STAT_SENT_SIZE:
95 if (operationMode == NET_BEARER_PS)
97 err = connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &returnVal);
98 SysLog(NID_NET, "Bearer type: NET_BEARER_PS, Statistics type: NET_STAT_SENT_SIZE, Value returned: %d", returnVal);
100 else if (operationMode == NET_BEARER_WIFI)
102 err = connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &returnVal);
103 SysLog(NID_NET, "Bearer type: NET_BEARER_WIFI, Statistics type :NET_STAT_SENT_SIZE, Value returned: %d", returnVal);
107 // should not reach here.
108 SysLog(NID_NET, "_NetStatisticsImpl::GetNetStatisticsInfo invalid mode: %d", operationMode);
109 SysTryReturn(NID_NET, false, INVALID_HANDLE, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
114 case NET_STAT_TOTAL_RCVD_SIZE:
115 if (operationMode == NET_BEARER_PS)
117 err = connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &returnVal);
118 SysLog(NID_NET, "Bearer type: NET_BEARER_PS, Statistics type: NET_STAT_TOTAL_RCVD_SIZE, Value returned: %d", returnVal);
120 else if (operationMode == NET_BEARER_WIFI)
122 err = connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &returnVal);
123 SysLog(NID_NET, "Bearer type: NET_BEARER_WIFI, Statistics type: NET_STAT_TOTAL_RCVD_SIZE, Value returned: %d", returnVal);
127 // should not reach here.
128 SysLog(NID_NET, "_NetStatisticsImpl::GetNetStatisticsInfo invalid mode: %d", operationMode);
129 SysTryReturn(NID_NET, false, INVALID_HANDLE, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
134 case NET_STAT_TOTAL_SENT_SIZE:
135 if (operationMode == NET_BEARER_PS)
137 err = connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &returnVal);
138 SysLog(NID_NET, "Bearer type: NET_BEARER_PS, Statistics type: NET_STAT_TOTAL_SENT_SIZE, Value returned: %d", returnVal);
140 else if (operationMode == NET_BEARER_WIFI)
142 err = connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &returnVal);
143 SysLog(NID_NET, "Bearer type: NET_BEARER_WIFI, Statistics type: NET_STAT_TOTAL_SENT_SIZE, Value returned: %d", returnVal);
147 // should not reach here.
148 SysLog(NID_NET, "_NetStatisticsImpl::GetNetStatisticsInfo invalid mode: %d", operationMode);
149 SysTryReturn(NID_NET, false, INVALID_HANDLE, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
155 SysTryReturn(NID_NET, false, INVALID_HANDLE, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
160 // make sure u catch error
161 SysLog(NID_NET, "_NetStatisticsImpl::GetNetStatisticsInfo err code: %d", err);
162 SysTryReturn(NID_NET, err == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
163 "[%s] A system error has been occurred. Operation failed .", GetErrorMessage(E_SYSTEM));
169 _NetStatisticsImpl::Reset(NetBearerType operationMode, NetStatisticsInfoType netStatType)
171 SysAssertf(__isConstructed, "Not yet constructed. Construct() should be called before use.");
173 result r = E_SUCCESS;
175 _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
176 SysTryReturnResult(NID_NET, pProxy != null, E_SYSTEM,
177 "A system error has been occurred. Failed to get an IPC proxy.");
179 r = pProxy->ResetNetStatistics(operationMode, netStatType);
180 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
186 _NetStatisticsImpl::ResetAll(NetBearerType operationMode)
188 SysAssertf(__isConstructed, "Not yet constructed. Construct() should be called before use.");
190 result r = E_SUCCESS;
192 _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
193 SysTryReturnResult(NID_NET, pProxy != null, E_SYSTEM,
194 "A system error has been occurred. Failed to get an IPC proxy.");
196 r = pProxy->ResetAllNetStatistics(operationMode);
197 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
203 _NetStatisticsImpl::GetInstance(NetStatistics& netStatistics)
205 return netStatistics.__pNetStatisticsImpl;
208 const _NetStatisticsImpl*
209 _NetStatisticsImpl::GetInstance(const NetStatistics& netStatistics)
211 return netStatistics.__pNetStatisticsImpl;