xorp

xorpsh_main.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 #ifdef XORP_USE_XORPSH
00021 
00022 #ifndef __RTRMGR_XORPSH_MAIN_HH__
00023 #define __RTRMGR_XORPSH_MAIN_HH__
00024 
00025 
00026 #include "libxorp/eventloop.hh"
00027 
00028 #include "libxipc/xrl_std_router.hh"
00029 
00030 #include "cli/cli_node.hh"
00031 
00032 #include "xrl/interfaces/rtrmgr_xif.hh"
00033 
00034 #include "rtrmgr_error.hh"
00035 #include "xorp_client.hh"
00036 #include "xrl_xorpsh_interface.hh"
00037 #include "slave_module_manager.hh"
00038 #include "xorpsh_base.hh"
00039 
00040 class OpCommandList;
00041 class RouterCLI;
00042 class SlaveConfigTree;
00043 class TemplateTree;
00044 
00045 class XorpShell : public XorpShellBase, XrlStdRouter {
00046 public:
00047     XorpShell(EventLoop& eventloop,
00048           const string& IPCname, 
00049           const string& xorp_root_dir,
00050           const string& config_template_dir, 
00051           bool verbose) throw (InitError);
00052     ~XorpShell();
00053 
00054     void run(const string& command, bool exit_on_error);
00055     bool done() const;
00056 
00057 
00058     void set_mode(Mode mode) { _mode = mode; }
00059     
00060     void register_done(const XrlError& e, const string* token,
00061                const uint32_t* pid, const uint32_t* clientid);
00062     void generic_done(const XrlError& e);
00063 #if 0
00064     bool request_config();
00065     void receive_config(const XrlError& e, const bool* ready,
00066             const string* config);
00067 #endif
00068 
00069     bool enter_config_mode(bool exclusive, GENERIC_CALLBACK cb);
00070 
00071     bool leave_config_mode(GENERIC_CALLBACK cb);
00072 
00073     bool lock_config(LOCK_CALLBACK cb);
00074 
00075     void config_saved_done(bool success, const string& error_msg);
00076     bool commit_changes(const string& deltas, const string& deletions,
00077             GENERIC_CALLBACK cb,
00078             CallBack final_cb);
00079     void commit_done(bool success, const string& error_msg);
00080 
00081     bool unlock_config(GENERIC_CALLBACK cb);
00082 
00083     bool get_config_users(GET_USERS_CALLBACK cb);
00084 
00085     void new_config_user(uid_t user_id);
00086 
00087     bool save_to_file(const string& filename, GENERIC_CALLBACK cb,
00088               CallBack final_cb);
00089 
00090     void save_lock_achieved(const XrlError& e, const bool* locked,
00091                 const uint32_t* lock_holder,
00092                 const string filename,
00093                 GENERIC_CALLBACK cb);
00094 
00095     bool load_from_file(const string& filename, GENERIC_CALLBACK cb,
00096             CallBack final_cb);
00097 
00098     void load_lock_achieved(const XrlError& e, const bool* locked,
00099                 const uint32_t* lock_holder,
00100                 const string filename,
00101                 GENERIC_CALLBACK cb);
00102 
00103     void config_changed(uid_t user_id, const string& deltas, 
00104             const string& deletions);
00105 
00106     void module_status_change(const string& module_name, 
00107                   GenericModule::ModuleStatus status);
00108 
00109     bool get_rtrmgr_pid(PID_CALLBACK cb);
00110 
00111     EventLoop& eventloop()      { return _eventloop; }
00112     OpCommandList* op_cmd_list()    { return _ocl; }
00113     SlaveConfigTree* config_tree()  { return _ct; }
00114     TemplateTree* template_tree()   { return _tt; }
00115     uint32_t clientid() const       { return _clientid; }
00116     uint32_t rtrmgr_pid() const     { return _rtrmgr_pid; }
00117     XorpClient& xorp_client()       { return _xclient; }
00118     const string& xorp_root_dir() const { return _xorp_root_dir; }
00119     bool verbose() const        { return _verbose; }
00120 
00121 private:
00127     virtual void finder_connect_event();
00128 
00134     virtual void finder_disconnect_event();
00135 
00136     EventLoop&      _eventloop; 
00137     XrlStdRouter&   _xrl_router;
00138     XorpClient      _xclient;
00139     XrlRtrmgrV0p1Client _rtrmgr_client;
00140     SlaveModuleManager  _mmgr;
00141     bool        _is_connected_to_finder;
00142 
00143     TemplateTree*   _tt;
00144     SlaveConfigTree*    _ct;
00145     OpCommandList*  _ocl;
00146     CliNode     _cli_node;
00147     RouterCLI*      _router_cli;
00148     string      _xorp_root_dir; // The root of the XORP tree
00149     bool        _verbose;   // Set to true if output is verbose
00150     string      _ipc_name;
00151     string      _authfile;
00152     string      _authtoken;
00153     bool        _got_config;
00154     bool        _got_modules;
00155     string      _configuration;
00156 
00157     bool        _xrl_generic_done;  // XRL startup/shutdown flag
00158     Mode        _mode;
00159 
00160     // Used to store the callback during a commit until we get called
00161     // with the response
00162     CallBack        _commit_callback;
00163     string      _commit_status; // Used for transient storage of error
00164                     // messages from commit
00165 
00166     // Used to store the callback during saving a file until we get called
00167     // with the response
00168     CallBack        _config_save_callback;
00169     string      _save_status;   // Used for transient storage of error
00170                     // messages from saving the config
00171 
00172     uint32_t        _rtrmgr_pid;
00173     uint32_t            _clientid;
00174 
00175     XorpTimer           _repeat_request_timer;
00176 
00177 #ifndef HOST_OS_WINDOWS
00178     XorpFd      _fddesc[2];
00179 #endif
00180 
00181     // XXX: must be last
00182     XrlXorpshInterface  _xorpsh_interface;
00183 };
00184 
00185 #endif // __RTRMGR_XORPSH_MAIN_HH__
00186 #endif // XORPSH
 All Classes Namespaces Functions Variables Typedefs Enumerations