Dali 3D User Interface Engine
debug.h
Go to the documentation of this file.
1 #ifndef __DALI_INTEGRATION_DEBUG_H__
2 #define __DALI_INTEGRATION_DEBUG_H__
3 
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20 
21 // EXTERNAL INCLUDES
22 #include <string>
23 #include <sstream>
24 #include <list>
25 
26 // INTERNAL INCLUDES
28 
29 // Using Debug namespace alias shortens the log usage significantly
30 namespace Dali{namespace Integration{namespace Log{}}}
31 namespace Debug = Dali::Integration::Log;
32 
33 namespace Dali
34 {
35 
36 struct Vector2;
37 struct Vector3;
38 struct Vector4;
39 class Matrix3;
40 class Matrix;
41 class Quaternion;
42 
43 namespace Integration
44 {
45 namespace Log
46 {
47 
49 {
53 };
54 
60 DALI_IMPORT_API void LogMessage(enum DebugPriority level,const char *format, ...);
61 
65 typedef void (*LogFunction)(DebugPriority priority, std::string& message);
66 
74 DALI_IMPORT_API void InstallLogFunction(const LogFunction& logFunction);
75 
81 
82 /********************************************************************************
83  * Error/Warning macros. *
84  ********************************************************************************/
85 
89 #define DALI_LOG_ERROR(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugError, "%s " format, __PRETTY_FUNCTION__, ## args)
90 
91 #define DALI_LOG_ERROR_NOFN(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugError, format, ## args)
92 
96 #define DALI_LOG_FPS(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, format, ## args)
97 
101 #define DALI_LOG_UPDATE_STATUS(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, format, ## args)
102 
106 #define DALI_LOG_RENDER_INFO(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, format, ## args)
107 
108 #ifdef DEBUG_ENABLED
109 
113 #define DALI_LOG_WARNING(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugWarning, "%s " format, __PRETTY_FUNCTION__, ## args)
114 
115 
116 #else // DEBUG_ENABLED
117 
118 // Don't warn on release build
119 #define DALI_LOG_WARNING(format, args...)
120 
121 #endif
122 
123 /********************************************************************************
124  * Filter *
125  ********************************************************************************/
126 
127 #ifdef DEBUG_ENABLED
128 
134 enum LogLevel
135 {
136  NoLogging = 0,
137  Concise = 1,
138  General = 2,
139  Verbose = 3
140 };
141 
142 
151 class DALI_IMPORT_API Filter
152 {
153 public:
154  typedef std::list<Filter*> FilterList;
155  typedef std::list<Filter*>::iterator FilterIter;
156 
157 public:
158 
164  bool IsEnabledFor(LogLevel level) { return level != Debug::NoLogging && level <= mLoggingLevel;}
165 
170  bool IsTraceEnabled() { return mTraceEnabled; }
171 
175  void EnableTrace() { mTraceEnabled = true; }
176 
180  void DisableTrace() { mTraceEnabled = false; }
181 
186  void SetLogLevel(LogLevel level) { mLoggingLevel = level; }
187 
191  void Log(LogLevel level, const char* format, ...);
192 
216  static Filter* New(LogLevel level, bool trace, const char * environmentVariableName );
217 
221  void EnableGlobalTrace();
222 
226  void DisableGlobalTrace();
227 
228 private:
229 
235  Filter(LogLevel level, bool trace) : mLoggingLevel(level), mTraceEnabled(trace), mNesting(0) {}
236 
237  static FilterList* GetActiveFilters();
238 
239 public:
240  // High level filters. If these filters are too broad for your current requirement, then
241  // you can add a filter to your own class or source file. If you do, use Filter::New()
242  // to tell this class about it.
243 
244  static Filter *gRender;
245  static Filter *gResource;
246  static Filter *gGLResource;
247  static Filter *gObject;
248  static Filter *gImage;
249  static Filter *gModel;
250  static Filter *gNode;
251  static Filter *gElement;
252  static Filter *gActor;
253  static Filter *gShader;
254 
255 private:
256  LogLevel mLoggingLevel;
257  bool mTraceEnabled;
258 public:
259  int mNesting;
260 
261 };
262 
263 
264 #define DALI_LOG_FILTER_SET_LEVEL(filter, level) filter->SetLogLevel(level)
265 #define DALI_LOG_FILTER_ENABLE_TRACE(filter) filter->EnableTrace()
266 #define DALI_LOG_FILTER_DISABLE_TRACE(filter) filter->DisableTrace()
267 
268 #else
269 
270 #define DALI_LOG_FILTER_SET_LEVEL(filter, level)
271 #define DALI_LOG_FILTER_ENABLE_TRACE(filter)
272 #define DALI_LOG_FILTER_DISABLE_TRACE(filter)
273 
274 #endif
275 
276 /********************************************************************************
277  * General Logging macros *
278  ********************************************************************************/
279 
280 #ifdef DEBUG_ENABLED
281 
282 #define DALI_LOG_INFO(filter, level, format, args...) \
283  if(filter && filter->IsEnabledFor(level)) { filter->Log(level, format, ## args); }
284 
285 #else // DEBUG_ENABLED
286 
287 #define DALI_LOG_INFO(filter, level, format, args...)
288 
289 #endif // DEBUG_ENABLED
290 
291 
292 /********************************************************************************
293  * Trace Macros *
294  ********************************************************************************/
295 
296 /*
297  * These macros allow the instrumentation of methods. These translate into calls
298  * to LogMessage(DebugInfo).
299  */
300 
301 #ifdef DEBUG_ENABLED
302 
303 class DALI_IMPORT_API TraceObj
304 {
305 public:
306  TraceObj(Filter* filter, const char* fmt, ...);
307  ~TraceObj();
308 
309 public:
310  std::string mMessage;
311  Filter* mFilter;
312 };
313 
314 
315 #define DALI_LOG_TRACE_METHOD_FMT(filter, format, args...) \
316  Dali::Integration::Log::TraceObj debugTraceObj(filter, "%s: " format, __PRETTY_FUNCTION__, ## args)
317 
318 #define DALI_LOG_TRACE_METHOD(filter) \
319  Dali::Integration::Log::TraceObj debugTraceObj(filter, __PRETTY_FUNCTION__)
320 
321 
322 #else // DEBUG_ENABLED
323 
324 #define DALI_LOG_TRACE_METHOD_FMT(filter, format, args...)
325 #define DALI_LOG_TRACE_METHOD(filter)
326 
327 
328 #endif
329 
330 /********************************************************************************
331  * Extra object debug *
332  ********************************************************************************/
333 
334 #ifdef DEBUG_ENABLED
335 
343 #define DALI_LOG_OBJECT_STRING_DECLARATION \
344 public: \
345  std::string mDebugString;
346 
350 #define DALI_LOG_ACTOR_TREE( node ) { \
351  std::stringstream branch; \
352  Node* tempNode = node; \
353  while( tempNode ) { \
354  branch << "<" << tempNode->mDebugString << ">::"; \
355  tempNode = tempNode->GetParent(); \
356  } \
357  DALI_LOG_ERROR_NOFN("Actor tree: %s\n", branch.str().c_str()); \
358 }
359 
363 #define DALI_LOG_SET_OBJECT_STRING(object, string) (object->mDebugString = string)
364 
368 #define DALI_LOG_FMT_OBJECT_STRING(object, fmt, args...) (object->mDebugString = FormatToString(fmt, ## args))
369 
373 #define DALI_LOG_GET_OBJECT_STRING(object) (object->mDebugString)
374 
378 #define DALI_LOG_GET_OBJECT_C_STR(object) (object->mDebugString.c_str())
379 
383 #define DALI_LOG_OBJECT(filter, object) DALI_LOG_INFO(filter, Debug::General, object->mDebugString)
384 
385 
386 #else // DEBUG_ENABLED
387 
388 #define DALI_LOG_OBJECT_STRING_DECLARATION
389 #define DALI_LOG_ACTOR_TREE(node)
390 #define DALI_LOG_SET_OBJECT_STRING(object, string)
391 #define DALI_LOG_FMT_OBJECT_STRING(object, fmt, args...)
392 #define DALI_LOG_GET_OBJECT_STRING(object)
393 #define DALI_LOG_GET_OBJECT_C_STR(object) ""
394 #define DALI_LOG_OBJECT(filter, object)
395 
396 #endif
397 
398 /********************************************************************************
399  * Helper writers *
400  ********************************************************************************/
401 
407 DALI_IMPORT_API std::string ColorToString(const Vector4& color);
408 
416 DALI_IMPORT_API std::string Vector4ToString(const Vector4& v, size_t precision=3, size_t indent=0);
417 
425 DALI_IMPORT_API std::string Vector3ToString(const Vector3& v, size_t precision=3, size_t indent=0);
426 
434 DALI_IMPORT_API std::string QuaternionToString(const Quaternion& q, size_t precision=3, size_t indent=0);
435 
443 DALI_IMPORT_API std::string Matrix3ToString(const Matrix3& m, size_t precision=3, size_t indent=0);
444 
452 DALI_IMPORT_API std::string MatrixToString(const Matrix& m, size_t precision=3, size_t indent=0);
453 
454 #ifdef DEBUG_ENABLED
455 
456 
460 #define DALI_LOG_MATRIX(filter, matrix) DALI_LOG_INFO(filter, Debug::General, MatrixToString(matrix))
461 
465 #define DALI_LOG_VECTOR4(filter, vector) DALI_LOG_INFO(filter, Debug::General, Vector4ToString(vector))
466 
470 #define DALI_LOG_VECTOR3(filter, vector) DALI_LOG_INFO(filter, Debug::General, Vector3ToString(vector))
471 
475 #define DALI_LOG_COLOR(filter, color) DALI_LOG_INFO(filter, Debug::General, ColorToString(color))
476 
477 #else
478 
479 #define DALI_LOG_MATRIX(filter, matrix)
480 #define DALI_LOG_VECTOR4(filter,vector)
481 #define DALI_LOG_VECTOR3(filter,vector)
482 #define DALI_LOG_COLOR(filter, color)
483 
484 #endif
485 
486 }}} // Dali/Integration/Debug namespaces
487 
488 
489 #endif // __DALI_INTEGRATION_DEBUG_H__
Dali Docs Home
Read more about Dali