xorp

slave_conf_tree.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/rtrmgr/slave_conf_tree.hh,v 1.31 2008/10/02 21:58:24 bms Exp $
00021 
00022 #ifndef __RTRMGR_SLAVE_CONF_FILE_HH__
00023 #define __RTRMGR_SLAVE_CONF_FILE_HH__
00024 
00025 
00026 
00027 
00028 
00029 
00030 #include "conf_tree.hh"
00031 #include "slave_conf_tree_node.hh"
00032 #include "slave_module_manager.hh"
00033 #include "rtrmgr_error.hh"
00034 #include "xorp_client.hh"
00035 #include "xorpsh_base.hh"
00036 #include "xorpsh_main.hh"
00037 
00038 
00039 class CommandTree;
00040 class ConfTemplate;
00041 class RouterCLI;
00042 
00047 class CommitStatus {
00048 public:
00049     enum Phase {
00050     COMMIT_PHASE_NONE = 0,
00051     COMMIT_PHASE_1,
00052     COMMIT_PHASE_2,
00053     COMMIT_PHASE_3,
00054     COMMIT_PHASE_4,
00055     COMMIT_PHASE_5,
00056     COMMIT_PHASE_DONE
00057     };
00058 
00062     CommitStatus() {
00063     reset();
00064     }
00065 
00069     void reset() {
00070     _success = true;
00071     _error_msg = "";
00072     _commit_phase = COMMIT_PHASE_NONE;
00073     }
00074 
00080     bool success() const { return _success; }
00081 
00087     const string& error_msg() const { return _error_msg; }
00088 
00094     void set_error(const string& error_msg) {
00095         _success = false;
00096         _error_msg = error_msg;
00097     }
00098 
00104     CommitStatus::Phase commit_phase() const { return _commit_phase; }
00105 
00111     void set_commit_phase(CommitStatus::Phase commit_phase) {
00112     _commit_phase = commit_phase;
00113     }
00114 
00115 private:
00116     bool    _success;   // True if current commit phase is successful
00117     string  _error_msg; // The error message (if error)
00118     Phase   _commit_phase;  // The current commit phase
00119 };
00120 
00121 
00122 class SlaveConfigTree : public ConfigTree {
00123     typedef XorpCallback2<void, bool, string>::RefPtr CallBack;
00124 public:
00125     SlaveConfigTree(XorpClient& xclient, bool verbose);
00126     SlaveConfigTree(const string& configuration, TemplateTree *tt,
00127             XorpClient& xclient, uint32_t clientid, 
00128             bool verbose) throw (InitError);
00129     virtual ConfigTreeNode* create_node(const string& segment, 
00130                     const string& path,
00131                     const TemplateTreeNode* ttn, 
00132                     ConfigTreeNode* parent_node, 
00133                     const ConfigNodeId& node_id,
00134                     uid_t user_id, bool verbose);
00135     virtual ConfigTree* create_tree(TemplateTree *tt, bool verbose);
00136 
00137 
00138     bool parse(const string& configuration, const string& config_file,
00139            string& errmsg);
00140     bool commit_changes(string& response, XorpShellBase& xorpsh, CallBack cb);
00141     void commit_phase2(const XrlError& e, const bool* locked,
00142                const uint32_t* lock_holder, CallBack cb,
00143                XorpShellBase* xorpsh);
00144     void commit_phase3(const XrlError& e, CallBack cb, XorpShellBase* xorpsh);
00145     void commit_phase4(bool success, const string& errmsg, CallBack cb,
00146                XorpShellBase* xorpsh);
00147     void commit_phase5(const XrlError& e, bool success, CallBack cb,
00148                XorpShellBase* xorpsh);
00149     void save_phase4(bool success, const string& errmsg, CallBack cb,
00150              XorpShellBase* xorpsh);
00151     void save_phase5(const XrlError& e, bool success, CallBack cb,
00152              XorpShellBase* xorpsh);
00153     string discard_changes();
00154     string mark_subtree_for_deletion(const list<string>& path_segments, 
00155                      uid_t user_id);
00156 
00157     bool get_deltas(const SlaveConfigTree& main_tree);
00158     bool get_deletions(const SlaveConfigTree& main_tree);
00159 
00160     virtual ConfigTreeNode& root_node() { return _root_node; }
00161     virtual const ConfigTreeNode& const_root_node() const {
00162     return _root_node;
00163     }
00164 
00165     SlaveConfigTreeNode& slave_root_node() { return _root_node; }
00166     const SlaveConfigTreeNode& const_slave_root_node() const {
00167     return _root_node;
00168     }
00169     SlaveConfigTreeNode* find_node(const list<string>& path) {
00170     return reinterpret_cast<SlaveConfigTreeNode*>(ConfigTree::find_node(path));
00171     }
00172 
00173     const CommitStatus& commit_status() const { return _commit_status; }
00174 
00175     void reset_commit_status() { _commit_status.reset(); }
00176 
00177 private:
00178     SlaveConfigTreeNode _root_node;
00179     XorpClient&     _xclient;
00180 
00181     XorpShellBase::LOCK_CALLBACK _stage2_cb;
00182 
00183     string      _commit_errmsg;
00184     string      _save_errmsg;
00185     uint32_t        _clientid;
00186     bool        _verbose;   // Set to true if output is verbose
00187 
00188     CommitStatus    _commit_status;
00189 };
00190 
00191 #endif // __RTRMGR_SLAVE_CONF_FILE_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations