ProcessIdle method added to Adaptor.
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / callback-manager.h
1 #ifndef DALI_INTERNAL_CALLBACK_MANAGER_H
2 #define DALI_INTERNAL_CALLBACK_MANAGER_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/signals/callback.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/dali-adaptor-common.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Adaptor
34 {
35
36 /**
37  * Abstract interface to install call backs in to an applications main loop.
38  */
39 class CallbackManager
40 {
41
42 public:
43
44     /**
45      * Create a new call back interface
46      */
47     static CallbackManager* New();
48
49     /**
50      * Virtual destructor
51      */
52     virtual ~CallbackManager() {}
53
54     /**
55      * @brief Adds a @p callback to be run on idle.
56      * @note Must be called from the main thread only.
57      *
58      * Callbacks of the following types may be used:
59      * @code
60      *   void MyFunction();
61      * @endcode
62      * This callback will be deleted once it is called.
63      *
64      * @code
65      *   bool MyFunction();
66      * @endcode
67      * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
68      *
69      * @param[in] callback custom callback function.
70      * @param[in] hasReturnValue Sould be set to true if the callback function has a return value.
71      *
72      * @return true on success
73      */
74     virtual bool AddIdleCallback( CallbackBase* callback, bool hasReturnValue ) = 0;
75
76     /**
77      * @brief Removes a previously added @p callback.
78      * @note Must be called from main thread only.
79      *
80      * Does nothing if the @p callback doesn't exist.
81      *
82      * @param[in] callback The callback to be removed.
83      */
84     virtual void RemoveIdleCallback( CallbackBase* callback ) = 0;
85
86     /**
87      * @brief Processes the idle callbacks.
88      *
89      * @return whether a DALi callback has been processed.
90      */
91     virtual bool ProcessIdle() = 0;
92
93     /**
94      * @brief Clears the container of callbacks.
95      */
96     virtual void ClearIdleCallbacks() = 0;
97
98     /**
99      * @brief Adds a @p callback to be run when entering an idle state.
100      * @note Must be called from the main thread only.
101      *
102      * A callback of the following type should be used:
103      * @code
104      *   bool MyFunction();
105      * @endcode
106      * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
107      *
108      * @param[in] callback custom callback function.
109      *
110      * @return true on success
111      */
112     virtual bool AddIdleEntererCallback( CallbackBase* callback ) = 0;
113
114     /**
115      * @brief Removes a previously added the idle enterer callback.
116      * @note Must be called from main thread only.
117      *
118      * Does nothing if the @p callback doesn't exist.
119      *
120      * @param[in] callback The callback to be removed.
121      */
122     virtual void RemoveIdleEntererCallback( CallbackBase* callback ) = 0;
123
124     /**
125      * Starts the callback manager.
126      */
127     virtual void Start() = 0;
128
129     /**
130      * Stop the callback manager and can remove all pending callbacks synchronously.
131      * This call will synchronise with the main loop and not return
132      * until all call backs have been deleted.
133      */
134     virtual void Stop() = 0;
135
136 protected:
137
138     /**
139      * constructor
140      */
141     CallbackManager() {}
142
143 private:
144
145     // Undefined copy constructor.
146     CallbackManager( const CallbackManager& );
147
148     // Undefined assignment operator.
149     CallbackManager& operator=( const CallbackManager& );
150
151 };
152
153 } // namespace Adaptor
154
155 } // namespace Internal
156
157 } // namespace Dali
158
159 #endif // DALI_INTERNAL_CALLBACK_MANAGER_H