Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class 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 #ifdef HAVE_CONFIG_H
00029 #  include "config.h"
00030 #endif
00031 
00032 #ifdef HAVE_OMNIORB3
00033 #  include <omniORB3/CORBA.h>
00034 #endif
00035 
00036 #ifdef HAVE_OMNIORB4
00037 #  include <omniORB4/CORBA.h>
00038 #endif
00039 
00040 namespace OmniEvents {
00041 
00042 
00043 EventQueue::EventQueue(long size)
00044 : _next(0),
00045   _size(size+1), // Always need an `empty' entry at the head of the buffer.
00046   _queue(new CORBA::Any*[_size]),
00047   _filter(NULL)
00048 {
00049   DB(5,"MaxQueueLength="<<size)
00050   assert(_size>1);
00051   // Explicitly clear the queue with memset, because MS VC++ doesn't like
00052   // it as an array initializer.
00053   memset(_queue,0,_size*sizeof(CORBA::Any*));
00054 }
00055 
00056 
00057 EventQueue::~EventQueue()
00058 {
00059   for(long i=0; i<_size; ++i)
00060       delete _queue[i];
00061   delete[] _queue;
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+1)%_eventQueue._size;
00088   return result;
00089 }
00090 
00091 
00092 }; // end namespace OmniEvents

Generated on Fri Aug 26 20:56:14 2005 for OmniEvents by  doxygen 1.4.3-20050530