bes Updated for version 3.20.13
BESInfoList.cc
1// BESInfoList.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 "config.h"
34
35#ifdef HAVE_STDLIB_H
36#include <stdlib.h>
37#endif
38
39#include <mutex>
40
41#include "BESInfoList.h"
42#include "BESInfo.h"
43#include "TheBESKeys.h"
44
45using std::endl;
46using std::ostream;
47using std::string;
48
49#define BES_DEFAULT_INFO_TYPE "txt"
50
51BESInfoList *BESInfoList::d_instance = nullptr;
52static std::once_flag d_euc_init_once;
53
54BESInfoList::~BESInfoList() {}
55
56BESInfoList::BESInfoList() {}
57
58bool
59BESInfoList::add_info_builder(const string &info_type,
60 p_info_builder info_builder) {
61
62 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
63
64 BESInfoList::Info_citer i;
65 i = _info_list.find(info_type);
66 if (i == _info_list.end()) {
67 _info_list[info_type] = info_builder;
68 return true;
69 }
70 return false;
71}
72
73bool
74BESInfoList::rem_info_builder(const string &info_type) {
75
76 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
77
78 BESInfoList::Info_iter i;
79 i = _info_list.find(info_type);
80 if (i != _info_list.end()) {
81 _info_list.erase(i);
82 return true;
83 }
84 return false;
85}
86
87BESInfo *
88BESInfoList::build_info() {
89
90 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
91
92 string info_type = "";
93 bool found = false;
94 TheBESKeys::TheKeys()->get_value("BES.Info.Type", info_type, found);
95
96 if (!found || info_type == "")
97 info_type = BES_DEFAULT_INFO_TYPE;
98
99 BESInfoList::Info_citer i;
100 i = _info_list.find(info_type);
101 if (i != _info_list.end()) {
102 p_info_builder p = (*i).second;
103 if (p) {
104 return p(info_type);
105 }
106 }
107 return 0;
108}
109
117void
118BESInfoList::dump(ostream &strm) const {
119
120 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
121
122 strm << BESIndent::LMarg << "BESInfoList::dump - ("
123 << (void *) this << ")" << endl;
124 BESIndent::Indent();
125 if (_info_list.size()) {
126 strm << BESIndent::LMarg << "registered builders:" << endl;
127 BESIndent::Indent();
128 BESInfoList::Info_citer i = _info_list.begin();
129 BESInfoList::Info_citer ie = _info_list.end();
130 for (; i != ie; i++) {
131 p_info_builder p = (*i).second;
132 if (p) {
133 BESInfo *info = p("dump");
134 info->dump(strm);
135 delete info;
136 } else {
137 strm << BESIndent::LMarg << "builder is null" << endl;
138 }
139 }
140 BESIndent::UnIndent();
141 } else {
142 strm << BESIndent::LMarg << "registered builders: none" << endl;
143 }
144 BESIndent::UnIndent();
145}
146
147void BESInfoList::initialize_instance() {
148 d_instance = new BESInfoList;
149#ifdef HAVE_ATEXIT
150 atexit(delete_instance);
151#endif
152}
153
154void BESInfoList::delete_instance() {
155 delete d_instance;
156 d_instance = 0;
157}
158
160BESInfoList::TheList() {
161 std::call_once(d_euc_init_once,BESInfoList::initialize_instance);
162 return d_instance;
163}
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESInfoList.cc:118
informational response object
Definition: BESInfo.h:63
virtual void dump(std::ostream &strm) const
Displays debug information about this object.
Definition: BESInfo.cc:275
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
Definition: TheBESKeys.cc:340
static TheBESKeys * TheKeys()
Definition: TheBESKeys.cc:71