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 
16 #ifndef DM_BINDING_INTERNAL_H
17 #define DM_BINDING_INTERNAL_H
18 
19 #include "dm_device_info.h"
20 
21 #include "dm_binding.h"
22 
23 struct CDmDeviceInfo {
24     char* deviceId;
25     char* deviceName;
26     uint16_t deviceTypeId;
27     char* networkId;
28     int32_t range;
29     CDmAuthForm authForm;
30 };
31 
32 struct CRegisterDevStateCallback {
33     void (*onDeviceOnline)(const CDmDeviceInfo* deviceInfo);
34     void (*onDeviceChanged)(const CDmDeviceInfo* deviceInfo);
35     void (*onDeviceReady)(const CDmDeviceInfo* deviceInfo);
36     void (*onDeviceOffline)(const CDmDeviceInfo* deviceInfo);
37 };
38 
39 class DeviceInitCallBack : public OHOS::DistributedHardware::DmInitCallback {
40 public:
41     explicit DeviceInitCallBack(void (*cb)());
42 
43     void OnRemoteDied() override;
44 private:
45     void (*callback_)();
46 };
47 
48 class DmDeviceStateCallback : public OHOS::DistributedHardware::DeviceStateCallback {
49 public:
50     explicit DmDeviceStateCallback(CRegisterDevStateCallback callbacks);
51 
52 private:
53     void OnDeviceOnline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
54     void OnDeviceChanged(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
55     void OnDeviceReady(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
56     void OnDeviceOffline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
57 
58 private:
59     void InitCallback(CRegisterDevStateCallback callbacks);
60     CDmDeviceInfo* CreateCDeviceInfo(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo);
61 
62     void (*onlineCallback_)(const CDmDeviceInfo*);
63     void (*changedCallback_)(const CDmDeviceInfo*);
64     void (*readyCallback_)(const CDmDeviceInfo*);
65     void (*offlineCallback_)(const CDmDeviceInfo*);
66 };
67 
68 #endif // DM_BINDING_INTERNAL_H