• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "driver_ext_mgr_callback_proxy.h"
17 #include "hilog_wrapper.h"
18 
19 namespace OHOS {
20 namespace ExternalDeviceManager {
OnConnect(uint64_t deviceId,const sptr<IRemoteObject> & drvExtObj,const ErrMsg & errMsg)21 void DriverExtMgrCallbackProxy::OnConnect(uint64_t deviceId, const sptr<IRemoteObject> &drvExtObj, const ErrMsg &errMsg)
22 {
23     sptr<IRemoteObject> remote = Remote();
24     if (remote == nullptr) {
25         EDM_LOGE(MODULE_DEV_MGR, "remote is nullptr");
26         return;
27     }
28 
29     MessageParcel data;
30     MessageParcel reply;
31     MessageOption option(MessageOption::TF_ASYNC);
32 
33     if (!data.WriteInterfaceToken(GetDescriptor())) {
34         EDM_LOGE(MODULE_FRAMEWORK, "failed to write interface token");
35         return;
36     }
37 
38     if (!errMsg.Marshalling(data)) {
39         EDM_LOGE(MODULE_DEV_MGR, "failed to write errMsg");
40         return;
41     }
42 
43     if (errMsg.IsOk()) {
44         if (!data.WriteUint64(deviceId)) {
45             EDM_LOGE(MODULE_DEV_MGR, "failed to write deviceId");
46             return;
47         }
48 
49         if (!data.WriteRemoteObject(drvExtObj)) {
50             EDM_LOGE(MODULE_DEV_MGR, "failed to write drvExtObj");
51             return;
52         }
53     }
54 
55     int32_t ret =
56         remote->SendRequest(static_cast<uint32_t>(DriverExtMgrCallbackInterfaceCode::ON_CONNECT), data, reply, option);
57     if (ret != UsbErrCode::EDM_OK) {
58         EDM_LOGE(MODULE_DEV_MGR, "SendRequest is failed, ret: %{public}d", ret);
59     }
60 }
61 
OnDisconnect(uint64_t deviceId,const ErrMsg & errMsg)62 void DriverExtMgrCallbackProxy::OnDisconnect(uint64_t deviceId, const ErrMsg &errMsg)
63 {
64     sptr<IRemoteObject> remote = Remote();
65     if (remote == nullptr) {
66         EDM_LOGE(MODULE_DEV_MGR, "remote is nullptr");
67         return;
68     }
69 
70     MessageParcel data;
71     MessageParcel reply;
72     MessageOption option(MessageOption::TF_ASYNC);
73 
74     if (!data.WriteInterfaceToken(GetDescriptor())) {
75         EDM_LOGE(MODULE_FRAMEWORK, "failed to write interface token");
76         return;
77     }
78 
79     if (!errMsg.Marshalling(data)) {
80         EDM_LOGE(MODULE_DEV_MGR, "failed to write errMsg");
81         return;
82     }
83 
84     if (errMsg.IsOk()) {
85         if (!data.WriteUint64(deviceId)) {
86             EDM_LOGE(MODULE_DEV_MGR, "failed to write deviceId");
87             return;
88         }
89     }
90 
91     int32_t ret = remote->SendRequest(
92         static_cast<uint32_t>(DriverExtMgrCallbackInterfaceCode::ON_DISCONNECT), data, reply, option);
93     if (ret != UsbErrCode::EDM_OK) {
94         EDM_LOGE(MODULE_DEV_MGR, "SendRequest is failed, ret: %{public}d", ret);
95     }
96 }
97 
OnUnBind(uint64_t deviceId,const ErrMsg & errMsg)98 void DriverExtMgrCallbackProxy::OnUnBind(uint64_t deviceId, const ErrMsg &errMsg)
99 {
100     sptr<IRemoteObject> remote = Remote();
101     if (remote == nullptr) {
102         EDM_LOGE(MODULE_DEV_MGR, "remote is nullptr");
103         return;
104     }
105 
106     MessageParcel data;
107     MessageParcel reply;
108     MessageOption option(MessageOption::TF_ASYNC);
109 
110     if (!data.WriteInterfaceToken(GetDescriptor())) {
111         EDM_LOGE(MODULE_FRAMEWORK, "failed to write interface token");
112         return;
113     }
114 
115     if (!errMsg.Marshalling(data)) {
116         EDM_LOGE(MODULE_DEV_MGR, "failed to write errMsg");
117         return;
118     }
119 
120     if (errMsg.IsOk()) {
121         if (!data.WriteUint64(deviceId)) {
122             EDM_LOGE(MODULE_DEV_MGR, "failed to write deviceId");
123             return;
124         }
125     }
126 
127     int32_t ret =
128         remote->SendRequest(static_cast<uint32_t>(DriverExtMgrCallbackInterfaceCode::ON_UNBIND), data, reply, option);
129     if (ret != UsbErrCode::EDM_OK) {
130         EDM_LOGE(MODULE_DEV_MGR, "SendRequest is failed, ret: %{public}d", ret);
131     }
132 }
133 } // namespace ExternalDeviceManager
134 } // namespace OHOS
135