1bc2ed2b3Sopenharmony_ci/*
2bc2ed2b3Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3bc2ed2b3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4bc2ed2b3Sopenharmony_ci * you may not use this file except in compliance with the License.
5bc2ed2b3Sopenharmony_ci * You may obtain a copy of the License at
6bc2ed2b3Sopenharmony_ci *
7bc2ed2b3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8bc2ed2b3Sopenharmony_ci *
9bc2ed2b3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10bc2ed2b3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11bc2ed2b3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12bc2ed2b3Sopenharmony_ci * See the License for the specific language governing permissions and
13bc2ed2b3Sopenharmony_ci * limitations under the License.
14bc2ed2b3Sopenharmony_ci */
15bc2ed2b3Sopenharmony_ci#ifndef NFC_EVENT_HANDLER_H
16bc2ed2b3Sopenharmony_ci#define NFC_EVENT_HANDLER_H
17bc2ed2b3Sopenharmony_ci#include "common_event_manager.h"
18bc2ed2b3Sopenharmony_ci#include "event_handler.h"
19bc2ed2b3Sopenharmony_ci#include "nfc_service.h"
20bc2ed2b3Sopenharmony_ci#include "tag_dispatcher.h"
21bc2ed2b3Sopenharmony_ci
22bc2ed2b3Sopenharmony_cinamespace OHOS {
23bc2ed2b3Sopenharmony_cinamespace NFC {
24bc2ed2b3Sopenharmony_ciclass NfcService;
25bc2ed2b3Sopenharmony_ciclass CeService;
26bc2ed2b3Sopenharmony_ciclass NfcPollingManager;
27bc2ed2b3Sopenharmony_ciclass NfcRoutingManager;
28bc2ed2b3Sopenharmony_ciclass NfcEventHandler final : public AppExecFwk::EventHandler {
29bc2ed2b3Sopenharmony_cipublic:
30bc2ed2b3Sopenharmony_ci    explicit NfcEventHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner,
31bc2ed2b3Sopenharmony_ci                             std::weak_ptr<NfcService> service);
32bc2ed2b3Sopenharmony_ci    ~NfcEventHandler();
33bc2ed2b3Sopenharmony_ci    NfcEventHandler& operator=(const NfcEventHandler&) = delete;
34bc2ed2b3Sopenharmony_ci    NfcEventHandler(const NfcEventHandler&) = delete;
35bc2ed2b3Sopenharmony_ci
36bc2ed2b3Sopenharmony_ci    void Intialize(std::weak_ptr<TAG::TagDispatcher> tagDispatcher,
37bc2ed2b3Sopenharmony_ci                   std::weak_ptr<CeService> ceService,
38bc2ed2b3Sopenharmony_ci                   std::weak_ptr<NfcPollingManager> nfcPollingManager,
39bc2ed2b3Sopenharmony_ci                   std::weak_ptr<NfcRoutingManager> nfcRoutingManager,
40bc2ed2b3Sopenharmony_ci                   std::weak_ptr<NCI::INciNfccInterface> nciNfccProxy);
41bc2ed2b3Sopenharmony_ci    void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override;
42bc2ed2b3Sopenharmony_ci
43bc2ed2b3Sopenharmony_ci    void SubscribeScreenChangedEvent();
44bc2ed2b3Sopenharmony_ci    void SubscribePackageChangedEvent();
45bc2ed2b3Sopenharmony_ci    void SubscribeShutdownEvent();
46bc2ed2b3Sopenharmony_ci    void SubscribeDataShareChangedEvent();
47bc2ed2b3Sopenharmony_ci    bool IsScreenOn();
48bc2ed2b3Sopenharmony_ci    bool IsScreenLocked();
49bc2ed2b3Sopenharmony_ci    ScreenState CheckScreenState();
50bc2ed2b3Sopenharmony_ci
51bc2ed2b3Sopenharmony_ciprotected:
52bc2ed2b3Sopenharmony_ci    // Screen Changed Receiver
53bc2ed2b3Sopenharmony_ci    class ScreenChangedReceiver;
54bc2ed2b3Sopenharmony_ci    // Package Changed Receiver
55bc2ed2b3Sopenharmony_ci    class PackageChangedReceiver;
56bc2ed2b3Sopenharmony_ci    // Shutdown Event Receiver
57bc2ed2b3Sopenharmony_ci    class ShutdownEventReceiver;
58bc2ed2b3Sopenharmony_ci    // DataShare changed Receiver
59bc2ed2b3Sopenharmony_ci    class DataShareChangedReceiver;
60bc2ed2b3Sopenharmony_ci
61bc2ed2b3Sopenharmony_ciprivate:
62bc2ed2b3Sopenharmony_ci    std::shared_ptr<EventFwk::CommonEventSubscriber> screenSubscriber_ {};
63bc2ed2b3Sopenharmony_ci    std::shared_ptr<EventFwk::CommonEventSubscriber> pkgSubscriber_ {};
64bc2ed2b3Sopenharmony_ci    std::shared_ptr<EventFwk::CommonEventSubscriber> shutdownSubscriber_ {};
65bc2ed2b3Sopenharmony_ci    std::shared_ptr<EventFwk::CommonEventSubscriber> dataShareSubscriber_ {};
66bc2ed2b3Sopenharmony_ci
67bc2ed2b3Sopenharmony_ci    std::weak_ptr<NfcService> nfcService_ {};
68bc2ed2b3Sopenharmony_ci    std::weak_ptr<TAG::TagDispatcher> tagDispatcher_ {};
69bc2ed2b3Sopenharmony_ci    std::weak_ptr<CeService> ceService_ {};
70bc2ed2b3Sopenharmony_ci    std::weak_ptr<NfcPollingManager> nfcPollingManager_ {};
71bc2ed2b3Sopenharmony_ci    std::weak_ptr<NfcRoutingManager> nfcRoutingManager_ {};
72bc2ed2b3Sopenharmony_ci    std::weak_ptr<NCI::INciNfccInterface> nciNfccProxy_ {};
73bc2ed2b3Sopenharmony_ci
74bc2ed2b3Sopenharmony_ci    std::mutex commonEventMutex_ {};
75bc2ed2b3Sopenharmony_ci
76bc2ed2b3Sopenharmony_ci    static constexpr const int WAIT_PROCESS_EVENT_TIMES = 60 * 1000;
77bc2ed2b3Sopenharmony_ci};
78bc2ed2b3Sopenharmony_ci}  // namespace NFC
79bc2ed2b3Sopenharmony_ci}  // namespace OHOS
80bc2ed2b3Sopenharmony_ci#endif  // NFC_EVENT_HANDLER_H
81