39 #include "BESContextManager.h"
49 #define MODULE "context"
50 #define prolog std::string("BESContextManager::").append(__func__).append("() - ")
59 BESDEBUG(MODULE, prolog <<
"name=\"" << name <<
"\", value=\"" << value <<
"\"" << endl);
60 _context_list[name] = value;
70 BESDEBUG(MODULE, prolog <<
"name=\"" << name <<
"\"" << endl);
71 _context_list.erase(name);
88 BESContextManager::Context_iter i;
89 i = _context_list.find(name);
90 if (i != _context_list.end()) {
94 BESDEBUG(MODULE, prolog <<
"name=\"" << name <<
"\", found=\"" << found <<
"\" value:\"" << ret <<
"\"" << endl);
97 string ret = _context_list[name];
98 BESDEBUG(MODULE, prolog <<
"name=\"" << name <<
"\" value: \"" << ret <<
"\"" << endl);
116 string value = BESContextManager::TheManager()->
get_context(name, found);
117 if (!found || value.empty())
return 0;
121 int val = strtol(value.c_str(), &endptr, 10);
122 if (val == 0 && errno > 0) {
123 throw BESInternalError(
string(
"Error reading an integer value for the context '") + name +
"': " + strerror(errno),
126 BESDEBUG(MODULE, prolog <<
"name=\"" << name <<
"\", found=\"" << found <<
"\" value: \"" << val <<
"\"" << endl);
138 std::map<string, string> props;
139 BESContextManager::Context_citer i = _context_list.begin();
140 BESContextManager::Context_citer e = _context_list.end();
141 for (; i != e; i++) {
145 props[
"name"] = name;
146 info.add_tag(
"context", value, &props);
159 strm << BESIndent::LMarg << prolog <<
"(this: " << (
void *)
this <<
")" << endl;
161 if (_context_list.size()) {
162 strm << BESIndent::LMarg <<
"current context:" << endl;
164 BESContextManager::Context_citer i = _context_list.begin();
165 BESContextManager::Context_citer ie = _context_list.end();
166 for (; i != ie; i++) {
167 strm << BESIndent::LMarg << (*i).first <<
": " << (*i).second << endl;
169 BESIndent::UnIndent();
172 strm << BESIndent::LMarg <<
"no context" << endl;
174 BESIndent::UnIndent();
178 BESContextManager::TheManager()
180 if (_instance == 0) {
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