00001 00002 00003 00004 00005 00006 00007 // =========================================================== 00008 // 00009 // Copyright (C) 2005-2007, all rights reserved by 00010 // - Institute of Telematics, Universitaet Karlsruhe (TH) 00011 // 00012 // More information and contact: 00013 // https://projekte.tm.uka.de/trac/NSIS 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; version 2 of the License 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License along 00025 // with this program; if not, write to the Free Software Foundation, Inc., 00026 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00027 // 00028 // =========================================================== 00034 #ifndef QUEUE_MANAGER_H 00035 #define QUEUE_MANAGER_H 00036 00037 #include "protlib_types.h" 00038 #include "cleanuphandler.h" 00039 00040 #include <vector> 00041 00042 #include "fqueue.h" 00043 #include "messages.h" 00044 00045 namespace protlib { 00046 00052 00053 class QueueManagerError : public ProtLibException { 00054 public: 00056 enum error_t { 00057 ERROR_NO_QUEUE_MANAGER, 00058 ERROR_REGISTER 00059 }; // end error_t 00060 const error_t err; 00062 QueueManagerError(error_t e); 00063 virtual const char* getstr() const; 00064 virtual const char *what() const throw() { return getstr(); } 00065 private: 00067 static const char* const errstr[]; 00068 }; // end class QueueManagerError 00069 00070 00085 class QueueManager { 00086 public: 00088 static QueueManager* instance(); 00090 static void clear(); 00092 void register_queue(FastQueue* fq, message::qaddr_t s); 00094 void unregister_queue(message::qaddr_t s); 00095 00097 FastQueue* get_queue(message::qaddr_t s) const; 00098 private: 00100 static QueueManager* inst; 00102 QueueManager(); 00104 ~QueueManager(); 00106 typedef vector<FastQueue*> qm_array_t; 00108 typedef qm_array_t::iterator qm_array_it_t; 00110 qm_array_t queue_arr; 00112 mutable pthread_mutex_t mutex; 00113 00114 static const size_t INITIAL_ARRAY_SIZE = 128; 00115 }; 00116 00118 00119 } // end namespace protlib 00120 00121 #endif