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