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
control_thread.cpp
1
2
/***************************************************************************
3
* control_thread.cpp - Fawkes Readylog Agent Thread
4
*
5
* Created: Wed Jul 15 15:09:09 2009
6
* Copyright 2009 Daniel Beck
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
#include "control_thread.h"
24
#include "eclipse_thread.h"
25
#include <core/exception.h>
26
#include <interfaces/TestInterface.h>
27
#include <cstring>
28
#include <cstdlib>
29
30
/** @class AgentControlThread "control_thread.h"
31
* This thread controls the agent thread by sending signals.
32
* @author Daniel Beck
33
*/
34
35
using namespace
fawkes;
36
37
/** Constructor.
38
* @param eclipse_thread the ECLiPSe agent thread
39
*/
40
AgentControlThread::AgentControlThread
(
EclipseAgentThread
* eclipse_thread )
41
:
Thread
(
"AgentControlThread"
,
Thread
::OPMODE_WAITFORWAKEUP ),
42
BlockedTimingAspect
(
BlockedTimingAspect
::WAKEUP_HOOK_THINK ),
43
m_eclipse_thread( eclipse_thread )
44
{
45
}
46
47
/** Destructor. */
48
AgentControlThread::~AgentControlThread
()
49
{
50
}
51
52
void
53
AgentControlThread::init
()
54
{
55
// open & register interfaces
56
m_test_iface =
blackboard
->
open_for_writing
<
TestInterface
>(
"readylog_test"
);
57
}
58
59
bool
60
AgentControlThread::prepare_finalize_user
()
61
{
62
m_eclipse_thread->
post_event
(
"terminate"
);
63
64
return
true
;
65
}
66
67
void
68
AgentControlThread::finalize
()
69
{
70
// close interfaces
71
blackboard
->
close
( m_test_iface );
72
}
73
74
void
75
AgentControlThread::loop
()
76
{
77
m_test_iface->
read
();
78
79
while
( !m_test_iface->
msgq_empty
() )
80
{
81
if
( m_test_iface->
msgq_first_is
<
TestInterface::CalculateMessage
>() )
82
{
83
TestInterface::CalculateMessage
* msg = m_test_iface->
msgq_first
<
TestInterface::CalculateMessage
>();
84
85
m_test_iface->
set_result
( msg->
summand
() + msg->
addend
() );
86
}
87
88
m_test_iface->
msgq_pop
();
89
}
90
91
m_test_iface->
write
();
92
93
m_eclipse_thread->
read_interfaces
();
94
m_eclipse_thread->
post_event
(
"update"
);
95
m_eclipse_thread->
write_interfaces
();
96
}
src
plugins
readylogagent
control_thread.cpp
Generated by
1.8.1.2