CommandInterpreter.hpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:3k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #ifndef CommandInterpreter_H
  14. #define CommandInterpreter_H
  15. #include <ndb_global.h>
  16. #include <Vector.hpp>
  17. #include <BaseString.hpp>
  18. class MgmtSrvr;
  19. class CommandInterpreter {
  20. public:
  21.   CommandInterpreter(MgmtSrvr& mgmtSrvr);
  22.   int readAndExecute();
  23. private:
  24.   char m_err_str[1024];
  25.   const char *get_error_text(int err_no);
  26.   char *readline_gets ()
  27.   {
  28.     static char linebuffer[254];
  29.     static char *line_read = (char *)NULL;
  30.     /* If the buffer has already been allocated, return the memory
  31.        to the free pool. */
  32.     if (line_read)
  33.     {
  34.       free (line_read);
  35.       line_read = (char *)NULL;
  36.     }
  37.     
  38.     /* Get a line from the user. */
  39.     fputs("ndb_mgmd> ", stdout);
  40.     linebuffer[sizeof(linebuffer)-1]=0;
  41.     line_read = fgets(linebuffer, sizeof(linebuffer)-1, stdin);
  42.     if (line_read == linebuffer) {
  43.       char *q=linebuffer;
  44.       while (*q > 31) q++;
  45.       *q=0;
  46.       line_read= strdup(linebuffer);
  47.     }
  48.     return (line_read);
  49.   }
  50.   
  51.   void analyseAfterFirstToken(int processId, char* allAfterFirstTokenCstr);
  52.   bool parseBlockSpecification(const char* allAfterLog, 
  53.        Vector<BaseString>& blocks);
  54. public:
  55.   void executeTrace(int processId, const char* parameters, bool all);
  56.   void executeLogIn(int processId, const char* parameters, bool all);
  57.   void executeLogOut(int processId, const char* parameters, bool all);
  58.   void executeLogOff(int processId, const char* parameters, bool all);
  59. public:
  60.   typedef void (CommandInterpreter::* ExecuteFunction)(int processId, 
  61.        const char * param, 
  62.        bool all);
  63.   
  64.   struct CommandFunctionPair {
  65.     const char * command;
  66.     ExecuteFunction executeFunction;
  67.   };
  68. private:
  69.   /**
  70.    * 
  71.    */
  72.   void executeForAll(const char * cmd, ExecuteFunction fun, const char * param);
  73.   /**
  74.    *   Management server to use when executing commands
  75.    */
  76.   MgmtSrvr& _mgmtSrvr; 
  77. };
  78. #endif // CommandInterpreter_H