00001 #ifndef MD_BEHAVIOR 00002 #define MD_BEHAVIOR 00003 00004 #include "Listener.h" 00005 #include "EventSender.h" 00006 #include "PolymorphEvent.h" 00007 00018 class mdMand; 00019 00020 typedef std::map<std::string,mdMand> MandLayer; 00021 00022 class mdMand { 00023 public: 00024 00025 md_mand kind; 00026 std::string fullname; 00027 MandLayer subsystem; // children 00028 MandLayer parent; 00029 void *handler; 00030 00031 // Subtypes must implement these. 00032 std::string *dO(std::string *text); 00033 00034 }; 00035 00036 class mdMandSpace { 00037 MandLayer catalog; 00038 00039 bool add(std::string name,md_mand typ) 00040 {if (catalog.find(name) == catalog.end()) { 00041 mdMand *newMand = new mdMand(); 00042 catalog[name] = *newMand; 00043 newMand->fullname = name; 00044 newMand->kind = typ; 00045 newMand->handler = NULL; 00046 } 00047 00048 } 00049 mdMand *find(std::string fn); 00050 mdMand *parseAndCreatePath(std::string fn); 00051 bool setFullName(void); 00052 }; 00053 00054 typedef struct { 00055 bool requiresResponse; 00056 bool hasArguments; 00057 unsigned short nArgs; 00058 char sVal; 00059 } 00060 mdCmdPOD; 00061 00062 class mdCommand : mdMand { 00063 public: 00064 mdCmdPOD parms; 00065 std::string signature; 00066 00067 mdCommand(md_mand typ=MD_USER_MAND,std::string name=std::string("")) 00068 {mdMand::handler = NULL; 00069 mdMand::fullname = name; 00070 mdMand::kind = typ; 00071 } 00072 ~mdCommand() {} 00073 00074 mdCommand *mand(int deviceHandle, std::string& text); 00075 std::string dO(void *target,std::string *text); 00076 void *getHandler() {return mdMand::handler;} 00077 void setHandler(void *to) {mdMand::handler = to;} 00078 00079 }; 00080 class mdResponse; 00081 class mdSCPI : mdCommand { 00082 public: 00083 00084 mdSCPI(std::string name) : mdCommand(MD_SCPI, name) {} 00085 mdSCPI *setHandler(mdResponse *mdr); 00086 std::string dO(void *target,std::string *text); 00087 00088 }; 00089 00090 typedef std::map<std::string,mdCommand *> InstructionSet; // The SCPI commands by cannonical name. 00091 00092 #endif
1.5.6