strusBase  0.17
debugTraceInterface.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
10 #ifndef _STRUS_DEBUG_TRACE_INTERFACE_HPP_INCLUDED
11 #define _STRUS_DEBUG_TRACE_INTERFACE_HPP_INCLUDED
12 #include "strus/errorCodes.hpp"
13 #include <string>
14 #include <vector>
15 
17 namespace strus
18 {
19 
23 {
24  enum Type {Open, Close, Event};
25 
26  DebugTraceMessage( Type type_, const char* component_, const char* id_, const std::string& content_)
27  :m_type(type_),m_component(component_),m_id(id_),m_content(content_){}
29  :m_type(o.m_type),m_component(o.m_component),m_id(o.m_id),m_content(o.m_content){}
30 
31  static const char* typeName( Type tp)
32  {
33  static const char* ar[] = {"open","close","event"};
34  return ar[tp];
35  }
36 
37  Type type() const {return m_type;}
38  const char* component() const {return m_component;}
39  const char* id() const {return m_id;}
40  const std::string& content() const {return m_content;}
41 
42  const char* typeName() const {return typeName( m_type);}
43 
44 private:
45  Type m_type;
46  const char* m_component;
47  const char* m_id;
48  std::string m_content;
49 };
50 
54 {
55 public:
58 
63  virtual void open( const char* type, const std::string& name=std::string())=0;
64 
66  virtual void close()=0;
67 
72  virtual void event( const char* eventid, const char* format, ...)
73 #ifdef __GNUC__
74  __attribute__ ((format (printf, 3, 4)))
75 #endif
76  =0;
77 };
78 
82 {
83 public:
86 
90  virtual bool setMaxNofThreads( unsigned int maxNofThreads)=0;
91 
96  virtual bool enable( const std::string& component)=0;
97 
100  virtual void disable( const std::string& component)=0;
101 
106  virtual DebugTraceContextInterface* createTraceContext( const char* component) const=0;
107 
110  virtual void allocContext()=0;
111 
114  virtual void releaseContext()=0;
115 
117  virtual bool hasError() const=0;
118 
120  virtual std::vector<DebugTraceMessage> fetchMessages() const=0;
121 };
122 
123 }//namespace
124 #endif
125 
virtual void releaseContext()=0
Dellocate context for current thread.
virtual bool enable(const std::string &component)=0
Enable debugging for a component adressed by name.
virtual void allocContext()=0
Allocate context for current thread.
const char * id() const
Definition: debugTraceInterface.hpp:39
Definition: debugTraceInterface.hpp:24
virtual void event(const char *eventid, const char *format,...)=0
Report an event.
virtual void disable(const std::string &component)=0
Disable debugging for a component adressed by name if enabled before.
Managing interface for reporting debug trace messages in a uniform way.
Definition: debugTraceInterface.hpp:81
virtual void open(const char *type, const std::string &name=std::string())=0
Hierarchical open of a scope of events.
virtual std::vector< DebugTraceMessage > fetchMessages() const =0
Get and clear all messages of the current thread an clears the error flag.
DebugTraceMessage(const DebugTraceMessage &o)
Definition: debugTraceInterface.hpp:28
const std::string & content() const
Definition: debugTraceInterface.hpp:40
const char * typeName() const
Definition: debugTraceInterface.hpp:42
Type type() const
Definition: debugTraceInterface.hpp:37
virtual void close()=0
Close of the current scope.
One item of a debug trace.
Definition: debugTraceInterface.hpp:22
virtual bool hasError() const =0
Test if an error occurred in the trace.
virtual bool setMaxNofThreads(unsigned int maxNofThreads)=0
Redefine the maximum number of threads using the debug trace.
Definition: debugTraceInterface.hpp:24
Structured error codes for strus components.
virtual DebugTraceContextInterface * createTraceContext(const char *component) const =0
Get the context for a component addressed by name if enabled for the current thread.
Interface for reporting debug trace messages in a uniform way.
Definition: debugTraceInterface.hpp:53
Definition: debugTraceInterface.hpp:24
virtual ~DebugTraceContextInterface()
Destructor.
Definition: debugTraceInterface.hpp:57
Type
Definition: debugTraceInterface.hpp:24
virtual ~DebugTraceInterface()
Destructor.
Definition: debugTraceInterface.hpp:85
DebugTraceMessage(Type type_, const char *component_, const char *id_, const std::string &content_)
Definition: debugTraceInterface.hpp:26
const char * component() const
Definition: debugTraceInterface.hpp:38
static const char * typeName(Type tp)
Definition: debugTraceInterface.hpp:31