• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 namespace OHOS {
24 namespace USB {
OnBulkWriteCallback(int32_t status,int32_t actLength)25 int32_t UsbdBulkCallbackImpl::OnBulkWriteCallback(int32_t status, int32_t actLength)
26 {
27     OHOS::MessageParcel data;
28     OHOS::MessageParcel reply;
29     OHOS::MessageOption option;
30     if (!data.WriteInt32(status)) {
31         USB_HILOGE(MODULE_USB_SERVICE, "%{public}s: write status failed", __func__);
32         return UEC_SERVICE_INVALID_VALUE;
33     }
34 
35     if (!data.WriteInt32(actLength)) {
36         USB_HILOGE(MODULE_USB_SERVICE, "%{public}s: write actLength failed", __func__);
37         return UEC_SERVICE_INVALID_VALUE;
38     }
39     int32_t ret = remote_->SendRequest(UsbdBulkCallBack::CMD_USBD_BULK_CALLBACK_WRITE, data, reply, option);
40     if (ret != UEC_OK) {
41         USB_HILOGE(MODULE_USB_SERVICE, "%{public}s failed, error code is %{public}d", __func__, ret);
42         return ret;
43     }
44     return UEC_OK;
45 }
46 
OnBulkReadCallback(int32_t status,int32_t actLength)47 int32_t UsbdBulkCallbackImpl::OnBulkReadCallback(int32_t status, int32_t actLength)
48 {
49     OHOS::MessageParcel data;
50     if (!data.WriteInt32(status)) {
51         USB_HILOGE(MODULE_USB_SERVICE, "%{public}s: write status failed", __func__);
52         return UEC_SERVICE_INVALID_VALUE;
53     }
54 
55     if (!data.WriteInt32(actLength)) {
56         USB_HILOGE(MODULE_USB_SERVICE, "%{public}s: write actLength failed", __func__);
57         return UEC_SERVICE_INVALID_VALUE;
58     }
59 
60     OHOS::MessageParcel reply;
61     OHOS::MessageOption option;
62     int32_t ret = remote_->SendRequest(UsbdBulkCallBack::CMD_USBD_BULK_CALLBACK_READ, data, reply, option);
63     if (ret != UEC_OK) {
64         USB_HILOGE(MODULE_USB_SERVICE, "%{public}s failed, error code is %{public}d", __func__, ret);
65         return ret;
66     }
67     return UEC_OK;
68 }
69 } // namespace USB
70 } // namespace OHOS