]> granicus.if.org Git - icinga2/blob - lib/base/context.hpp
lib->compat->statusdatawriter: fix notifications_enabled
[icinga2] / lib / base / context.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef CONTEXT_H
21 #define CONTEXT_H
22
23 #include "base/i2-base.hpp"
24 #include "base/string.hpp"
25 #include <list>
26
27 namespace icinga
28 {
29
30 class ContextTrace
31 {
32 public:
33         ContextTrace();
34
35         void Print(std::ostream& fp) const;
36
37         size_t GetLength() const;
38
39 private:
40         std::list<String> m_Frames;
41 };
42
43 std::ostream& operator<<(std::ostream& stream, const ContextTrace& trace);
44
45 /**
46  * A context frame.
47  *
48  * @ingroup base
49  */
50 class ContextFrame
51 {
52 public:
53         ContextFrame(const String& message);
54         ~ContextFrame();
55
56 private:
57         static std::list<String>& GetFrames();
58
59         friend class ContextTrace;
60 };
61
62 /* The currentContextFrame variable has to be volatile in order to prevent
63  * the compiler from optimizing it away. */
64 #define CONTEXT(message) volatile icinga::ContextFrame currentContextFrame(message)
65 }
66
67 #endif /* CONTEXT_H */