-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathBESReturnManager.cc
More file actions
107 lines (91 loc) · 3.5 KB
/
BESReturnManager.cc
File metadata and controls
107 lines (91 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// BESReturnManager.cc
// This file is part of bes, A C++ back-end server implementation framework
// for the OPeNDAP Data Access Protocol.
// Copyright (c) 2004-2009 University Corporation for Atmospheric Research
// Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact University Corporation for Atmospheric Research at
// 3080 Center Green Drive, Boulder, CO 80301
// (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
// Please read the full copyright statement in the file COPYRIGHT_UCAR.
//
// Authors:
// pwest Patrick West <pwest@ucar.edu>
// jgarcia Jose Garcia <jgarcia@ucar.edu>
#include <mutex>
#include "BESReturnManager.h"
using std::endl;
using std::ostream;
using std::string;
BESReturnManager *BESReturnManager::TheManager() {
static BESReturnManager the_manager;
return &the_manager;
}
bool BESReturnManager::add_transmitter(const string &name, BESTransmitter *transmitter) {
std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
if (find_transmitter(name) == nullptr) {
transmitter_list_[name] = transmitter;
return true;
}
return false;
}
bool BESReturnManager::del_transmitter(const string &name) {
std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
bool ret = false;
auto i = transmitter_list_.find(name);
if (i != transmitter_list_.end()) {
auto *obj = i->second;
transmitter_list_.erase(i);
delete obj;
ret = true;
}
return ret;
}
BESTransmitter *BESReturnManager::find_transmitter(const string &name) {
std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
auto i = transmitter_list_.find(name);
if (i != transmitter_list_.end()) {
return i->second;
}
return nullptr;
}
/** @brief dumps information about this object
*
* Displays the pointer value of this instance along with the transmitters
* registered with the return manager.
*
* @param strm C++ i/o stream to dump the information to
*/
void BESReturnManager::dump(ostream &strm) const {
std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
strm << BESIndent::LMarg << "BESReturnManager::dump - (" << (void *)this << ")" << endl;
BESIndent::Indent();
if (!transmitter_list_.empty()) {
strm << BESIndent::LMarg << "registered transmitters:" << endl;
BESIndent::Indent();
for (const auto &i : transmitter_list_) {
strm << BESIndent::LMarg << i.first << endl;
BESIndent::Indent();
i.second->dump(strm);
BESIndent::UnIndent();
}
BESIndent::UnIndent();
} else {
strm << BESIndent::LMarg << "registered transmitters: none" << endl;
}
BESIndent::UnIndent();
}