• 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 #include "net_stats_callback_proxy.h"
16 #include "net_mgr_log_wrapper.h"
17 
18 namespace OHOS {
19 namespace NetManagerStandard {
NetStatsCallbackProxy(const sptr<IRemoteObject> & impl)20 NetStatsCallbackProxy::NetStatsCallbackProxy(const sptr<IRemoteObject> &impl)
21     : IRemoteProxy<INetStatsCallback>(impl)
22 {}
23 
~NetStatsCallbackProxy()24 NetStatsCallbackProxy::~NetStatsCallbackProxy() {}
25 
NetIfaceStatsChanged(const std::string & iface)26 int32_t NetStatsCallbackProxy::NetIfaceStatsChanged(const std::string &iface)
27 {
28     MessageParcel data;
29     if (!WriteInterfaceToken(data)) {
30         NETMGR_LOG_E("WriteInterfaceToken failed");
31         return ERR_FLATTEN_OBJECT;
32     }
33     NETMGR_LOG_D("proxy iface[%{public}s]", iface.c_str());
34     if (!data.WriteString(iface)) {
35         return ERR_NULL_OBJECT;
36     }
37 
38     sptr<IRemoteObject> remote = Remote();
39     if (remote == nullptr) {
40         NETMGR_LOG_E("Remote is null");
41         return ERR_NULL_OBJECT;
42     }
43 
44     MessageParcel reply;
45     MessageOption option;
46     int32_t ret = remote->SendRequest(NET_STATS_IFACE_CHANGED, data, reply, option);
47     if (ret != ERR_NONE) {
48         NETMGR_LOG_E("Proxy SendRequest failed, ret code:[%{public}d]", ret);
49     }
50     return ret;
51 }
52 
NetUidStatsChanged(const std::string & iface,uint32_t uid)53 int32_t NetStatsCallbackProxy::NetUidStatsChanged(const std::string &iface, uint32_t uid)
54 {
55     MessageParcel data;
56     if (!WriteInterfaceToken(data)) {
57         NETMGR_LOG_E("WriteInterfaceToken failed");
58         return ERR_FLATTEN_OBJECT;
59     }
60     NETMGR_LOG_D("proxy iface[%{public}s], uid[%{public}d]", iface.c_str(), uid);
61     if (!data.WriteString(iface)) {
62         return ERR_NULL_OBJECT;
63     }
64 
65     if (!data.WriteUint32(uid)) {
66         return ERR_NULL_OBJECT;
67     }
68 
69     sptr<IRemoteObject> remote = Remote();
70     if (remote == nullptr) {
71         NETMGR_LOG_E("Remote is null");
72         return ERR_NULL_OBJECT;
73     }
74 
75     MessageParcel reply;
76     MessageOption option;
77     int32_t ret = remote->SendRequest(NET_STATS_UID_CHANGED, data, reply, option);
78     if (ret != ERR_NONE) {
79         NETMGR_LOG_E("Proxy SendRequest failed, ret code:[%{public}d]", ret);
80     }
81     return ret;
82 }
83 
WriteInterfaceToken(MessageParcel & data)84 bool NetStatsCallbackProxy::WriteInterfaceToken(MessageParcel &data)
85 {
86     if (!data.WriteInterfaceToken(NetStatsCallbackProxy::GetDescriptor())) {
87         NETMGR_LOG_E("WriteInterfaceToken failed");
88         return false;
89     }
90     return true;
91 }
92 } // namespace NetManagerStandard
93 } // namespace OHOS
94