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
vision.cpp
1
2
/***************************************************************************
3
* vision.cpp - Fawkes VisionAspect initializer/finalizer
4
*
5
* Created: Wed Nov 24 00:13:36 2010
6
* Copyright 2006-2010 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. A runtime exception applies to
14
* this software (see LICENSE.GPL_WRE file mentioned below for details).
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Library General Public License for more details.
20
*
21
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22
*/
23
24
#include <aspect/inifins/vision.h>
25
#include <aspect/inifins/vision_master.h>
26
#include <aspect/vision.h>
27
#include <core/threading/thread_finalizer.h>
28
29
namespace
fawkes {
30
#if 0
/* just to make Emacs auto-indent happy */
31
}
32
#endif
33
34
/** @class VisionAspectIniFin <aspect/inifins/vision.h>
35
* Initializer/finalizer for the VisionAspect.
36
* @author Tim Niemueller
37
*/
38
39
/** Constructor.
40
* @param master_inifin vision master aspect inifin to get master from
41
*/
42
VisionAspectIniFin::VisionAspectIniFin(
VisionMasterAspectIniFin
*master_inifin)
43
:
AspectIniFin
(
"VisionAspect"
)
44
{
45
__master_inifin = master_inifin;
46
}
47
48
49
void
50
VisionAspectIniFin::init
(
Thread
*thread)
51
{
52
VisionAspect
*vision_thread;
53
vision_thread =
dynamic_cast<
VisionAspect
*
>
(thread);
54
if
(vision_thread == 0) {
55
throw
CannotInitializeThreadException
(
"Thread '%s' claims to have the "
56
"VisionAspect, but RTTI says it "
57
"has not. "
, thread->
name
());
58
}
59
60
try
{
61
if
( (vision_thread->
vision_thread_mode
() ==
VisionAspect::CONTINUOUS
) &&
62
(thread->
opmode
() !=
Thread::OPMODE_CONTINUOUS
) ) {
63
throw
CannotInitializeThreadException
(
"Vision thread '%s' operates in "
64
"continuous mode but thread does not"
,
65
thread->
name
());
66
}
67
if
( (vision_thread->
vision_thread_mode
() ==
VisionAspect::CYCLIC
) &&
68
(thread->
opmode
() !=
Thread::OPMODE_WAITFORWAKEUP
) ) {
69
throw
CannotInitializeThreadException
(
"Vision thread '%s' operates in "
70
"cyclic mode but thread does not "
71
"operate in wait-for-wakeup mode."
,
72
thread->
name
());
73
}
74
75
__master_inifin->
add_vision_thread
(vision_thread);
76
vision_thread->
init_VisionAspect
(__master_inifin->
vision_master
());
77
}
catch
(
DependencyViolationException
&e) {
78
CannotInitializeThreadException
ce(
"Dependency violation for "
79
"VisionAspect detected"
);
80
ce.
append
(e);
81
throw
ce;
82
}
83
84
}
85
86
87
bool
88
VisionAspectIniFin::prepare_finalize
(
Thread
*thread)
89
{
90
VisionAspect
*vision_thread;
91
vision_thread =
dynamic_cast<
VisionAspect
*
>
(thread);
92
if
(vision_thread == 0) {
93
return
true
;
94
}
95
96
if
( ! __master_inifin->
can_remove_vision_thread
(vision_thread) ) {
97
//__logger->log_warn("AspectIniFin", "Cannot remove vision master, there are "
98
// "still vision threads that depend on it");
99
return
false
;
100
}
101
102
return
true
;
103
}
104
105
void
106
VisionAspectIniFin::finalize
(
Thread
*thread)
107
{
108
VisionAspect
*vision_thread;
109
vision_thread =
dynamic_cast<
VisionAspect
*
>
(thread);
110
if
(vision_thread == 0) {
111
throw
CannotFinalizeThreadException
(
"Thread '%s' claims to have the "
112
"VisionAspect, but RTTI says it "
113
"has not. "
, thread->
name
());
114
}
115
116
try
{
117
__master_inifin->
remove_vision_thread
(vision_thread);
118
}
catch
(
DependencyViolationException
&e) {
119
CannotFinalizeThreadException
ce(
"Dependency violation for "
120
"VisionAspect detected"
);
121
ce.
append
(e);
122
throw
ce;
123
}
124
}
125
126
}
// end namespace fawkes
src
libs
aspect
inifins
vision.cpp
Generated by
1.8.1.1