Merge "Added UIThreadLoader to GLIB framework" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / windows / callback-manager-win.h
1 #ifndef DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_CALLBACK_MANAGER_H
2 #define DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_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/common/list-wrapper.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/internal/system/common/callback-manager.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 namespace Adaptor
32 {
33 struct WindowsCallbackData;
34
35 /**
36  * @brief Windows callback manager used to install call backs in the applications main loop.
37  * The manager keeps track of all callbacks, so that if Stop() is called it can remove them.
38  */
39 class WinCallbackManager : public CallbackManager
40 {
41 public:
42   /**
43    * @brief constructor
44    */
45   WinCallbackManager();
46
47   /**
48    * @brief destructor
49    */
50   ~WinCallbackManager();
51
52   /**
53    * @copydoc CallbackManager::AddIdleCallback()
54    */
55   bool AddIdleCallback(CallbackBase* callback, bool hasReturnValue) override;
56
57   /**
58    * @copydoc CallbackManager::RemoveIdleCallback()
59    */
60   void RemoveIdleCallback(CallbackBase* callback) override;
61
62   /**
63    * @copydoc CallbackManager::ProcessIdle()
64    */
65   bool ProcessIdle() override;
66
67   /**
68    * @copydoc CallbackManager::ClearIdleCallbacks()
69    */
70   void ClearIdleCallbacks() override;
71
72   /**
73    * @brief Adds a @p callback to be run when entering an idle state.
74    * @note Must be called from the main thread only.
75    *
76    * A callback of the following type should be used:
77    * @code
78    *   bool MyFunction();
79    * @endcode
80    * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
81    *
82    * @param[in] callback custom callback function.
83    *
84    * @return true on success
85    */
86   bool AddIdleEntererCallback(CallbackBase* callback) override;
87
88   /**
89    * @brief Removes a previously added the idle enterer callback.
90    * @note Must be called from main thread only.
91    *
92    * Does nothing if the @p callback doesn't exist.
93    *
94    * @param[in] callback The callback to be removed.
95    */
96   void RemoveIdleEntererCallback(CallbackBase* callback) override;
97
98   /**
99    * @copydoc CallbackManager::Start()
100    */
101   void Start() override;
102
103   /**
104    * @copydoc CallbackManager::Stop()
105    */
106   void Stop() override;
107
108 private:
109   // Undefined
110   WinCallbackManager(const WinCallbackManager&) = delete;
111   WinCallbackManager& operator=(WinCallbackManager&) = delete;
112
113   /**
114    * @brief Callback function comes from framework.
115    * It will be self callback.
116    */
117   void ProcessIdleFromFramework();
118
119 private:
120   CallbackBase* mSelfCallback{nullptr};
121   bool          mSelfCallbackRegistered{false}; ///< flag is set to true if we send processIdle callback register.
122
123   typedef std::list<WindowsCallbackData*> CallbackList;
124
125   CallbackList mCallbackContainer;
126   bool         mRunning; ///< flag is set to true if when running
127 };
128
129 } // namespace Adaptor
130
131 } // namespace Internal
132
133 } // namespace Dali
134
135 #endif // DALI_INTERNAL_ADAPTOR_SYSTEM_WINDOWS_CALLBACK_MANAGER_H