Trace Macros Example
Example 50 uses the set declaration macros with the event generation macros in a typical class. A more comprehensive example can be found in buildspace\examples\trace\example1.cpp.
Example 50 – Declaring trace event sets
// File: CoffeeRobot.h
 
#define RW_USER_TRACE_LEVEL 8 //1
#include <rw/trace/trace.h>
 
RW_USER_DECLARE_TRACEABLE_CLASS(CoffeeRobot) //2
 
Class CoffeeRobot
{
CoffeeRobot() {
RW_USER_TRACEABLE_INLINE_MEMBER("CoffeeRobot_ctor”,
CoffeeRobot); //3
}
void makeCoffee(int cups);
};
 
 
// File: CoffeeRobot.cpp
 
#include "CoffeeRobot.h”
 
RW_USER_DEFINE_TRACEABLE_CLASS(CoffeeRobot) //4
 
void
CoffeeRobot::makeCoffee(int cups)
{
RW_USER_TRACEABLE_MEMBER("CoffeeRobot_makeCoffee”,
CoffeeRobot) //5
 
RW_USER_TRACE_OBJECT_DEBUG(
RW_STREAM_TO_STRING("Number of cups = " << cups ) ); //6
. . .
}
 
void globalHelper( void )
{
RW_USER_TRACEABLE_FUNCTION( "globalHelper” ); //7
RW_USER_TRACE_INFO("I’m here to help”); //8
}
 
//1 This line sets the maximum trace level to compile into the code. To compile in all the trace macros, the level is set to the maximum 8 (Entry/Exit). You could also define the trace level on the command line for your compiler, using the -DRW_USER_TRACE_LEVEL=8 flag.
//2 This macro declares the class CoffeeRobot as traceable. The declaration enables you to set an environment variable CoffeeRobot to ON or OFF to toggle tracing for this class at runtime. Remember to use the appropriate DEFINE macro in the implementation file (see Class Declaration Macros).
//3 This macro declares the constructor as traceable and a member of the CoffeeRobot class (for tracing purposes). The declaration enables you to set an environment variable CoffeeRobot_ctor to ON or OFF to toggle tracing for this function at runtime. This macro automatically generates ENTRY and EXIT events when this function is called. Note the use of the INLINE version of the macro, because this constructor is defined inline.
//4 This macro matches the DECLARE macro in line //2. This DEFINE macro must appear in an implementation file exactly once for each class declared as traceable. If this macro is not used, the linker reports that some symbols are undefined.
//5 This macro declares the member function makeCoffee() as traceable and as a member of the CoffeeRobot class (for tracing purposes). The macro also enables you to set an environment variable CoffeeRobot_makeCoffee to ON or OFF to toggle tracing for this function at runtime. The macro automatically generates ENTRY and EXIT events when this function is called.
//6 This macro generates a DEBUG event for this member function. Because it is a member function, the OBJECT version of the macro is used. This macro uses the RW_STREAM_TO_STRING macro to include the value of the parameter in the trace message.
//7 This macro declares the function as traceable and enables you to set an environment variable named globalHelper to ON or OFF to toggle tracing for this function at runtime. ENTRY and EXIT events are generated automatically when this function is called. Note the macro used for this global function.
//8 This macro generates an INFO event for this function. The macro name does not contain the word OBJECT, because this is not a member function.