blob: 3462b96fd7b048d2df11de7535caa0ae0acc6f4d [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
Manoj Kumar AVM4746f242015-01-06 20:25:22 -080028#include <stdint.h>
Dileep Marchya3ffb4702014-12-04 16:31:37 -080029#include <core/sde_types.h>
Dileep Marchyab61346f2014-11-06 14:36:19 -080030
Dileep Marchya3ffb4702014-12-04 16:31:37 -080031#define DLOG(tag, method, format, ...) Debug::GetLogHandler()->method(tag, \
32 __CLASS__ "::%s: " format, __FUNCTION__, ##__VA_ARGS__)
Dileep Marchyab61346f2014-11-06 14:36:19 -080033
Dileep Marchya3ffb4702014-12-04 16:31:37 -080034#define DLOGE_IF(tag, format, ...) DLOG(tag, Error, format, ##__VA_ARGS__)
35#define DLOGW_IF(tag, format, ...) DLOG(tag, Warning, format, ##__VA_ARGS__)
36#define DLOGI_IF(tag, format, ...) DLOG(tag, Info, format, ##__VA_ARGS__)
37#define DLOGV_IF(tag, format, ...) DLOG(tag, Verbose, format, ##__VA_ARGS__)
Dileep Marchyab61346f2014-11-06 14:36:19 -080038
Dileep Marchya3ffb4702014-12-04 16:31:37 -080039#define DLOGE(format, ...) DLOGE_IF(kTagNone, format, ##__VA_ARGS__)
40#define DLOGW(format, ...) DLOGW_IF(kTagNone, format, ##__VA_ARGS__)
41#define DLOGI(format, ...) DLOGI_IF(kTagNone, format, ##__VA_ARGS__)
42#define DLOGV(format, ...) DLOGV_IF(kTagNone, format, ##__VA_ARGS__)
Dileep Marchyab61346f2014-11-06 14:36:19 -080043
Dileep Marchyaf9ba4852014-10-24 19:56:57 -070044namespace sde {
45
Dileep Marchyaf9ba4852014-10-24 19:56:57 -070046class Debug {
47 public:
Dileep Marchya3ffb4702014-12-04 16:31:37 -080048 static inline void SetLogHandler(LogHandler *log_handler) { debug_.log_handler_ = log_handler; }
49 static inline LogHandler* GetLogHandler() { return debug_.log_handler_; }
50 static inline bool IsVirtualDriver() { return debug_.virtual_driver_; }
Manoj Kumar AVM4746f242015-01-06 20:25:22 -080051 static uint32_t GetSimulationFlag();
Dileep Marchyaf9ba4852014-10-24 19:56:57 -070052
53 private:
54 Debug();
Dileep Marchya3ffb4702014-12-04 16:31:37 -080055
56 // By default, drop any log messages coming from Display Engine. It will be overriden by Display
57 // Engine client when core is successfully initialized.
58 class DefaultLogHandler : public LogHandler {
59 public:
60 virtual void Error(LogTag /*tag*/, const char */*format*/, ...) { }
61 virtual void Warning(LogTag /*tag*/, const char */*format*/, ...) { }
62 virtual void Info(LogTag /*tag*/, const char */*format*/, ...) { }
63 virtual void Verbose(LogTag /*tag*/, const char */*format*/, ...) { }
64 };
65
66 DefaultLogHandler default_log_handler_;
67 LogHandler *log_handler_;
Dileep Marchyaf9ba4852014-10-24 19:56:57 -070068 bool virtual_driver_;
69 static Debug debug_;
70};
71
72} // namespace sde
73
74#endif // __DEBUG_H__
75