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
time_source.cpp
1
2
/***************************************************************************
3
* timesource.cpp - Fawkes TimeSourceAspect initializer/finalizer
4
*
5
* Created: Wed Nov 24 00:39:37 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/time_source.h>
25
#include <aspect/time_source.h>
26
#include <utils/time/clock.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 TimeSourceAspectIniFin <aspect/inifins/time_source.h>
35
* Initializer/finalizer for the TimeSourceAspect.
36
* @author Tim Niemueller
37
*/
38
39
/** Constructor.
40
* @param clock clock to register time source to
41
*/
42
TimeSourceAspectIniFin::TimeSourceAspectIniFin(
Clock
*clock)
43
:
AspectIniFin
(
"TimeSourceAspect"
)
44
{
45
__clock = clock;
46
}
47
48
49
void
50
TimeSourceAspectIniFin::init
(
Thread
*thread)
51
{
52
TimeSourceAspect
*timesource_thread;
53
timesource_thread =
dynamic_cast<
TimeSourceAspect
*
>
(thread);
54
if
(timesource_thread == NULL) {
55
throw
CannotInitializeThreadException
(
"Thread '%s' claims to have the "
56
"TimeSourceAspect, but RTTI says it "
57
"has not. "
, thread->
name
());
58
}
59
60
try
{
61
__timesource_uc.
add
(timesource_thread->
get_timesource
());
62
__clock->
register_ext_timesource
(timesource_thread->
get_timesource
(),
63
/* make default */
true
);
64
}
catch
(
Exception
&e) {
65
throw
CannotInitializeThreadException
(
"Thread has TimeSourceAspect but there "
66
"is already another time provider."
);
67
}
68
}
69
70
71
void
72
TimeSourceAspectIniFin::finalize
(
Thread
*thread)
73
{
74
TimeSourceAspect
*timesource_thread;
75
timesource_thread =
dynamic_cast<
TimeSourceAspect
*
>
(thread);
76
if
(timesource_thread == NULL) {
77
throw
CannotInitializeThreadException
(
"Thread '%s' claims to have the "
78
"TimeSourceAspect, but RTTI says it "
79
"has not. "
, thread->
name
());
80
}
81
82
try
{
83
__clock->
remove_ext_timesource
(timesource_thread->
get_timesource
());
84
__timesource_uc.
remove
(timesource_thread->
get_timesource
());
85
}
catch
(
Exception
&e) {
86
CannotFinalizeThreadException
ce(
"Failed to remove time source"
);
87
ce.
append
(e);
88
throw
;
89
}
90
}
91
92
93
}
// end namespace fawkes
src
libs
aspect
inifins
time_source.cpp
Generated by
1.8.1.2