Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / dali / public-api / object / base-object.cpp
index a72ca28..98ed327 100644 (file)
@@ -1,64 +1,66 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // CLASS HEADER
 #include <dali/public-api/object/base-object.h>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/object/type-registry.h>
 #include <dali/integration-api/debug.h>
+#include <dali/internal/event/common/base-object-impl.h>
 #include <dali/internal/event/common/object-registry-impl.h>
 #include <dali/internal/event/common/stage-impl.h>
+#include <dali/internal/event/common/thread-local-storage.h>
 #include <dali/internal/event/common/type-registry-impl.h>
-
-using namespace std;
+#include <dali/public-api/object/type-registry.h>
 
 namespace Dali
 {
-
 BaseObject::BaseObject()
+: mImpl(new Impl(*this))
 {
 }
 
-BaseObject::~BaseObject()
-{
-}
+BaseObject::~BaseObject() = default;
 
 void BaseObject::RegisterObject()
 {
-  if( Internal::Stage::IsInstalled() )
+  Internal::ThreadLocalStorage* tls = Internal::ThreadLocalStorage::GetInternal();
+  if(tls)
   {
-    Internal::Stage::GetCurrent()->GetObjectRegistry().RegisterObject( this );
+    tls->GetEventThreadServices().RegisterObject(this);
   }
 }
 
 void BaseObject::UnregisterObject()
 {
+  Internal::ThreadLocalStorage* tls = Internal::ThreadLocalStorage::GetInternal();
+
   // Guard to allow handle destruction after Core has been destroyed
-  if( Internal::Stage::IsInstalled() )
+  if(tls)
   {
-    Internal::Stage::GetCurrent()->GetObjectRegistry().UnregisterObject( this );
+    tls->GetEventThreadServices().UnregisterObject(this);
   }
 }
 
-bool BaseObject::DoAction(const std::string& actionName, const std::vector<Property::Value>& attributes)
+bool BaseObject::DoAction(const std::string& actionName, const Property::Map& attributes)
 {
   Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get();
 
-  if( registry )
+  if(registry)
   {
     return registry->DoActionTo(this, actionName, attributes);
   }
@@ -66,35 +68,51 @@ bool BaseObject::DoAction(const std::string& actionName, const std::vector<Prope
   return false;
 }
 
-std::string BaseObject::GetTypeName()
+const std::string& BaseObject::GetTypeName() const
 {
-  std::string name;
-
   Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get();
 
-  if( registry )
+  if(registry)
   {
-    Dali::TypeInfo typeInfo = registry->GetTypeInfo(this);
-    if( typeInfo )
+    Internal::TypeRegistry::TypeInfoPointer typeInfo = registry->GetTypeInfo(this);
+    if(typeInfo)
     {
-      name = typeInfo.GetName();
+      return typeInfo->GetName();
     }
   }
 
-  return name;
+  // Return an empty string if type-name not found.
+  DALI_LOG_WARNING("TypeName Not Found\n");
+  static std::string empty;
+  return empty;
+}
+
+bool BaseObject::GetTypeInfo(Dali::TypeInfo& typeInfo) const
+{
+  Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get();
+
+  Internal::TypeRegistry::TypeInfoPointer info = registry->GetTypeInfo(this);
+  if(info)
+  {
+    typeInfo = Dali::TypeInfo(info.Get());
+    return true;
+  }
+  else
+  {
+    return false;
+  }
 }
 
-bool BaseObject::DoConnectSignal( ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor )
+bool BaseObject::DoConnectSignal(ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor)
 {
   Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get();
 
-  if( registry )
+  if(registry)
   {
-    return registry->ConnectSignal( this, connectionTracker, signalName, functor );
+    return registry->ConnectSignal(this, connectionTracker, signalName, functor);
   }
 
   return false;
 }
 
 } // namespace Dali
-