• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 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, // Use this error code when the service is exception.
33     SERVICE_NOT_ALLOW_ACCESS = 26300002, // Use this error code when the service does not allow access.
34     SERVICE_NOT_BOUND = 26300003, // Use this error code when the service has no binding relationship.
35 };
36 
37 class AsyncData : public RefBase {
38 public:
39     uint64_t deviceId;
40     napi_env env;
41     napi_ref bindCallback;
42     napi_ref onDisconnect;
43     napi_ref unbindCallback;
44     napi_deferred bindDeferred;
45     napi_deferred unbindDeferred;
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     }
55 };
56 
57 struct AsyncDataWorker {
58     napi_env env = nullptr;
59     napi_ref bindCallback = nullptr;
60     napi_ref onDisconnect = nullptr;
61     napi_ref unbindCallback = nullptr;
62 };
63 
64 class DeviceManagerCallback : public DriverExtMgrCallbackStub {
65 public:
66     ErrCode OnConnect(uint64_t deviceId, const sptr<IRemoteObject> &drvExtObj, const ErrMsg &errMsg) override;
67 
68     ErrCode OnDisconnect(uint64_t deviceId, const ErrMsg &errMsg) override;
69 
70     ErrCode OnUnBind(uint64_t deviceId, const ErrMsg &errMsg) override;
71 };
72 }
73 }
74 #endif