Fawkes API Fawkes Development Version
metrics_inifin.cpp
1
2/***************************************************************************
3 * metrics_inifin.cpp - Fawkes MetricsAspect initializer/finalizer
4 *
5 * Created: Fri Jul 28 21:34:47 2017
6 * Copyright 2006-2017 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 <plugins/metrics/aspect/metrics_inifin.h>
25#include <plugins/metrics/aspect/metrics_manager.h>
26
27namespace fawkes {
28
29/** @class MetricsAspectIniFin <plugins/clips/aspect/clips_inifin.h>
30 * MetricsAspect initializer/finalizer.
31 * This initializer/finalizer will provide the Metrics node handle to
32 * threads with the MetricsAspect.
33 * @author Tim Niemueller
34 */
35
36/** Constructor. */
38{
39}
40
41/** Destructor. */
43{
44}
45
46void
48{
49 MetricsAspect *metrics_thread;
50 metrics_thread = dynamic_cast<MetricsAspect *>(thread);
51 if (metrics_thread == NULL) {
52 throw CannotInitializeThreadException("Thread '%s' claims to have the "
53 "MetricsAspect, but RTTI says it "
54 "has not. ",
55 thread->name());
56 }
57
58 metrics_mgr_->add_supplier(metrics_thread->get_metrics_supplier());
59}
60
61void
63{
64 MetricsAspect *metrics_thread;
65 metrics_thread = dynamic_cast<MetricsAspect *>(thread);
66 if (metrics_thread == NULL) {
67 throw CannotFinalizeThreadException("Thread '%s' claims to have the "
68 "MetricsAspect, but RTTI says it "
69 "has not. ",
70 thread->name());
71 }
72
73 metrics_mgr_->remove_supplier(metrics_thread->get_metrics_supplier());
74}
75
76/** Set Metrics environment manger.
77 * @param metrics_mgr metrics manager
78 */
79void
81{
82 metrics_mgr_ = metrics_mgr;
83}
84
85} // end namespace fawkes
Aspect initializer/finalizer base class.
Definition: inifin.h:34
Thread cannot be finalized.
virtual void finalize(Thread *thread)
Finalize thread.
void set_manager(MetricsManager *supplier_mgr)
Set Metrics environment manger.
virtual void init(Thread *thread)
Initialize thread.
Thread aspect to provide metrics.
Definition: metrics.h:35
Base class for metrics managers.
virtual void add_supplier(MetricsSupplier *supplier)=0
Add metrics supplier.
virtual void remove_supplier(MetricsSupplier *supplier)=0
Remove metrics supplier.
Thread class encapsulation of pthreads.
Definition: thread.h:46
const char * name() const
Get name of thread.
Definition: thread.h:100
Fawkes library namespace.