Safir SDK Core
Loading...
Searching...
No Matches
Tracer.h
Go to the documentation of this file.
1/******************************************************************************
2*
3* Copyright Saab AB, 2007-2013 (http://safirsdkcore.com)
4*
5* Created by: Lars Hagström / stlrha
6*
7*******************************************************************************
8*
9* This file is part of Safir SDK Core.
10*
11* Safir SDK Core is free software: you can redistribute it and/or modify
12* it under the terms of version 3 of the GNU General Public License as
13* published by the Free Software Foundation.
14*
15* Safir SDK Core is distributed in the hope that it will be useful,
16* but WITHOUT ANY WARRANTY; without even the implied warranty of
17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18* GNU General Public License for more details.
19*
20* You should have received a copy of the GNU General Public License
21* along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22*
23******************************************************************************/
24#ifndef __SWRE_TRACER_H__
25#define __SWRE_TRACER_H__
26
27#include <Safir/Application/Internal/SwReportExportDefs.h>
28#include <Safir/Application/Internal/TraceStreamBuffer.h>
30#include <iostream>
31
32namespace Safir
33{
34namespace Application
35{
39 class SWRE_INTERFACE_CPP_API TracerBackdoor
40 {
41 public:
57 static void Start(const Safir::Dob::ConnectionBase& connection);
58
62 static void Stop();
63 };
64
65
69 class SWRE_INTERFACE_CPP_API Tracer
70 {
71 private:
72 typedef std::basic_ios<wchar_t, std::char_traits<wchar_t> > ios_type;
73 public:
74 typedef std::basic_ostream<wchar_t, std::char_traits<wchar_t> > stream_type;
75
81 explicit Tracer(const std::wstring & prefix);
82
87
93 void Enable(const bool enabled) {if (m_isEnabled == NULL) {InitializeEnabledHandling();} *m_isEnabled = enabled;}
94
100 inline bool IsEnabled() const {if (m_isEnabled == NULL) {InitializeEnabledHandling();} return *m_isEnabled;}
101
106 inline const Tracer & operator << (stream_type & (* _Pfn)(stream_type&)) const
107 {
108 if (IsEnabled())
109 {
110 (*_Pfn)(m_ostream);
111 }
112 return *this;
113 }
114
119 inline const Tracer & operator << (std::ios_base & (* _Pfn)(std::ios_base &)) const
120 {
121 if (IsEnabled())
122 {
123 (*_Pfn)(m_ostream);
124 }
125 return *this;
126 }
127
132 inline const Tracer & operator<<(ios_type & (*_Pfn)(ios_type&)) const
133 {
134 if (IsEnabled())
135 {
136 (*_Pfn)(m_ostream);
137 }
138 return *this;
139 }
140
145 template <class T>
146 inline const Tracer & operator << (const T & data) const
147 {
148 if (IsEnabled())
149 {
150 m_ostream << data;
151 }
152 return *this;
153 }
154
167 stream_type & stream() const {return m_ostream;}
168 private:
169 void InitializeEnabledHandling() const;
170
171 mutable stream_type m_ostream;
172 mutable Internal::TraceStreamBuffer m_buf;
173 mutable volatile bool * m_isEnabled;
174 };
175
176}
177}
178#endif
179
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
This class just contains two static methods, for starting and stopping the tracers backdoor.
Definition Tracer.h:40
static void Stop()
Stop reception of trace on/off commands.
static void Start(const Safir::Dob::ConnectionBase &connection)
Start reception of trace on/off commands.
A class for trace logging.
Definition Tracer.h:70
void Enable(const bool enabled)
Turn logging of this prefix on or off.
Definition Tracer.h:93
const Tracer & operator<<(ios_type &(*_Pfn)(ios_type &)) const
Output operator for io manipulators.
Definition Tracer.h:132
bool IsEnabled() const
Check whether this prefix is enabled or not.
Definition Tracer.h:100
stream_type & stream() const
Get the underlying ostream of the logger.
Definition Tracer.h:167
Tracer(const std::wstring &prefix)
Constructor.
std::basic_ostream< wchar_t, std::char_traits< wchar_t > > stream_type
Definition Tracer.h:74
Common base class for connections to the DOB.
Definition ConnectionBase.h:59