00001
00002
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
00029
00030
00031 #ifndef __COMMAND_H__
00032 #define __COMMAND_H__
00033
00034 #include "global.h"
00035
00036 namespace tacpp {
00037
00038 enum commandStatus {
00039 CMD_NO_HELP_AVAIL=0,
00040 CMD_COMMAND_HELP_AVAIL,
00041 CMD_PARAM_HELP_AVAIL,
00042
00043 CMD_AMBIGUOUS,
00044 CMD_UNKNOWN,
00045
00046 CMD_PARAM_ERROR,
00047 CMD_PARAM_COUNT_ERROR,
00048
00049 CMD_PARSE_SUCCESS,
00050
00051 CMD_COMPLETED,
00052 CMD_COMPLETED_BY_CMD_PART,
00053 CMD_NOT_COMPLETED,
00054 CMD_NOT_COMPLETED_PARAM_ENCOUNTERED,
00055
00056 CMD_EXECUTED,
00057 CMD_MAKEACTION_FAILED,
00058 CMD_FAILED,
00059 CMD_NO_ACTION,
00060 CMD_EXIT,
00061
00062 CMD_END_OF_STREAM,
00063 CMD_ERR_OPEN_FSTREAM,
00064 CMD_TIMEOUT
00065 };
00066 class Terminal;
00067 class Command;
00068 class Vty;
00069
00072 class cmdComplete {
00073 public:
00076 bool couldComplete;
00079 int paramNum;
00082 int paramVtyLen;
00085 char * cmd;
00086 };
00087
00090 class commandFacility {
00091 public:
00094 virtual commandStatus makeAction(char * const*mask,const string cmdname,const list<string>paramList,Command * cmd=NULL)throw (CmdErr)=0 ;
00097 virtual ~commandFacility() {};
00098 };
00099
00103 class Command {
00104 private:
00105 protected:
00108 char **command;
00111 char **help;
00114 string cmdID;
00117 int depthH;
00120 int depthC;
00123 CmdErr errCmd;
00126 cmdComplete completeStat;
00129 Vty *vt;
00132 commandFacility *cf;
00133
00134 public:
00137 Command *upNode;
00140 list<string> paramList;
00143 Command(char **cmd,char **hlp,char * cmdID,Command *up=NULL);
00146 virtual ~Command();
00149 CmdErr getCmdErr();
00152 cmdComplete getCmdComplete();
00155 const char *getCommand(int cmdNum);
00158 const char *getCommandHlp(int cmdNum);
00161 int getCommandDepth();
00164 virtual void setCFVty(Vty*,commandFacility*);
00167 virtual commandStatus makeHelp();
00170 virtual commandStatus completeCommand();
00173 virtual commandStatus makeAction();
00176 virtual commandStatus parseCommand();
00179 virtual commandStatus executeCommand();
00180 };
00181
00182 const int maxHistSize=10;
00186 const int maxInvStr=256;
00187
00190 class NonInteractiveCommandNode: public Command {
00191 protected:
00194 list<Command*> cmdList;
00197 list<CmdErr> execErrors;
00198
00199 public:
00202 NonInteractiveCommandNode(char **cmd,char **hlp,char*cmdi,char **cmdExit,char **hlpExit,char*ecmdi,Command *up=NULL);
00205 ~NonInteractiveCommandNode();
00208 NonInteractiveCommandNode *insertCommand(Command* cmd);
00211 virtual void setCFVty(Vty*,commandFacility *);
00214 virtual commandStatus makeAction() throw(CmdErr,VtyErr);
00217 virtual void errReport(commandStatus) throw(CmdErr,VtyErr);
00218 };
00219
00222 class CommandNode: public Command {
00223 protected:
00226 char inviteStr[maxInvStr+1];
00229 char inviteStrM[maxInvStr+1];
00232 list<Command*> cmdList;
00235 list<string> histList;
00238 list<string>::iterator histIt;
00241 list<CmdErr> execErrors;
00244 list<cmdComplete> completeStatus;
00247 VtyTerm *vtt;
00248
00249 public:
00252 CommandNode(char **cmd,char **hlp,char*cmdi,char **cmdExit,char **hlpExit,char*ecmdi,char *invStr,char *invStrM,Command *up=NULL);
00255 ~CommandNode();
00258 char *invStr();
00261 CommandNode *insertCommand(Command *cmd);
00264 void insertHistory();
00267 void getHistory(bool next);
00268 virtual void setCFVty(Vty*,commandFacility *);
00271 virtual commandStatus makeHelpNode();
00274 virtual commandStatus makeHelp();
00277 virtual commandStatus completeNodeCommand();
00280 virtual commandStatus makeAction();
00283 virtual void errReport(commandStatus);
00284 };
00285
00291 class VtyLineSplitter {
00292 private:
00295 class mypair {
00296 public:
00299 int first;
00302 int second;
00305 mypair(int fi,int se){first=fi;second=se;};
00308 mypair(){first=0;second=0;};
00309 };
00312 Vty *vt;
00315 vector<mypair> splitLine;
00318 mypair comment;
00321 mypair cmdUnderCursor;
00324 void split();
00325
00326 public:
00329 VtyLineSplitter(Vty *vtt);
00333 bool getCmdPartPos(int cmdPartnum, int &start,int & len);
00336 bool getCmdUnderCursorNum(int& cmdPartnum);
00339 bool getCommentPos(int &start,int &len);
00342 int getCmdPartCount();
00343 };
00344
00345 };
00346
00347 #endif //__COMMAND_H__