• 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 "notify_callback_stub.h"
16 
17 #include "netnative_log_wrapper.h"
18 
19 namespace OHOS {
20 namespace NetsysNative {
NotifyCallbackStub()21 NotifyCallbackStub::NotifyCallbackStub()
22 {
23     memberFuncMap_[ON_INTERFACE_ADDRESS_UPDATED] = &NotifyCallbackStub::CmdOnInterfaceAddressUpdated;
24     memberFuncMap_[ON_INTERFACE_ADDRESS_REMOVED] = &NotifyCallbackStub::CmdOnInterfaceAddressRemoved;
25     memberFuncMap_[ON_INTERFACE_ADDED] = &NotifyCallbackStub::CmdOnInterfaceAdded;
26     memberFuncMap_[ON_INTERFACE_REMOVED] = &NotifyCallbackStub::CmdOnInterfaceRemoved;
27     memberFuncMap_[ON_INTERFACE_CHANGED] = &NotifyCallbackStub::CmdOnInterfaceChanged;
28     memberFuncMap_[ON_INTERFACE_LINK_STATE_CHANGED] = &NotifyCallbackStub::CmdOnInterfaceLinkStateChanged;
29     memberFuncMap_[ON_ROUTE_CHANGED] = &NotifyCallbackStub::CmdOnRouteChanged;
30     memberFuncMap_[ON_DHCP_SUCCESS] = &NotifyCallbackStub::CmdDhcpSuccess;
31 }
32 
~NotifyCallbackStub()33 NotifyCallbackStub::~NotifyCallbackStub() {}
34 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)35 int32_t NotifyCallbackStub::OnRemoteRequest(
36     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
37 {
38     NETNATIVE_LOGI("Stub call start, code:[%{public}d]", code);
39     std::u16string myDescripter = NotifyCallbackStub::GetDescriptor();
40     std::u16string remoteDescripter = data.ReadInterfaceToken();
41     if (myDescripter != remoteDescripter) {
42         NETNATIVE_LOGE("Descriptor checked failed");
43         return ERR_FLATTEN_OBJECT;
44     }
45 
46     auto itFunc = memberFuncMap_.find(code);
47     if (itFunc != memberFuncMap_.end()) {
48         auto requestFunc = itFunc->second;
49         if (requestFunc != nullptr) {
50             return (this->*requestFunc)(data, reply);
51         }
52     }
53 
54     NETNATIVE_LOGI("Stub default case, need check");
55     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
56 }
57 
CmdOnInterfaceAddressUpdated(MessageParcel & data,MessageParcel & reply)58 int32_t NotifyCallbackStub::CmdOnInterfaceAddressUpdated(MessageParcel &data, MessageParcel &reply)
59 {
60     std::string str1 = "";
61     std::string str2 = "";
62 
63     int32_t result = OnInterfaceAddressUpdated(str1, str2, 0, 0);
64     if (!reply.WriteInt32(result)) {
65         NETNATIVE_LOGE("Write parcel failed");
66         return result;
67     }
68 
69     return ERR_NONE;
70 }
71 
CmdOnInterfaceAddressRemoved(MessageParcel & data,MessageParcel & reply)72 int32_t NotifyCallbackStub::CmdOnInterfaceAddressRemoved(MessageParcel &data, MessageParcel &reply)
73 {
74     std::string str1 = "";
75     std::string str2 = "";
76 
77     int32_t result = OnInterfaceAddressRemoved(str1, str2, 0, 0);
78     if (!reply.WriteInt32(result)) {
79         NETNATIVE_LOGE("Write parcel failed");
80         return result;
81     }
82 
83     return ERR_NONE;
84 }
85 
CmdOnInterfaceAdded(MessageParcel & data,MessageParcel & reply)86 int32_t NotifyCallbackStub::CmdOnInterfaceAdded(MessageParcel &data, MessageParcel &reply)
87 {
88     std::string str1 = "";
89 
90     int32_t result = OnInterfaceAdded(str1);
91     if (!reply.WriteInt32(result)) {
92         NETNATIVE_LOGE("Write parcel failed");
93         return result;
94     }
95 
96     return ERR_NONE;
97 }
CmdOnInterfaceRemoved(MessageParcel & data,MessageParcel & reply)98 int32_t NotifyCallbackStub::CmdOnInterfaceRemoved(MessageParcel &data, MessageParcel &reply)
99 {
100     std::string str1 = "";
101 
102     int32_t result = OnInterfaceRemoved(str1);
103     if (!reply.WriteInt32(result)) {
104         NETNATIVE_LOGE("Write parcel failed");
105         return result;
106     }
107 
108     return ERR_NONE;
109 }
110 
CmdOnInterfaceChanged(MessageParcel & data,MessageParcel & reply)111 int32_t NotifyCallbackStub::CmdOnInterfaceChanged(MessageParcel &data, MessageParcel &reply)
112 {
113     std::string str1 = "";
114 
115     int32_t result = OnInterfaceChanged(str1, true);
116     if (!reply.WriteInt32(result)) {
117         NETNATIVE_LOGE("Write parcel failed");
118         return result;
119     }
120 
121     return ERR_NONE;
122 }
123 
CmdOnInterfaceLinkStateChanged(MessageParcel & data,MessageParcel & reply)124 int32_t NotifyCallbackStub::CmdOnInterfaceLinkStateChanged(MessageParcel &data, MessageParcel &reply)
125 {
126     std::string str1 = "";
127 
128     int32_t result = OnInterfaceLinkStateChanged(str1, true);
129     if (!reply.WriteInt32(result)) {
130         NETNATIVE_LOGE("Write parcel failed");
131         return result;
132     }
133 
134     return ERR_NONE;
135 }
136 
CmdOnRouteChanged(MessageParcel & data,MessageParcel & reply)137 int32_t NotifyCallbackStub::CmdOnRouteChanged(MessageParcel &data, MessageParcel &reply)
138 {
139     std::string str1 = "";
140     std::string str2 = "";
141     std::string str3 = "";
142 
143     int32_t result = OnRouteChanged(true, str1, str2, str3);
144     if (!reply.WriteInt32(result)) {
145         NETNATIVE_LOGE("Write parcel failed");
146         return result;
147     }
148 
149     return ERR_NONE;
150 }
151 
CmdDhcpSuccess(MessageParcel & data,MessageParcel & reply)152 int32_t NotifyCallbackStub::CmdDhcpSuccess(MessageParcel &data, MessageParcel &reply)
153 {
154     NETNATIVE_LOGI("CmdDhcpSuccess");
155     static sptr<DhcpResultParcel> dhcpResult = DhcpResultParcel::Unmarshalling(data);
156     OnDhcpSuccess(dhcpResult);
157     return ERR_NONE;
158 }
159 } // namespace NetsysNative
160 } // namespace OHOS
161