00001 // Package : omniEvents 00002 // EventQueue.h Created : 2003/12/04 00003 // Author : Alex Tingle 00004 // 00005 // Copyright (C) 2003 Alex Tingle. 00006 // 00007 // This file is part of the omniEvents application. 00008 // 00009 // omniEvents is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU Lesser General Public 00011 // License as published by the Free Software Foundation; either 00012 // version 2.1 of the License, or (at your option) any later version. 00013 // 00014 // omniEvents is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // Lesser General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU Lesser General Public 00020 // License along with this library; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 // 00023 00024 #ifndef OMNIEVENTS__EVENTQUEUE_H 00025 #define OMNIEVENTS__EVENTQUEUE_H 00026 00027 #ifdef HAVE_CONFIG_H 00028 # include "config.h" 00029 #endif 00030 00031 #include "Orb.h" 00032 #include "Filter.h" 00033 00034 #include <memory> 00035 00036 #ifdef HAVE_STD_STL 00037 using namespace std; 00038 #endif 00039 00040 00041 namespace OmniEvents { 00042 00043 00056 class EventQueue 00057 { 00058 public: 00059 class Reader 00060 { 00061 public: 00062 Reader(EventQueue& eventQueue); 00063 bool moreEvents() const; 00064 CORBA::Any* nextEvent(); 00065 private: 00066 EventQueue& _eventQueue; 00067 int _next; 00068 }; 00069 00070 EventQueue(long size=1023); 00071 virtual ~EventQueue(); 00072 void setFilter(Filter* filter) 00073 { 00074 auto_ptr<Filter> f(filter); 00075 _filter=f; // MS VC++ 6 has no auto_ptr::reset() 00076 } 00077 00078 inline void append(CORBA::Any* event) 00079 { 00080 if(!_filter.get() || _filter->keep(*event)) 00081 { 00082 delete _queue[_next]; 00083 _queue[_next]=event; 00084 _next=(_next+1)%_size; 00085 } 00086 } 00087 00088 private: 00090 long _next; 00091 long _size; 00092 CORBA::Any** _queue; 00093 auto_ptr<Filter> _filter; 00094 00095 friend class Reader; 00096 }; 00097 00098 }; // end namespace OmniEvents 00099 00100 #endif // OMNIEVENTS__EVENTQUEUE_H