2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/events/actor-observer.h>
20 #include <dali/integration-api/debug.h>
21 #include <dali/internal/event/actors/actor-impl.h>
31 #if defined(DEBUG_ENABLED)
32 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACTOR_OBSERVER" );
33 #endif // defined(DEBUG_ENABLED)
36 ActorObserver::ActorObserver()
38 mActorDisconnected( false ),
39 mRemoveCallback( NULL )
41 DALI_LOG_TRACE_METHOD( gLogFilter );
44 ActorObserver::ActorObserver( CallbackBase* callback )
46 mActorDisconnected( false ),
47 mRemoveCallback( callback )
51 ActorObserver::~ActorObserver()
53 DALI_LOG_TRACE_METHOD( gLogFilter );
56 delete mRemoveCallback;
59 Actor* ActorObserver::GetActor()
61 return mActorDisconnected ? NULL : mActor;
64 void ActorObserver::SetActor( Actor* actor )
66 DALI_LOG_TRACE_METHOD( gLogFilter );
68 if ( mActor != actor )
76 mActor->AddObserver( *this );
77 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Start Observing: %p\n", mActor);
81 // Make sure this flag is unset (as we may have been disconnected if it's the same actor)
82 mActorDisconnected = false;
85 void ActorObserver::ResetActor()
89 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Stop Observing: %p\n", mActor);
90 mActor->RemoveObserver( *this );
92 mActorDisconnected = false;
96 void ActorObserver::SceneObjectRemoved( Object& object )
98 DALI_LOG_TRACE_METHOD( gLogFilter );
100 if ( mActor == &object )
102 if ( mRemoveCallback )
104 // CallbackBase::Execute( *mRemoveCallback, mActor );
107 // do not call object.RemoveObserver here, object is currently iterating through observers
108 mActorDisconnected = true;
112 void ActorObserver::ObjectDestroyed(Object& object)
114 DALI_LOG_TRACE_METHOD( gLogFilter );
116 if ( mActor == &object )
118 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Stop Observing: %p\n", mActor);
123 } // namespace Internal