]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re/util/include/debug
update
[l4.git] / l4 / pkg / l4re / util / include / debug
1 // vi:ft=cpp
2 /**
3  * \internal
4  * \file
5  * \brief Debug interface
6  */
7 /*
8  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9  *               Alexander Warg <warg@os.inf.tu-dresden.de>
10  *     economic rights: Technische Universität Dresden (Germany)
11  *
12  * This file is part of TUD:OS and distributed under the terms of the
13  * GNU General Public License 2.
14  * Please see the COPYING-GPL-2 file for details.
15  *
16  * As a special exception, you may use this file as part of a free software
17  * library without restriction.  Specifically, if other files instantiate
18  * templates or use macros or inline functions from this file, or you compile
19  * this file and link it with other files to produce an executable, this
20  * file does not by itself cause the resulting executable to be covered by
21  * the GNU General Public License.  This exception does not however
22  * invalidate any other reasons why the executable file might be covered by
23  * the GNU General Public License.
24  */
25 #pragma once
26
27 #include <l4/sys/types.h>
28
29 namespace L4Re { namespace Util {
30 class Err
31 {
32 public:
33   enum Level
34   {
35     Normal = 0,
36     Fatal,
37   };
38
39   static char const *const levels[];
40
41   void tag() const
42   { cprintf("%s: %s", _component, levels[_l]); }
43
44   int printf(char const *fmt, ...) const
45     __attribute__((format(printf,2,3)));
46
47   int cprintf(char const *fmt, ...) const
48     __attribute__((format(printf,2,3)));
49
50 protected:
51   Err(Level l, char const *component) : _l(l), _component(component)
52   {}
53
54 private:
55   Level _l;
56   char const *_component;
57 };
58
59
60 class Dbg
61 {
62 private:
63   void tag() const;
64
65 #ifndef NDEBUG
66
67   unsigned long _m;
68   char const *const _component;
69   char const *const _subsys;
70
71 public:
72   static unsigned long level;
73
74   static void set_level(unsigned long l) { level = l; }
75
76   bool is_active() const { return _m & level; }
77
78   int printf(char const *fmt, ...) const
79     __attribute__((format(printf, 2, 3)));
80
81   int cprintf(char const *fmt, ...) const
82     __attribute__((format(printf, 2, 3)));
83
84 protected:
85   explicit
86   Dbg(unsigned long mask, char const *comp, char const *subs)
87   : _m(mask), _component(comp), _subsys(subs)
88   {}
89
90 #else
91
92 public:
93   static void set_level(unsigned long) {}
94   bool is_active() const { return false; }
95
96   int printf(char const * /*fmt*/, ...) const
97     __attribute__((format(printf, 2, 3)))
98   { return 0; }
99
100   int cprintf(char const * /*fmt*/, ...) const
101     __attribute__((format(printf, 2, 3)))
102   { return 0; }
103
104 protected:
105   explicit
106   Dbg(unsigned long, char const *, char const *) {}
107
108 #endif
109
110 };
111
112 }}
113