1 /* 2 * Copyright (c) 2022-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 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 "ipublisher_listener.h" 28 #include "idistributed_hardware.h" 29 30 #ifndef API_EXPORT 31 #define API_EXPORT __attribute__((visibility("default"))) 32 #endif 33 34 namespace OHOS { 35 namespace DistributedHardware { 36 class DistributedHardwareFwkKit final { 37 public: 38 /** 39 * @brief Constructor. 40 * @return No return value. 41 */ 42 API_EXPORT DistributedHardwareFwkKit(); 43 44 /** 45 * @brief Destructor. 46 * @return No return value. 47 */ 48 API_EXPORT ~DistributedHardwareFwkKit(); 49 50 /** 51 * @brief Register publisher listener. 52 * @param topic Distributed hardware topic. 53 * @param listener Publisher listener. 54 * @return Returns 0 if success. 55 */ 56 API_EXPORT int32_t RegisterPublisherListener(const DHTopic topic, sptr<IPublisherListener> listener); 57 58 /** 59 * @brief Unregister publisher listener. 60 * @param topic Distributed hardware topic. 61 * @param listener Publisher listener. 62 * @return Returns 0 if success. 63 */ 64 API_EXPORT int32_t UnregisterPublisherListener(const DHTopic topic, sptr<IPublisherListener> listener); 65 66 /** 67 * @brief Publish message. 68 * @param topic Distributed hardware topic. 69 * @param message Message content. 70 * @return Returns 0 if success. 71 */ 72 API_EXPORT int32_t PublishMessage(const DHTopic topic, const std::string &message); 73 74 /** 75 * @brief Distributed hardware framework online. 76 * @param isOnLine Online or not. 77 * @return No return value. 78 */ 79 void OnDHFWKOnLine(bool isOnLine); 80 81 /** 82 * @brief Query Local system specifications 83 * 84 * @param spec specification type 85 * @return specification in string format 86 */ 87 API_EXPORT std::string QueryLocalSysSpec(QueryLocalSysSpecType spec); 88 89 /** 90 * @brief Initialize distributed av control center 91 * 92 * @param transRole transport role, eg. sender or receiver 93 * @param engineId transport engine id 94 * @return Returns 0 if success. 95 */ 96 API_EXPORT int32_t InitializeAVCenter(const TransRole &transRole, int32_t &engineId); 97 98 /** 99 * @brief Release distributed av control center 100 * 101 * @param engineId transport engine id 102 * @return Returns 0 if success. 103 */ 104 API_EXPORT int32_t ReleaseAVCenter(int32_t engineId); 105 106 /** 107 * @brief Create control channel betweent the local and the remote av control center 108 * 109 * @param engineId transport engine id 110 * @param peerDevId the peer device id 111 * @return Returns 0 if success. 112 */ 113 API_EXPORT int32_t CreateControlChannel(int32_t engineId, const std::string &peerDevId); 114 115 /** 116 * @brief Notify event from transport engine to av control center 117 * 118 * @param engineId transport engine id 119 * @param event the event content 120 * @return Returns 0 if success. 121 */ 122 API_EXPORT int32_t NotifyAVCenter(int32_t engineId, const AVTransEvent &event); 123 124 /** 125 * @brief Register av control center callback. 126 * 127 * @param engineId transport engine id 128 * @param callback av control center callback. 129 * @return Returns 0 if success. 130 */ 131 API_EXPORT int32_t RegisterCtlCenterCallback(int32_t engineId, const sptr<IAVTransControlCenterCallback> callback); 132 133 /** 134 * @brief Pause distributed hardware. 135 * 136 * @param dhType distributed hardware type 137 * @param networkId distributed hardware networkId. 138 * @return Returns 0 if success. 139 */ 140 API_EXPORT int32_t PauseDistributedHardware(DHType dhType, const std::string &networkId); 141 142 /** 143 * @brief Resume distributed hardware. 144 * 145 * @param dhType distributed hardware type 146 * @param networkId distributed hardware networkId. 147 * @return Returns 0 if success. 148 */ 149 API_EXPORT int32_t ResumeDistributedHardware(DHType dhType, const std::string &networkId); 150 151 /** 152 * @brief Stop distributed hardware. 153 * 154 * @param dhType distributed hardware type 155 * @param networkId distributed hardware networkId. 156 * @return Returns 0 if success. 157 */ 158 API_EXPORT int32_t StopDistributedHardware(DHType dhType, const std::string &networkId); 159 160 private: 161 /** 162 * @brief Determine whether the topic is valid. 163 * @param topic Distributed hardware topic. 164 * @return Returns true if success. 165 */ 166 bool IsDHTopicValid(DHTopic topic); 167 168 /** 169 * @brief Determine whether the QueryLocalSysSpecType is valid. 170 * @param topic Query Local Sys Spec Type. 171 * @return Returns true if success. 172 */ 173 bool IsQueryLocalSysSpecTypeValid(QueryLocalSysSpecType spec); 174 175 private: 176 std::atomic<bool> isDHFWKOnLine_; 177 }; 178 } // namespace DistributedHardware 179 } // namespace OHOS 180 #endif // OHOS_DISTRIBUTED_HARDWARE_FWK_KIT_H