xorp

cli_command_pipe.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
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, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/cli/cli_command_pipe.hh,v 1.18 2008/10/02 21:56:29 bms Exp $
00021 
00022 
00023 #ifndef __CLI_CLI_COMMAND_PIPE_HH__
00024 #define __CLI_CLI_COMMAND_PIPE_HH__
00025 
00026 
00027 //
00028 // CLI command "pipe" ("|") definition.
00029 //
00030 #ifdef HAVE_SYS_TYPES_H
00031 #include <sys/types.h>
00032 #endif
00033 
00034 
00035 
00036 
00037 #ifdef HAVE_REGEX_H
00038 #  include <regex.h>
00039 #else // ! HAVE_REGEX_H
00040 #  ifdef HAVE_PCRE_H
00041 #    include <pcre.h>
00042 #  endif
00043 #  ifdef HAVE_PCREPOSIX_H
00044 #    include <pcreposix.h>
00045 #  endif
00046 #endif // ! HAVE_REGEX_H
00047 
00048 #include "cli_command.hh"
00049 
00050 
00051 //
00052 // Constants definitions
00053 //
00054 
00055 //
00056 // Structures/classes, typedefs and macros
00057 //
00058 
00062 class CliPipe : public CliCommand {
00063 public:
00081     CliPipe(const string& init_pipe_name);
00082     
00086     virtual ~CliPipe();
00087     
00088 private:
00089     friend class CliClient;
00090     
00091     bool is_invalid() { return (_pipe_type == CLI_PIPE_MAX); }
00092     void add_pipe_arg(const string& v) { _pipe_args_list.push_back(v); }
00093     void set_cli_client(CliClient *v) { _cli_client = v; }
00094     
00095     int start_func(string& input_line, string& error_msg) { return (this->*_start_func_ptr)(input_line, error_msg); }
00096     int stop_func(string& error_msg) { return (this->*_stop_func_ptr)(error_msg); }
00097     int process_func(string& input_line) { return (this->*_process_func_ptr)(input_line); }
00098     int eof_func(string& input_line) { return (this->*_eof_func_ptr)(input_line); }
00099     
00100     // The "pipe" types
00101     enum cli_pipe_t {
00102     CLI_PIPE_COMPARE        = 0,
00103     CLI_PIPE_COMPARE_ROLLBACK   = 1,
00104     CLI_PIPE_COUNT          = 2,
00105     CLI_PIPE_DISPLAY        = 3,
00106     CLI_PIPE_DISPLAY_DETAIL     = 4,
00107     CLI_PIPE_DISPLAY_INHERITANCE    = 5,
00108     CLI_PIPE_DISPLAY_XML        = 6,
00109     CLI_PIPE_EXCEPT         = 7,
00110     CLI_PIPE_FIND           = 8,
00111     CLI_PIPE_HOLD           = 9,
00112     CLI_PIPE_MATCH          = 10,
00113     CLI_PIPE_NOMORE         = 11,
00114     CLI_PIPE_RESOLVE        = 12,
00115     CLI_PIPE_SAVE           = 13,
00116     CLI_PIPE_TRIM           = 14,
00117     CLI_PIPE_MAX
00118     };
00119     string name2help(const string& pipe_name);
00120     cli_pipe_t name2pipe_type(const string& pipe_name);
00121     cli_pipe_t pipe_type() { return (_pipe_type); }
00122     
00123     // The line processing functions
00124     typedef int (CliPipe::*StartPipe)(string& input_line, string& error_msg);
00125     typedef int (CliPipe::*StopPipe)(string& error_msg);
00126     typedef int (CliPipe::*LineProcess)(string& input_line);
00127     StartPipe   _start_func_ptr;
00128     StopPipe    _stop_func_ptr;
00129     LineProcess _process_func_ptr;
00130     LineProcess _eof_func_ptr;
00131     
00132     int pipe_compare_start(string& input_line, string& error_msg);
00133     int pipe_compare_stop(string& error_msg);
00134     int pipe_compare_process(string& input_line);
00135     int pipe_compare_eof(string& input_line);
00136     int pipe_compare_rollback_start(string& input_line, string& error_msg);
00137     int pipe_compare_rollback_stop(string& error_msg);
00138     int pipe_compare_rollback_process(string& input_line);
00139     int pipe_compare_rollback_eof(string& input_line);
00140     int pipe_count_start(string& input_line, string& error_msg);
00141     int pipe_count_stop(string& error_msg);
00142     int pipe_count_process(string& input_line);
00143     int pipe_count_eof(string& input_line);
00144     int pipe_display_start(string& input_line, string& error_msg);
00145     int pipe_display_stop(string& error_msg);
00146     int pipe_display_process(string& input_line);
00147     int pipe_display_eof(string& input_line);
00148     int pipe_display_detail_start(string& input_line, string& error_msg);
00149     int pipe_display_detail_stop(string& error_msg);
00150     int pipe_display_detail_process(string& input_line);
00151     int pipe_display_detail_eof(string& input_line);
00152     int pipe_display_inheritance_start(string& input_line, string& error_msg);
00153     int pipe_display_inheritance_stop(string& error_msg);
00154     int pipe_display_inheritance_process(string& input_line);
00155     int pipe_display_inheritance_eof(string& input_line);
00156     int pipe_display_xml_start(string& input_line, string& error_msg);
00157     int pipe_display_xml_stop(string& error_msg);
00158     int pipe_display_xml_process(string& input_line);
00159     int pipe_display_xml_eof(string& input_line);
00160     int pipe_except_start(string& input_line, string& error_msg);
00161     int pipe_except_stop(string& error_msg);
00162     int pipe_except_process(string& input_line);
00163     int pipe_except_eof(string& input_line);
00164     int pipe_find_start(string& input_line, string& error_msg);
00165     int pipe_find_stop(string& error_msg);
00166     int pipe_find_process(string& input_line);
00167     int pipe_find_eof(string& input_line);
00168     int pipe_hold_start(string& input_line, string& error_msg);
00169     int pipe_hold_stop(string& error_msg);
00170     int pipe_hold_process(string& input_line);
00171     int pipe_hold_eof(string& input_line);
00172     int pipe_match_start(string& input_line, string& error_msg);
00173     int pipe_match_stop(string& error_msg);
00174     int pipe_match_process(string& input_line);
00175     int pipe_match_eof(string& input_line);
00176     int pipe_nomore_start(string& input_line, string& error_msg);
00177     int pipe_nomore_stop(string& error_msg);
00178     int pipe_nomore_process(string& input_line);
00179     int pipe_nomore_eof(string& input_line);
00180     int pipe_resolve_start(string& input_line, string& error_msg);
00181     int pipe_resolve_stop(string& error_msg);
00182     int pipe_resolve_process(string& input_line);
00183     int pipe_resolve_eof(string& input_line);
00184     int pipe_save_start(string& input_line, string& error_msg);
00185     int pipe_save_stop(string& error_msg);
00186     int pipe_save_process(string& input_line);
00187     int pipe_save_eof(string& input_line);
00188     int pipe_trim_start(string& input_line, string& error_msg);
00189     int pipe_trim_stop(string& error_msg);
00190     int pipe_trim_process(string& input_line);
00191     int pipe_trim_eof(string& input_line);
00192     int pipe_unknown_start(string& input_line, string& error_msg);
00193     int pipe_unknown_stop(string& error_msg);
00194     int pipe_unknown_process(string& input_line);
00195     int pipe_unknown_eof(string& input_line);
00196     
00197     cli_pipe_t      _pipe_type;
00198     vector<string>  _pipe_args_list; // The arguments for the pipe command
00199     bool        _is_running;    // True if pipe is running
00200     int         _counter;   // Internal counter to keep state
00201     regex_t     _preg;      // Regular expression (internal form)
00202     bool        _bool_flag; // Internal bool flag to keep state
00203     
00204     CliClient       *_cli_client;   // The CliClient I belong to, or NULL
00205 };
00206 
00207 
00208 //
00209 // Global variables
00210 //
00211 
00212 
00213 //
00214 // Global functions prototypes
00215 //
00216 
00217 #endif // __CLI_CLI_COMMAND_PIPE_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations