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 "usb_request.h"
17 #include "usb_common.h"
18 #include "usb_srv_client.h"
19
20 namespace OHOS {
21 namespace USB {
UsbRequest()22 UsbRequest::UsbRequest() : usbClient((uint8_t *)(&UsbSrvClient::GetInstance())) {}
Initialize(const USBDevicePipe & pipe,const USBEndpoint & endpoint)23 int32_t UsbRequest::Initialize(const USBDevicePipe &pipe, const USBEndpoint &endpoint)
24 {
25 this->pipe = pipe;
26 this->endpoint = endpoint;
27 int32_t ret = ((UsbSrvClient *)usbClient)->RequestInitialize(*this);
28 if (ERR_OK != ret) {
29 USB_HILOGE(MODULE_USB_INNERKIT, "UsbRequest::%{public}s:%{public}d failed width ret = %{public}d.", __func__,
30 __LINE__, ret);
31 }
32 return ret;
33 }
34
Queue()35 int32_t UsbRequest::Queue()
36 {
37 int32_t ret = ((UsbSrvClient *)usbClient)->RequestQueue(*this);
38 if (ERR_OK != ret) {
39 USB_HILOGE(MODULE_USB_INNERKIT, "UsbRequest::%{public}s:%{public}d failed width ret = %{public}d.", __func__,
40 __LINE__, ret);
41 }
42 return ret;
43 }
44
Free()45 int32_t UsbRequest::Free()
46 {
47 int32_t ret = ((UsbSrvClient *)usbClient)->RequestFree(*this);
48 if (ERR_OK != ret) {
49 USB_HILOGE(MODULE_USB_INNERKIT, "UsbRequest::%{public}s:%{public}d failed width ret = %{public}d.", __func__,
50 __LINE__, ret);
51 }
52 return ret;
53 }
54
Abort()55 int32_t UsbRequest::Abort()
56 {
57 int32_t ret = ((UsbSrvClient *)usbClient)->RequestAbort(*this);
58 if (ERR_OK != ret) {
59 USB_HILOGE(MODULE_USB_INNERKIT, "UsbRequest::%{public}s:%{public}d failed width ret = %{public}d.", __func__,
60 __LINE__, ret);
61 }
62 return ret;
63 }
64 } // namespace USB
65 } // namespace OHOS
66