[aspectc-user] Is there a possibility to get the context from cflow ?

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Mon Jun 28 16:25:43 CEST 2004


Hi Bartosz,

Bartosz Blimke wrote:
> Hi,
> 
> I have found an problem during trying to implement some aspects.
> Here is the situation.
> 
> 
> //Aspect.ah
> #ifndef __Aspect_ah__
> #define __Aspect_ah__
> 
> #include <stdio.h>
> 
> aspect Aspect
> {
> public:
> 
>    void worker(AC::Action& action);
> 
> 
>    pointcut topLevelExecutedMethod(Aspect* _aspect) =
>        execution("% SomeClass::%(...)")
>        && !cflow( execution( "% Aspect::worker(...)" ) );
> 
>    advice topLevelExecutedMethod(_aspect) : around(Aspect* _aspect)
>    {
> 		printf("We are in method that was executed first! \nIt's method %s\n",
> tjp->signature());
> 		worker(tjp->action());
>    }
> 
>    advice "SomeClass" : Aspect m_instance;
> 
>    static Aspect *aspectOf()
>    {
>    	 return &tjp->target()->m_instance;
>    };
> 
> 
> };
> 
> #endif // __Aspect_ah__
> // end of Aspect.ah
> 
> //Aspect.cpp
> #include "Aspect.ah"
> 
> void Aspect::worker(AC::Action &action)
> {
>      action.trigger();
> }
> //End of Aspect.cpp
> 
> 
> 
> //SomeClass.h
> #ifndef _SOME_CLASS_
> #define _SOME_CLASS_
> 
> class SomeClass
> {
> public:
> 	SomeClass(void){};
> 	~SomeClass(void){};
> 
> 	void firstMethod(){};
> 	void secondMethod(SomeClass& delegate){ delegate.firstMethod(); };
> };
> 
> #endif //some class
> //end of SomeClass.h
> 
> 
> int main()
> {
>  SomeClass someClassInstance;
>  SomeClass someAnotherClassInstance;
> 
>  bool x;
> 
>  x = true;
> 
>  if(x)
>   someClassInstance.secondMethod(someClassInstance);
>  else
>   someClassInstance.secondMethod(someAnotherClassInstance);
> 
>  return 0;
> }
> 
> 
> After execution of the program I should have now
> the same output for different values of x:
> 
> "We are in method that was executed first!
> It's method void SomeClass::secondMethod(SomeClass &)"
> 
> where
> 
> someClassInstance.secondMethod is a top level method.
> 
> 
> Now I would like to have the same functionality
> but topLevelExecutedMethod() should mean
> top level executed method but "per-object" not "per-class".
> 
> If context variables would be supported in cflow then:
> Redefinition of pointcut:
> pointcut topLevelExecutedMethod(Aspect* _aspect) =
>        execution("% SomeClass::%(...)")
>        && !cflow( execution( "% Aspect::worker(...)" ) && that(_aspect) );
> 
> 
> 
> and redefinition of advice to:
> 
> advice topLevelExecutedMethod(_aspect) : around(Aspect* _aspect)
>    {
>     if(_aspect == this)
>     {
> 	printf("We are in method that was executed first!         method %s\n",
> tjp->signature());
> 	worker(tjp->action());
>     }
>     else
>         tjp->proceed();
>   }
> 
> should solve the problem and
> if x is true we should have the same result,
> but if x is false then we should get
> 
> "We are in method that was executed first!
> It's method void SomeClass::secondMethod(SomeClass &)
> We are in method that was executed first!
> It's method void SomeClass::firstMethod(SomeClass &)"
> 
> The problem is that its not possible to put context variable into cflow.
> I could always introduce some state variable into the object and check
> if some aspect already modified it but it wouldnt be "aspect solution" but
> rather some workaround solution.
> Do you have maybe some solution for this problem,
> is it possible in the future to have context variables inside cflow
> in AspectC++?
> 
> Bartosz Blimke

context variables in cflow will definitly be supported in the future. 
This is an AOP feature, which I like very much, because it shows that 
AOP is more than just a "simple wrapper technique". I already played a 
bit with the code generation pattern for context in cflows, but at the 
moment there are some other tasks with a higher priority. For example, 
finalizing the 0.9pre1 version, which is again a great step forward, and 
improving the template parsing capabilities ;-).

Best regards,

Olaf



More information about the aspectc-user mailing list