40#include "TheBESKeys.h"
41#include "BESInternalError.h"
45#define BES_INFO_FILE_BUFFER_SIZE 4096
53 _strm(0), _strm_owned(false), _buffered(true), _response_started(false) {
54 _strm =
new ostringstream;
72 _strm(nullptr), _strm_owned(false), _buffered(true), _response_started(false) {
77 if (b ==
"true" || b ==
"True" || b ==
"TRUE" || b ==
"yes" || b ==
"Yes" || b ==
"YES") {
78 _strm =
new ostringstream;
81 if (strm && strm_owned)
delete strm;
84 string s =
"Informational response not buffered but no stream passed";
88 _strm_owned = strm_owned;
94 if (_strm && _strm_owned) {
109 _response_started =
true;
110 _response_name = response_name;
121 _response_started =
true;
122 _response_name = response_name;
125void BESInfo::end_response() {
126 _response_started =
false;
128 string s =
"Not all tags were ended in info response";
133void BESInfo::begin_tag(
const string &tag_name, map<
string,
string, std::less<>> *) {
134 _tags.push(tag_name);
137void BESInfo::end_tag(
const string &tag_name) {
138 if (_tags.empty() || _tags.top() != tag_name) {
139 string s = (string)
"tag " + tag_name +
" already ended or not started";
140 throw BESInternalError(s, __FILE__, __LINE__);
181 if (found ==
false) {
182 add_data(name +
" file key " + key +
" not found, information not available\n");
184 ifstream ifs(file.c_str());
187 string serr = name +
" file " + file +
" not found, information not available: ";
188 char *err = strerror(myerrno);
192 serr +=
"Unknown error";
198 char line[BES_INFO_FILE_BUFFER_SIZE];
200 ifs.getline(line, BES_INFO_FILE_BUFFER_SIZE);
222 begin_tag(
"BESError");
225 add_tag(
"Type", stype.str());
227 add_tag(
"Administrator", admin);
231 begin_tag(
"Location");
235 add_tag(
"Line", sline.str());
251 strm << ((ostringstream *) _strm)->str();
263 strm << BESIndent::LMarg <<
"BESInfo::dump - (" << (
void *)
this <<
")" << endl;
265 strm << BESIndent::LMarg <<
"response name: " << _response_name << endl;
266 strm << BESIndent::LMarg <<
"is it buffered? " << _buffered << endl;
267 strm << BESIndent::LMarg <<
"has response been started? " << _response_started << endl;
269 strm << BESIndent::LMarg <<
"tags:" << endl;
271 stack<string> temp_tags = _tags;
272 while (!temp_tags.empty()) {
273 string tag = temp_tags.top();
274 strm << BESIndent::LMarg << tag << endl;
277 BESIndent::UnIndent();
279 strm << BESIndent::LMarg <<
"tags: empty" << endl;
281 BESIndent::UnIndent();
Structure storing information used by the BES to handle the request.
Base exception class for the BES with basic string message.
unsigned int get_line() const
get the line number where the exception was thrown
unsigned int get_bes_error_type() const
Return the return code for this error class.
std::string get_file() const
get the file name where the exception was thrown
std::string get_message() const
get the error message for this exception
virtual void add_my_error_details_to(BESInfo &) const
virtual void add_data(const std::string &s)
add data to this informational object. If buffering is not set then the information is output directl...
BESInfo()
constructs a BESInfo object
virtual void begin_response(const std::string &response_name, BESDataHandlerInterface &dhi)
begin the informational response
virtual void print(std::ostream &strm)
print the information from this informational object to the specified stream
virtual void dump(std::ostream &strm) const
Displays debug information about this object.
virtual void add_data_from_file(const std::string &key, const std::string &name)
add data from a file to the informational object.
virtual void add_exception(const BESError &e, const std::string &admin)
add exception information to this informational object
exception thrown if internal error encountered
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()
Access to the singleton.