BcPOC
SF-HRP ASM implementation
D:/bcatch/bcpoc_src/bcpoc/src/sfhrp/SFHRP/base_rule.hpp
Go to the documentation of this file.
00001 #ifndef BASE_RULE
00002 #define BASE_RULE
00003 
00004 #include <iostream>
00005 
00006 //#include "../action_engine/ActionEngine.hpp"
00007 //#include "../cond_engine/ConditionEngine.hpp"
00008 
00009 #include "types.hpp"
00010 #include "i_releaseable.hpp"
00011 
00012 #define SF_FAIL -1
00013 #define SF_SUCCESS -2
00014 
00015 //abstract class
00016 class BaseRule : public IReleaseable {
00017 public:
00018         //typedef BaseRule* ptrBaseRule;
00019 
00020         //parent_plan, priority, weight, flags, sticky timeout, fails, successes
00021         BaseRule(ptrSimplePlan, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
00022 
00023         //activate rule
00024         virtual void Activate();
00025 
00026         //schedule for deactivation
00027         virtual void Deactivate();
00028 
00029         //when choosen
00030         #ifndef CONDITION_ENGINE_DEBUG
00031                 virtual int     GetAction() = 0;
00032         #else
00033                 BaseRule() { };
00034 
00035                 virtual int     GetAction() { //std::cout << "Executing rule " << "\n";}
00036         #endif
00037 
00038         //force fail
00039         //virtual void  Fail() = 0;
00040 
00041         //force success
00042         //virtual void  Success() = 0;
00043 
00044         
00045         //rule flags
00046         enum RuleFlags {
00047                 NO_FLAGS = 0,
00048                 INTERRUPT_SAFE = 1,
00049                 RELEASER_SAFE = 2,
00050                 STICKY = 4
00051         };
00052 
00053         bool CheckFlags(RuleFlags); //check if rule has certain flags
00054 
00055         unsigned int GetPriority() const;
00056         unsigned int GetWeight() const;
00057 
00058         //DEBUG 
00059         void out() { 
00060                 //if(TEST_DEBUG == true) 
00061                 /*std::cout << "prio: " << _priority << std::endl << 
00062                         "weight: " << _weight << std::endl <<
00063                         "flags: " << _flags << std::endl <<
00064                         "sttout: " << _sticky_timeout << std::endl <<
00065                         "fails: " << _fails << std::endl <<
00066                         "successes: " << _successes << std::endl;/**/
00067                 };
00068 
00069 
00070 protected:
00071         ptrSimplePlan _parent_plan;
00072 
00073 
00074         unsigned int _priority;
00075         unsigned int _weight;
00076         unsigned int _flags;
00077         unsigned int _sticky_timeout; //in engine cycles
00078 
00079         unsigned int _fails; //default count of fails
00080         unsigned int _successes; //default count of successes
00081 
00082         unsigned int _fails_act; //actual count
00083         unsigned int _successes_act; // actual count
00084 
00085         
00086 };
00087 
00088 #endif
00089