bes  Updated for version 3.20.10
BESReturnManager.cc
1 // BESReturnManager.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 "BESReturnManager.h"
36 
37 using std::endl;
38 using std::ostream;
39 using std::string;
40 
41 BESReturnManager *BESReturnManager::d_instance = nullptr;
42 std::once_flag d_euc_init_once;
43 
44 BESReturnManager::BESReturnManager() {}
45 
46 BESReturnManager::~BESReturnManager()
47 {
48  BESReturnManager::Transmitter_iter i;
49  BESTransmitter *t = 0;
50  for (i = _transmitter_list.begin(); i != _transmitter_list.end(); i++) {
51  t = (*i).second;
52  delete t;
53  }
54 }
55 
56 bool BESReturnManager::add_transmitter(const string &name, BESTransmitter *transmitter)
57 {
58  std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
59 
60  if (find_transmitter(name) == 0) {
61  _transmitter_list[name] = transmitter;
62  return true;
63  }
64  return false;
65 }
66 
67 bool BESReturnManager::del_transmitter(const string &name)
68 {
69  std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
70 
71  bool ret = false;
72  BESReturnManager::Transmitter_iter i;
73  i = _transmitter_list.find(name);
74  if (i != _transmitter_list.end()) {
75  BESTransmitter *obj = (*i).second;
76  _transmitter_list.erase(i);
77  if (obj) delete obj;
78  ret = true;
79  }
80  return ret;
81 }
82 
84 BESReturnManager::find_transmitter(const string &name)
85 {
86  std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
87 
88  BESReturnManager::Transmitter_citer i;
89  i = _transmitter_list.find(name);
90  if (i != _transmitter_list.end()) {
91  return (*i).second;
92  }
93  return 0;
94 }
95 
103 void BESReturnManager::dump(ostream &strm) const
104 {
105  std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
106 
107  strm << BESIndent::LMarg << "BESReturnManager::dump - (" << (void *) this << ")" << endl;
108  BESIndent::Indent();
109  if (_transmitter_list.size()) {
110  strm << BESIndent::LMarg << "registered transmitters:" << endl;
111  BESIndent::Indent();
112  BESReturnManager::Transmitter_citer i = _transmitter_list.begin();
113  BESReturnManager::Transmitter_citer ie = _transmitter_list.end();
114  for (; i != ie; i++) {
115  strm << BESIndent::LMarg << (*i).first << endl;
116  BESIndent::Indent();
117  (*i).second->dump(strm);
118  BESIndent::UnIndent();
119  }
120  BESIndent::UnIndent();
121  }
122  else {
123  strm << BESIndent::LMarg << "registered transmitters: none" << endl;
124  }
125  BESIndent::UnIndent();
126 }
127 
129 BESReturnManager::TheManager()
130 {
131  std::call_once(d_euc_init_once, BESReturnManager::initialize_instance);
132  return d_instance;
133 }
134 
135 void BESReturnManager::initialize_instance() {
136  d_instance = new BESReturnManager;
137 #ifdef HAVE_ATEXIT
138  atexit(delete_instance);
139 #endif
140 }
141 
142 void BESReturnManager::delete_instance() {
143  delete d_instance;
144  d_instance = 0;
145 }
146 
ReturnManager holds the list of response object transmitter that knows how to transmit response objec...
virtual void dump(std::ostream &strm) const
dumps information about this object