[dali_2.3.26] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / callback-manager.h
1 #ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_CALLBACK_MANAGER_H
2 #define DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_CALLBACK_MANAGER_H
3
4 /*
5  * Copyright (c) 2023 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 namespace Internal
30 {
31 namespace Adaptor
32 {
33 /**
34  * Abstract interface to install call backs in to an applications main loop.
35  */
36 class CallbackManager
37 {
38 public:
39   /**
40      * Virtual destructor
41      */
42   virtual ~CallbackManager()
43   {
44   }
45
46   /**
47      * @brief Adds a @p callback to be run on idle.
48      * @note Must be called from the main thread only.
49      *
50      * Callbacks of the following types may be used:
51      * @code
52      *   void MyFunction();
53      * @endcode
54      * This callback will be deleted once it is called.
55      *
56      * @code
57      *   bool MyFunction();
58      * @endcode
59      * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
60      *
61      * @param[in] callback custom callback function.
62      * @param[in] hasReturnValue Sould be set to true if the callback function has a return value.
63      *
64      * @return true on success
65      */
66   virtual bool AddIdleCallback(CallbackBase* callback, bool hasReturnValue) = 0;
67
68   /**
69      * @brief Removes a previously added @p callback.
70      * @note Must be called from main thread only.
71      *
72      * Does nothing if the @p callback doesn't exist.
73      *
74      * @param[in] callback The callback to be removed.
75      */
76   virtual void RemoveIdleCallback(CallbackBase* callback) = 0;
77
78   /**
79      * @brief Processes the idle callbacks.
80      *
81      * @return whether a DALi callback has been processed.
82      */
83   virtual bool ProcessIdle() = 0;
84
85   /**
86      * @brief Clears the container of callbacks.
87      */
88   virtual void ClearIdleCallbacks() = 0;
89
90   /**
91      * @brief Adds a @p callback to be run when entering an idle state.
92      * @note Must be called from the main thread only.
93      *
94      * A callback of the following type should be used:
95      * @code
96      *   bool MyFunction();
97      * @endcode
98      * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
99      *
100      * @param[in] callback custom callback function.
101      *
102      * @return true on success
103      */
104   virtual bool AddIdleEntererCallback(CallbackBase* callback) = 0;
105
106   /**
107      * @brief Removes a previously added the idle enterer callback.
108      * @note Must be called from main thread only.
109      *
110      * Does nothing if the @p callback doesn't exist.
111      *
112      * @param[in] callback The callback to be removed.
113      */
114   virtual void RemoveIdleEntererCallback(CallbackBase* callback) = 0;
115
116   /**
117      * Starts the callback manager.
118      */
119   virtual void Start() = 0;
120
121   /**
122      * Stop the callback manager and can remove all pending callbacks synchronously.
123      * This call will synchronise with the main loop and not return
124      * until all call backs have been deleted.
125      */
126   virtual void Stop() = 0;
127
128 protected:
129   /**
130      * constructor
131      */
132   CallbackManager()
133   {
134   }
135
136 private:
137   // Undefined copy constructor.
138   CallbackManager(const CallbackManager&);
139
140   // Undefined assignment operator.
141   CallbackManager& operator=(const CallbackManager&);
142 };
143
144 } // namespace Adaptor
145
146 } // namespace Internal
147
148 } // namespace Dali
149
150 #endif // DALI_INTERNAL_ADAPTOR_SYSTEM_COMMON_CALLBACK_MANAGER_H