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
43
EventQueue::EventQueue
(
long
size)
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
57
EventQueue::~EventQueue
()
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
70
EventQueue::Reader::Reader
(
EventQueue
& eventQueue)
71
: _eventQueue(eventQueue),
72
_next(eventQueue._next)
73
{
74
// pass
75
}
76
77
78
bool
EventQueue::Reader::moreEvents
()
const
79
{
80
return
(
_next
!=_eventQueue._next );
81
}
82
83
84
CORBA::Any*
EventQueue::Reader::nextEvent
()
85
{
86
CORBA::Any* result =_eventQueue._queue[
_next
];
87
_next
=(
_next
+1)%_eventQueue._size;
88
return
result;
89
}
90
91
92
};
// end namespace OmniEvents
config.h
EventQueue.h
DB
#define DB(l, x)
Definition
Orb.h:49
OmniEvents
Definition
Callback.h:39
OmniEvents::EventQueue
The EventQueue is a circular buffer, that contains _size-1 events.
Definition
EventQueue.h:57
OmniEvents::EventQueue::_size
long _size
Definition
EventQueue.h:91
OmniEvents::EventQueue::_next
long _next
Always points to the next slot to which an event will be written.
Definition
EventQueue.h:90
OmniEvents::EventQueue::EventQueue
EventQueue(long size=1023)
Definition
EventQueue.cc:43
OmniEvents::EventQueue::_queue
CORBA::Any ** _queue
Definition
EventQueue.h:92
OmniEvents::EventQueue::~EventQueue
virtual ~EventQueue()
Definition
EventQueue.cc:57
OmniEvents::EventQueue::Reader::nextEvent
CORBA::Any * nextEvent()
Definition
EventQueue.cc:84
OmniEvents::EventQueue::Reader::moreEvents
bool moreEvents() const
Definition
EventQueue.cc:78
OmniEvents::EventQueue::Reader::Reader
Reader(EventQueue &eventQueue)
Definition
EventQueue.cc:70
src
EventQueue.cc
Generated by
1.9.8