Support multiple window rendering
[platform/core/uifw/dali-core.git] / dali / public-api / object / base-object.cpp
1 /*
2  * Copyright (c) 2015 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
19 #include <dali/public-api/object/base-object.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/internal/event/common/object-registry-impl.h>
25 #include <dali/internal/event/common/stage-impl.h>
26 #include <dali/internal/event/common/type-registry-impl.h>
27 #include <dali/internal/event/common/thread-local-storage.h>
28
29 namespace Dali
30 {
31
32 BaseObject::BaseObject()
33 {
34 }
35
36 BaseObject::~BaseObject()
37 {
38 }
39
40 void BaseObject::RegisterObject()
41 {
42   Internal::ThreadLocalStorage* tls = Internal::ThreadLocalStorage::GetInternal();
43   if ( tls )
44   {
45     tls->GetEventThreadServices().RegisterObject( this );
46   }
47 }
48
49 void BaseObject::UnregisterObject()
50 {
51   Internal::ThreadLocalStorage* tls = Internal::ThreadLocalStorage::GetInternal();
52
53   // Guard to allow handle destruction after Core has been destroyed
54   if( tls )
55   {
56     tls->GetEventThreadServices().UnregisterObject( this );
57   }
58 }
59
60 bool BaseObject::DoAction(const std::string& actionName, const Property::Map& attributes)
61 {
62   Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get();
63
64   if( registry )
65   {
66     return registry->DoActionTo(this, actionName, attributes);
67   }
68
69   return false;
70 }
71
72 const std::string& BaseObject::GetTypeName() const
73 {
74   Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get();
75
76   if( registry )
77   {
78     Internal::TypeRegistry::TypeInfoPointer typeInfo = registry->GetTypeInfo(this);
79     if( typeInfo )
80     {
81       return typeInfo->GetName();
82     }
83   }
84
85   // Return an empty string if type-name not found.
86   DALI_LOG_WARNING( "TypeName Not Found\n" );
87   static std::string empty;
88   return empty;
89 }
90
91 bool BaseObject::GetTypeInfo(Dali::TypeInfo& typeInfo) const
92 {
93   Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get();
94
95   Internal::TypeRegistry::TypeInfoPointer info = registry->GetTypeInfo(this);
96   if(info)
97   {
98     typeInfo = Dali::TypeInfo( info.Get() );
99     return true;
100   }
101   else
102   {
103     return false;
104   }
105 }
106
107 bool BaseObject::DoConnectSignal( ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor )
108 {
109   Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get();
110
111   if( registry )
112   {
113     return registry->ConnectSignal( this, connectionTracker, signalName, functor );
114   }
115
116   return false;
117 }
118
119 } // namespace Dali
120