Dali 3D User Interface Engine
actor-observer.cpp
Go to the documentation of this file.
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
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 
37 : mActor ( NULL ),
38  mActorDisconnected( false ),
39  mRemoveCallback( NULL )
40 {
41  DALI_LOG_TRACE_METHOD( gLogFilter );
42 }
43 
45 : mActor ( NULL ),
46  mActorDisconnected( false ),
47  mRemoveCallback( callback )
48 {
49 }
50 
52 {
53  DALI_LOG_TRACE_METHOD( gLogFilter );
54  SetActor( NULL );
55 
56  delete mRemoveCallback;
57 }
58 
60 {
61  return mActorDisconnected ? NULL : mActor;
62 }
63 
65 {
66  DALI_LOG_TRACE_METHOD( gLogFilter );
67 
68  if ( mActor != actor )
69  {
70  ResetActor();
71 
72  mActor = actor;
73 
74  if ( mActor )
75  {
76  mActor->AddObserver( *this );
77  DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Start Observing: %p\n", mActor);
78  }
79  }
80 
81  // Make sure this flag is unset (as we may have been disconnected if it's the same actor)
82  mActorDisconnected = false;
83 }
84 
86 {
87  if ( mActor )
88  {
89  DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Stop Observing: %p\n", mActor);
90  mActor->RemoveObserver( *this );
91  mActor = NULL;
92  mActorDisconnected = false;
93  }
94 }
95 
97 {
98  DALI_LOG_TRACE_METHOD( gLogFilter );
99 
100  if ( mActor == &object )
101  {
102  if ( mRemoveCallback )
103  {
105  }
106 
107  // do not call object.RemoveObserver here, object is currently iterating through observers
108  mActorDisconnected = true;
109  }
110 }
111 
113 {
114  DALI_LOG_TRACE_METHOD( gLogFilter );
115 
116  if ( mActor == &object )
117  {
118  DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Stop Observing: %p\n", mActor);
119  mActor = NULL;
120  }
121 }
122 
123 } // namespace Internal
124 
125 } // namespace Dali
126 
Dali Docs Home
Read more about Dali