xorp

generic_module_manager.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/generic_module_manager.hh,v 1.15 2008/10/02 21:58:22 bms Exp $
00021 
00022 #ifndef __RTRMGR_GENERIC_MODULE_MANAGER_HH__
00023 #define __RTRMGR_GENERIC_MODULE_MANAGER_HH__
00024 
00025 
00026 
00027 
00028 class EventLoop;
00029 
00030 class GenericModule {
00031 public:
00032     GenericModule(const string& name);
00033     virtual ~GenericModule();
00034 
00035     enum ModuleStatus {
00036     // The process has started, but we haven't started configuring it yet
00037     MODULE_STARTUP      = 0,
00038 
00039     // The process has started, and we're in the process of configuring it
00040     // (or it's finished configuration, but waiting for another process)
00041     MODULE_INITIALIZING = 1,
00042 
00043     // The process is operating normally
00044     MODULE_RUNNING      = 2,
00045 
00046     // The process has failed, and is no longer runnning
00047     MODULE_FAILED       = 3,
00048 
00049     // The process has failed; it's running, but not responding anymore
00050     MODULE_STALLED      = 4,
00051 
00052     // The process has been signalled to shut down, but hasn't exitted yet
00053     MODULE_SHUTTING_DOWN    = 5,
00054 
00055     // The process has not been started
00056     MODULE_NOT_STARTED  = 6,
00057 
00058     // We have no record of such a module
00059     NO_SUCH_MODULE          = 7
00060     };
00061  
00062     virtual string str() const;
00063     ModuleStatus status() const { return _status; }
00064     const string& name() const { return _name; }
00065     virtual void new_status(ModuleStatus new_status);
00066 
00067 protected:
00068     string      _name;
00069     ModuleStatus    _status;
00070 
00071 private:
00072 };
00073 
00074 class GenericModuleManager {
00075 public:
00076     GenericModuleManager(EventLoop& eventloop, bool verbose);
00077     virtual ~GenericModuleManager();
00078 
00079     bool module_exists(const string& module_name) const;
00080     GenericModule::ModuleStatus module_status(const string& module_name) const;
00081     EventLoop& eventloop() { return _eventloop; }
00082     GenericModule* find_module(const string& module_name);
00083     const GenericModule* const_find_module(const string& module_name) const;
00084 
00085 protected:
00086     bool store_new_module(GenericModule *module, string& error_msg);
00087 
00088     EventLoop&  _eventloop;
00089     map<string, GenericModule *> _modules;  // Map module name to module
00090     bool    _verbose;   // Set to true if output is verbose
00091 private:
00092 };
00093 
00094 #endif // __RTRMGR_GENERIC_MODULE_MANAGER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations