Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Threads Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

6.7 Using Trace Clients

Trace clients process trace event information, pass it on to another client, or both. Only one client can receive event messages directly from the trace manager. If you need multiple clients with different behavior, see the discussion of filters in Section 6.8.

6.7.1 Using the Predefined Client

The Execution Tracing package provides one predefined client RWTraceOstreamClient. To instantiate the client, use code similar to this:

The RWTraceOstreamClient sends output to any ostream specified to its constructor, such as cerr in the above example. This code comes from Example 52.

After instantiation, connect the client to the trace manager using the client's connectToManager() member function:

To connect the client to another filter, use the client's connect() member function and pass it the filter as an argument:

See Section 6.8 for the discussion of filters.

6.7.2 Creating User-defined Clients

If you need a client to do something more exotic than send trace output to an ostream, you need to define your own trace client class. For example, you could send the trace data out over a socket or perhaps over a serial line for remote debugging. The example in this section simply adds a timestamp to each trace message before sending it to an ostream.


Do not embed trace macros in the client's trace event processing code. To prevent infinite recursion, the trace manager ignores any trace messages generated by a client.

Figure 32 shows the trace client classes. Like other Threads Module packages, the Execution Tracing package uses the handle-body idiom. For example, an RWTraceOstreamClient object is a handle to an RWTraceOstreamClientImp instance, which actually processes the trace messages. RWTraceOstreamClient and RWTraceOstreamClientImp together form a complete client.

Figure 32: Architecture of RWTraceOstreamClient and its related classes

To create your own trace client, you must supply a new implementation derived from the body class RWTraceEventClientImp. If your client's body class has any new public member functions (in addition to those inherited from WTraceEventClientImp), you also need to create a new handle class that forwards those calls to your body. The handle must be derived from RWTraceEventClient.

The RWTraceEventClientImp::doTrace() function, which actually processes the trace events, is declared pure-virtual, so a derived body class must provide an implementation of this function. If you do not create your own derived handle class, the body class must also supply a static make() function. The function constructs a body and returns a handle to it, similar to Example 54.

Example 54: Providing a static make function for a derived body class


The returned handle's type is actually the parent class of your derived handle.

The above code is from buildspace\examples\threads\trace\example4.cpp, which shows how to create a client both ways, with or without a derived handle.

6.7.2.1 Including a Timestamp in Trace Output

Example 55 provides an implementation for the pure-virtual function doTrace() in a class derived from RWTraceEventClientImp. The code is taken from buildspace\examples\trace\example4.cpp. In this example, the class derives from RWTraceOstreamClientImp, which already has most of the necessary behavior. Only the doTrace() function is modified to provide timestamping.

Example 55: Producing trace output with a timestamp

6.7.2.2 Including Thread IDs in Trace Output

In Example 56 the derived client shown in Example 55 is given the ability to record which thread produced the trace events. The code is taken from one of the Threads package examples, -buildspace\examples\thread\trace.cpp.

Example 56: Producing trace output with thread IDs

6.7.2.3 Using Your Client

To use your client, assuming you created a derived handle, instantiate the handle and connect it to the trace manager:

or connect it to another filter:

If you did not create your own derived handle class, you must supply a static make() function (see Section 6.7.2). To use your client, instantiate a body with your client's make() function and pass it to a handle of type RWTraceEventClient. Then connect the client handle to the manager or a filter:



Previous fileTop of DocumentContentsIndex pageNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.