1/* 2 * Copyright (c) 2022 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_bulkcallback_impl.h" 17#include "message_option.h" 18#include "message_parcel.h" 19#include "usbd_bulk_callback.h" 20#include "usb_errors.h" 21#include "hilog_wrapper.h" 22 23namespace OHOS { 24namespace USB { 25int32_t UsbdBulkCallbackImpl::OnBulkWriteCallback(int32_t status, int32_t actLength) 26{ 27 if (remote_ == nullptr) { 28 USB_HILOGE(MODULE_USB_SERVICE, "%{public}s: remote_ is nullptr", __func__); 29 return UEC_SERVICE_INVALID_VALUE; 30 } 31 OHOS::MessageParcel data; 32 OHOS::MessageParcel reply; 33 OHOS::MessageOption option; 34 if (!data.WriteInt32(status)) { 35 USB_HILOGE(MODULE_USB_SERVICE, "%{public}s: write status failed", __func__); 36 return UEC_SERVICE_INVALID_VALUE; 37 } 38 if (!data.WriteInt32(actLength)) { 39 USB_HILOGE(MODULE_USB_SERVICE, "%{public}s: write actLength failed", __func__); 40 return UEC_SERVICE_INVALID_VALUE; 41 } 42 int32_t ret = remote_->SendRequest(UsbdBulkCallBack::CMD_USBD_BULK_CALLBACK_WRITE, data, reply, option); 43 if (ret != UEC_OK) { 44 USB_HILOGE(MODULE_USB_SERVICE, "%{public}s failed, error code is %{public}d", __func__, ret); 45 return ret; 46 } 47 return UEC_OK; 48} 49 50int32_t UsbdBulkCallbackImpl::OnBulkReadCallback(int32_t status, int32_t actLength) 51{ 52 if (remote_ == nullptr) { 53 USB_HILOGE(MODULE_USB_SERVICE, "%{public}s: remote_ is nullptr", __func__); 54 return UEC_SERVICE_INVALID_VALUE; 55 } 56 OHOS::MessageParcel data; 57 if (!data.WriteInt32(status)) { 58 USB_HILOGE(MODULE_USB_SERVICE, "%{public}s: write status failed", __func__); 59 return UEC_SERVICE_INVALID_VALUE; 60 } 61 if (!data.WriteInt32(actLength)) { 62 USB_HILOGE(MODULE_USB_SERVICE, "%{public}s: write actLength failed", __func__); 63 return UEC_SERVICE_INVALID_VALUE; 64 } 65 OHOS::MessageParcel reply; 66 OHOS::MessageOption option; 67 int32_t ret = remote_->SendRequest(UsbdBulkCallBack::CMD_USBD_BULK_CALLBACK_READ, data, reply, option); 68 if (ret != UEC_OK) { 69 USB_HILOGE(MODULE_USB_SERVICE, "%{public}s failed, error code is %{public}d", __func__, ret); 70 return ret; 71 } 72 return UEC_OK; 73} 74} // namespace USB 75} // namespace OHOS 76