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 PARAMETER_ERROR = 401, // Use this error code when the input parameter type or range does not match. 30 SERVICE_EXCEPTION = 22900001 // Use this error code when the service is exception. 31 }; 32 33 class AsyncData : public RefBase { 34 public: 35 uint64_t deviceId; 36 napi_env env; 37 napi_ref bindCallback; 38 napi_ref onDisconnect; 39 napi_ref unbindCallback; 40 napi_deferred bindDeferred; 41 napi_deferred unbindDeferred; 42 sptr<IRemoteObject> drvExtObj; 43 ErrMsg errMsg; 44 ErrMsg unBindErrMsg; 45 46 void DeleteNapiRef(); 47 ~AsyncData()48 ~AsyncData() 49 { 50 EDM_LOGE(MODULE_DEV_MGR, "Release callback data: %{public}016" PRIX64, deviceId); 51 DeleteNapiRef(); 52 drvExtObj = nullptr; 53 } 54 }; 55 56 struct AsyncDataWorker { 57 napi_env env = nullptr; 58 napi_ref bindCallback = nullptr; 59 napi_ref onDisconnect = nullptr; 60 napi_ref unbindCallback = nullptr; 61 }; 62 63 class DeviceManagerCallback : public DriverExtMgrCallbackStub { 64 public: 65 void OnConnect(uint64_t deviceId, const sptr<IRemoteObject> &drvExtObj, const ErrMsg &errMsg) override; 66 67 void OnDisconnect(uint64_t deviceId, const ErrMsg &errMsg) override; 68 69 void OnUnBind(uint64_t deviceId, const ErrMsg &errMsg) override; 70 }; 71 } 72 } 73 #endif