#include "EventSystem.h"
#include "TaskResult.h"
#include <boost/function.hpp>
#include <boost/bind.hpp>
Go to the source code of this file.
#define __CLEAN_THREAD_AND_EVENTS decision_making::ScoppedThreads::Cleaner SUBMACHINESTHREADSCLEANER(SUBMACHINESTHREADS); |
#define __DEFCALLCONTEXT decision_making::CallContext call_ctx(parent_call_ctx?decision_making::CallContext(*parent_call_ctx, tao_name):decision_making::CallContext(tao_name)); |
#define __DEFEVENTQUEUE decision_making::EventQueue* events_queue(parent_event_queue); |
#define __DEFSUBCTEXT | ( | TASK | ) | decision_making::ScoppedThreads::CallContextPtr call_ctx##TASK( new decision_making::CallContext(plan_call_ctx, #TASK) ); |
#define __DEFSUBEVENTQUEUE | ( | TASK | ) | decision_making::ScoppedThreads::EventQueuePtr events_queu##TASK( new decision_making::EventQueue(events_queue) ); |
#define __ENDOFSTATE |
DMDEBUG( struct _STATE_FINISHER_PRINT{std::string n; bool jc; _STATE_FINISHER_PRINT( std::string n, bool jc): n(n),jc(jc){}~_STATE_FINISHER_PRINT(){if(jc)return;DMDEBUG( cout<<"}"<<n<<" "; )} void r(){}}_ep(outname,justCondition);_ep.r(); )\ struct _STATE_FINISHER{\ std::string plan_name; decision_making::CallContext& ctx; decision_making::EventQueue& queue; bool jc;\ _STATE_FINISHER(std::string plan_name, decision_making::CallContext& ctx, decision_making::EventQueue& queue, bool jc): plan_name(plan_name),ctx(ctx),queue(queue),jc(jc){}\ ~_STATE_FINISHER(){\ if(!jc){ ON_TAO_STATE_END(plan_name, ctx, queue); }\ } void r(){}\ }_e(plan_name, call_ctx, *events_queue, justCondition);_e.r();
#define __SHR_TO_REF | ( | X | ) | (*(X.get())) |
#define __STARTOFSTATE | ( | X | ) |
std::string plan_name(#X);\ decision_making::CallContext plan_call_ctx(call_ctx, plan_name);\ if(!justCondition){\ DMDEBUG( string outname("STT("+tao_name+":"+call_ctx.str()+"/"+#X+")");cout<<outname<<"{ "; )\ ON_TAO_STATE_START(plan_name, call_ctx, *events_queue);\ }
#define __TAO_FINISHER |
struct _tao_finisher_type{\ bool run;\ const decision_making::CallContext* parent_call_ctx;\ decision_making::EventQueue* parent_event_queue;\ _tao_finisher_type(bool run, const decision_making::CallContext* parent_call_ctx, decision_making::EventQueue* parent_event_queue):\ run(run),parent_call_ctx(parent_call_ctx), parent_event_queue(parent_event_queue){}\ ~_tao_finisher_type(){\ if(!run or !parent_event_queue or !parent_call_ctx)return; \ parent_event_queue->raiseEvent(decision_making::Event("SUBPLAN_FINISHED",*parent_call_ctx));\ }\ } _tao_finisher(!justCondition, parent_call_ctx, parent_event_queue);\
#define _TAO_FUN_SIG boost::function<decision_making::TaskResult(int)> |
TAO_HEADER(NAME)\ decision_making::TaskResult Tao##NAME##_cond(const decision_making::CallContext* p, decision_making::EventQueue* q, int tss){\ class Cond: public TaoConditionCallback{ } f;\ return Tao##NAME(p,q,#NAME, true, tss, &f);\ }\ decision_making::TaskResult Tao##NAME(const decision_making::CallContext* p, decision_making::EventQueue* q){\ class Cond: public TaoConditionCallback{ } f;\ f.cond = boost::bind(&Tao##NAME##_cond, p, q, _1);\ return Tao##NAME(p,q,#NAME, false, -1, &f);\ }\ decision_making::TaskResult Tao##NAME(\ const decision_making::CallContext* parent_call_ctx,\ decision_making::EventQueue* parent_event_queue,\ std::string tao_name,\ bool justCondition, int try_start_state, TaoConditionCallback* this_function)
#define TAO_ALLOCATE | ( | ProtocolName | ) |
#define TAO_ALLOCATE_EMPTY TAO_ALLOCATE(_AllocPEMPTY) |
#define TAO_BGN |
bool tao_stop = false; \ while(not tao_stop and not events_queue->isTerminated() DM_SYSTEM_STOP){ \ switch((TAOPLANS)state){ { {
#define TAO_CALL_BT | ( | NAME | ) |
__DEFSUBEVENTQUEUE(NAME) __DEFSUBCTEXT(NAME) \ SUBMACHINESTHREADS.add(events_queu##NAME); \ SUBMACHINESTHREADS.add(call_ctx##NAME); \ decision_making::EventQueue& __t_events_queu##NAME = __SHR_TO_REF(events_queu##NAME);\ decision_making::CallContext& __t_call_ctx##NAME = __SHR_TO_REF(call_ctx##NAME);\ __BT_CREATE_BT_CALL_FUNCTION(NAME, __t_call_ctx##NAME, __t_events_queu##NAME)\ SUBMACHINESTHREADS.add(\ __CALL_BT_FUNCTION(NAME, boost::ref(__t_call_ctx##NAME), boost::ref(__t_events_queu##NAME)) \ );
#define TAO_CALL_FSM | ( | NAME | ) |
__DEFSUBEVENTQUEUE(NAME) \ SUBMACHINESTHREADS.add(events_queu##NAME); \ SUBMACHINESTHREADS.add(\ new boost::thread(boost::bind(&Fsm##NAME, &call_ctx, events_queu##NAME.get()) ));
#define TAO_CALL_TAO | ( | NAME | ) |
__DEFSUBEVENTQUEUE(NAME) \ SUBMACHINESTHREADS.add(events_queu##NAME); \ SUBMACHINESTHREADS.add(\ new boost::thread(boost::bind(&Tao##NAME, &call_ctx, events_queu##NAME.get()) ));
#define TAO_CALL_TASK | ( | TASK | ) |
__DEFSUBEVENTQUEUE(TASK) __DEFSUBCTEXT(TASK) \ SUBMACHINESTHREADS.add(events_queu##TASK); \ SUBMACHINESTHREADS.add(call_ctx##TASK); \ SUBMACHINESTHREADS.add(\ new boost::thread( CALL_REMOTE(TASK, boost::ref(__SHR_TO_REF(call_ctx##TASK)), boost::ref(__SHR_TO_REF(events_queu##TASK))) ));
#define TAO_CLEANUP_BGN |
#define TAO_CLEANUP_END |
}\ };\ decision_making::ScoppedThreadsOnExit* __tmp___ON_STATE_EXIT_STRUCT = new __ON_STATE_EXIT_STRUCT(call_ctx, events_queue);\ SUBMACHINESTHREADS.add(decision_making::ScoppedThreads::ScoppedThreadsOnExitPtr(__tmp___ON_STATE_EXIT_STRUCT));
#define TAO_CONTEXT plan_call_ctx |
#define TAO_DROP_EVENTS events_queue->drop_all(); |
#define TAO_END |
}}break;\ default: tao_stop=true; tao_result = decision_making::TaskResult::FAIL("SELECTED BEH DOES NOT EXIST") ; break;}} \ if(!justCondition){\ DMDEBUG( cout<<" TAO("<<tao_name<<":FINISH) "; ) \ ON_TAO_END(tao_name, call_ctx, *events_queue, tao_result);\ }\ return tao_result;
#define TAO_EVENT | ( | EVENT | ) | decision_making::Event(#EVENT,plan_call_ctx) |
#define TAO_EVENTS_DROP events_queue->drop_all(); |
#define TAO_GO_NEXT | ( | STATE | ) |
#define TAO_HEADER | ( | NAME | ) |
decision_making::TaskResult Tao##NAME(const decision_making::CallContext*, decision_making::EventQueue*, std::string, bool jc, int tss, TaoConditionCallback*);\ decision_making::TaskResult Tao##NAME##_cond(const decision_making::CallContext* p, decision_making::EventQueue* q, int tss);\ decision_making::TaskResult Tao##NAME(const decision_making::CallContext* p, decision_making::EventQueue* q);
#define TAO_NEXT | ( | ProtocolName | ) |
#define TAO_NEXT_EMPTY TAO_NEXT(_NextPEMPTY) |
#define TAO_NEXT_PLAN | ( | BEHNAME | ) | protocol.add((int)BEHNAME, #BEHNAME, this_function->cond(BEHNAME).isSuccess()); |
#define TAO_ON_CONDITION | ( | COND, | |
DO | |||
) |
if(COND){ \ DMDEBUG( cout<<" GOTO("<<tao_name<<":"<<decision_making::Event(#COND,plan_call_ctx)<< "->" #DO ") "; ) \ DO;\ }
#define TAO_ON_EVENT | ( | EVENT, | |
DO | |||
) |
if(event==decision_making::Event(EVENT,plan_call_ctx)){ \ DMDEBUG( cout<<" GOTO("<<tao_name<<":"<<decision_making::Event(EVENT,plan_call_ctx)<< "->" #DO ") "; ) \ DO;\ }
}}}break; \ case X: { \ decision_making::ScoppedThreads SUBMACHINESTHREADS; \ __STARTOFSTATE(X) __ENDOFSTATE
#define TAO_PRINT_EVENT if(not event.equals(decision_making::Event::SPIN_EVENT())){ cout<<" READ("<<tao_name<<":"<<event<<") "; } |
#define TAO_RAISE | ( | EVENT | ) |
DMDEBUG( cout<<" RAISE("<<tao_name<<":"<<decision_making::Event(EVENT, plan_call_ctx)<<") "; ) \ events_queue->raiseEvent(decision_making::Event(EVENT, plan_call_ctx));
#define TAO_RESULT | ( | EVENT, | |
RESULT | |||
) |
#define TAO_START_CONDITION | ( | CONDITION | ) |
if(justCondition){\ tao_stop=true; \ bool _l_cond_satis = (CONDITION);\ tao_result = _l_cond_satis ? decision_making::TaskResult::SUCCESS() : decision_making::TaskResult::FAIL(#CONDITION" is False") ; \ return tao_result;\ }
#define TAO_START_PLAN | ( | STATE | ) |
; int state ( try_start_state<0? (int)STATE : try_start_state ); \ decision_making::TaskResult tao_result = decision_making::TaskResult::TERMINATED();\ __DEFCALLCONTEXT __DEFEVENTQUEUE __TAO_FINISHER\ if(!justCondition){\ DMDEBUG( cout<<" TAO("<<tao_name<<":START) "; )\ ON_TAO_START(tao_name, call_ctx, *events_queue);\ }
#define TAO_STOP_CONDITION | ( | COND | ) |
#define TAO_STOP_CONDITION_AND_PRINT_EVENTS | ( | COND | ) |
#define TAO_SUBPLAN | ( | TAONAME | ) |
#define TAO_TRANSITIONS __CLEAN_THREAD_AND_EVENTS {Event event; while((event=events_queue->waitEvent())==true){ |