1 /*
2  * Copyright (c) 2021-2024 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 OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SOURCE_H
17 #define OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SOURCE_H
18 
19 #include <memory>
20 #include <string>
21 
22 namespace OHOS {
23 namespace DistributedHardware {
24 const std::string COMPONENT_LOADER_GET_SOURCE_HANDLER = "GetSourceHardwareHandler";
25 class RegisterCallback {
26 public:
27     virtual int32_t OnRegisterResult(const std::string &networkId, const std::string &dhId, int32_t status,
28         const std::string &data) = 0;
29 };
30 
31 class UnregisterCallback {
32 public:
33     virtual int32_t OnUnregisterResult(const std::string &networkId, const std::string &dhId, int32_t status,
34         const std::string &data) = 0;
35 };
36 
37 struct EnableParam {
38     std::string sourceVersion;
39     std::string sourceAttrs;
40     std::string sinkVersion;
41     std::string sinkAttrs;
42     std::string subtype;
43 };
44 
45 enum class BusinessState : uint32_t {
46     UNKNOWN,
47     IDLE,
48     RUNNING,
49     PAUSING
50 };
51 
52 class DistributedHardwareStateListener {
53 public:
54     /**
55      * @brief report the business state of local virtual driver
56      *        corresponding the remote device with the device id and dhid.
57      *
58      * @param networkId the remote device networkId.
59      * @param dhId the remote device peripheral dhId.
60      * @param state business state.
61      */
62     virtual void OnStateChanged(const std::string &networkId, const std::string &dhId, const BusinessState state) = 0;
63 };
64 
65 class DataSyncTriggerListener {
66 public:
67     /**
68      * @brief trigger local distributed hardware open session with remote device with uuid
69      *
70      * @param networkId the remote device networkId
71      */
72     virtual void OnDataSyncTrigger(const std::string &networkId) = 0;
73 };
74 
75 class IDistributedHardwareSource {
76 public:
77     virtual int32_t InitSource(const std::string &params) = 0;
78     virtual int32_t ReleaseSource() = 0;
79     virtual int32_t RegisterDistributedHardware(const std::string &networkId, const std::string &dhId,
80         const EnableParam &param, std::shared_ptr<RegisterCallback> callback) = 0;
81     virtual int32_t UnregisterDistributedHardware(const std::string &networkId, const std::string &dhId,
82         std::shared_ptr<UnregisterCallback> callback) = 0;
83     virtual int32_t ConfigDistributedHardware(const std::string &networkId, const std::string &dhId,
84         const std::string &key, const std::string &value) = 0;
85     virtual void RegisterDistributedHardwareStateListener(
86         std::shared_ptr<DistributedHardwareStateListener> listener) = 0;
87     virtual void UnregisterDistributedHardwareStateListener() = 0;
88     virtual void RegisterDataSyncTriggerListener(std::shared_ptr<DataSyncTriggerListener> listener) = 0;
89     virtual void UnregisterDataSyncTriggerListener() = 0;
90 };
91 extern "C" __attribute__((visibility("default"))) IDistributedHardwareSource* GetSourceHardwareHandler();
92 } // namespace DistributedHardware
93 } // namespace OHOS
94 #endif
95