../../AspectXLib/CodeInstrumentation/Tracer/aspects/TraceMethodEntryUsingTracer.axTracer object for tracing. This example is implemented according to the
Trace design pattern
This aspect program shows an example
of how the implementation of selected methods in a
certain code base can be modified to output a tracing message every time the method is entered.
In this example, the tracing message is output using a dedicated object of type
DC_TestTracer
that encapsulates the code that process the tracing messages.
DC_TestTracer class extends the
Tracer
abstract class, which is a part of the
OBS Framework.
An instance of class DC_TestTracer is accessed through the TracerSingleton class.
Hence the TracerSingleton is used as a component that sends the trace
signals to a log file or standard output.
See the Trace
design pattern for more information.
This aspect defines four advices that describe four separate but related
changes. The first advice inserts the tracing code in the target methods. The second advice
inserts a new include statement to include the stdio library that is
required by the printf method. The third advice modifies the comments of the
classes that are affected by the change to include a statement that the class code has been
automatically modified by an aspect program. The fourth advice modifies the comment of the
methods that are affected by the change to include a description of the type of change that has
been woven into the code.
This sample aspect program targets all methods called
fTwoParameter.
Pointcuts | |
| function | targetMethodImplementation |
| Points to the implementations of the methods that must be modified | |
| unit | targetImplementationUnit |
| Points to all the units that contain implementations of methods that must be
modified | |
Advices | |
| add | addIncludeRootObject |
| Add the #include "TracerSingleton | |
| begin | insertTrace |
| Insert the tracing instruction in the target method | |
fTwoParameter.
The implementation of the restriction relies on the
fact that in srcML the element name contains two other name subelements
where the first of them contains the class name and the second contains name of the method.
Therefore to access the name of the method the following expression is used:
src:name/src:name[2].
If it were
desired to capture more than one target class, this could be done by modifying the XPath
expression in the constraint to include names whose class part matches several class names.
This pointcut only points to the method implementation. A second pointcut
(targetMethodDeclaration) points to the method declarations.Triplet: unit add include
#include "TracerSingleton.h" preprocessor directive.
The inclusion of this header file is necessary because the code that is woven into the target methods
uses the static method getInstance() declared in the this file.Refers to global pointcut: unit targetImplementationUnit
Triplet: function begin codeFragment
sendSynchTrace() method. The Tracer object is encapsulated in the
TracerSingleton
class. Thus only one Tracer object is available to the whole application.
Refers to global pointcut: function targetMethodImplementation