[Tizen] Print processor name for debug
[platform/core/uifw/dali-extension.git] / dali-extension / internal / rive-animation-view / rive-animation-manager.h
1 #ifndef DALI_EXTENSION_INTERNAL_RIVE_ANIMATION_MANAGER_H
2 #define DALI_EXTENSION_INTERNAL_RIVE_ANIMATION_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/integration-api/processor-interface.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/signals/callback.h>
25 #include <memory>
26 #include <mutex>
27
28 namespace Dali
29 {
30 namespace Extension
31 {
32 namespace Internal
33 {
34 class RiveAnimationThread;
35 class RiveAnimationManager;
36
37 /**
38  * @brief Rive animation manager
39  */
40 class RiveAnimationManager : public Integration::Processor
41 {
42 public:
43   struct LifecycleObserver
44   {
45     virtual void RiveAnimationManagerDestroyed() = 0;
46   };
47
48   /**
49    * @brief GetInstance.
50    */
51   static RiveAnimationManager& GetInstance();
52
53   /**
54    * @brief Constructor.
55    */
56   RiveAnimationManager();
57
58   /**
59    * @brief Destructor.
60    */
61   ~RiveAnimationManager() override;
62
63   /**
64    * Add a lifecycle observer
65    * @param[in] observer The object watching this one
66    */
67   void AddObserver(LifecycleObserver& observer);
68
69   /**
70    * Remove a lifecycle observer
71    * @param[in] observer The object watching this one
72    */
73   void RemoveObserver(LifecycleObserver& observer);
74
75   /**
76    * Get the rive animation thread.
77    * @return A raw pointer pointing to the rive animation thread.
78    */
79   RiveAnimationThread& GetRiveAnimationThread();
80
81   /**
82    * @brief Register a callback.
83    *
84    * @param callback The callback to register
85    * @note Ownership of the callback is passed onto this class.
86    */
87   void RegisterEventCallback(CallbackBase* callback);
88
89   /**
90    * @brief Unregister a previously registered callback
91    *
92    * @param callback The callback to unregister
93    */
94   void UnregisterEventCallback(CallbackBase* callback);
95
96 protected: // Implementation of Processor
97   /**
98    * @copydoc Dali::Integration::Processor::Process()
99    */
100   void Process(bool postProcessor) override;
101
102   /**
103    * @copydoc Dali::Integration::Processor::GetProcessorName()
104    */
105   std::string_view GetProcessorName() const override
106   {
107     return "RiveAnimationManager";
108   }
109
110 private:
111   // Undefined
112   RiveAnimationManager(const RiveAnimationManager& manager) = delete;
113
114   // Undefined
115   RiveAnimationManager& operator=(const RiveAnimationManager& manager) = delete;
116
117 private:
118   static std::unique_ptr<RiveAnimationManager> mInstance;
119   static std::once_flag                        mOnceFlag;
120
121   std::vector<std::unique_ptr<CallbackBase>> mEventCallbacks;
122   std::vector<LifecycleObserver*>            mLifecycleObservers;
123   std::unique_ptr<RiveAnimationThread>       mRiveAnimationThread;
124   bool                                       mProcessorRegistered;
125 };
126
127 } // namespace Internal
128
129 } // namespace Extension
130
131 } // namespace Dali
132
133 #endif // DALI_EXTENSION_INTERNAL_RIVE_ANIMATION_MANAGER_H