blob: 8fbfb7147df601799407d5de9ed0005cfe976e4f [file] [log] [blame]
Dileep Marchyaf9ba4852014-10-24 19:56:57 -07001/*
2* Copyright (c) 2014, The Linux Foundation. All rights reserved.
3*
4* Redistribution and use in source and binary forms, with or without modification, are permitted
5* provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright notice, this list of
7* conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright notice, this list of
9* conditions and the following disclaimer in the documentation and/or other materials provided
10* with the distribution.
11* * Neither the name of The Linux Foundation nor the names of its contributors may be used to
12* endorse or promote products derived from this software without specific prior written
13* permission.
14*
15* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24
25#ifndef __DEBUG_H__
26#define __DEBUG_H__
27
Dileep Marchya3ffb4702014-12-04 16:31:37 -080028#include <core/sde_types.h>
Dileep Marchyab61346f2014-11-06 14:36:19 -080029
Dileep Marchya3ffb4702014-12-04 16:31:37 -080030#define DLOG(tag, method, format, ...) Debug::GetLogHandler()->method(tag, \
31 __CLASS__ "::%s: " format, __FUNCTION__, ##__VA_ARGS__)
Dileep Marchyab61346f2014-11-06 14:36:19 -080032
Dileep Marchya3ffb4702014-12-04 16:31:37 -080033#define DLOGE_IF(tag, format, ...) DLOG(tag, Error, format, ##__VA_ARGS__)
34#define DLOGW_IF(tag, format, ...) DLOG(tag, Warning, format, ##__VA_ARGS__)
35#define DLOGI_IF(tag, format, ...) DLOG(tag, Info, format, ##__VA_ARGS__)
36#define DLOGV_IF(tag, format, ...) DLOG(tag, Verbose, format, ##__VA_ARGS__)
Dileep Marchyab61346f2014-11-06 14:36:19 -080037
Dileep Marchya3ffb4702014-12-04 16:31:37 -080038#define DLOGE(format, ...) DLOGE_IF(kTagNone, format, ##__VA_ARGS__)
39#define DLOGW(format, ...) DLOGW_IF(kTagNone, format, ##__VA_ARGS__)
40#define DLOGI(format, ...) DLOGI_IF(kTagNone, format, ##__VA_ARGS__)
41#define DLOGV(format, ...) DLOGV_IF(kTagNone, format, ##__VA_ARGS__)
Dileep Marchyab61346f2014-11-06 14:36:19 -080042
Dileep Marchyaf9ba4852014-10-24 19:56:57 -070043namespace sde {
44
Dileep Marchyaf9ba4852014-10-24 19:56:57 -070045class Debug {
46 public:
Dileep Marchya3ffb4702014-12-04 16:31:37 -080047 static inline void SetLogHandler(LogHandler *log_handler) { debug_.log_handler_ = log_handler; }
48 static inline LogHandler* GetLogHandler() { return debug_.log_handler_; }
49 static inline bool IsVirtualDriver() { return debug_.virtual_driver_; }
Dileep Marchyaf9ba4852014-10-24 19:56:57 -070050
51 private:
52 Debug();
Dileep Marchya3ffb4702014-12-04 16:31:37 -080053
54 // By default, drop any log messages coming from Display Engine. It will be overriden by Display
55 // Engine client when core is successfully initialized.
56 class DefaultLogHandler : public LogHandler {
57 public:
58 virtual void Error(LogTag /*tag*/, const char */*format*/, ...) { }
59 virtual void Warning(LogTag /*tag*/, const char */*format*/, ...) { }
60 virtual void Info(LogTag /*tag*/, const char */*format*/, ...) { }
61 virtual void Verbose(LogTag /*tag*/, const char */*format*/, ...) { }
62 };
63
64 DefaultLogHandler default_log_handler_;
65 LogHandler *log_handler_;
Dileep Marchyaf9ba4852014-10-24 19:56:57 -070066 bool virtual_driver_;
67 static Debug debug_;
68};
69
70} // namespace sde
71
72#endif // __DEBUG_H__
73