1e0dac50fSopenharmony_ci/* 2e0dac50fSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License. 5e0dac50fSopenharmony_ci * You may obtain a copy of the License at 6e0dac50fSopenharmony_ci * 7e0dac50fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0dac50fSopenharmony_ci * 9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and 13e0dac50fSopenharmony_ci * limitations under the License. 14e0dac50fSopenharmony_ci */ 15e0dac50fSopenharmony_ci 16e0dac50fSopenharmony_ci#ifndef WINDOW_COMMON_EVENT_H 17e0dac50fSopenharmony_ci#define WINDOW_COMMON_EVENT_H 18e0dac50fSopenharmony_ci 19e0dac50fSopenharmony_ci#include <common_event_data.h> 20e0dac50fSopenharmony_ci#include <common_event_manager.h> 21e0dac50fSopenharmony_ci#include <common_event_support.h> 22e0dac50fSopenharmony_ci#include <event_handler.h> 23e0dac50fSopenharmony_ci 24e0dac50fSopenharmony_ci#include "window_root.h" 25e0dac50fSopenharmony_ci 26e0dac50fSopenharmony_cinamespace OHOS { 27e0dac50fSopenharmony_cinamespace Rosen { 28e0dac50fSopenharmony_ciclass WindowCommonEvent : public RefBase, public std::enable_shared_from_this<WindowCommonEvent> { 29e0dac50fSopenharmony_cipublic: 30e0dac50fSopenharmony_ci WindowCommonEvent(); 31e0dac50fSopenharmony_ci ~WindowCommonEvent(); 32e0dac50fSopenharmony_ci void SubscriberEvent(); 33e0dac50fSopenharmony_ci void UnSubscriberEvent(); 34e0dac50fSopenharmony_ci void OnReceiveEvent(const EventFwk::CommonEventData& data); 35e0dac50fSopenharmony_ci 36e0dac50fSopenharmony_ciprivate: 37e0dac50fSopenharmony_ci class EventSubscriber : public EventFwk::CommonEventSubscriber { 38e0dac50fSopenharmony_ci public: 39e0dac50fSopenharmony_ci EventSubscriber(const EventFwk::CommonEventSubscribeInfo& subscriberInfo, 40e0dac50fSopenharmony_ci const std::shared_ptr<WindowCommonEvent>& eventHandler) 41e0dac50fSopenharmony_ci : EventFwk::CommonEventSubscriber(subscriberInfo), eventHandler_(eventHandler) {}; 42e0dac50fSopenharmony_ci ~EventSubscriber() = default; 43e0dac50fSopenharmony_ci void OnReceiveEvent(const EventFwk::CommonEventData& data) override 44e0dac50fSopenharmony_ci { 45e0dac50fSopenharmony_ci eventHandler_->OnReceiveEvent(data); 46e0dac50fSopenharmony_ci } 47e0dac50fSopenharmony_ci 48e0dac50fSopenharmony_ci private: 49e0dac50fSopenharmony_ci std::shared_ptr<WindowCommonEvent> eventHandler_; 50e0dac50fSopenharmony_ci }; 51e0dac50fSopenharmony_ci void SubscriberEventInner(int retry); 52e0dac50fSopenharmony_ci void HandleAccountSwitched(const EventFwk::CommonEventData& data) const; 53e0dac50fSopenharmony_ci 54e0dac50fSopenharmony_ci std::shared_ptr<EventSubscriber> subscriber_; 55e0dac50fSopenharmony_ci std::shared_ptr<AppExecFwk::EventHandler> eventHandler_; 56e0dac50fSopenharmony_ci}; 57e0dac50fSopenharmony_ci} // Rosen 58e0dac50fSopenharmony_ci} // OHOS 59e0dac50fSopenharmony_ci#endif // WINDOW_COMMON_EVENT_H