(Observers)Fix memory issues during observer iteration
[platform/core/uifw/dali-core.git] / dali / internal / event / events / touch-event-processor.h
1 #ifndef __DALI_INTERNAL_TOUCH_EVENT_PROCESSOR_H__
2 #define __DALI_INTERNAL_TOUCH_EVENT_PROCESSOR_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/render-tasks/render-task.h>
22 #include <dali/internal/event/common/proxy-object.h>
23
24 namespace Dali
25 {
26
27 class Actor;
28 struct Vector2;
29 struct Vector4;
30
31 namespace Integration
32 {
33 struct TouchEvent;
34 }
35
36 namespace Internal
37 {
38
39 class Actor;
40 class Stage;
41
42 /**
43  * <h3>Multi-Touch Event Processing:</h3>
44  *
45  * The TouchEventProcessor processes touch events and emits the Touched signal on the hit actor (and
46  * its parents).
47  *
48  * - Hit Testing & Touch Event Delivery are described in Dali::Actor.
49  */
50 class TouchEventProcessor
51 {
52 public:
53
54   /**
55    * Create an event processor.
56    * @param[in] stage The stage.
57    */
58   TouchEventProcessor( Stage& stage );
59
60   /**
61    * Non-virtual destructor; TouchEventProcessor is not a base class
62    */
63   ~TouchEventProcessor();
64
65   /**
66    * This function is called by the event processor whenever a touch event occurs.
67    * @param[in] event The touch event that has occurred.
68    */
69   void ProcessTouchEvent( const Integration::TouchEvent& event );
70
71 private:
72
73   // Undefined
74   TouchEventProcessor(const TouchEventProcessor&);
75
76   // Undefined
77   TouchEventProcessor& operator=(const TouchEventProcessor& rhs);
78
79 private:
80
81   /**
82    * Stores an actor pointer and connects/disconnects to any required signals appropriately when set/unset.
83    */
84   struct ActorObserver : public ProxyObject::Observer
85   {
86   public:
87
88     // Construction & Destruction
89
90     /**
91      * Constructor.
92      */
93     ActorObserver();
94
95     /**
96      * Non virtual destructor
97      */
98     ~ActorObserver();
99
100     // Methods
101
102     /**
103      * Return the stored Actor pointer.
104      * @return The Actor pointer.
105      */
106     Actor* GetActor();
107
108     /**
109      * Assignment operator.
110      * This disconnects the required signals from the currently set actor and connects to the required
111      * signals for the the actor specified (if set).
112      */
113     void SetActor( Actor* actor );
114
115     /**
116      * Resets the set actor and disconnects any connected signals.
117      */
118     void ResetActor();
119
120   private:
121
122     // Undefined
123     ActorObserver( const ActorObserver& );
124     ActorObserver& operator=( const ActorObserver& );
125
126   private:
127
128     /**
129      * This will never get called as we do not observe objects that have not been added to the scene.
130      * @param[in] proxy The proxy object.
131      * @see ProxyObject::Observer::SceneObjectAdded()
132      */
133     virtual void SceneObjectAdded(ProxyObject& proxy) { }
134
135     /**
136      * This will be called when the actor is removed from the stage, we should clear and stop
137      * observing it.
138      * @param[in] proxy The proxy object.
139      * @see ProxyObject::Observer::SceneObjectRemoved()
140      */
141     virtual void SceneObjectRemoved(ProxyObject& proxy);
142
143     /**
144      * This will be called when the actor is destroyed. We should clear the actor.
145      * No need to stop observing as the object is being destroyed anyway.
146      * @see ProxyObject::Observer::ProxyDestroyed()
147      */
148     virtual void ProxyDestroyed(ProxyObject& proxy);
149
150   private:
151     Actor* mActor;              ///< Raw pointer to an Actor.
152     bool   mActorDisconnected;  ///< Indicates whether the actor has been disconnected from the scene
153   };
154
155   Stage& mStage; ///< Used to deliver touch events
156   ActorObserver mLastPrimaryHitActor; ///< Stores the last primary point hit actor
157   ActorObserver mLastConsumedActor; ///< Stores the last consumed actor
158   Dali::RenderTask mLastRenderTask; ///< The RenderTask used for the last hit actor
159 };
160
161 } // namespace Internal
162
163 } // namespace Dali
164
165 #endif // __DALI_INTERNAL_TOUCH_EVENT_PROCESSOR_H__