1 /* 2 * Copyright (c) 2025 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 OHOS_DRIVER_DEVICE_MANAGER_IMPL_H 16 #define OHOS_DRIVER_DEVICE_MANAGER_IMPL_H 17 18 #include <cinttypes> 19 20 #include "hilog_wrapper.h" 21 #include "idriver_ext_mgr_callback.h" 22 #include "driver_ext_mgr_callback_stub.h" 23 #include "driver_ext_mgr_client.h" 24 #include "event_handler.h" 25 #include <ani.h> 26 27 namespace OHOS { 28 namespace ExternalDeviceManager { 29 enum ErrorCode : int32_t { 30 PERMISSION_DENIED = 201, // Use this error code when permission is denied. 31 PERMISSION_NOT_SYSTEM_APP = 202, 32 PARAMETER_ERROR = 401, // Use this error code when the input parameter type or range does not match. 33 SERVICE_EXCEPTION = 22900001, // Use this error code when the service is exception. 34 SERVICE_EXCEPTION_NEW = 26300001, // Use this error code when the service is exception. 35 SERVICE_NOT_ALLOW_ACCESS = 26300002, // Use this error code when the service does not allow access. 36 SERVICE_NOT_BOUND = 26300003, // Use this error code when the service has no binding relationship. 37 }; 38 39 ani_object BindDriverWithDeviceIdSync([[maybe_unused]] ani_env *env, ani_long deviceId, ani_object onDisconnect); 40 41 class AsyncData : public RefBase { 42 public: 43 uint64_t deviceId; 44 ani_vm *vm = nullptr; 45 ani_env *env = nullptr; 46 ani_ref onDisconnect; 47 ani_resolver bindDeferred; 48 ErrMsg unBindErrMsg; 49 50 void DeleteNapiRef(); AsyncData(ani_vm * vm,ani_env * env)51 AsyncData(ani_vm *vm, ani_env *env): vm(vm), env(env) {} ~AsyncData()52 ~AsyncData() 53 { 54 EDM_LOGE(MODULE_DEV_MGR, "Release callback data: %{public}016" PRIX64, deviceId); 55 DeleteNapiRef(); 56 } 57 }; 58 59 class DeviceManagerCallback : public DriverExtMgrCallbackStub { 60 public: 61 ErrCode OnConnect(uint64_t deviceId, const sptr<IRemoteObject> &drvExtObj, const ErrMsg &errMsg) override; 62 63 ErrCode OnDisconnect(uint64_t deviceId, const ErrMsg &errMsg) override; 64 65 ErrCode OnUnBind(uint64_t deviceId, const ErrMsg &errMsg) override; 66 }; 67 } 68 } 69 #endif 70