Dileep Marchya | f9ba485 | 2014-10-24 19:56:57 -0700 | [diff] [blame] | 1 | /* |
| 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 Marchya | 3ffb470 | 2014-12-04 16:31:37 -0800 | [diff] [blame] | 28 | #include <core/sde_types.h> |
Dileep Marchya | b61346f | 2014-11-06 14:36:19 -0800 | [diff] [blame] | 29 | |
Dileep Marchya | 3ffb470 | 2014-12-04 16:31:37 -0800 | [diff] [blame] | 30 | #define DLOG(tag, method, format, ...) Debug::GetLogHandler()->method(tag, \ |
| 31 | __CLASS__ "::%s: " format, __FUNCTION__, ##__VA_ARGS__) |
Dileep Marchya | b61346f | 2014-11-06 14:36:19 -0800 | [diff] [blame] | 32 | |
Dileep Marchya | 3ffb470 | 2014-12-04 16:31:37 -0800 | [diff] [blame] | 33 | #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 Marchya | b61346f | 2014-11-06 14:36:19 -0800 | [diff] [blame] | 37 | |
Dileep Marchya | 3ffb470 | 2014-12-04 16:31:37 -0800 | [diff] [blame] | 38 | #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 Marchya | b61346f | 2014-11-06 14:36:19 -0800 | [diff] [blame] | 42 | |
Dileep Marchya | f9ba485 | 2014-10-24 19:56:57 -0700 | [diff] [blame] | 43 | namespace sde { |
| 44 | |
Dileep Marchya | f9ba485 | 2014-10-24 19:56:57 -0700 | [diff] [blame] | 45 | class Debug { |
| 46 | public: |
Dileep Marchya | 3ffb470 | 2014-12-04 16:31:37 -0800 | [diff] [blame] | 47 | 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 Marchya | f9ba485 | 2014-10-24 19:56:57 -0700 | [diff] [blame] | 50 | |
| 51 | private: |
| 52 | Debug(); |
Dileep Marchya | 3ffb470 | 2014-12-04 16:31:37 -0800 | [diff] [blame] | 53 | |
| 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 Marchya | f9ba485 | 2014-10-24 19:56:57 -0700 | [diff] [blame] | 66 | bool virtual_driver_; |
| 67 | static Debug debug_; |
| 68 | }; |
| 69 | |
| 70 | } // namespace sde |
| 71 | |
| 72 | #endif // __DEBUG_H__ |
| 73 | |