Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
qa_interface_msgq.cpp
1
2
/***************************************************************************
3
* qa_interface_msgq.cpp - QA for interface message queue
4
*
5
* Created: Tue Oct 24 14:34:40 2006
6
* Copyright 2006 Tim Niemueller [www.niemueller.de]
7
*
8
****************************************************************************/
9
10
/* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Library General Public License for more details.
19
*
20
* Read the full text in the LICENSE.GPL file in the doc directory.
21
*/
22
23
/// @cond QA
24
25
#include <interface/message_queue.h>
26
#include <iostream>
27
28
#include <interfaces/test.h>
29
#include <typeinfo>
30
31
using namespace
std;
32
using namespace
fawkes;
33
34
void
35
printMessages(
MessageQueue
*mq)
36
{
37
cout <<
"Iterating through messages:"
<< endl;
38
MessageQueue::MessageIterator
i;
39
mq->
lock
();
40
for
( i = mq->
begin
(); i != mq->
end
(); ++i) {
41
if
( i.
is
<
TestInterface::SetTestIntMessage
>() ) {
42
cout <<
"Message "
<< i.
id
() <<
" int: "
43
<< i.
get
<
TestInterface::SetTestIntMessage
>()->test_int()
44
<<
" type: "
<<
typeid
((*i)).name()
45
<< endl;
46
}
else
if
( i.
is
<
Message
>() ) {
47
cout <<
"It's just a message"
<< endl;
48
}
else
{
49
cout <<
"Message "
<< i.
id
() <<
" is not of correct type, it is "
<<
typeid
((*i)).name() << endl;
50
}
51
}
52
mq->
unlock
();
53
}
54
55
int
56
main(
int
argc,
char
**argv)
57
{
58
59
unsigned
int
id;
60
MessageQueue
*mq =
new
MessageQueue
();
61
62
cout <<
"Message queue initialized, now appending three test messages"
<< endl;
63
64
TestInterface::SetTestIntMessage
*m1 =
new
TestInterface::SetTestIntMessage
(1);
65
TestInterface::SetTestIntMessage
*m2 =
new
TestInterface::SetTestIntMessage
(2);
66
TestInterface::SetTestIntMessage
*m3 =
new
TestInterface::SetTestIntMessage
(3);
67
TestInterface::SetTestStringMessage
*m4 =
new
TestInterface::SetTestStringMessage
();
68
id
= mq->
append
(m1);
69
cout <<
"m1 added with id "
<<
id
<< endl;
70
id
= mq->
append
(m1);
71
cout <<
"m1 added with id "
<<
id
<< endl;
72
id
= mq->
append
(m2);
73
cout <<
"m2 added with id "
<<
id
<< endl;
74
id
= mq->
append
(m3);
75
cout <<
"m3 added with id "
<<
id
<< endl;
76
id
= mq->
append
(m4);
77
cout <<
"m4 (of different type!) added with id "
<<
id
<< endl;
78
79
cout <<
"Size is now "
<< mq->
size
() << endl;
80
81
cout <<
"Unreferencing messages"
<< endl;
82
m1->
unref
();
83
m2->
unref
();
84
m3->
unref
();
85
m4->
unref
();
86
87
cout <<
"Appending m1 again"
<< endl;
88
id
= mq->
append
(m1);
89
cout <<
"m1 added with id "
<<
id
<< endl;
90
cout <<
"Size is now "
<< mq->
size
() << endl;
91
cout <<
"m1 refcount is now "
<< m1->
refcount
() << endl;
92
93
printMessages(mq);
94
95
cout <<
"Now removing message m1 once"
<< endl;
96
mq->
remove
(m1);
97
printMessages(mq);
98
99
100
cout <<
"m1 has refcount "
<< m1->
refcount
() << endl;
101
102
cout <<
"Now removing message m2"
<< endl;
103
mq->
remove
(m2);
104
printMessages(mq);
105
106
cout <<
"Now removing message m4"
<< endl;
107
mq->
remove
(m4);
108
printMessages(mq);
109
110
cout <<
"Size is now "
<< mq->
size
() << endl;
111
112
printMessages(mq);
113
114
delete
mq;
115
// messages will be erased when enqueued in mq!
116
117
}
118
119
/// @endcond
src
libs
interfaces
qa
qa_interface_msgq.cpp
Generated by
1.8.1.1