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 OHOS_SOFTBUS_ADAPTER_H 17 #define OHOS_SOFTBUS_ADAPTER_H 18 19 #include <string> 20 #include <thread> 21 22 #include "dsched_data_buffer.h" 23 #include "event_handler.h" 24 #include "single_instance.h" 25 #ifdef DMSFWK_INTERACTIVE_ADAPTER 26 #include "dms_softbus_structure.h" 27 #endif 28 #include "softbus_adapter_listener.h" 29 30 namespace OHOS { 31 namespace DistributedSchedule { 32 class SoftbusAdapter { 33 public: 34 DECLARE_SINGLE_INSTANCE_BASE(SoftbusAdapter); 35 public: 36 void Init(); 37 void UnInit(); 38 int32_t SendSoftbusEvent(std::shared_ptr<DSchedDataBuffer> buffer); 39 int32_t StopSoftbusEvent(); 40 int32_t RegisterSoftbusEventListener(const std::shared_ptr<SoftbusAdapterListener>& listener); 41 int32_t UnregisterSoftbusEventListener(const std::shared_ptr<SoftbusAdapterListener>& listener); 42 void OnBroadCastRecv(std::string& networkId, uint8_t* data, uint32_t dataLen); 43 void ReRegister(); 44 #ifdef DMSFWK_INTERACTIVE_ADAPTER 45 IDmsBroadcastAdapter dmsAdapetr_ = { 46 .SendSoftbusEvent = nullptr, 47 .StopSoftbusEvent = nullptr, 48 .RegisterSoftbusEventListener = nullptr, 49 .UnregisterSoftbusEventListener = nullptr, 50 .QueryValidQos = nullptr, 51 }; 52 #endif 53 54 private: SoftbusAdapter()55 SoftbusAdapter() {} 56 void StartEvent(); 57 int32_t DealSendSoftbusEvent(std::shared_ptr<DSchedDataBuffer> buffer, const int32_t retry = 0); 58 int32_t RetrySendSoftbusEvent(std::shared_ptr<DSchedDataBuffer> buffer, const int32_t retry); 59 std::shared_ptr<SoftbusAdapterListener> softbusAdapterListener_; 60 std::string pkgName_ = "dms"; 61 std::thread eventThread_; 62 std::condition_variable eventCon_; 63 std::mutex eventMutex_; 64 std::mutex softbusAdapterListenerMutex_; 65 std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_ = nullptr; 66 }; 67 } // namespace DistributedSchedule 68 } // namespace OHOS 69 #endif /* OHOS_SOFTBUS_ADAPTER_H */ 70