4e5c8f153e17bb588daa1f6fd10ceb638ab3ddd5
[platform/core/uifw/aurum.git] / libaurum / inc / Impl / Accessibility / AtspiAccessibleWatcher.h
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *               http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17
18 #ifndef _ATSPI_ACCESSIBLE_WATCHER_H_
19 #define _ATSPI_ACCESSIBLE_WATCHER_H_
20
21 #include "AccessibleNode.h"
22 #include "AccessibleWatcher.h"
23 #include "AtspiAccessibleApplication.h"
24
25 #include <atspi/atspi.h>
26 #include <gio/gio.h>
27
28 #include <shared_mutex>
29 #include <memory>
30 #include <list>
31 #include <vector>
32 #include <set>
33 #include <map>
34
35 using namespace Aurum;
36
37 namespace AurumInternal {
38
39 /**
40  * @internal
41  *
42  * @brief WindowActivateInfoType enum class.
43  *
44  * @since_tizen 6.5
45  */
46 enum class WindowActivateInfoType {
47     DEFAULT_LABEL_ENALBED = 0x00,
48     DEFAULT_LABEL_ENALBED_WITHOUT_WINDOW = 0x01,
49     DEFAULT_LABEL_DISABLED = 0x02,
50     KEYBOARD = 0x04,
51 };
52
53 /**
54  * @internal
55  *
56  * @brief IAtspiEvents Interface
57  * @since_tizen 6.5
58  */
59 class IAtspiEvents {
60 public:
61     /**
62      * @brief TBD
63      * @since_tizen 6.5
64      */
65     virtual ~IAtspiEvents() {}
66
67     /**
68      * @brief TBD
69      * @since_tizen 6.5
70      */
71     virtual void onObjectDefunct(AtspiAccessible *node) = 0;
72 };
73
74 /**
75  * @internal
76  *
77  * @class AtspiAccessibleWatcher
78  *
79  * @ingroup aurum
80  *
81  * @brief Class that communicates with the atspi sever and generates an event,
82  *        and generates a node that matches with atspi node.
83  */
84 class AtspiAccessibleWatcher : public AccessibleWatcher, public IAtspiEvents {
85 public:
86     AtspiAccessibleWatcher();
87     virtual ~AtspiAccessibleWatcher();
88
89 public:
90     /**
91      * @copydoc @AccessibleWatcher::getApplicationCount()
92      */
93     virtual int getApplicationCount(void) const override;
94
95     /**
96      * @copydoc @AccessibleWatcher::getApplicationAt()
97      */
98     virtual std::shared_ptr<AccessibleApplication> getApplicationAt(int index) const override;
99
100     /**
101      * @copydoc @AccessibleWatcher::getApplications()
102      */
103     virtual std::vector<std::shared_ptr<AccessibleApplication>> getApplications(void) const override;
104
105     /**
106      * @copydoc @AccessibleWatcher::executeAndWaitForEvents()
107      */
108     virtual bool executeAndWaitForEvents(const Runnable *cmd, const A11yEvent type, const int timeout) override;
109
110     /**
111      * @copydoc @AccessibleWatcher::getActiveAppMap()
112      */
113     virtual std::map<AtspiAccessible *, std::shared_ptr<AccessibleApplication>> getActiveAppMap(void) override;
114
115 public:
116     /**
117      * @brief Listen atspi events.
118      *
119      * @param[in] event AtspiEvent
120      * @param[in] watcher @AtspiAccessibleWatcher
121      *
122      * @since_tizen 6.5
123      */
124     static void onAtspiEvents(AtspiEvent *event, void *watcher);
125
126     /**
127      * @brief Notifies when object defunct.
128      *
129      * @param[in] node @AtspiAccessible
130      *
131      * @since_tizen 6.5
132      */
133     void onObjectDefunct(AtspiAccessible *node) override;
134
135     /**
136      * @brief AtspiEvent listener.
137      *
138      * @param[in] event AtspiEvent
139      * @param[in] user_data data for event by user
140      *
141      * @since_tizen 6.5
142      */
143     static void onEventListener(AtspiEvent *event, void *user_data);
144 private:
145     /** Private methods for Mock Test **/
146     bool removeFromActivatedList(AtspiAccessible *node);
147     bool addToActivatedList(AtspiAccessible *node);
148     bool removeFromWindowSet(AtspiAccessible *node);
149     bool addToWindowSet(AtspiAccessible *node);
150     void addEventListener(AtspiEventListener *listener, A11yEvent type);
151     void removeEventListener(AtspiEventListener *listener, A11yEvent type);
152
153 private:
154     GDBusProxy *mDbusProxy;
155     std::list<AtspiAccessible *> mActivatedWindowList;
156     std::list<AtspiAccessible *> mActivatedApplicationList;
157     std::set<AtspiAccessible *> mWindowSet;
158     std::map<AtspiAccessible *, std::shared_ptr<AccessibleApplication>> mActiveAppMap;
159     static GThread *mEventThread;
160     static std::vector<std::shared_ptr<A11yEventInfo>> mEventQueue;
161     static std::mutex mMutex;
162 };
163
164 }
165
166 #endif