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