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
thread.cpp
1
2
/***************************************************************************
3
* thread.cpp - Fawkes Example Plugin Thread
4
*
5
* Generated: Wed Nov 22 17:13:57 2006
6
* Copyright 2006-2008 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
#include <plugins/examples/basics/thread.h>
24
25
#include <unistd.h>
26
27
using namespace
std;
28
using namespace
fawkes;
29
30
/** @class ExampleThread thread.h <plugins/examples/basics/thread.h>
31
* Thread of example plugin.
32
* @author Tim Niemueller
33
*/
34
35
/** Constructor.
36
* @param hook hook to register this thread for
37
* @param name thread name
38
* @param modc modulo count, every modc iterations a message is printed to stdout
39
*/
40
ExampleThread::ExampleThread
(
BlockedTimingAspect::WakeupHook
hook,
const
char
*name,
41
unsigned
int
modc)
42
:
Thread
(name,
Thread
::OPMODE_WAITFORWAKEUP),
43
BlockedTimingAspect
(hook)
44
{
45
this->modc = modc;
46
m = 0;
47
}
48
49
50
/** Destructor. */
51
ExampleThread::~ExampleThread
()
52
{
53
/** We cannot do the following:
54
* logger->log_info("ExampleThread", "Destroying thread %s", name());
55
*
56
* The reason: We do not know if this thread has been successfully initialized.
57
* It could be, that any other thread that is in the same thread list as this
58
* thread failed to initialize, before the current thread has been initialized.
59
* In this case the LoggingAspect has not been initialized and thus logger is
60
* undefined and this would cause a fatal segfault.
61
*/
62
}
63
64
65
void
66
ExampleThread::init
()
67
{
68
69
/* Try this code to see a failing init in the middle of the thread list.
70
if ( blockedTimingAspectHook() == WAKEUP_HOOK_WORLDSTATE ) {
71
throw Exception("Boom!");
72
}
73
*/
74
logger
->
log_info
(
"ExampleThread"
,
"%s::init() called"
,
name
());
75
}
76
77
78
void
79
ExampleThread::finalize
()
80
{
81
logger
->
log_info
(
"ExampleThread"
,
"%s::finalize() called"
,
name
());
82
}
83
84
85
/** Thread loop.
86
* If num iterations module modc is 0 print out messaege, otherwise do nothing.
87
*/
88
void
89
ExampleThread::loop
()
90
{
91
if
( (m % modc) == 0 ) {
92
logger
->
log_info
(
"ExampleThread"
,
"ExampleThread %s called %u times"
,
name
(), m);
93
}
94
++m;
95
usleep(0);
96
}
src
plugins
examples
basics
thread.cpp
Generated by
1.8.3.1