../../AspectXLib/RealTime/PassiveToCyclical/aspects/PassiveToCyclical.ax
main
,
MicroTime
, Task1
, and Task2
. The two task classes
are the classes that are initially passive and that must be provided with activation code.
These two classes expose a method called activate
. This is the method through
which the classes should be activated.
The main
class contains a small main program that consists of an endless loop
that, at every iteration, calls the activate
methods on the two task classes.
The MicroTime
class is just a helper class that encapsulates access to timing service.
This class is not affected by the aspect transformation.
The most important transformations performed by aspect program are:_activate
. This
method consists of an endless loop that calls the pre-existing activate
method and then
suspends itself for the duration of one activation cycle. Normally the sleep_until()
function
should be used to suspend the execution of the task. Unfortunately this function is not
always supported by underlaying operating system. Hence we use a sleep()
function to demonstrate
the implementation
of the aspect. In this example microSleep()
is used to achieve higher timing precision.
activate
methods of the two task class with code that creates and starts two threads whose entry points are
the new _activate
methods.sleep()
function is used instead of sleep_until()
.
Pointcuts | |
unit | targetInitializationUnit |
Points to the unit that contains main() method | |
block | targetSchedulerMethodBody |
Points to the body of the function scheduler() | |
class | targetTaskClassDeclaration |
Points to target classes to which declarations of _activate() method
should be added | |
unit | targetTaskClassDefinition |
Points to the target units where are definitions of methods classes identified
by pointcut targetTaskClassDeclaration | |
Advices | |
add | addCyclicalActivateDeclaraion |
Add declaration of the _activate() method to the class declaration | |
add | addCyclicalActivateDefinition |
Add definition of _activate() method to class definition files | |
add | addActivationHelperFunctions |
Adds definition of two methods that
activate the threads of active objects | |
add | addIncludesToMain |
Add the #include "main | |
around | replaceSchedulerBody |
Replaces the body of schedule() function |
unit
that contains main()
method. In srcML, a unit
is
a source file (a definition file, a declaration file, or
an inline file). The pointcut is restricted to include only those units that contain
function whose full name is main
.
scheduler()
.
_activate()
method
should be added.
The classes that must be modified are identified by their full name. The name
have to contain substring Task
.
targetTaskClassDeclaration
.
Triplet: class add declaration
_activate()
method to the class declaration.
This method is to be called as a POSIX thread. Therefore its
return value has to be a pointer (void *
) and has to have
one untyped pointer as a parameter.
Refers to global pointcut: class targetTaskClassDeclaration
Triplet: unit add definition
_activate()
method to class definition files.
The full name of the method is constructed using dollar variable
${className}
.
The method body contains a loop that call the activate()
method of the
same class with period of 7 seconds. The activate()
method
is called at the beginning of the loop.
After the method call the thread is suspended for time remaining to the
end of the period.
Refers to global pointcut: unit targetTaskClassDefinition
Triplet: unit add definition
pthread_create()
)
is associated with the two helper functions
_activate1()
and _activate2()
that
pass the calls to the respective methods in classes
Task1
and Task2
.
These helper functions are used because POSIX function
pthread_create()
does not allow
to use C++ method
as a parameter - only C functions are accepted.
Refers to global pointcut: unit targetInitializationUnit
Triplet: unit add include
#include "main.h"
preprocessor instruction.
Header file main.h
contains signatures of two functions
(_activate1()
and _activate2()
)
added to the main module. Since
both functions are woven at the end of the file their declarations have to
be inserted at the beginning of the unit using the header file.
Refers to global pointcut: unit targetInitializationUnit
Triplet: block around codeFragment
schedule()
function.
It inserts code that
initializes the two threads and suspends the execution of the
main thread.
The threads are executed using helper functions
_activate1()
and _activate2()
that
pass the calls to the respective methods in classes
Task1
and Task2
.
Refers to global pointcut: block targetSchedulerMethodBody