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 // =========================================================== 00029 00034 #ifndef __FQUEUE_H__ 00035 #define __FQUEUE_H__ 00036 00037 #include <string> 00038 00039 #include "protlib_types.h" 00040 #include "messages.h" 00041 00042 extern "C" { 00043 #include"fastqueue.h" 00044 } 00045 00046 namespace protlib { 00047 00052 // declared in messages.h 00053 class message; 00054 00055 00063 class FastQueue { 00064 public: 00066 class FQError{}; 00068 FastQueue(const char *qname = 0, bool exp = false); 00070 ~FastQueue(); 00072 bool enqueue(message *element, bool exp = false); 00074 message *dequeue(bool blocking = true); 00076 message *dequeue_timedwait(const struct timespec &tspec); 00078 message *dequeue_timedwait(const long int msec); 00080 bool is_empty() const; 00082 unsigned long size() const; 00084 bool is_expedited_enabled() const; 00086 bool enable_expedited(bool exp); 00088 void shutdown(); 00090 unsigned long cleanup(); 00092 const char* get_name() const { return queue_name.c_str(); } 00093 private: 00095 queue_t *queue; 00097 string queue_name; 00099 bool shutdownflag; 00100 }; 00101 00102 00118 inline 00119 message * 00120 FastQueue::dequeue(bool blocking) 00121 { 00122 return static_cast<message*>(blocking ? 00123 dequeue_element_wait(queue) : 00124 dequeue_element_nonblocking(queue)); 00125 } 00126 00127 00137 inline 00138 message * 00139 FastQueue::dequeue_timedwait(const struct timespec& tspec) 00140 { 00141 return (message*)dequeue_element_timedwait(queue, &tspec); 00142 } 00143 00145 00146 } // end namespace protlib 00147 00148 #endif