1 /* 2 * Copyright (c) 2023-2024 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 FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_UICAST_UICAST_SUBSCRIBER_H 17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_UICAST_UICAST_SUBSCRIBER_H 18 19 #include <string> 20 21 #include "common_event_manager.h" 22 #include "common_event_subscriber.h" 23 #include "interfaces/inner_api/ace/ui_content.h" 24 #include "singleton.h" 25 26 namespace OHOS::Ace { 27 using OHOS::EventFwk::CommonEventData; 28 using OHOS::EventFwk::CommonEventManager; 29 using OHOS::EventFwk::CommonEventSubscribeInfo; 30 using OHOS::EventFwk::CommonEventSubscriber; 31 using OHOS::EventFwk::MatchingSkills; 32 33 class UICastEventSubscriber : public CommonEventSubscriber { 34 public: UICastEventSubscriber(const CommonEventSubscribeInfo & info,UIContent * context)35 explicit UICastEventSubscriber(const CommonEventSubscribeInfo& info, UIContent* context) 36 : CommonEventSubscriber(info), context_(context) 37 {} 38 ~UICastEventSubscriber()39 ~UICastEventSubscriber() {} 40 41 void UICastProxyStart(int castSessionId, UIContent* context); 42 void UICastProxyStop(); 43 void UICastProxyUpdateContext(UIContent* context); 44 45 void OnReceiveEvent(const CommonEventData& data) override; 46 47 private: 48 UIContent* context_; 49 void* handle_ { nullptr }; 50 }; 51 52 class UICastEventSubscribeProxy : public DelayedSingleton<UICastEventSubscribeProxy> { 53 public: ~UICastEventSubscribeProxy()54 ~UICastEventSubscribeProxy() 55 { 56 UnSubscribeStartEvent(); 57 } 58 void SubscribeStartEvent(UIContent* context); 59 void UnSubscribeStartEvent(void); 60 61 private: 62 std::shared_ptr<CommonEventSubscriber> eventReceiver_; 63 std::shared_ptr<UICastEventSubscriber> uicastEventReceiver_; 64 }; 65 } // namespace OHOS::Ace 66 67 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_UICAST_UICAST_SUBSCRIBER_H 68