40#include "BESContextManager.h"
49static std::once_flag d_euc_init_once;
51#define MODULE "context"
52#define prolog std::string("BESContextManager::").append(__func__).append("() - ")
54BESContextManager::BESContextManager() {}
56BESContextManager::~BESContextManager() {}
65 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
67 BESDEBUG(MODULE, prolog <<
"name=\"" << name <<
"\", value=\"" << value <<
"\"" << endl);
68 _context_list[name] = value;
78 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
80 BESDEBUG(MODULE, prolog <<
"name=\"" << name <<
"\"" << endl);
81 _context_list.erase(name);
95 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
99 BESContextManager::Context_iter i;
100 i = _context_list.find(name);
101 if (i != _context_list.end()) {
105 BESDEBUG(MODULE, prolog <<
"name=\"" << name <<
"\", found=\"" << found <<
"\" value:\"" << ret <<
"\"" << endl);
108 string ret = _context_list[name];
109 BESDEBUG(MODULE, prolog <<
"name=\"" << name <<
"\" value: \"" << ret <<
"\"" << endl);
127 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
129 string value = BESContextManager::TheManager()->
get_context(name, found);
131 if (!found || value.empty())
return 0;
135 int val = strtol(value.c_str(), &endptr, 10);
136 if (val == 0 && errno > 0) {
137 throw BESInternalError(
string(
"Error reading an integer value for the context '") + name +
"': " + strerror(errno),
140 BESDEBUG(MODULE, prolog <<
"name=\"" << name <<
"\", found=\"" << found <<
"\" value: \"" << val <<
"\"" << endl);
150 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
154 std::map<string, string> props;
155 BESContextManager::Context_citer i = _context_list.begin();
156 BESContextManager::Context_citer e = _context_list.end();
157 for (; i != e; i++) {
161 props[
"name"] = name;
162 info.add_tag(
"context", value, &props);
175 std::lock_guard<std::recursive_mutex> lock_me(d_cache_lock_mutex);
177 strm << BESIndent::LMarg << prolog <<
"(this: " << (
void *)
this <<
")" << endl;
179 if (_context_list.size()) {
180 strm << BESIndent::LMarg <<
"current context:" << endl;
182 BESContextManager::Context_citer i = _context_list.begin();
183 BESContextManager::Context_citer ie = _context_list.end();
184 for (; i != ie; i++) {
185 strm << BESIndent::LMarg << (*i).first <<
": " << (*i).second << endl;
187 BESIndent::UnIndent();
190 strm << BESIndent::LMarg <<
"no context" << endl;
192 BESIndent::UnIndent();
196BESContextManager::TheManager()
198 std::call_once(d_euc_init_once,BESContextManager::initialize_instance);
202void BESContextManager::initialize_instance() {
205 atexit(delete_instance);
209void BESContextManager::delete_instance() {
maintains the list of registered request handlers for this server
virtual void list_context(BESInfo &info)
Adds all context and their values to the given informational object.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual int get_context_int(const std::string &name, bool &found)
Get the value of the given context and return it as an integer.
virtual void set_context(const std::string &name, const std::string &value)
set context in the BES
virtual std::string get_context(const std::string &name, bool &found)
retrieve the value of the specified context from the BES
virtual void unset_context(const std::string &name)
set context in the BES
informational response object
exception thrown if internal error encountered