xorp

proto_node_cli.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
00003 
00004 // Copyright (c) 2001-2011 XORP, Inc and Others
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU Lesser General Public License, Version
00008 // 2.1, June 1999 as published by the Free Software Foundation.
00009 // Redistribution and/or modification of this program under the terms of
00010 // any other version of the GNU Lesser General Public License is not
00011 // permitted.
00012 // 
00013 // This program is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00016 // see the GNU Lesser General Public License, Version 2.1, a copy of
00017 // which can be found in the XORP LICENSE.lgpl file.
00018 // 
00019 // XORP, Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00020 // http://xorp.net
00021 
00022 // $XORP: xorp/libproto/proto_node_cli.hh,v 1.11 2008/10/02 21:57:18 bms Exp $
00023 
00024 
00025 #ifndef __LIBPROTO_PROTO_NODE_CLI_HH__
00026 #define __LIBPROTO_PROTO_NODE_CLI_HH__
00027 
00028 
00029 
00030 
00031 
00032 
00033 #include "libxorp/xorp.h"
00034 #include "libxorp/callback.hh"
00035 #include "proto_unit.hh"
00036 
00037 
00038 //
00039 // Protocol generic CLI access
00040 //
00041 
00042 
00043 //
00044 // Constants definitions
00045 //
00046 
00047 //
00048 // Structures/classes, typedefs and macros
00049 //
00050 
00051 typedef XorpCallback1<int, const vector<string>& >::RefPtr CLIProcessCallback;
00052 
00053 
00054 // 
00058 class ProtoNodeCli : public ProtoUnit {
00059 public:
00067     ProtoNodeCli(int init_family, xorp_module_id init_module_id);
00068     
00072     virtual ~ProtoNodeCli();
00073     
00084     int     add_cli_dir_command(const char *dir_command_name,
00085                     const char *dir_command_help);
00086 
00101     int     add_cli_dir_command(const char *dir_command_name,
00102                     const char *dir_command_help,
00103                     bool is_allow_cd,
00104                     const char *dir_cd_prompt);
00105     
00115     int     add_cli_command(const char *command_name,
00116                 const char *command_help,
00117                 const CLIProcessCallback& cli_process_callback);
00118 
00125     int     delete_cli_command(const char *command_name);
00126 
00132     int     delete_all_cli_commands();
00133 
00151     int     cli_process_command(const string& processor_name,
00152                     const string& cli_term_name,
00153                     const uint32_t& cli_session_id,
00154                     const string& command_name,
00155                     const string& command_args,
00156                     string& ret_processor_name,
00157                     string& ret_cli_term_name,
00158                     uint32_t& ret_cli_session_id,
00159                     string& ret_command_output);
00160     
00168     int     cli_print(const string& msg);
00169     
00186     virtual int add_cli_command_to_cli_manager(const char *command_name,
00187                            const char *command_help,
00188                            bool is_command_cd,
00189                            const char *command_cd_prompt,
00190                            bool is_command_processor) = 0;
00191 
00201     virtual int delete_cli_command_from_cli_manager(const char *command_name) = 0;
00202     
00203 private:
00204     
00205     int     add_cli_command_entry(const char *command_name,
00206                       const char *command_help,
00207                       bool is_command_cd,
00208                       const char *command_cd_prompt,
00209                       bool is_command_processor,
00210                       const CLIProcessCallback& cli_process_callback);
00211     int cli_process_dummy(const vector<string>& /* argv */) { return (XORP_OK); }
00212     
00213     
00214     string      _cli_result_string; // The string with the CLI result
00215     map<string, CLIProcessCallback> _cli_callback_map; // Map with commands
00216     vector<string> _cli_callback_vector; // Keep commands in order of adding
00217 };
00218 
00219 //
00220 // Global variables
00221 //
00222 
00223 //
00224 // Global functions prototypes
00225 //
00226 
00227 #endif // __LIBPROTO_PROTO_NODE_CLI_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations