OmniEvents
EventQueue.cc
Go to the documentation of this file.
1 // Package : omniEvents
2 // EventQueue.cc Created : 2003/12/04
3 // Author : Alex Tingle
4 //
5 // Copyright (C) 2003 Alex Tingle.
6 //
7 // This file is part of the omniEvents application.
8 //
9 // omniEvents is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // omniEvents is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //
23 
24 #include "EventQueue.h"
25 #include <string.h> // memset
26 #include <assert.h>
27 
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31 
32 #ifdef HAVE_OMNIORB3
33 # include <omniORB3/CORBA.h>
34 #endif
35 
36 #ifdef HAVE_OMNIORB4
37 # include <omniORB4/CORBA.h>
38 #endif
39 
40 namespace OmniEvents {
41 
42 
44 : _next(0),
45  _size(size+1), // Always need an `empty' entry at the head of the buffer.
46  _queue(new CORBA::Any*[_size]),
47  _filter(NULL)
48 {
49  DB(5,"MaxQueueLength="<<size)
50  assert(_size>1);
51  // Explicitly clear the queue with memset, because MS VC++ doesn't like
52  // it as an array initializer.
53  memset(_queue,0,_size*sizeof(CORBA::Any*));
54 }
55 
56 
58 {
59  for(long i=0; i<_size; ++i)
60  delete _queue[i];
61  delete[] _queue;
62 }
63 
64 
65 //
66 // EventQueue::Reader
67 //
68 
69 
71 : _eventQueue(eventQueue),
72  _next(eventQueue._next)
73 {
74  // pass
75 }
76 
77 
79 {
80  return( _next!=_eventQueue._next );
81 }
82 
83 
85 {
86  CORBA::Any* result =_eventQueue._queue[_next];
87  _next=(_next+1)%_eventQueue._size;
88  return result;
89 }
90 
91 
92 }; // end namespace OmniEvents
#define DB(l, x)
Definition: Orb.h:49
The EventQueue is a circular buffer, that contains _size-1 events.
Definition: EventQueue.h:57
long _next
Always points to the next slot to which an event will be written.
Definition: EventQueue.h:90
EventQueue(long size=1023)
Definition: EventQueue.cc:43
CORBA::Any ** _queue
Definition: EventQueue.h:92
Reader(EventQueue &eventQueue)
Definition: EventQueue.cc:70