Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

EventQueue.cc

Go to the documentation of this file.
00001 //                            Package   : omniEvents
00002 // EventQueue.cc              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 #include "EventQueue.h"
00025 #include <string.h> // memset
00026 #include <assert.h>
00027 
00028 #include <omniORB4/CORBA.h>
00029 
00030 namespace OmniEvents {
00031 
00032 
00033 EventQueue::EventQueue(long size)
00034 : _next(0),
00035   _size(size+1), // Always need an `empty' entry at the head of the buffer.
00036   _queue(new CORBA::Any*[_size])
00037 {
00038   assert(_size>1);
00039   // Explicitly clear the queue with memset, because MS VC++ doesn't like
00040   // it as an array initializer.
00041   memset(_queue,0,_size*sizeof(CORBA::Any*));
00042 }
00043 
00044 
00045 EventQueue::~EventQueue()
00046 {
00047   for(long i=0; i<_size; ++i)
00048       delete _queue[i];
00049   delete[] _queue;
00050 }
00051 
00052 
00053 void EventQueue::append(list<CORBA::Any*>& events)
00054 {
00055   for(list<CORBA::Any*>::iterator i=events.begin(); i!=events.end(); ++i)
00056   {
00057     delete _queue[_next];
00058     _queue[_next]=*i;
00059     _next=(++_next)%_size;
00060   }
00061   events.clear();
00062 }
00063 
00064 
00065 //
00066 //  EventQueue::Reader
00067 //
00068 
00069 
00070 EventQueue::Reader::Reader(EventQueue& eventQueue)
00071 : _eventQueue(eventQueue),
00072   _next(eventQueue._next)
00073 {
00074   // pass
00075 }
00076 
00077 
00078 bool EventQueue::Reader::moreEvents() const
00079 {
00080   return( _next!=_eventQueue._next );
00081 }
00082 
00083 
00084 CORBA::Any* EventQueue::Reader::nextEvent()
00085 {
00086   CORBA::Any* result =_eventQueue._queue[_next];
00087   _next=(++_next)%_eventQueue._size;
00088   return result;
00089 }
00090 
00091 
00092 }; // end namespace OmniEvents

Generated on Fri Dec 12 10:53:02 2003 for OmniEvents by doxygen1.2.15