40using std::stringstream;
47#include "BESContainerStorageFile.h"
48#include "BESFileContainer.h"
49#include "TheBESKeys.h"
50#include "BESInternalError.h"
51#include "BESSyntaxUserError.h"
53#include "BESServiceRegistry.h"
91 string key =
"BES.Container.Persistence.File." + n;
95 string s = key +
" not defined in BES configuration file";
99 ifstream persistence_file(_file.c_str());
101 if (!persistence_file) {
102 char *err = strerror(myerrno);
103 string s =
"Unable to open persistence file " + _file +
": ";
107 s +=
"Unknown error";
115 while (!persistence_file.eof()) {
117 persistence_file.getline(cline, 80);
118 if (!persistence_file.eof()) {
120 BESContainerStorageFile::container *c =
new BESContainerStorageFile::container;
121 strm >> c->_symbolic_name;
122 strm >> c->_real_name;
123 strm >> c->_container_type;
126 if (c->_symbolic_name ==
"" || c->_real_name ==
"" || c->_container_type ==
"") {
128 persistence_file.close();
129 string s =
"Incomplete container persistence line in file " + _file;
133 persistence_file.close();
135 string s =
"Too many fields in persistence file " + _file;
138 _container_list[c->_symbolic_name] = c;
141 persistence_file.close();
144 persistence_file.close();
149BESContainerStorageFile::~BESContainerStorageFile()
151 BESContainerStorageFile::Container_citer i = _container_list.begin();
152 BESContainerStorageFile::Container_citer ie = _container_list.end();
153 for (; i != ie; i++) {
154 BESContainerStorageFile::container *c = (*i).second;
174 BESContainerStorageFile::Container_citer i;
175 i = _container_list.find(sym_name);
176 if (i != _container_list.end()) {
177 BESContainerStorageFile::container *c = (*i).second;
178 ret_container =
new BESFileContainer(c->_symbolic_name, c->_real_name, c->_container_type);
181 return ret_container;
196 string err =
"Unable to add a container to a file, not yet implemented";
202 string err =
"Unable to add a container to a file, not yet implemented";
218 BESContainerStorageFile::Container_iter i;
219 i = _container_list.find(s_name);
220 if (i != _container_list.end()) {
221 BESContainerStorageFile::container *c = (*i).second;
222 _container_list.erase(i);
240 while (_container_list.size() != 0) {
241 Container_iter ci = _container_list.begin();
242 BESContainerStorageFile::container *c = (*ci).second;
243 _container_list.erase(ci);
265 BESServiceRegistry::TheRegistry()->services_handled(node_type, provides);
290 BESContainerStorageFile::Container_citer i;
291 i = _container_list.begin();
292 for (i = _container_list.begin(); i != _container_list.end(); i++) {
293 BESContainerStorageFile::container *c = (*i).second;
294 string sym = c->_symbolic_name;
295 string real = c->_real_name;
296 string type = c->_container_type;
310 strm << BESIndent::LMarg <<
"BESContainerStorageFile::dump - (" << (
void *)
this <<
")" << endl;
312 strm << BESIndent::LMarg <<
"name: " <<
get_name() << endl;
313 strm << BESIndent::LMarg <<
"file: " << _file << endl;
314 if (_container_list.size()) {
315 strm << BESIndent::LMarg <<
"containers:" << endl;
317 BESContainerStorageFile::Container_citer i = _container_list.begin();
318 BESContainerStorageFile::Container_citer ie = _container_list.end();
319 for (i = _container_list.begin(); i != ie; i++) {
320 BESContainerStorageFile::container *c = (*i).second;
321 strm << BESIndent::LMarg << c->_symbolic_name;
322 strm <<
", " << c->_real_name;
323 strm <<
", " << c->_container_type;
326 BESIndent::UnIndent();
329 strm << BESIndent::LMarg <<
" containers: none" << endl;
331 BESIndent::UnIndent();
virtual void show_containers(BESInfo &info)
show information for each container in this persistent store
virtual void add_container(const std::string &sym_name, const std::string &real_name, const std::string &type)
adds a container with the provided information
virtual bool isData(const std::string &inQuestion, std::list< std::string > &provides)
determine if the given container is data and what servies are available for it
virtual BESContainer * look_for(const std::string &sym_name)
looks for the specified container in the list of containers loaded from the file.
virtual bool del_container(const std::string &s_name)
removes a container with the given symbolic name
BESContainerStorageFile(const std::string &n)
pull container information from the specified file
virtual bool del_containers()
removes all containers
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void show_container(const std::string &sym_name, const std::string &real_name, const std::string &type, BESInfo &info)
add information for a container to the informational response object
virtual const std::string & get_name() const
retrieve the name of this persistent store
BESContainerStorage(const std::string &name)
create an instance of BESContainerStorage with the given name.
A container is something that holds data. E.G., a netcdf file or a database entry.
std::string get_container_type() const
retrieve the type of data this container holds, such as cedar or netcdf.
Holds real data, container type and constraint for symbolic name read from persistence.
informational response object
exception thrown if internal error encountered
error thrown if there is a user syntax error in the request or any other user error
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.