merge with master
[framework/osp/net.git] / src / FNetNetStatistics.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17 /**
18  * @file                        FNetNetStatistics.cpp
19  * @brief               This is the implementation for the FNetNetStatistics class.
20  */
21
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 "FNet_NetStatisticsImpl.h"
29
30 using namespace std;
31 using namespace Tizen::Base;
32 using namespace Tizen::Security;
33
34 namespace Tizen { namespace Net
35 {
36
37 NetStatistics::NetStatistics(void)
38         : __pNetStatisticsImpl(null)
39 {
40 }
41
42 result
43 NetStatistics::Construct(void)
44 {
45         result r = E_SUCCESS;
46
47         SysAssertf(__pNetStatisticsImpl == null,
48                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
49
50         unique_ptr<_NetStatisticsImpl> pNetStatisticsImpl(new (std::nothrow) _NetStatisticsImpl());
51         SysTryReturnResult(NID_NET, pNetStatisticsImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
52
53         r = pNetStatisticsImpl->Construct();
54         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
55
56         __pNetStatisticsImpl = pNetStatisticsImpl.release();
57
58         return r;
59 }
60
61 NetStatistics::~NetStatistics(void)
62 {
63         delete __pNetStatisticsImpl;
64         __pNetStatisticsImpl = null;
65 }
66
67 long long
68 NetStatistics::GetNetStatisticsInfo(NetBearerType operationMode, NetStatisticsInfoType netStatType) const
69 {
70         result r = E_SUCCESS;
71         long long ret = INVALID_HANDLE;
72
73         ClearLastResult();
74
75         r = _AccessController::CheckUserPrivilege(_PRV_NETWORK_STATISTICS_READ, _PRV_NETWORK_STATISTICS);
76         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY);
77         SysTryReturn(NID_NET, r == E_SUCCESS, INVALID_HANDLE, r,
78                         "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r));
79
80         SysAssertf(__pNetStatisticsImpl != null, "Not yet constructed. Construct() should be called before use.");
81
82         ret = __pNetStatisticsImpl->GetNetStatisticsInfo(operationMode, netStatType);
83         r = GetLastResult();
84         SysTryReturn(NID_NET, r == E_SUCCESS, ret, r, "[%s] Propagating.", GetErrorMessage(r));
85
86         return ret;
87 }
88
89 result
90 NetStatistics::Reset(NetBearerType operationMode, NetStatisticsInfoType netStatType)
91 {
92         result r = E_SUCCESS;
93
94         SysAssertf(__pNetStatisticsImpl != null, "Not yet constructed. Construct() should be called before use.");
95
96         r = __pNetStatisticsImpl->Reset(operationMode, netStatType);
97         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
98
99         return r;
100 }
101
102 result
103 NetStatistics::ResetAll(NetBearerType operationMode)
104 {
105         result r = E_SUCCESS;
106
107         SysAssertf(__pNetStatisticsImpl != null, "Not yet constructed. Construct() should be called before use.");
108
109         r = __pNetStatisticsImpl->ResetAll(operationMode);
110         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
111
112         return r;
113 }
114
115 } } // Tizen::Net