1 /*
2  * Copyright (c) 2023 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 "vpn_event_callback_proxy.h"
17 #include "netmgr_ext_log_wrapper.h"
18 
19 #include "ipc_types.h"
20 #include "parcel.h"
21 
22 namespace OHOS {
23 namespace NetManagerStandard {
VpnEventCallbackProxy(const sptr<IRemoteObject> & object)24 VpnEventCallbackProxy::VpnEventCallbackProxy(const sptr<IRemoteObject> &object)
25     : IRemoteProxy<IVpnEventCallback>(object)
26 {
27 }
28 
OnVpnStateChanged(const bool & isConnected)29 void VpnEventCallbackProxy::OnVpnStateChanged(const bool &isConnected)
30 {
31     MessageParcel data;
32     if (!data.WriteInterfaceToken(IVpnEventCallback::GetDescriptor())) {
33         NETMGR_EXT_LOG_E("write interface token failed");
34         return;
35     }
36 
37     if (!data.WriteBool(isConnected)) {
38         NETMGR_EXT_LOG_E("OnVpnStateChanged WriteBool error.");
39         return;
40     }
41 
42     sptr<IRemoteObject> remote = Remote();
43     if (remote == nullptr) {
44         NETMGR_EXT_LOG_E("OnVpnStateChanged get Remote() error.");
45         return;
46     }
47 
48     MessageParcel reply;
49     MessageOption option;
50     int32_t ret = remote->SendRequest(static_cast<uint32_t>(IVpnEventCallback::Message::GLOBAL_VPN_STATE_CHANGED), data,
51                                       reply, option);
52     if (ret != ERR_NONE) {
53         NETMGR_EXT_LOG_E("OnVpnStateChanged SendRequest error=[%{public}d].", ret);
54     }
55 }
56 
OnVpnMultiUserSetUp()57 void VpnEventCallbackProxy::OnVpnMultiUserSetUp()
58 {
59     MessageParcel data;
60     if (!data.WriteInterfaceToken(IVpnEventCallback::GetDescriptor())) {
61         NETMGR_EXT_LOG_E("write interface token failed");
62         return;
63     }
64 
65     sptr<IRemoteObject> remote = Remote();
66     if (remote == nullptr) {
67         NETMGR_EXT_LOG_E("OnVpnMultiUserSetUp get Remote() error.");
68         return;
69     }
70 
71     MessageParcel reply;
72     MessageOption option;
73     int32_t ret = remote->SendRequest(static_cast<uint32_t>(IVpnEventCallback::Message::GLOBAL_VPN_MULTI_USER_SETUP),
74                                       data, reply, option);
75     if (ret != ERR_NONE) {
76         NETMGR_EXT_LOG_E("OnVpnMultiUserSetUp SendRequest error=[%{public}d].", ret);
77     }
78 }
79 } // namespace NetManagerStandard
80 } // namespace OHOS
81