39 using std::ostringstream;
43 #include "TheBESKeys.h" 44 #include "BESInternalError.h" 46 #define BES_INFO_FILE_BUFFER_SIZE 4096 54 _strm(0), _strm_owned(false), _buffered(true), _response_started(false)
56 _strm =
new ostringstream;
74 _strm(0), _strm_owned(false), _buffered(true), _response_started(false), _response_name(
"")
77 vector < string > vals;
80 if (b ==
"true" || b ==
"True" || b ==
"TRUE" || b ==
"yes" || b ==
"Yes" || b ==
"YES") {
81 _strm =
new ostringstream;
84 if (strm && strm_owned)
delete strm;
88 string s =
"Informational response not buffered but no stream passed";
92 _strm_owned = strm_owned;
99 if (_strm && _strm_owned) {
114 _response_started =
true;
115 _response_name = response_name;
118 void BESInfo::end_response()
120 _response_started =
false;
122 string s =
"Not all tags were ended in info response";
127 void BESInfo::begin_tag(
const string &tag_name, map<string, string> *)
129 _tags.push(tag_name);
132 void BESInfo::end_tag(
const string &tag_name)
134 if (_tags.size() == 0 || _tags.top() != tag_name) {
135 string s = (string)
"tag " + tag_name +
" already ended or not started";
180 if (found ==
false) {
181 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";
199 char line[BES_INFO_FILE_BUFFER_SIZE];
201 ifs.getline(line, BES_INFO_FILE_BUFFER_SIZE);
224 begin_tag(
"BESError");
227 add_tag(
"Type", stype.str());
229 add_tag(
"Administrator", admin);
231 begin_tag(
"Location" );
235 add_tag(
"Line", sline.str() );
236 end_tag(
"Location" );
252 strm << ((ostringstream *) _strm)->str();
265 strm << BESIndent::LMarg <<
"BESInfo::dump - (" << (
void *)
this <<
")" << endl;
267 strm << BESIndent::LMarg <<
"response name: " << _response_name << endl;
268 strm << BESIndent::LMarg <<
"is it buffered? " << _buffered << endl;
269 strm << BESIndent::LMarg <<
"has response been started? " << _response_started << endl;
271 strm << BESIndent::LMarg <<
"tags:" << endl;
273 stack < string > temp_tags = _tags;
274 while (!temp_tags.empty()) {
275 string tag = temp_tags.top();
276 strm << BESIndent::LMarg << tag << endl;
279 BESIndent::UnIndent();
282 strm << BESIndent::LMarg <<
"tags: empty" << endl;
284 BESIndent::UnIndent();
exception thrown if inernal error encountered
virtual void add_data_from_file(const string &key, const string &name)
add data from a file to the informational object.
BESInfo()
constructs a BESInfo object
virtual std::string get_message()
get the error message for this exception
virtual void dump(ostream &strm) const
Displays debug information about this object.
virtual int get_error_type()
Return the return code for this error class.
Abstract exception class for the BES with basic string message.
virtual void add_exception(BESError &e, const string &admin)
add exception information to this informational object
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
Structure storing information used by the BES to handle the request.
virtual std::string get_file()
get the file name where the exception was thrown
virtual void begin_response(const string &response_name, BESDataHandlerInterface &dhi)
begin the informational response
virtual void add_data(const string &s)
add data to this informational object. If buffering is not set then the information is output directl...
virtual void print(ostream &strm)
print the information from this informational object to the specified stream
static BESKeys * TheKeys()
virtual int get_line()
get the line number where the exception was thrown