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

Bartosz Blimke masb at chorwacja.com
Thu Jun 24 16:30:36 CEST 2004


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

ps:
I found that if I will insert definition of SomeClass to main.cpp file
from SomeClass.h I get:

compiling ... ACPPTest1_LinkOnce.cpp
./ac_gen.cc(5) : error C2039: 'Aspect' : is not a member of
'operator``global namespace'''

VisualStudio .NET 2003 with aspectc++ add-in v.1.07











More information about the aspectc-user mailing list