Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 82 lines (72 sloc) 2.702 kb
f2ae825 Martin Roth add pdm10 branch
authored
1 /*
ede4c1e Martin Roth Updated OrderedMessageQueue to use stl queue. WARNING: Tests crash!
authored
2 * Copyright 2009,2010,2011 Reality Jockey, Ltd.
f2ae825 Martin Roth add pdm10 branch
authored
3 * info@rjdj.me
4 * http://rjdj.me/
5 *
6 * This file is part of ZenGarden.
7 *
8 * ZenGarden is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ZenGarden is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with ZenGarden. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include "OrderedMessageQueue.h"
24
ede4c1e Martin Roth Updated OrderedMessageQueue to use stl queue. WARNING: Tests crash!
authored
25 OrderedMessageQueue::OrderedMessageQueue() {
26 orderedMessageQueue = list<ObjectMessageLetPair>();
f2ae825 Martin Roth add pdm10 branch
authored
27 }
28
29 OrderedMessageQueue::~OrderedMessageQueue() {
cbab65b Martin Roth Check to see if the global message queue is empty when processing it.
authored
30 // destroy all remaining inserted messages
31 list<ObjectMessageLetPair>::iterator it = orderedMessageQueue.begin();
32 list<ObjectMessageLetPair>::iterator end = orderedMessageQueue.end();
33 while (it != end) {
34 ObjectMessageLetPair omlPair = *it++;
35 omlPair.second.first->freeMessage();
36 }
f2ae825 Martin Roth add pdm10 branch
authored
37 }
38
39 void OrderedMessageQueue::insertMessage(MessageObject *messageObject, int outletIndex, PdMessage *message) {
ede4c1e Martin Roth Updated OrderedMessageQueue to use stl queue. WARNING: Tests crash!
authored
40 ObjectMessageLetPair omlPair = make_pair(messageObject, make_pair(message, outletIndex));
f2ae825 Martin Roth add pdm10 branch
authored
41
ede4c1e Martin Roth Updated OrderedMessageQueue to use stl queue. WARNING: Tests crash!
authored
42 list<ObjectMessageLetPair>::iterator it = orderedMessageQueue.begin();
43 list<ObjectMessageLetPair>::iterator end = orderedMessageQueue.end();
44 while (it != end) {
cbab65b Martin Roth Check to see if the global message queue is empty when processing it.
authored
45 if (message->getTimestamp() < it->second.first->getTimestamp()) {
ede4c1e Martin Roth Updated OrderedMessageQueue to use stl queue. WARNING: Tests crash!
authored
46 orderedMessageQueue.insert(it, omlPair);
f2ae825 Martin Roth add pdm10 branch
authored
47 return;
48 } else {
ede4c1e Martin Roth Updated OrderedMessageQueue to use stl queue. WARNING: Tests crash!
authored
49 ++it;
f2ae825 Martin Roth add pdm10 branch
authored
50 }
51 }
cbab65b Martin Roth Check to see if the global message queue is empty when processing it.
authored
52 orderedMessageQueue.push_back(omlPair); // insert at end
f2ae825 Martin Roth add pdm10 branch
authored
53 }
54
8d5e4f5 Martin Roth Implement PdGraph::cancelMessage(). Allows messages to be removed from t...
authored
55 void OrderedMessageQueue::removeMessage(MessageObject *messageObject, int outletIndex, PdMessage *message) {
ede4c1e Martin Roth Updated OrderedMessageQueue to use stl queue. WARNING: Tests crash!
authored
56 list<ObjectMessageLetPair>::iterator it = orderedMessageQueue.begin();
57 list<ObjectMessageLetPair>::iterator end = orderedMessageQueue.end();
58 while (it != end) {
59 ObjectMessageLetPair omlPair = *it;
60 if (omlPair.first == messageObject &&
61 omlPair.second.first == message &&
62 omlPair.second.second == outletIndex) {
63 orderedMessageQueue.erase(it);
8d5e4f5 Martin Roth Implement PdGraph::cancelMessage(). Allows messages to be removed from t...
authored
64 return;
65 } else {
ede4c1e Martin Roth Updated OrderedMessageQueue to use stl queue. WARNING: Tests crash!
authored
66 ++it;
8d5e4f5 Martin Roth Implement PdGraph::cancelMessage(). Allows messages to be removed from t...
authored
67 }
68 }
69 }
70
ede4c1e Martin Roth Updated OrderedMessageQueue to use stl queue. WARNING: Tests crash!
authored
71 ObjectMessageLetPair OrderedMessageQueue::peek() {
72 return orderedMessageQueue.front();
f2ae825 Martin Roth add pdm10 branch
authored
73 }
74
ede4c1e Martin Roth Updated OrderedMessageQueue to use stl queue. WARNING: Tests crash!
authored
75 void OrderedMessageQueue::pop() {
76 orderedMessageQueue.pop_front();
f2ae825 Martin Roth add pdm10 branch
authored
77 }
cbab65b Martin Roth Check to see if the global message queue is empty when processing it.
authored
78
79 bool OrderedMessageQueue::empty() {
80 return orderedMessageQueue.empty();
81 }
Something went wrong with that request. Please try again.