OmniEvents
EventQueue.h
Go to the documentation of this file.
1 // Package : omniEvents
2 // EventQueue.h 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 #ifndef OMNIEVENTS__EVENTQUEUE_H
25 #define OMNIEVENTS__EVENTQUEUE_H
26 
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30 
31 #include "Orb.h"
32 #include "Filter.h"
33 
34 #include <memory>
35 
36 #ifdef HAVE_STD_STL
37 using namespace std;
38 #endif
39 
40 
41 namespace OmniEvents {
42 
43 
57 {
58 public:
59  class Reader
60  {
61  public:
62  Reader(EventQueue& eventQueue);
63  bool moreEvents() const;
64  CORBA::Any* nextEvent();
65  private:
67  int _next;
68  };
69 
70  EventQueue(long size=1023);
71  virtual ~EventQueue();
72  void setFilter(Filter* filter)
73  {
74  auto_ptr<Filter> f(filter);
75  _filter=f; // MS VC++ 6 has no auto_ptr::reset()
76  }
77 
78  inline void append(CORBA::Any* event)
79  {
80  if(!_filter.get() || _filter->keep(*event))
81  {
82  delete _queue[_next];
83  _queue[_next]=event;
84  _next=(_next+1)%_size;
85  }
86  }
87 
88 private:
90  long _next;
91  long _size;
92  CORBA::Any** _queue;
93  auto_ptr<Filter> _filter;
94 
95  friend class Reader;
96 };
97 
98 }; // end namespace OmniEvents
99 
100 #endif // OMNIEVENTS__EVENTQUEUE_H
The EventQueue is a circular buffer, that contains _size-1 events.
Definition: EventQueue.h:57
auto_ptr< Filter > _filter
Definition: EventQueue.h:93
void setFilter(Filter *filter)
Definition: EventQueue.h:72
long _next
Always points to the next slot to which an event will be written.
Definition: EventQueue.h:90
CORBA::Any ** _queue
Definition: EventQueue.h:92
void append(CORBA::Any *event)
Definition: EventQueue.h:78
int _next
Points to the next event to read.
Definition: EventQueue.h:67
Event filter interface.
Definition: Filter.h:50