xorp

module_command.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2009 XORP, Inc.
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/module_command.hh,v 1.29 2008/10/02 21:58:23 bms Exp $
00021 
00022 #ifndef __RTRMGR_MODULE_COMMAND_HH__
00023 #define __RTRMGR_MODULE_COMMAND_HH__
00024 
00025 
00026 #include "template_commands.hh"
00027 
00028 
00029 class TaskManager;
00030 class TemplateTreeNode;
00031 class Validation;
00032 class MasterConfigTreeNode;
00033 
00034 class ModuleCommand : public Command {
00035 public:
00036     ModuleCommand(TemplateTree& template_tree,
00037           TemplateTreeNode& template_tree_node,
00038           const string& cmd_name);
00039     ~ModuleCommand();
00040 
00041     void add_action(const list<string>& action,
00042             const XRLdb* xrldb) throw (ParseError);
00043     virtual bool expand_actions(string& error_msg);
00044     virtual bool check_referred_variables(string& error_msg) const;
00045 
00046     Validation* startup_validation(TaskManager& taskmgr) const;
00047     Validation* config_validation(TaskManager& taskmgr) const;
00048     Validation* ready_validation(TaskManager& taskmgr) const;
00049     Validation* shutdown_validation(TaskManager& taskmgr) const;
00050     Startup*    startup_method(TaskManager& taskmgr) const;
00051     Shutdown*   shutdown_method(TaskManager& taskmgr) const;
00052 
00053     const string& module_name() const { return _module_name; }
00054     const string& module_exec_path() const { return _module_exec_path; }
00055     const list<string>& depends() const { return _depends; }
00056     int start_transaction(MasterConfigTreeNode& ctn,
00057               TaskManager& task_manager) const;
00058     int end_transaction(MasterConfigTreeNode& ctn,
00059             TaskManager& task_manager) const;
00060     string str() const;
00061 
00062     typedef XorpCallback3<void, bool, const string&, const string&>::RefPtr ProgramCallback;
00063 
00064 protected:
00065     void xrl_action_complete(const XrlError& err,
00066                  XrlArgs* xrl_args,
00067                  MasterConfigTreeNode *ctn,
00068                  Action *action,
00069                  string cmd) const;
00070 
00071     void program_action_complete(bool success,
00072                  const string& stdout_output,
00073                  const string& stderr_output,
00074                  bool do_exec,
00075                  MasterConfigTreeNode *ctn,
00076                  Action *action,
00077                  string cmd) const;
00078 
00079 private:
00080     TemplateTree&   _tt;
00081     string      _module_name;
00082     string      _module_exec_path;
00083     string      _default_target_name;
00084     list<string>    _depends;
00085     Action*     _start_commit;
00086     Action*     _end_commit;
00087     Action*     _status_method;
00088     Action*     _startup_method;
00089     Action*     _shutdown_method;
00090     bool        _execute_done;
00091     bool        _verbose;   // Set to true if output is verbose
00092 };
00093 
00094 #endif // __RTRMGR_MODULE_COMMAND_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations