• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_MANAGER_H
17 #define NET_STATS_MANAGER_H
18 
19 #include <string>
20 
21 #include "parcel.h"
22 #include "singleton.h"
23 
24 #include "i_net_stats_service.h"
25 #include "net_stats_constants.h"
26 #include "net_stats_info.h"
27 
28 namespace OHOS {
29 namespace NetManagerStandard {
30 class NetStatsClient {
31     DECLARE_DELAYED_SINGLETON(NetStatsClient)
32 
33 public:
34     int32_t RegisterNetStatsCallback(const sptr<INetStatsCallback> &callback);
35     int32_t UnregisterNetStatsCallback(const sptr<INetStatsCallback> &callback);
36     int64_t GetIfaceRxBytes(const std::string &interfaceName);
37     int64_t GetIfaceTxBytes(const std::string &interfaceName);
38     int64_t GetCellularRxBytes();
39     int64_t GetCellularTxBytes();
40     int64_t GetAllRxBytes();
41     int64_t GetAllTxBytes();
42     int64_t GetUidRxBytes(uint32_t uid);
43     int64_t GetUidTxBytes(uint32_t uid);
44 
45 private:
46     class NetStatsDeathRecipient : public IRemoteObject::DeathRecipient {
47     public:
NetStatsDeathRecipient(NetStatsClient & client)48         explicit NetStatsDeathRecipient(NetStatsClient &client) : client_(client) {}
49         ~NetStatsDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)50         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
51         {
52             client_.OnRemoteDied(remote);
53         }
54 
55     private:
56         NetStatsClient &client_;
57     };
58 
59 private:
60     sptr<INetStatsService> GetProxy();
61     void OnRemoteDied(const wptr<IRemoteObject> &remote);
62 
63 private:
64     std::mutex mutex_;
65     sptr<INetStatsService> netStatsService_;
66     sptr<IRemoteObject::DeathRecipient> deathRecipient_;
67 };
68 } // namespace NetManagerStandard
69 } // namespace OHOS
70 #endif // NET_STATS_MANAGER_H