Main Page | Class Hierarchy | Class List | File List | Class Members

Command.h

00001 // tacppd CLI commands processing
00002 // (c) Copyright 2000-2005 by tacppd team and contributors
00003 // see http://tacppd.org for more information
00004 //
00005 //  This program is free software; you can redistribute it and/or modify
00006 //  it under the terms of the GNU General Public License as published by
00007 //  the Free Software Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //
00010 //  This program is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //  GNU General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU General Public License
00016 //  along with this program; if not, write to the Free Software
00017 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // all comments which start from /**<CR> - this is comments for KDoc */
00020 // for classes
00021 //   @short [short description of the class]
00022 //   @author [class author]
00023 //   @version [class version]
00024 //   @see [references to other classes or methods]
00025 // for methods
00026 //   @see [references]
00027 //   @return [sentence describing the return value]
00028 //   @exception [list the exeptions that could be thrown]
00029 //   @param [name id] [description]     - can be multiple
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); //{{"SHow"},{"EXxit"},{"STAtus"},{'\0'}};
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; //comment could be '!','#',';' if comment.first=true there is comment inside, second is start position
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__

Generated on Thu Jul 21 23:09:45 2005 for tacppd.kdevelop by doxygen 1.3.5