1/*
2 * Copyright (C) 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#ifndef SCREENLOCK_COMMEVENT_SUBSCRIBE_H
16#define SCREENLOCK_COMMEVENT_SUBSCRIBE_H
17
18#include <string>
19#include <singleton.h>
20
21#include "common_event_manager.h"
22#include "common_event_subscriber.h"
23#include "common_event_support.h"
24
25namespace OHOS {
26namespace ScreenLock {
27using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber;
28using CommonEventData = OHOS::EventFwk::CommonEventData;
29using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo;
30
31class CommeventMgr {
32    DECLARE_SINGLETON(CommeventMgr)
33public:
34    void SubscribeEvent();
35    void UnSubscribeEvent();
36    void OnReceiveEvent(const AAFwk::Want &want);
37
38private:
39    class CommEventSubscriber : public CommonEventSubscriber {
40    public:
41        explicit CommEventSubscriber(CommonEventSubscribeInfo &subscriberInfo, CommeventMgr &registry)
42            : CommonEventSubscriber(subscriberInfo), registry_(registry)
43        {}
44        ~CommEventSubscriber() = default;
45
46        void OnReceiveEvent(const CommonEventData &data) override
47        {
48            registry_.OnReceiveEvent(data.GetWant());
49        }
50
51    private:
52        CommeventMgr &registry_;
53    };
54
55    std::shared_ptr<CommEventSubscriber> subscriber_ = nullptr;
56};
57} // namespace ScreenLock
58} // namespace OHOS
59
60#endif  //SCREENLOCK_COMMEVENT_SUBSCRIBE_H