|
OpenTop 1.5 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||||
#include "ot/base/Tracer.h"

Traditionally, C++ applications use a pre-processor macro-based approach to tracing. The implementations are sometimes inefficient and often restricted to debug builds of the program.
OpenTop takes a different approach. The Tracer class provides an abstract interface for raising trace events and for controlling which events should be recorded. We do provide an example implementation in the form of the TraceHelper class, but applications are free to implement their own Tracer class which offers the desired level of performance and functionality. For example, the TraceHelper class writes trace events to a file, but it would be possible for other implementations to write to a memory buffer, to a console or both. One important feature of OpenTop tracing is that it is available in both the debug and release builds of the library.
The Tracer class is both a class module, containing static methods to raise and control the output of trace events, as well as an abstract base class which must be derived from when creating a concrete implementation.
The static tracing methods are called from many OpenTop service routines when performing significant tasks such as creating network connections, opening files or starting and stopping threads. These static methods, in turn, call virtual member functions which must be implemented by a concrete Tracer class.
Finally, the OpenTop tracing service is extensible, allowing application code to be traced as well as OpenTop system calls.
| Method Summary | |
static void |
Activate(short nSection, short nLevel)Informs the registered Tracer that events for the specified section with a level less than or equal to nLevel should be processed. |
protected virtual void |
doActivate(short nSection, short nLevel)=0Virtual function called in response to Activate(). |
protected virtual void |
doTrace(short nSection, short nLevel, const CharType* message, size_t len)=0Virtual function called in response to Trace(). |
protected virtual void |
doTraceBytes(short nSection, short nLevel, const String& message, const Byte* bytes, size_t len)=0Virtual function called in response to Trace(). |
static void |
Enable(bool bEnable)Enables or disables tracing. |
static const CharType* |
GetSectionName(short nSection)Translates a numeric section identifier into a null-terminated CharType string. |
static short |
GetSectionNumber(const String& section)Translates a section name into a numeric identifier. |
protected virtual const CharType* |
getUserSectionName(short nSection)Returns the name of the code section with the supplied identifier. |
protected virtual short |
getUserSectionNumber(const String& section)Returns the name of the code section with the supplied identifier or -1 if the identifier is not recognized. |
static bool |
IsEnabled()Tests whether tracing has been enabled. |
static void |
SetTracer(Tracer* pTracer)Sets the system Tracer object. |
static void |
Trace(short nSection, short nLevel, const String& message)Raises a trace event. |
static void |
Trace(short nSection, short nLevel, const CharType* message, size_t len)Raises a trace event. |
static void |
TraceBytes(short nSection, short nLevel, const String& message, const Byte* bytes, size_t len)Raises a trace event. |
| Methods inherited from class ot::ManagedObject |
addRef(), getRefCount(), onFinalRelease(), operator=(const ManagedObject&), release() |
| Enumerations |
enum Levels { |
Highest =0, |
/* important events that are always traced */ |
|
Exceptions =10, |
/* exception events */ |
|
High =20, |
/* high priority events */ |
|
Medium =40, |
/* medium priority events */ |
|
Low =60, |
/* low-priority events */ |
|
Min =99} |
/* the lowest priority */ |
enum Sections { |
All =0, |
/* used to activate all sections */ |
|
Base =1, |
/* classes within the top-level OpenTop namespace */ |
|
Util =2, |
/* classes within the util namespace */ |
|
IO =3, |
/* classes within the io namespace */ |
|
Net =4, |
/* classes within the net namespace */ |
|
NIO =5, |
/* classes within the nio namespace */ |
|
Web =6, |
/* classes within the web namespace */ |
|
SSL =7, |
/* classes within the ssl namespace */ |
|
Auxil =9, |
/* classes within the auxil namespace */ |
|
XML =10, |
/* classes within the xml namespace */ |
|
User =16} |
/* starting value for user-assigned sections */ |
| Method Detail |
static void Activate(short nSection,
short nLevel)
A concrete Tracer implementation may maintain a table of section names together with the level of tracing that has been requested for each one. For example, it may record that the user wants all network access to be logged, but only exceptions from other sections of the library.
Note that the Tracer must be both activated and enabled before any trace events will be processed.
nSection - nLevel - protected virtual void doActivate(short nSection,
short nLevel)=0
nSection - nLevel - protected virtual void doTrace(short nSection,
short nLevel,
const CharType* message,
size_t len)=0
nSection - nLevel - message - len - protected virtual void doTraceBytes(short nSection,
short nLevel,
const String& message,
const Byte* bytes,
size_t len)=0
nSection - nLevel - message - bytes - len - static void Enable(bool bEnable)
Enable() has no effect on the activation options in effect, so it is possible to specify which sections of code should be traced, but not actually have tracing enabled. This makes it easy to enable and disable tracing at various points within an application without having to deal with the individual activation options each time.
bEnable - static const CharType* GetSectionName(short nSection)
If nSection is within the OpenTop assigned range, a pre-determined section name is returned. Otherwise the request is delegated to the registered Tracer object (if any).
nSection - static short GetSectionNumber(const String& section)
section - protected virtual const CharType* getUserSectionName(short nSection)
For optimum tracing efficiency, a CharType pointer is returned instead of a String. The puts a requirement on concrete implementations to ensure that the returned pointer references a valid memory location which is constant. Furthermore, regard should be given to the fact that this method may be called concurrently from multiple threads, therefore it would not be appropriate to allocate a single static buffer and update its contents with the results from each call.
nSection - protected virtual short getUserSectionNumber(const String& section)
section - static bool IsEnabled()
static void SetTracer(Tracer* pTracer)
To ensure that the passed object exists for as long as the application needs it, the Tracer object is registered with the system's ObjectManager which holds a (counted) reference to it until system termination.
static void Trace(short nSection,
short nLevel,
const String& message)
nSection - nLevel - message - static void Trace(short nSection,
short nLevel,
const CharType* message,
size_t len)
nSection - nLevel - message - len - static void TraceBytes(short nSection,
short nLevel,
const String& message,
const Byte* bytes,
size_t len)
nSection - nLevel - message - bytes - len -
|
OpenTop 1.5 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||||