1885b47fbSopenharmony_ci/*
2885b47fbSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3885b47fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4885b47fbSopenharmony_ci * you may not use this file except in compliance with the License.
5885b47fbSopenharmony_ci * You may obtain a copy of the License at
6885b47fbSopenharmony_ci *
7885b47fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8885b47fbSopenharmony_ci *
9885b47fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10885b47fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11885b47fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12885b47fbSopenharmony_ci * See the License for the specific language governing permissions and
13885b47fbSopenharmony_ci * limitations under the License.
14885b47fbSopenharmony_ci */
15885b47fbSopenharmony_ci
16885b47fbSopenharmony_ci#ifndef ACCESSIBILITY_COMMON_EVENT_REGISTRY_H
17885b47fbSopenharmony_ci#define ACCESSIBILITY_COMMON_EVENT_REGISTRY_H
18885b47fbSopenharmony_ci
19885b47fbSopenharmony_ci#include <map>
20885b47fbSopenharmony_ci#include <memory>
21885b47fbSopenharmony_ci#include <functional>
22885b47fbSopenharmony_ci#include <string>
23885b47fbSopenharmony_ci#include "common_event_subscriber.h"
24885b47fbSopenharmony_ci#include "event_handler.h"
25885b47fbSopenharmony_ci#include "singleton.h"
26885b47fbSopenharmony_ci#include "want.h"
27885b47fbSopenharmony_ci
28885b47fbSopenharmony_ciusing EventHandle = std::function<void(const OHOS::EventFwk::CommonEventData &)>;
29885b47fbSopenharmony_ci
30885b47fbSopenharmony_cinamespace OHOS {
31885b47fbSopenharmony_cinamespace Accessibility {
32885b47fbSopenharmony_ciclass AccessibilityCommonEvent {
33885b47fbSopenharmony_ci    DECLARE_SINGLETON(AccessibilityCommonEvent)
34885b47fbSopenharmony_cipublic:
35885b47fbSopenharmony_ci    void SubscriberEvent(const std::shared_ptr<AppExecFwk::EventHandler> &handler);
36885b47fbSopenharmony_ci    void UnSubscriberEvent();
37885b47fbSopenharmony_ci    void OnReceiveEvent(const EventFwk::CommonEventData &data);
38885b47fbSopenharmony_ci
39885b47fbSopenharmony_ciprivate:
40885b47fbSopenharmony_ci    class AccessibilityCommonEventSubscriber : public EventFwk::CommonEventSubscriber {
41885b47fbSopenharmony_ci    public:
42885b47fbSopenharmony_ci        explicit AccessibilityCommonEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo,
43885b47fbSopenharmony_ci            AccessibilityCommonEvent &registry)
44885b47fbSopenharmony_ci            : CommonEventSubscriber(subscriberInfo), registry_(registry) {}
45885b47fbSopenharmony_ci        ~AccessibilityCommonEventSubscriber() = default;
46885b47fbSopenharmony_ci
47885b47fbSopenharmony_ci        void OnReceiveEvent(const EventFwk::CommonEventData &data) override
48885b47fbSopenharmony_ci        {
49885b47fbSopenharmony_ci            registry_.OnReceiveEvent(data);
50885b47fbSopenharmony_ci        }
51885b47fbSopenharmony_ci
52885b47fbSopenharmony_ci    private:
53885b47fbSopenharmony_ci        AccessibilityCommonEvent &registry_;
54885b47fbSopenharmony_ci    };
55885b47fbSopenharmony_ci
56885b47fbSopenharmony_ci    void HandleUserAdded(const EventFwk::CommonEventData &data) const;
57885b47fbSopenharmony_ci    void HandleUserRemoved(const EventFwk::CommonEventData &data) const;
58885b47fbSopenharmony_ci    void HandleUserSwitched(const EventFwk::CommonEventData &data) const;
59885b47fbSopenharmony_ci
60885b47fbSopenharmony_ci    void HandlePackageRemoved(const EventFwk::CommonEventData &data) const;
61885b47fbSopenharmony_ci    void HandlePackageChanged(const EventFwk::CommonEventData &data) const;
62885b47fbSopenharmony_ci    void HandlePackageAdd(const EventFwk::CommonEventData &data) const;
63885b47fbSopenharmony_ci
64885b47fbSopenharmony_ci    typedef void (AccessibilityCommonEvent::*HandleEventFunc)(const EventFwk::CommonEventData &) const;
65885b47fbSopenharmony_ci    std::map<std::string, EventHandle> eventHandles_;
66885b47fbSopenharmony_ci    std::map<std::string, HandleEventFunc> handleEventFunc_;
67885b47fbSopenharmony_ci    std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
68885b47fbSopenharmony_ci    std::shared_ptr<AccessibilityCommonEventSubscriber> subscriber_ = nullptr;
69885b47fbSopenharmony_ci};
70885b47fbSopenharmony_ci} // namespace Accessibility
71885b47fbSopenharmony_ci} // namespace OHOS
72885b47fbSopenharmony_ci#endif // ACCESSIBILITY_COMMON_EVENT_REGISTRY_H