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 #include "usbd_bulk_callback.h"
17
18 #include "hilog_wrapper.h"
19 #include "usb_errors.h"
20
21 namespace OHOS::USB {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)22 int32_t UsbdBulkCallBack::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
23 MessageOption &option)
24 {
25 switch (code) {
26 case CMD_USBD_BULK_CALLBACK_WRITE: {
27 int32_t status;
28 int32_t actLength;
29 if (!data.ReadInt32(status)) {
30 USB_HILOGE(MODULE_USB_INNERKIT, "get status error");
31 return UEC_SERVICE_WRITE_PARCEL_ERROR;
32 }
33 if (!data.ReadInt32(actLength)) {
34 USB_HILOGE(MODULE_USB_INNERKIT, "get actLength error");
35 return UEC_SERVICE_WRITE_PARCEL_ERROR;
36 }
37 USB_HILOGI(MODULE_USB_INNERKIT, "status:%{public}d actLength:%{public}d", status, actLength);
38 OnBulkWriteCallback(status, actLength);
39 break;
40 }
41 case CMD_USBD_BULK_CALLBACK_READ: {
42 int32_t status;
43 int32_t actLength;
44 if (!data.ReadInt32(status)) {
45 USB_HILOGE(MODULE_USB_INNERKIT, "get status error code=%{public}u", code);
46 return UEC_SERVICE_WRITE_PARCEL_ERROR;
47 }
48 if (!data.ReadInt32(actLength)) {
49 USB_HILOGE(MODULE_USB_INNERKIT, "get actLength error code=%{public}u", code);
50 return UEC_SERVICE_WRITE_PARCEL_ERROR;
51 }
52 USB_HILOGI(MODULE_USB_INNERKIT, "%{public}d status:%{public}d actLength:%{public}d", __LINE__, status,
53 actLength);
54 OnBulkReadCallback(status, actLength);
55 break;
56 }
57 default: {
58 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
59 }
60 }
61 return UEC_OK;
62 }
63 } // namespace OHOS::USB
64