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 #ifndef DEVICE_MANAGER_MIDDLE_H 16 #define DEVICE_MANAGER_MIDDLE_H 17 18 #include "hilog_wrapper.h" 19 #include "napi/native_api.h" 20 #include "napi/native_node_api.h" 21 #include "idriver_ext_mgr_callback.h" 22 #include "driver_ext_mgr_callback_stub.h" 23 #include "driver_ext_mgr_client.h" 24 25 namespace OHOS { 26 namespace ExternalDeviceManager { 27 enum ErrorCode : int32_t { 28 PERMISSION_DENIED = 201, // Use this error code when permission is denied. 29 PERMISSION_NOT_SYSTEM_APP = 202, 30 PARAMETER_ERROR = 401, // Use this error code when the input parameter type or range does not match. 31 SERVICE_EXCEPTION = 22900001, // Use this error code when the service is exception. 32 SERVICE_EXCEPTION_NEW = 26300001 33 }; 34 35 class AsyncData : public RefBase { 36 public: 37 uint64_t deviceId; 38 napi_env env; 39 napi_ref bindCallback; 40 napi_ref onDisconnect; 41 napi_ref unbindCallback; 42 napi_deferred bindDeferred; 43 napi_deferred unbindDeferred; 44 sptr<IRemoteObject> drvExtObj; 45 ErrMsg errMsg; 46 ErrMsg unBindErrMsg; 47 48 void DeleteNapiRef(); 49 ~AsyncData()50 ~AsyncData() 51 { 52 EDM_LOGE(MODULE_DEV_MGR, "Release callback data: %{public}016" PRIX64, deviceId); 53 DeleteNapiRef(); 54 drvExtObj = nullptr; 55 } 56 }; 57 58 struct AsyncDataWorker { 59 napi_env env = nullptr; 60 napi_ref bindCallback = nullptr; 61 napi_ref onDisconnect = nullptr; 62 napi_ref unbindCallback = nullptr; 63 }; 64 65 class DeviceManagerCallback : public DriverExtMgrCallbackStub { 66 public: 67 void OnConnect(uint64_t deviceId, const sptr<IRemoteObject> &drvExtObj, const ErrMsg &errMsg) override; 68 69 void OnDisconnect(uint64_t deviceId, const ErrMsg &errMsg) override; 70 71 void OnUnBind(uint64_t deviceId, const ErrMsg &errMsg) override; 72 }; 73 } 74 } 75 #endif