• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 
16 #ifndef OHOS_DISTRIBUTED_HARDWARE_FWK_KIT_H
17 #define OHOS_DISTRIBUTED_HARDWARE_FWK_KIT_H
18 
19 #include <atomic>
20 #include <cstdint>
21 #include <mutex>
22 #include <unordered_map>
23 #include <set>
24 #include "refbase.h"
25 
26 #include "distributed_hardware_fwk_kit_paras.h"
27 #include "dhardware_descriptor.h"
28 #include "ipublisher_listener.h"
29 #include "idistributed_hardware.h"
30 #include "iget_dh_descriptors_callback.h"
31 #include "ihardware_status_listener.h"
32 #include "device_type.h"
33 #include "av_trans_types.h"
34 #include "iav_trans_control_center_callback.h"
35 
36 #ifndef API_EXPORT
37 #define API_EXPORT __attribute__((visibility("default")))
38 #endif
39 
40 namespace OHOS {
41 namespace DistributedHardware {
42 class DistributedHardwareFwkKit final {
43 public:
44     /**
45      * @brief Constructor.
46      * @return No return value.
47      */
48     API_EXPORT DistributedHardwareFwkKit();
49 
50     /**
51      * @brief Destructor.
52      * @return No return value.
53      */
54     API_EXPORT ~DistributedHardwareFwkKit();
55 
56     /**
57      * @brief Register publisher listener.
58      * @param topic    Distributed hardware topic.
59      * @param listener Publisher listener.
60      * @return Returns 0 if success.
61      */
62     API_EXPORT int32_t RegisterPublisherListener(const DHTopic topic, sptr<IPublisherListener> listener);
63 
64     /**
65      * @brief Unregister publisher listener.
66      * @param topic    Distributed hardware topic.
67      * @param listener Publisher listener.
68      * @return Returns 0 if success.
69      */
70     API_EXPORT int32_t UnregisterPublisherListener(const DHTopic topic, sptr<IPublisherListener> listener);
71 
72     /**
73      * @brief Publish message.
74      * @param topic   Distributed hardware topic.
75      * @param message Message content.
76      * @return Returns 0 if success.
77      */
78     API_EXPORT int32_t PublishMessage(const DHTopic topic, const std::string &message);
79 
80     /**
81      * @brief Distributed hardware framework online.
82      * @param isOnLine Online or not.
83      * @return No return value.
84      */
85     void OnDHFWKOnLine(bool isOnLine);
86 
87     /**
88      * @brief Query Local system specifications
89      *
90      * @param spec specification type
91      * @return specification in string format
92      */
93     API_EXPORT std::string QueryLocalSysSpec(QueryLocalSysSpecType spec);
94 
95     /**
96      * @brief Initialize distributed av control center
97      *
98      * @param transRole transport role, eg. sender or receiver
99      * @param engineId  transport engine id
100      * @return Returns 0 if success.
101      */
102     API_EXPORT int32_t InitializeAVCenter(const TransRole &transRole, int32_t &engineId);
103 
104     /**
105      * @brief Release distributed av control center
106      *
107      * @param engineId  transport engine id
108      * @return Returns 0 if success.
109      */
110     API_EXPORT int32_t ReleaseAVCenter(int32_t engineId);
111 
112     /**
113      * @brief Create control channel betweent the local and the remote av control center
114      *
115      * @param engineId  transport engine id
116      * @param peerDevId the peer device id
117      * @return Returns 0 if success.
118      */
119     API_EXPORT int32_t CreateControlChannel(int32_t engineId, const std::string &peerDevId);
120 
121     /**
122      * @brief Notify event from transport engine to av control center
123      *
124      * @param engineId  transport engine id
125      * @param event the event content
126      * @return Returns 0 if success.
127      */
128     API_EXPORT int32_t NotifyAVCenter(int32_t engineId, const AVTransEvent &event);
129 
130     /**
131      * @brief Register av control center callback.
132      *
133      * @param engineId  transport engine id
134      * @param callback av control center callback.
135      * @return Returns 0 if success.
136      */
137     API_EXPORT int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr<IAvTransControlCenterCallback> callback);
138 
139     /**
140      * @brief Pause distributed hardware.
141      *
142      * @param dhType  distributed hardware type
143      * @param networkId distributed hardware networkId.
144      * @return Returns 0 if success.
145      */
146     API_EXPORT int32_t PauseDistributedHardware(DHType dhType, const std::string &networkId);
147 
148     /**
149      * @brief Resume distributed hardware.
150      *
151      * @param dhType  distributed hardware type
152      * @param networkId distributed hardware networkId.
153      * @return Returns 0 if success.
154      */
155     API_EXPORT int32_t ResumeDistributedHardware(DHType dhType, const std::string &networkId);
156 
157     /**
158      * @brief Stop distributed hardware.
159      *
160      * @param dhType  distributed hardware type
161      * @param networkId distributed hardware networkId.
162      * @return Returns 0 if success.
163      */
164     API_EXPORT int32_t StopDistributedHardware(DHType dhType, const std::string &networkId);
165 
166     /**
167      * @brief Get distributed hardware.
168      *
169      * @param networkId distributed hardware networkId.
170      * @param descriptors distributed hardware descriptor list.
171      * @return Returns 0 if success.
172      */
173     API_EXPORT int32_t GetDistributedHardware(const std::string &networkId, EnableStep enableStep,
174         const sptr<IGetDhDescriptorsCallback> callback);
175 
176     /**
177      * @brief Register distributed hardware status listener.
178      *
179      * @param listener distributed hardware status listener.
180      * @return Returns 0 if success.
181      */
182     API_EXPORT int32_t RegisterDHStatusListener(sptr<IHDSinkStatusListener> listener);
183 
184     /**
185      * @brief Unregister distributed hardware status listener.
186      *
187      * @param listener distributed hardware status listener.
188      * @return Returns 0 if success.
189      */
190     API_EXPORT int32_t UnregisterDHStatusListener(sptr<IHDSinkStatusListener> listener);
191 
192     /**
193      * @brief Register distributed hardware status listener.
194      *
195      * @param networkId distributed hardware networkId.
196      * @param listener distributed hardware status listener.
197      * @return Returns 0 if success.
198      */
199     API_EXPORT int32_t RegisterDHStatusListener(const std::string &networkId, sptr<IHDSourceStatusListener> listener);
200 
201     /**
202      * @brief Unregister distributed hardware status listener.
203      *
204      * @param networkId distributed hardware networkId.
205      * @param listener distributed hardware status listener.
206      * @return Returns 0 if success.
207      */
208     API_EXPORT int32_t UnregisterDHStatusListener(const std::string &networkId, sptr<IHDSourceStatusListener> listener);
209 
210     /**
211      * @brief Enable distributed hardware sink.
212      *
213      * @param descriptors distributed hardware descriptor list.
214      * @return Returns 0 if success.
215      */
216     API_EXPORT int32_t EnableSink(const std::vector<DHDescriptor> &descriptors);
217 
218     /**
219      * @brief Disable distributed hardware sink.
220      *
221      * @param descriptors distributed hardware descriptor list.
222      * @return Returns 0 if success.
223      */
224     API_EXPORT int32_t DisableSink(const std::vector<DHDescriptor> &descriptors);
225 
226     /**
227      * @brief Enable distributed hardware source.
228      *
229      * @param networkId distributed hardware networkId.
230      * @param descriptors distributed hardware descriptor list.
231      * @return Returns 0 if success.
232      */
233     API_EXPORT int32_t EnableSource(const std::string &networkId, const std::vector<DHDescriptor> &descriptors);
234 
235     /**
236      * @brief Disable distributed hardware source.
237      *
238      * @param networkId distributed hardware networkId.
239      * @param descriptors distributed hardware descriptor list.
240      * @return Returns 0 if success.
241      */
242     API_EXPORT int32_t DisableSource(const std::string &networkId, const std::vector<DHDescriptor> &descriptors);
243 
244     /**
245      * @brief Load distributed HDF.
246      *
247      * @param dhType distributed hardware type.
248      * @return Returns 0 if success.
249      */
250     API_EXPORT int32_t LoadDistributedHDF(const DHType dhType);
251 
252     /**
253      * @brief Unload distributed HDF.
254      *
255      * @param dhType distributed hardware type.
256      * @return Returns 0 if success.
257      */
258     API_EXPORT int32_t UnLoadDistributedHDF(const DHType dhType);
259 
260 private:
261     /**
262      * @brief Determine whether the topic is valid.
263      * @param topic Distributed hardware topic.
264      * @return Returns true if success.
265      */
266     bool IsDHTopicValid(DHTopic topic);
267 
268     /**
269      * @brief Determine whether the QueryLocalSysSpecType is valid.
270      * @param topic Query Local Sys Spec Type.
271      * @return Returns true if success.
272      */
273     bool IsQueryLocalSysSpecTypeValid(QueryLocalSysSpecType spec);
274 
275     /**
276      * @brief Load distributed hardware SA.
277      *
278      * @return Returns 0 if success.
279      */
280     int32_t LoadDistributedHardwareSA();
281 
282 private:
283     std::atomic<bool> isDHFWKOnLine_;
284     std::mutex dfwkLoadServiceMutex_;
285 };
286 } // namespace DistributedHardware
287 } // namespace OHOS
288 #endif // OHOS_DISTRIBUTED_HARDWARE_FWK_KIT_H