Merge changes I523a4ff5,Ic7d369c0 into devel/master
[platform/core/uifw/dali-core.git] / dali / integration-api / debug.cpp
index 14148d9..e67b165 100644 (file)
@@ -1,33 +1,31 @@
-//
-// 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) 2014 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/integration-api/debug.h>
 
 // EXTERNAL INCLUDES
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
+#include <cstdio>
+#include <cstdarg>
+#include <cstring>
+#include <cstdlib>
 #include <sstream>
 #include <iomanip>
 
-#ifndef EMSCRIPTEN
-# include <boost/thread/tss.hpp>
-#endif
-
 // INTERNAL INCLUDES
 #include <dali/public-api/common/constants.h>
 #include <dali/public-api/math/matrix3.h>
@@ -84,28 +82,7 @@ namespace Integration
 namespace Log
 {
 
-typedef LogFunction* LogFunctionPtr; ///< LogFunction pointer
-
-/**
- * This stores a pointer to a log function in thread local storage.
- * The data has to be allocated from the heap because
- * it will automatically be deleted when the thread terminates
- */
-struct ThreadLocalLogging
-{
-  ThreadLocalLogging(LogFunction func)
-  :function(func)
-  {
-  }
-
-  LogFunction function;
-};
-
-#ifndef EMSCRIPTEN // single threaded
-boost::thread_specific_ptr<ThreadLocalLogging> threadLocal;
-#else
-std::auto_ptr<ThreadLocalLogging> threadLocal;
-#endif
+__thread LogFunction gthreadLocalLogFunction = NULL;
 
 /* Forward declarations */
 std::string FormatToString(const char *format, ...);
@@ -113,14 +90,7 @@ std::string ArgListToString(const char *format, va_list args);
 
 void LogMessage(DebugPriority priority, const char* format, ...)
 {
-  ThreadLocalLogging* threadLogging = threadLocal.get();
-  // see if there is a log function for this thread
-  if (!threadLogging)
-  {
-    return;
-  }
-  const LogFunction& logfunction = threadLogging->function;
-  if (!logfunction)
+  if ( !gthreadLocalLogFunction )
   {
     return;
   }
@@ -130,7 +100,7 @@ void LogMessage(DebugPriority priority, const char* format, ...)
   std::string message = ArgListToString(format, arg);
   va_end(arg);
 
-  logfunction(priority,message);
+  gthreadLocalLogFunction(priority,message);
 }
 
 void InstallLogFunction(const LogFunction& logFunction)
@@ -138,14 +108,12 @@ void InstallLogFunction(const LogFunction& logFunction)
   // TLS stores a pointer to an object.
   // It needs to be allocated on the heap, because TLS will destroy it when the thread exits.
 
-  ThreadLocalLogging* logStruct = new ThreadLocalLogging(logFunction);
-
-  threadLocal.reset(logStruct);
+  gthreadLocalLogFunction = logFunction;
 }
 
 void UninstallLogFunction()
 {
-  threadLocal.reset();
+  gthreadLocalLogFunction = NULL;
 }
 
 #ifdef DEBUG_ENABLED
@@ -161,7 +129,6 @@ Filter* Filter::gNode       = NULL;
 Filter* Filter::gElement    = NULL;
 Filter* Filter::gActor      = Filter::New(Debug::Concise, false, "LOG_ACTOR");
 Filter* Filter::gShader     = Filter::New(Debug::Concise, false, "LOG_SHADER");
-Filter* Filter::gDynamics   = Filter::New(Debug::Concise, false, "LOG_DYNAMICS");
 
 Filter::FilterList* Filter::GetActiveFilters()
 {
@@ -231,13 +198,21 @@ void Filter::Log(LogLevel level, const char* format, ...)
     va_list arg;
     va_start(arg, format);
 
-    char *buffer = NULL;
-    int numChars = asprintf(&buffer, "%-*c %s", mNesting, ':', format);
-    if(numChars >= 0) // No error
+    if( mTraceEnabled )
     {
-      std::string message = ArgListToString(buffer, arg);
-      LogMessage(DebugInfo, message.c_str());
-      free(buffer);
+      char *buffer = NULL;
+      int numChars = asprintf( &buffer, "    %-*c %s", mNesting, ':', format );
+      if( numChars >= 0 ) // No error
+      {
+        std::string message = ArgListToString( buffer, arg );
+        LogMessage( DebugInfo, message.c_str() );
+        free( buffer );
+      }
+    }
+    else
+    {
+      std::string message = ArgListToString( format, arg );
+      LogMessage( DebugInfo, message.c_str() );
     }
     va_end(arg);
   }
@@ -331,11 +306,11 @@ std::string QuaternionToString(const Quaternion& q, size_t precision, size_t ind
   std::ostringstream oss;
 
   Vector3 axis;
-  float angle;
+  Radian angle;
   q.ToAxisAngle(axis, angle);
 
   oss << std::setw(indent+3) << std::setfill(' ') << std::setprecision(precision) << std::right;
-  oss << "<A:" << std::setw(precision+4) << angle * 180.0 / Math::PI << ", " << Vector3ToString(axis, precision, 0) << ">";
+  oss << "<A:" << std::setw(precision+4) << Degree( angle ).degree << ", " << Vector3ToString(axis, precision, 0) << ">";
 
   return oss.str();
 }