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
logger.cpp
1
2
/***************************************************************************
3
* logger.cpp - Fawkes LoggerAspect initializer/finalizer
4
*
5
* Created: Wed Nov 24 01:17:09 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/logger.h>
25
#include <aspect/logger.h>
26
#include <logging/logger_employer.h>
27
#include <core/threading/thread_initializer.h>
28
#include <core/threading/thread_finalizer.h>
29
30
namespace
fawkes {
31
#if 0
/* just to make Emacs auto-indent happy */
32
}
33
#endif
34
35
/** @class LoggerAspectIniFin <aspect/inifins/logger.h>
36
* Initializer/finalizer for the LoggerAspect.
37
* @author Tim Niemueller
38
*/
39
40
/** Constructor.
41
* @param employer logger employer to register loggers to
42
*/
43
LoggerAspectIniFin::LoggerAspectIniFin(
LoggerEmployer
*employer)
44
:
AspectIniFin
(
"LoggerAspect"
)
45
{
46
__employer = employer;
47
}
48
49
50
void
51
LoggerAspectIniFin::init
(
Thread
*thread)
52
{
53
LoggerAspect
*logger_thread;
54
logger_thread =
dynamic_cast<
LoggerAspect
*
>
(thread);
55
if
(logger_thread == 0) {
56
throw
CannotInitializeThreadException
(
"Thread '%s' claims to have the "
57
"LoggerAspect, but RTTI says it "
58
"has not. "
, thread->
name
());
59
}
60
61
try
{
62
__employer->
add_logger
(logger_thread->
get_logger
());
63
}
catch
(
Exception
&e) {
64
CannotInitializeThreadException
ce(
"Thread has LoggerAspect but Logger "
65
"could not be added."
);
66
ce.
append
(e);
67
throw
ce;
68
}
catch
(...) {
69
throw
CannotInitializeThreadException
(
"Thread has LoggerAspect but Logger "
70
"could not be added."
);
71
}
72
}
73
74
75
void
76
LoggerAspectIniFin::finalize
(
Thread
*thread)
77
{
78
LoggerAspect
*logger_thread;
79
logger_thread =
dynamic_cast<
LoggerAspect
*
>
(thread);
80
if
(logger_thread == 0) {
81
throw
CannotFinalizeThreadException
(
"Thread '%s' claims to have the "
82
"LoggerAspect, but RTTI says it "
83
"has not. "
, thread->
name
());
84
}
85
86
try
{
87
__employer->
remove_logger
(logger_thread->
get_logger
());
88
}
catch
(
Exception
&e) {
89
CannotFinalizeThreadException
ce(
"Failed to remove logger"
);
90
ce.
append
(e);
91
throw
;
92
}
93
}
94
95
}
// end namespace fawkes
src
libs
aspect
inifins
logger.cpp
Generated by
1.8.1.2