bes Updated for version 3.20.13
BESReporterList.cc
1// BESReporterList.cc
2
3// This file is part of bes, A C++ back-end server implementation framework
4// for the OPeNDAP Data Access Protocol.
5
6// Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7// Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact University Corporation for Atmospheric Research at
24// 3080 Center Green Drive, Boulder, CO 80301
25
26// (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27// Please read the full copyright statement in the file COPYRIGHT_UCAR.
28//
29// Authors:
30// pwest Patrick West <pwest@ucar.edu>
31// jgarcia Jose Garcia <jgarcia@ucar.edu>
32
33#include <mutex>
34
35#include "BESReporterList.h"
36#include "BESReporter.h"
37
38using std::endl;
39using std::ostream;
40using std::string;
41
42BESReporterList *BESReporterList::d_instance = nullptr ;
43static std::once_flag d_euc_init_once;
44
45BESReporterList::BESReporterList() {}
46
47BESReporterList::~BESReporterList()
48{
49 BESReporter *reporter = 0 ;
50 BESReporterList::Reporter_iter i = _reporter_list.begin() ;
51 for( ; i != _reporter_list.end(); i++ )
52 {
53 reporter = (*i).second ;
54 if( reporter ) { delete reporter ; (*i).second = 0 ; }
55 // instead of erasing each element as I go, call clear outside
56 // of the for loop
57 }
58 _reporter_list.clear() ;
59}
60
61bool
62BESReporterList::add_reporter( string reporter_name,
63 BESReporter *reporter_object )
64{
65 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
66
67 if( find_reporter( reporter_name ) == 0 )
68 {
69 _reporter_list[reporter_name] = reporter_object ;
70 return true ;
71 }
72 return false ;
73}
74
76BESReporterList::remove_reporter( string reporter_name )
77{
78 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
79
80 BESReporter *ret = 0 ;
81 BESReporterList::Reporter_iter i ;
82 i = _reporter_list.find( reporter_name ) ;
83 if( i != _reporter_list.end() )
84 {
85 ret = (*i).second;
86 _reporter_list.erase( i ) ;
87 }
88 return ret ;
89}
90
92BESReporterList::find_reporter( string reporter_name )
93{
94 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
95
96 BESReporterList::Reporter_citer i ;
97 i = _reporter_list.find( reporter_name ) ;
98 if( i != _reporter_list.end() )
99 {
100 return (*i).second;
101 }
102 return 0 ;
103}
104
105void
106BESReporterList::report( BESDataHandlerInterface &dhi )
107{
108 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
109
110 BESReporter *reporter = 0 ;
111 BESReporterList::Reporter_iter i = _reporter_list.begin() ;
112 for( ; i != _reporter_list.end(); i++ )
113 {
114 reporter = (*i).second ;
115 if( reporter ) reporter->report( dhi ) ;
116 }
117}
118
126void
127BESReporterList::dump( ostream &strm ) const
128{
129 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
130
131 strm << BESIndent::LMarg << "BESReporterList::dump - ("
132 << (void *)this << ")" << endl ;
133 BESIndent::Indent() ;
134 if( _reporter_list.size() )
135 {
136 strm << BESIndent::LMarg << "registered reporters:" << endl ;
137 BESIndent::Indent() ;
138 BESReporterList::Reporter_citer i = _reporter_list.begin() ;
139 BESReporterList::Reporter_citer ie = _reporter_list.end() ;
140 for( ; i != ie; i++ )
141 {
142 strm << BESIndent::LMarg << "reporter: " << (*i).first << endl ;
143 BESIndent::Indent() ;
144 BESReporter *reporter = (*i).second ;
145 reporter->dump( strm ) ;
146 BESIndent::UnIndent() ;
147 }
148 BESIndent::UnIndent() ;
149 }
150 else
151 {
152 strm << BESIndent::LMarg << "registered reporters: none" << endl ;
153 }
154 BESIndent::UnIndent() ;
155}
156
158BESReporterList::TheList()
159{
160 std::call_once(d_euc_init_once,BESReporterList::initialize_instance);
161 return d_instance;
162}
163
164void BESReporterList::initialize_instance() {
165 d_instance = new BESReporterList;
166#ifdef HAVE_ATEXIT
167 atexit(delete_instance);
168#endif
169}
170
171void BESReporterList::delete_instance() {
172 delete d_instance;
173 d_instance = 0;
174}
175
Structure storing information used by the BES to handle the request.
void dump(std::ostream &strm) const override
dumps information about this object
virtual void dump(std::ostream &strm) const =0
dump the contents of this object to the specified ostream