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)
55 _strm =
new ostringstream;
73 _strm(0), _strm_owned(false), _buffered(true), _response_started(false), _response_name(
"")
76 vector < string > vals;
79 if (b ==
"true" || b ==
"True" || b ==
"TRUE" || b ==
"yes" || b ==
"Yes" || b ==
"YES") {
80 _strm =
new ostringstream;
83 if (strm && strm_owned)
delete strm;
87 string s =
"Informational response not buffered but no stream passed";
91 _strm_owned = strm_owned;
98 if (_strm && _strm_owned) {
113 _response_started =
true;
114 _response_name = response_name;
126 _response_started =
true;
127 _response_name = response_name;
130void BESInfo::end_response()
132 _response_started =
false;
134 string s =
"Not all tags were ended in info response";
139void BESInfo::begin_tag(
const string &tag_name, map<string, string> *)
141 _tags.push(tag_name);
144void BESInfo::end_tag(
const string &tag_name)
146 if (_tags.size() == 0 || _tags.top() != tag_name) {
147 string s = (string)
"tag " + tag_name +
" already ended or not started";
192 if (found ==
false) {
193 add_data(name +
" file key " + key +
" not found, information not available\n");
196 ifstream ifs(file.c_str());
199 string serr = name +
" file " + file +
" not found, information not available: ";
200 char *err = strerror(myerrno);
204 serr +=
"Unknown error";
211 char line[BES_INFO_FILE_BUFFER_SIZE];
213 ifs.getline(line, BES_INFO_FILE_BUFFER_SIZE);
236 begin_tag(
"BESError");
239 add_tag(
"Type", stype.str());
241 add_tag(
"Administrator", admin);
243 begin_tag(
"Location" );
247 add_tag(
"Line", sline.str() );
248 end_tag(
"Location" );
264 strm << ((ostringstream *) _strm)->str();
277 strm << BESIndent::LMarg <<
"BESInfo::dump - (" << (
void *)
this <<
")" << endl;
279 strm << BESIndent::LMarg <<
"response name: " << _response_name << endl;
280 strm << BESIndent::LMarg <<
"is it buffered? " << _buffered << endl;
281 strm << BESIndent::LMarg <<
"has response been started? " << _response_started << endl;
283 strm << BESIndent::LMarg <<
"tags:" << endl;
285 stack < string > temp_tags = _tags;
286 while (!temp_tags.empty()) {
287 string tag = temp_tags.top();
288 strm << BESIndent::LMarg << tag << endl;
291 BESIndent::UnIndent();
294 strm << BESIndent::LMarg <<
"tags: empty" << endl;
296 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_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()