• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef NET_STATS_WRAPPER_H
17 #define NET_STATS_WRAPPER_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "netsys_bpf_stats.h"
23 
24 namespace OHOS {
25 namespace NetManagerStandard {
26 class NetStatsWrapper {
27 public:
28     ~NetStatsWrapper();
29 
30     static NetStatsWrapper &GetInstance();
31 
32     /**
33      * Get the Total Stats object
34      *
35      * @param type stats type
36      * @return int64_t Total traffic bytes
37      */
38     int64_t GetTotalStats(StatsType type);
39 
40     /**
41      * Get the Uid Stat object
42      *
43      * @param type stats type
44      * @param uid  uid
45      * @return int64_t traffic bytes for uid
46      */
47     int64_t GetUidStats(StatsType type, uint32_t uid);
48 
49     /**
50      * Get the Iface Stat object
51      *
52      * @param type stats type
53      * @param interfaceName iface name
54      * @return int64_t traffic bytes for iface
55      */
56     int64_t GetIfaceStats(StatsType type, const std::string &interfaceName);
57 
58 private:
59     NetStatsWrapper();
60 
61 private:
62     std::unique_ptr<NetsysBpfStats> netSysBpf_ = nullptr;
63     NetStatsWrapper(const NetStatsWrapper &) = delete;
64     NetStatsWrapper &operator=(const NetStatsWrapper &) = delete;
65 };
66 } // namespace NetManagerStandard
67 } // namespace OHOS
68 #endif // NET_STATS_WRAPPER_H