1 /* 2 * Copyright (c) 2022 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_DSCREEN_MGR_H 17 #define OHOS_DSCREEN_MGR_H 18 19 #include "distributed_hardware_fwk_kit.h" 20 #include "dm_common.h" 21 #include "single_instance.h" 22 #include "screen_manager.h" 23 24 #include "dscreen.h" 25 #include "dscreen_maprelation.h" 26 #include "idscreen_sink.h" 27 #include "idscreen_source_callback.h" 28 #include "video_param.h" 29 30 namespace OHOS { 31 namespace DistributedHardware { 32 class DScreenCallback : public IDScreenCallback { 33 public: 34 void OnRegResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId, 35 const int32_t status, const std::string &data) override; 36 void OnUnregResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId, 37 const int32_t status, const std::string &data) override; 38 }; 39 40 class DScreenGroupListener : public Rosen::ScreenManager::IScreenGroupListener { 41 public: 42 void OnChange(const std::vector<uint64_t> &screenIds, Rosen::ScreenGroupChangeEvent event) override; 43 }; 44 45 class DScreenManager { 46 DECLARE_SINGLE_INSTANCE_BASE(DScreenManager); 47 public: 48 void OnRegResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId, 49 const int32_t status, const std::string &data); 50 void OnUnregResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId, 51 const int32_t status, const std::string &data); 52 53 int32_t Init(); 54 int32_t UnInit(); 55 int32_t EnableDistributedScreen(const std::string &devId, const std::string &dhId, const std::string ¶m, 56 const std::string &reqId); 57 int32_t DisableDistributedScreen(const std::string &devId, const std::string &dhId, const std::string &reqId); 58 void HandleDScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent); 59 void RegisterDScreenCallback(const sptr<IDScreenSourceCallback> &callback); 60 void HandleScreenChange(const std::shared_ptr<DScreen> &changedScreen, Rosen::ScreenGroupChangeEvent event); 61 std::shared_ptr<DScreen> FindDScreenByScreenId(uint64_t screenId); 62 int32_t AddToGroup(const std::shared_ptr<DScreen> &changedScreen, uint64_t screenId); 63 int32_t RemoveFromGroup(const std::shared_ptr<DScreen> &changedScreen, uint64_t screenId); 64 void GetScreenDumpInfo(std::string &result); 65 void PublishMessage(const DHTopic topic, const std::shared_ptr<DScreen> &dScreen); 66 private: 67 ~DScreenManager(); 68 DScreenManager(); 69 std::mutex dScreenMapMtx_; 70 std::mutex dScreenMapRelationMtx_; 71 std::map<uint64_t, std::shared_ptr<DScreenMapRelation>> mapRelations_; 72 std::map<std::string, std::shared_ptr<DScreen>> dScreens_; 73 sptr<IDScreenSourceCallback> dScreenSourceCallbackProxy_ = nullptr; 74 sptr<DScreenGroupListener> dScreenGroupListener_ = nullptr; 75 std::shared_ptr<IDScreenCallback> dScreenCallback_ = nullptr; 76 std::string localDevId_; 77 78 sptr<IDScreenSink> GetDScreenSinkSA(const std::string &devId); 79 int32_t NotifyRemoteScreenService(const std::string &devId, int32_t eventCode, const std::string &eventContent); 80 void NotifyRemoteSinkSetUp(const std::shared_ptr<DScreen> &dScreen); 81 bool CheckContent(json &eventContent); 82 void HandleNotifySetUpResult(const std::string &remoteDevId, const std::string &eventContent); 83 }; 84 } // namespace DistributedHardware 85 } // namespace OHOS 86 #endif