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:
53 static void Start(const Safir::Dob::ConnectionBase& connection);
54
58 static void Stop();
59 };
60
61
65 class SWRE_INTERFACE_CPP_API Tracer
66 {
67 private:
68 typedef std::basic_ios<wchar_t, std::char_traits<wchar_t> > ios_type;
69 public:
70 typedef std::basic_ostream<wchar_t, std::char_traits<wchar_t> > stream_type;
71
77 explicit Tracer(const std::wstring & prefix);
78
83
89 void Enable(const bool enabled) {if (m_isEnabled == NULL) {InitializeEnabledHandling();} *m_isEnabled = enabled;}
90
96 inline bool IsEnabled() const {if (m_isEnabled == NULL) {InitializeEnabledHandling();} return *m_isEnabled;}
97
102 inline const Tracer & operator << (stream_type & (* _Pfn)(stream_type&)) const
103 {
104 if (IsEnabled())
105 {
106 (*_Pfn)(m_ostream);
107 }
108 return *this;
109 }
110
115 inline const Tracer & operator << (std::ios_base & (* _Pfn)(std::ios_base &)) const
116 {
117 if (IsEnabled())
118 {
119 (*_Pfn)(m_ostream);
120 }
121 return *this;
122 }
123
128 inline const Tracer & operator<<(ios_type & (*_Pfn)(ios_type&)) const
129 {
130 if (IsEnabled())
131 {
132 (*_Pfn)(m_ostream);
133 }
134 return *this;
135 }
136
141 template <class T>
142 inline const Tracer & operator << (const T & data) const
143 {
144 if (IsEnabled())
145 {
146 m_ostream << data;
147 }
148 return *this;
149 }
150
163 stream_type & stream() const {return m_ostream;}
164 private:
165 void InitializeEnabledHandling() const;
166
167 mutable stream_type m_ostream;
168 mutable Internal::TraceStreamBuffer m_buf;
169 mutable volatile bool * m_isEnabled;
170 };
171
172}
173}
174#endif
175
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
Application.
Definition Backdoor.h:33
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.
void Enable(const bool enabled)
Turn logging of this prefix on or off.
Definition Tracer.h:89
const Tracer & operator<<(ios_type &(*_Pfn)(ios_type &)) const
Output operator for io manipulators.
Definition Tracer.h:128
bool IsEnabled() const
Check whether this prefix is enabled or not.
Definition Tracer.h:96
stream_type & stream() const
Get the underlying ostream of the logger.
Definition Tracer.h:163
Tracer(const std::wstring &prefix)
Constructor.
std::basic_ostream< wchar_t, std::char_traits< wchar_t > > stream_type
Definition Tracer.h:70
Common base class for connections to the DOB.
Definition ConnectionBase.h:59