2 * Copyright (c) 2019 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()
37 : ActorObserver( nullptr )
41 ActorObserver::ActorObserver( CallbackBase* callback )
43 mActorDisconnected( false ),
44 mRemoveCallback( callback )
46 DALI_LOG_TRACE_METHOD( gLogFilter );
49 ActorObserver::~ActorObserver()
51 DALI_LOG_TRACE_METHOD( gLogFilter );
54 delete mRemoveCallback;
57 ActorObserver::ActorObserver( ActorObserver&& other )
58 : ActorObserver( nullptr )
60 operator=( std::move( other ) );
63 ActorObserver& ActorObserver::operator=( ActorObserver&& other )
67 SetActor( other.mActor );
68 mActorDisconnected = other.mActorDisconnected;
69 mRemoveCallback = other.mRemoveCallback;
71 other.mRemoveCallback = nullptr;
76 Actor* ActorObserver::GetActor() const
78 return mActorDisconnected ? nullptr : mActor;
81 void ActorObserver::SetActor( Actor* actor )
83 DALI_LOG_TRACE_METHOD( gLogFilter );
85 if ( mActor != actor )
93 mActor->AddObserver( *this );
94 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Start Observing: %p\n", mActor);
98 // Make sure this flag is unset (as we may have been disconnected if it's the same actor)
99 mActorDisconnected = false;
102 void ActorObserver::ResetActor()
106 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Stop Observing: %p\n", mActor);
107 mActor->RemoveObserver( *this );
109 mActorDisconnected = false;
113 void ActorObserver::SceneObjectAdded( Object& object )
115 DALI_LOG_TRACE_METHOD( gLogFilter );
117 if ( mActor == &object )
119 mActorDisconnected = false;
123 void ActorObserver::SceneObjectRemoved( Object& object )
125 DALI_LOG_TRACE_METHOD( gLogFilter );
127 if ( mActor == &object )
129 if ( mRemoveCallback )
131 // CallbackBase::Execute( *mRemoveCallback, mActor );
134 // do not call object.RemoveObserver here, object is currently iterating through observers
135 mActorDisconnected = true;
139 void ActorObserver::ObjectDestroyed(Object& object)
141 DALI_LOG_TRACE_METHOD( gLogFilter );
143 if ( mActor == &object )
145 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Stop Observing: %p\n", mActor);
150 } // namespace Internal