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 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 "hilog/log.h" 24 #include "interfaces/inner_api/ace/ui_content.h" 25 #include "singleton.h" 26 27 namespace OHOS::Ace { 28 using OHOS::EventFwk::CommonEventData; 29 using OHOS::EventFwk::CommonEventManager; 30 using OHOS::EventFwk::CommonEventSubscribeInfo; 31 using OHOS::EventFwk::CommonEventSubscriber; 32 using OHOS::EventFwk::MatchingSkills; 33 34 constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, 0xD003900, "ACE_UI_CONTENT" }; 35 36 #define HIVIEW_PRINTF(func, fmt, ...) func(LOG_LABEL, "<%{public}d>" fmt, __LINE__, ##__VA_ARGS__) 37 38 #define WLOGD(fmt, ...) HIVIEW_PRINTF(HiviewDFX::HiLog::Debug, fmt, ##__VA_ARGS__) 39 #define WLOGI(fmt, ...) HIVIEW_PRINTF(HiviewDFX::HiLog::Info, fmt, ##__VA_ARGS__) 40 #define WLOGW(fmt, ...) HIVIEW_PRINTF(HiviewDFX::HiLog::Warn, fmt, ##__VA_ARGS__) 41 #define WLOGE(fmt, ...) HIVIEW_PRINTF(HiviewDFX::HiLog::Error, fmt, ##__VA_ARGS__) 42 43 #define LOGD(fmt, ...) WLOGD("%{public}s: " fmt, __func__, ##__VA_ARGS__) 44 #define LOGI(fmt, ...) WLOGI("%{public}s: " fmt, __func__, ##__VA_ARGS__) 45 #define LOGW(fmt, ...) WLOGW("%{public}s: " fmt, __func__, ##__VA_ARGS__) 46 #define LOGE(fmt, ...) WLOGE("%{public}s: " fmt, __func__, ##__VA_ARGS__) 47 48 class UICastEventSubscriber : public CommonEventSubscriber { 49 public: UICastEventSubscriber(const CommonEventSubscribeInfo & info,UIContent * context)50 explicit UICastEventSubscriber(const CommonEventSubscribeInfo& info, UIContent* context) 51 : CommonEventSubscriber(info), context_(context) 52 {} 53 ~UICastEventSubscriber()54 ~UICastEventSubscriber() {} 55 56 void UICastProxyStart(int castSessionId, UIContent* context); 57 void UICastProxyStop(); 58 void UICastProxyUpdateContext(UIContent* context); 59 60 void OnReceiveEvent(const CommonEventData& data) override; 61 62 private: 63 UIContent* context_; 64 void* handle_ { nullptr }; 65 }; 66 67 class UICastEventSubscribeProxy : public DelayedSingleton<UICastEventSubscribeProxy> { 68 public: ~UICastEventSubscribeProxy()69 ~UICastEventSubscribeProxy() 70 { 71 UnSubscribeStartEvent(); 72 } 73 void SubscribeStartEvent(UIContent* context); 74 void UnSubscribeStartEvent(void); 75 76 private: 77 std::shared_ptr<CommonEventSubscriber> eventReceiver_; 78 std::shared_ptr<UICastEventSubscriber> uicastEventReceiver_; 79 }; 80 } // namespace OHOS::Ace 81 82 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_UICAST_UICAST_SUBSCRIBER_H 83