00001 #ifndef agwsCMD_HANDLER_H
00002 #define agwsCMD_HANDLER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __cplusplus
00029 #error This is a C++ include file and cannot be used from plain C
00030 #endif
00031
00032
00033
00034
00035 #include "agws.h"
00036 #include "agwsSTATE.h"
00037
00038
00039
00040
00041 #include "evhTASK.h"
00042 #include "evhSTD_COMMANDS.h"
00043
00044 enum agwsCMD_MODE
00045 {
00046 agwsCMD_NONE,
00047 agwsCMD_ACCEPTED,
00048 agwsCMD_REJECTED,
00049 agwsCMD_PREV_ABORTED,
00050 agwsCMD_PREV_OVERRIDDEN
00051 };
00052
00053 class agwsCMD_HANDLER;
00054
00055 class agwsCMD_DICT: public fndDICTIONARY, virtual public eccsERROR_CLASS
00056 {
00057 public:
00058
00059 agwsCMD_DICT(const unsigned sz = fndDEFAULT_DICT_SIZE ):
00060 fndDICTIONARY(sz) { DelItemsOnDelete(); }
00061
00062 virtual ccsCOMPL_STAT AddCmdHandler(const char *cmd,
00063 agwsCMD_HANDLER &handler);
00064 virtual ccsCOMPL_STAT DelCmdHandler(const char *cmd);
00065 virtual agwsCMD_HANDLER &Lookup(const char *cmd);
00066
00067 fndStdObjectDef(agwsCMD_DICT, fndDICTIONARY);
00068
00069 protected:
00070
00071 };
00072
00073
00074 typedef evhCB_COMPL_STAT
00075 (fndOBJECT::*agwsCMD_METHOD)(msgMESSAGE &, agwsCMD_HANDLER &);
00076
00077 class agwsCMD_HANDLER : public evhSIMPLE_TASK
00078 {
00079 public:
00080 agwsCMD_HANDLER(const msgCMD command,
00081 const evhCALLBACK &cb);
00082 agwsCMD_HANDLER(const msgCMD command,
00083 fndOBJECT *obj,
00084 const agwsCMD_METHOD procedure);
00085
00086 virtual ~agwsCMD_HANDLER();
00087
00088 vltLOGICAL CmdActive() const;
00089 char * CmdBuffer() const;
00090 agwsCMD_MODE CmdMode() const;
00091 msgMESSAGE &CmdMsg();
00092 msgMESSAGE &CmdExtMsg();
00093 vltLOGICAL OriginIsExtern(void);
00094
00095 virtual evhCB_COMPL_STAT CommandCB(msgMESSAGE &msg, void *);
00096
00097 vltLOGICAL InternalCall() const;
00098
00099 virtual ccsCOMPL_STAT SendReply(const char *buffer,
00100 msgLENGTH size = 0,
00101 vltLOGICAL last = ccsTRUE);
00102 virtual ccsCOMPL_STAT SendReply(const ccsERROR &errMsg);
00103 virtual ccsCOMPL_STAT SendReply(ccsMODULEID moduleId,
00104 vltINT16 errorNumber,
00105 ccsLOC_ID location, ...);
00106
00107
00108 static ccsCOMPL_STAT RegResetHandler(const evhCALLBACK &cb);
00109
00110 static ccsCOMPL_STAT SendInternal(msgMESSAGE &msg,
00111 const evhCALLBACK &reply,
00112 const evhCALLBACK &errReply,
00113 vltLOGICAL loopSafe = ccsFALSE);
00114 ccsCOMPL_STAT Reset();
00115
00116 protected:
00117 virtual ccsCOMPL_STAT AcceptCommand(msgMESSAGE &msg);
00118 virtual ccsCOMPL_STAT CheckState(const char *cmd);
00119
00120 virtual ccsCOMPL_STAT IntCommand(msgMESSAGE &msg,
00121 const evhCALLBACK &reply,
00122 const evhCALLBACK &errReply,
00123 vltLOGICAL loopSafe);
00124
00125 ccsCOMPL_STAT RegCommandCB(const evhCALLBACK &cb);
00126 ccsCOMPL_STAT RegReplyHandlers(const evhCALLBACK &reply,
00127 const evhCALLBACK &errReply);
00128
00129 private:
00130 msgCMD command;
00131 msgMESSAGE orgMsg;
00132 msgMESSAGE orgExtMsg;
00133 evhCALLBACK *applCmdCB;
00134 evhCALLBACK *applReplyCB;
00135 evhCALLBACK *applErrorCB;
00136 vltLOGICAL internalCall;
00137 vltLOGICAL replyInternally;
00138 vltLOGICAL cmdActive;
00139 agwsSTATE state;
00140 agwsCMD_MODE cmdMode;
00141 vltLOGICAL originIsExtern;
00142
00143
00144 static vltLOGICAL parActive;
00145 static agwsCMD_HANDLER *parCmd;
00146
00147 static vltLOGICAL exclActive;
00148 static agwsCMD_HANDLER *exclCmd;
00149
00150 static evhCALLBACK *resetHandler;
00151
00152 static agwsCMD_DICT intCommands;
00153 };
00154
00155 #endif