1 #ifndef __DALI_INTERNAL_OBJECT_REGISTRY_H__
2 #define __DALI_INTERNAL_OBJECT_REGISTRY_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/public-api/object/object-registry.h>
24 #include <dali/public-api/object/base-object.h>
41 typedef IntrusivePtr<ObjectRegistry> ObjectRegistryPtr;
44 * The ObjectRegistry notifies it's observers when an object is created.
45 * There is a single instance of Object registry for each Dali-core instance.
46 * All Dali Objects need to register with ObjectRegistry to be observed by
47 * feedback plugin's and other observers.
49 class ObjectRegistry : public BaseObject
54 * Create the objectRegistry
56 static ObjectRegistryPtr New();
59 * Registers the Object into the Object Registry, which notifies
60 * about this object creation to its observers using signals. As
61 * the signals use a BaseHandle, the object must already have a
62 * ref-count > 0, otherwise it will get deleted on signal completion.
63 * @pre The object is not already registered.
64 * @pre the object is ref counted (held in an intrusive pointer)
65 * @param[in] object Pointer to the object.
67 void RegisterObject( Dali::BaseObject* object );
70 * Unregisters the Object from the Object Registry, Which notifies
71 * about this object destruction to its observers.
72 * @pre The object is already registered.
73 * @param[in] object Pointer to the object.
75 void UnregisterObject( Dali::BaseObject* object );
78 * @copydoc Dali::ObjectRegistry::ObjectCreatedSignal()
80 Dali::ObjectRegistry::ObjectCreatedSignalType& ObjectCreatedSignal()
82 return mObjectCreatedSignal;
86 * @copydoc Dali::ObjectRegistry::ObjectDestroyedSignal()
88 Dali::ObjectRegistry::ObjectDestroyedSignalType& ObjectDestroyedSignal()
90 return mObjectDestroyedSignal;
94 * Connects a callback function with the object registry signals.
95 * @param[in] object The object providing the signal.
96 * @param[in] tracker Used to disconnect the signal.
97 * @param[in] signalName The signal to connect to.
98 * @param[in] functor A newly allocated FunctorDelegate.
99 * @return True if the signal was connected.
100 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
102 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
107 * Protected constructor; see also ObjectRegistry::New()
112 * A reference counted object may only be deleted by calling Unreference()
118 Dali::ObjectRegistry::ObjectCreatedSignalType mObjectCreatedSignal;
119 Dali::ObjectRegistry::ObjectDestroyedSignalType mObjectDestroyedSignal;
123 } // namespace Internal
125 // Helpers for public-api forwarding methods
127 inline Internal::ObjectRegistry& GetImplementation(Dali::ObjectRegistry& objectRegistry)
129 DALI_ASSERT_ALWAYS( objectRegistry && "ObjectRegistry handle is empty" );
131 BaseObject& handle = objectRegistry.GetBaseObject();
133 return static_cast<Internal::ObjectRegistry&>(handle);
136 inline const Internal::ObjectRegistry& GetImplementation(const Dali::ObjectRegistry& objectRegistry)
138 DALI_ASSERT_ALWAYS( objectRegistry && "ObjectRegistry handle is empty" );
140 const BaseObject& handle = objectRegistry.GetBaseObject();
142 return static_cast<const Internal::ObjectRegistry&>(handle);
147 #endif // __DALI_INTERNAL_OBJECT_REGISTRY_H__