2 * Copyright (c) 2021 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/integration-api/debug.h>
20 #include <dali/internal/event/actors/actor-impl.h>
21 #include <dali/internal/event/events/actor-observer.h>
29 #if defined(DEBUG_ENABLED)
30 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ACTOR_OBSERVER");
31 #endif // defined(DEBUG_ENABLED)
34 ActorObserver::ActorObserver()
35 : ActorObserver(nullptr)
39 ActorObserver::ActorObserver(CallbackBase* callback)
41 mActorDisconnected(false),
42 mRemoveCallback(callback)
44 DALI_LOG_TRACE_METHOD(gLogFilter);
47 ActorObserver::~ActorObserver()
49 DALI_LOG_TRACE_METHOD(gLogFilter);
52 delete mRemoveCallback;
55 ActorObserver::ActorObserver(ActorObserver&& other) noexcept
56 : ActorObserver(nullptr)
58 operator=(std::move(other));
61 ActorObserver& ActorObserver::operator=(ActorObserver&& other) noexcept
65 SetActor(other.mActor);
66 mActorDisconnected = other.mActorDisconnected;
67 mRemoveCallback = other.mRemoveCallback;
69 other.mRemoveCallback = nullptr;
74 Actor* ActorObserver::GetActor() const
76 return mActorDisconnected ? nullptr : mActor;
79 void ActorObserver::SetActor(Actor* actor)
81 DALI_LOG_TRACE_METHOD(gLogFilter);
91 mActor->AddObserver(*this);
92 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Start Observing: %p\n", mActor);
96 // Make sure this flag is unset (as we may have been disconnected if it's the same actor)
97 mActorDisconnected = false;
100 void ActorObserver::ResetActor()
104 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Stop Observing: %p\n", mActor);
105 mActor->RemoveObserver(*this);
107 mActorDisconnected = false;
111 void ActorObserver::SceneObjectAdded(Object& object)
113 DALI_LOG_TRACE_METHOD(gLogFilter);
115 if(mActor == &object)
117 mActorDisconnected = false;
121 void ActorObserver::SceneObjectRemoved(Object& object)
123 DALI_LOG_TRACE_METHOD(gLogFilter);
125 if(mActor == &object)
129 CallbackBase::Execute(*mRemoveCallback, mActor);
132 // do not call object.RemoveObserver here, object is currently iterating through observers
133 mActorDisconnected = true;
137 void ActorObserver::ObjectDestroyed(Object& object)
139 DALI_LOG_TRACE_METHOD(gLogFilter);
141 if(mActor == &object)
143 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Stop Observing: %p\n", mActor);
148 } // namespace Internal