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 #include "driver_ext_mgr_client.h"
16 #include "hilog_wrapper.h"
17 #include "usb_ddk_api.h"
18
19 using namespace OHOS::ExternalDeviceManager;
20 namespace {
21 static DriverExtMgrClient &g_edmClient = DriverExtMgrClient::GetInstance();
22 }
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
OH_Usb_CreateDevice(uint32_t maxX,uint32_t maxY,uint32_t maxPressure)26 int32_t OH_Usb_CreateDevice(uint32_t maxX, uint32_t maxY, uint32_t maxPressure)
27 {
28 if (auto ret = g_edmClient.CreateDevice(maxX, maxY, maxPressure); ret != UsbErrCode::EDM_OK) {
29 EDM_LOGE(MODULE_USB_DDK, "create device failed:%{public}d", ret);
30 return ret;
31 }
32 return EDM_OK;
33 }
34
OH_Usb_EmitEvent(int32_t deviceId,const EmitItem items[],uint32_t length)35 int32_t OH_Usb_EmitEvent(int32_t deviceId, const EmitItem items[], uint32_t length)
36 {
37 if (length > MAX_EMIT_ITEM_NUM) {
38 EDM_LOGE(MODULE_DEV_MGR, "length out of range");
39 return EDM_ERR_INVALID_PARAM;
40 }
41
42 std::vector<EmitItem> itemsTmp(items, items + length);
43 if (auto ret = g_edmClient.EmitEvent(deviceId, itemsTmp); ret != UsbErrCode::EDM_OK) {
44 EDM_LOGE(MODULE_USB_DDK, "emit event failed:%{public}d", ret);
45 return ret;
46 }
47 return EDM_OK;
48 }
49
OH_Usb_DestroyDevice(int32_t deviceId)50 int32_t OH_Usb_DestroyDevice(int32_t deviceId)
51 {
52 if (auto ret = g_edmClient.DestroyDevice(); ret != UsbErrCode::EDM_OK) {
53 EDM_LOGE(MODULE_USB_DDK, "destroy device failed:%{public}d", ret);
54 return ret;
55 }
56 return EDM_OK;
57 }
58 #ifdef __cplusplus
59 }
60 #endif /* __cplusplus */
61