1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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_SHARING_WFD_SOURCE_DEMO_H 17 #define OHOS_SHARING_WFD_SOURCE_DEMO_H 18 19 #include "wfd_source.h" 20 namespace OHOS { 21 namespace Sharing { 22 class WfdSourceDemoListener; 23 class WfdSourceDemo : public std::enable_shared_from_this<WfdSourceDemo> { 24 public: 25 WfdSourceDemo(); 26 ~WfdSourceDemo() = default; 27 28 bool Stop(); 29 bool Start(); 30 bool CreateClient(); 31 bool StopDiscover(); 32 bool StartDiscover(); 33 34 void DoCmd(std::string cmd); 35 void AddCastDevice(const std::string deviceId); 36 void RemoveCastDevice(const std::string deviceId); 37 void ExecuteCmd(int32_t cmd, std::string &deviceId); 38 39 std::shared_ptr<WfdSource> GetClient(); 40 41 private: 42 std::shared_ptr<WfdSource> client_ = nullptr; 43 std::shared_ptr<WfdSourceDemoListener> listener_ = nullptr; 44 }; 45 46 class WfdSourceDemoListener : public IWfdEventListener { 47 public: 48 void OnInfo(std::shared_ptr<BaseMsg> &msg) override; 49 void OnConnectionChanged(const ConnectionInfo &info); 50 void OnDeviceFound(const std::vector<WfdCastDeviceInfo> &deviceInfos); 51 void OnError(uint32_t regionId, uint32_t agentId, SharingErrorCode errorCode); SetListener(std::shared_ptr<WfdSourceDemo> listener)52 void SetListener(std::shared_ptr<WfdSourceDemo> listener) 53 { 54 listener_ = listener; 55 } 56 57 private: 58 std::weak_ptr<WfdSourceDemo> listener_; 59 }; 60 61 } // namespace Sharing 62 } // namespace OHOS 63 #endif 64