1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "net_stats_history.h"
17 
18 #include "net_mgr_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
22 
GetHistory(std::vector<NetStatsInfo> & recv,uint64_t start,uint64_t end)23 int32_t NetStatsHistory::GetHistory(std::vector<NetStatsInfo> &recv, uint64_t start, uint64_t end)
24 {
25     auto handler = std::make_unique<NetStatsDataHandler>();
26     if (handler == nullptr) {
27         NETMGR_LOG_E("NetStatsDataHandler instance is nullptr");
28         return NETMANAGER_ERR_INTERNAL;
29     }
30     return handler->ReadStatsData(recv, start, end);
31 }
32 
GetHistory(std::vector<NetStatsInfo> & recv,uint32_t uid,uint64_t start,uint64_t end)33 int32_t NetStatsHistory::GetHistory(std::vector<NetStatsInfo> &recv, uint32_t uid, uint64_t start, uint64_t end)
34 {
35     auto handler = std::make_unique<NetStatsDataHandler>();
36     if (handler == nullptr) {
37         NETMGR_LOG_E("NetStatsDataHandler instance is nullptr");
38         return NETMANAGER_ERR_INTERNAL;
39     }
40     return handler->ReadStatsData(recv, uid, start, end);
41 }
42 
GetHistory(std::vector<NetStatsInfo> & recv,const std::string & iface,uint64_t start,uint64_t end)43 int32_t NetStatsHistory::GetHistory(std::vector<NetStatsInfo> &recv, const std::string &iface, uint64_t start,
44                                     uint64_t end)
45 {
46     auto handler = std::make_unique<NetStatsDataHandler>();
47     if (handler == nullptr) {
48         NETMGR_LOG_E("NetStatsDataHandler instance is nullptr");
49         return NETMANAGER_ERR_INTERNAL;
50     }
51     return handler->ReadStatsData(recv, iface, start, end);
52 }
53 
GetHistory(std::vector<NetStatsInfo> & recv,const std::string & iface,uint32_t uid,uint64_t start,uint64_t end)54 int32_t NetStatsHistory::GetHistory(std::vector<NetStatsInfo> &recv, const std::string &iface, uint32_t uid,
55                                     uint64_t start, uint64_t end)
56 {
57     auto handler = std::make_unique<NetStatsDataHandler>();
58     if (handler == nullptr) {
59         NETMGR_LOG_E("NetStatsDataHandler instance is nullptr");
60         return NETMANAGER_ERR_INTERNAL;
61     }
62     return handler->ReadStatsData(recv, iface, uid, start, end);
63 }
64 
GetHistoryByIdent(std::vector<NetStatsInfo> & recv,const std::string & ident,uint64_t start,uint64_t end)65 int32_t NetStatsHistory::GetHistoryByIdent(std::vector<NetStatsInfo> &recv, const std::string &ident, uint64_t start,
66                                            uint64_t end)
67 {
68     auto handler = std::make_unique<NetStatsDataHandler>();
69     if (handler == nullptr) {
70         NETMGR_LOG_E("NetStatsDataHandler instance is nullptr");
71         return NETMANAGER_ERR_INTERNAL;
72     }
73     return handler->ReadStatsDataByIdent(recv, ident, start, end);
74 }
75 
GetHistory(std::vector<NetStatsInfo> & recv,uint32_t uid,const std::string & ident,uint64_t start,uint64_t end)76 int32_t NetStatsHistory::GetHistory(std::vector<NetStatsInfo> &recv, uint32_t uid, const std::string &ident,
77                                     uint64_t start, uint64_t end)
78 {
79     auto handler = std::make_unique<NetStatsDataHandler>();
80     if (handler == nullptr) {
81         NETMGR_LOG_E("NetStatsDataHandler instance is nullptr");
82         return NETMANAGER_ERR_INTERNAL;
83     }
84     return handler->ReadStatsData(recv, uid, ident, start, end);
85 }
86 } // namespace NetManagerStandard
87 } // namespace OHOS