[dali_1.0.12] Merge branch 'tizen'
[platform/core/uifw/dali-core.git] / dali / internal / event / events / actor-observer.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/integration-api/debug.h>
20 #include <dali/internal/event/actors/actor-impl.h>
21 #include <dali/internal/event/events/actor-observer.h>
22
23 namespace Dali
24 {
25
26 namespace Internal
27 {
28
29 namespace
30 {
31 #if defined(DEBUG_ENABLED)
32 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACTOR_OBSERVER" );
33 #endif // defined(DEBUG_ENABLED)
34 }
35
36 ActorObserver::ActorObserver::ActorObserver()
37 : mActor ( NULL ),
38   mActorDisconnected(false)
39 {
40   DALI_LOG_TRACE_METHOD( gLogFilter );
41 }
42
43 ActorObserver::ActorObserver::~ActorObserver()
44 {
45   DALI_LOG_TRACE_METHOD( gLogFilter );
46   SetActor( NULL );
47 }
48
49 Actor* ActorObserver::ActorObserver::GetActor()
50 {
51   return mActorDisconnected ? NULL : mActor;
52 }
53
54 void ActorObserver::ActorObserver::SetActor( Actor* actor )
55 {
56   DALI_LOG_TRACE_METHOD( gLogFilter );
57
58   if ( mActor != actor )
59   {
60     ResetActor();
61
62     mActor = actor;
63
64     if ( mActor )
65     {
66       mActor->AddObserver( *this );
67       DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Start Observing:            %p\n", mActor);
68     }
69   }
70
71   // Make sure this flag is unset (as we may have been disconnected if it's the same actor)
72   mActorDisconnected = false;
73 }
74
75 void ActorObserver::ActorObserver::ResetActor()
76 {
77   if ( mActor )
78   {
79     DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Stop Observing:             %p\n", mActor);
80     mActor->RemoveObserver( *this );
81     mActor = NULL;
82     mActorDisconnected = false;
83   }
84 }
85
86 void ActorObserver::ActorObserver::SceneObjectRemoved( ProxyObject& proxy )
87 {
88   DALI_LOG_TRACE_METHOD( gLogFilter );
89
90   if ( mActor == &proxy )
91   {
92     // do not call proxy.RemoveObserver here, proxy is currently iterating through observers... you wouldnt want to upset proxy now would you?
93     mActorDisconnected = true;
94   }
95 }
96
97 void ActorObserver::ActorObserver::ProxyDestroyed(ProxyObject& proxy)
98 {
99   DALI_LOG_TRACE_METHOD( gLogFilter );
100
101   if ( mActor == &proxy )
102   {
103     DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Stop Observing:             %p\n", mActor);
104     mActor = NULL;
105   }
106 }
107
108 } // namespace Internal
109
110 } // namespace Dali
111