00001 // -*- C++ -*- 00002 // vim:ts=8 sts=4 sw=4: 00003 00012 // ***** BEGIN LICENSE BLOCK ***** 00013 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 00014 // 00015 // The contents of this file are subject to the Mozilla Public License 00016 // Version 1.1 (the "License"); you may not use this file except in 00017 // compliance with the License. You may obtain a copy of the License at 00018 // http://www.mozilla.org/MPL/ 00019 // 00020 // Software distributed under the License is distributed on an "AS IS" 00021 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00022 // the License for the specific language governing rights and limitations 00023 // under the License. 00024 // 00025 // The Original Code is the consmgr network/serial-line monitoring package. 00026 // 00027 // The Initial Developer of the Original Code is Chris P. Ross. 00028 // Portions created by the Initial Developer are Copyright (C) 2000-2008 00029 // the Initial Developer. All Rights Reserved. 00030 // 00031 // Contributor(s): 00032 // Geoff Adams 00033 // 00034 // Alternatively, the contents of this file may be used under the terms of 00035 // either the GNU General Public License Version 2 or later (the "GPL"), or 00036 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 00037 // in which case the provisions of the GPL or the LGPL are applicable instead 00038 // of those above. If you wish to allow use of your version of this file only 00039 // under the terms of either the GPL or the LGPL, and not to allow others to 00040 // use your version of this file under the terms of the MPL, indicate your 00041 // decision by deleting the provisions above and replace them with the notice 00042 // and other provisions required by the GPL or the LGPL. If you do not delete 00043 // the provisions above, a recipient may use your version of this file under 00044 // the terms of any one of the MPL, the GPL or the LGPL. 00045 // 00046 // ***** END LICENSE BLOCK ***** 00047 00048 #ifndef __MASTERCONT_H 00049 #define __MASTERCONT_H 00050 00051 extern "C" { 00052 #include <pthread.h> 00053 }; 00054 00055 #include <deque> 00056 00057 #include "cmconfig.h" 00058 #include "message.h" 00059 #include "messageable.h" 00060 #include "messager.h" 00061 00067 class MasterController : public Messageable, public Messager 00068 { 00069 public: 00077 static void run(ConfigP &config, bool server=false); 00078 00084 static MasterController *get_instance(); 00085 00086 std::string get_id(void) const; 00087 00088 protected: 00089 MasterController(ConfigP &config, bool server); 00090 ~MasterController(); 00091 00092 // Do we also need to make our copy constructor and assignment operator 00093 // protected? Web research suggests maybe so. 00094 //Singleton(const Singleton&); 00095 //Singleton& operator= (const Singleton&); 00096 00097 private: 00100 void manage_connections(); 00101 00102 void start_connections(); 00103 00104 void destroy_children(void); 00105 00107 static void * signal_handler_thread(void *); 00108 00110 void block_signals(); 00114 void handle_signals(); 00118 int wait_for_signal(); 00119 00121 sigset_t all, prev; 00122 00124 ConfigP config; 00127 bool server; 00128 00130 static MasterController *single_instance; 00131 }; 00132 00133 #endif /* __MASTERCONT_H */