[aspectc-user] Aspects advising aspects

mike-mortensen at comcast.net mike-mortensen at comcast.net
Fri Jan 6 06:46:27 CET 2006


I'm exploring aspects that have multiple concerns in them...

For example, Caching is a concern that can be implemented in an aspect. 
In addition, we could have a Caching aspect that not only uses around advice to 'intercept'
calls and return precomputed values, but also keeps track of the number of 'hits' and 'misses' for
each function that it is caching.  Each separate function of course has a separate cache
(e.g. static map <key,value>) and separate hit/miss stats.  This can be useful, because
caching a function that rarely recomputes the same value will not save run time...

One could argue that tracking the stats of a cache is a separate concern of the cacher, in
the same way that adding caching code directly to each method is adding an extra concern
to the functions.

I've created a Cache that tracks stats per join point, but one thing I am trying
(not so successfully) is to use to two aspects -- one to implement Caching using
around advice and a Cache class, and another to implement calls to the Cache class
from the CachingAspect.

So, in a nutshell, I want to create an aspect that captures calls from inside another aspect.
This is kind of like AspectJ's adviceexecution, but I don't believe AspectC++ has that.

What I have found from experimenting with a trivial case (not even caching) is that I
can have:
   AspectA, which calls a function HELLO
  AspectB, which uses the execution pointcut of HELLO

BUT, if AspectB tries to use   call("% HELLO(...)") instead of execution (so that it's
weaving inide of AspectA) or if AspectB tries to use something like 
   JoinPoint::signature() 
even with the execution joinpoint, I get errors when the woven code is compiled.

I'm guessing that trying to weave into another aspect's advice or access JoinPoint
info there is not supported, but without doing this the second aspect doesn't have
enough context to be able to do anything useful...

Here's an example of the aspect file that works.  It has an Advisor
aspect that calls HELLO, and a Monitor aspect that weaves against
the execution of HELLO but doesn't use JoinPoint information
(since the joinpoint would occur when Advisor's advice calls HELLO).

#include <iostream>
#include <map>
#include <string>
void HELLO() { std::cerr << " IN HELLO" << std::endl; }
aspect Advisor {
   pointcut CallCircleArea() = call("% CircleArea(...)");
   advice CallCircleArea() : around()
   {
      HELLO();
      tjp->proceed();
      std::cerr << " In Advisor aspect..." << std::endl;
   }
};
aspect Monitor {
   pointcut Hello() = execution("% HELLO(...)");
   advice Hello() : before() {
      std::cerr << " In Monitor, about to call HELLO ............." << std::endl;
   }
};


Is this aspects that weave into other aspects beyond the scope of what AspectC++ can currently do,
or am I just missing something?  

Thanks!
-Mike Mortensen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.aspectc.org/pipermail/aspectc-user/attachments/20060106/40cd3e2a/attachment.html>


More information about the aspectc-user mailing list