33 #include <libdap/DMR.h>
34 #include <libdap/XMLWriter.h>
38 #include "BESInternalFatalError.h"
40 #include "DmrppParserSax2.h"
41 #include "DmrppTypeFactory.h"
42 #include "DmrppMetadataStore.h"
46 #define DEBUG_KEY "dmrpp_store"
47 #define MAINTAIN_STORE_SIZE_EVEN_WHEN_UNLIMITED 0
50 #define AT_EXIT(x) atexit((x))
64 #undef SYMETRIC_ADD_RESPONSES
70 using namespace dmrpp;
73 bool DmrppMetadataStore::d_enabled =
true;
108 DmrppMetadataStore::get_instance(
const string &cache_dir,
const string &prefix,
unsigned long long size)
110 if (d_enabled && d_instance == 0) {
112 d_enabled = d_instance->cache_enabled();
117 BESDEBUG(DEBUG_KEY,
"DmrppMetadataStore::"<<__func__ <<
"() - " <<
"Cache is DISABLED"<< endl);
120 AT_EXIT(delete_instance);
122 BESDEBUG(DEBUG_KEY,
"DmrppMetadataStore::"<<__func__ <<
"() - " <<
"Cache is ENABLED"<< endl);
126 BESDEBUG(DEBUG_KEY,
"DmrppMetadataStore::get_instance(dir,prefix,size) - d_instance: " << d_instance << endl);
138 DmrppMetadataStore::get_instance()
140 if (d_enabled && d_instance == 0) {
142 d_enabled = d_instance->cache_enabled();
146 BESDEBUG(DEBUG_KEY,
"DmrppMetadataStore::"<<__func__ <<
"() - " <<
"Cache is DISABLED"<< endl);
149 AT_EXIT(delete_instance);
151 BESDEBUG(DEBUG_KEY,
"DmrppMetadataStore::"<<__func__ <<
"() - " <<
"Cache is ENABLED"<< endl);
155 BESDEBUG(DEBUG_KEY,
"DmrppMetadataStore::get_instance() - d_instance: " << (
void *) d_instance << endl);
161 void DmrppMetadataStore::StreamDMRpp::operator()(ostream &os)
169 dmrpp->set_print_chunks(
true);
175 static_cast<dmrpp::DMRpp*
>(d_dmr)->print_dmrpp(xml, href);
181 throw BESInternalFatalError(
"StreamDMRpp output operator call with non-DMRpp instance.", __FILE__, __LINE__);
197 DmrppMetadataStore::add_responses(DMR *dmr,
const string &name)
199 bool stored_dmr = GlobalMetadataStore::add_responses(dmr, name);
201 bool stored_dmrpp =
false;
203 d_ledger_entry = string(
"add DMR++ ").append(name);
206 stored_dmrpp = store_dap_response(write_the_dmrpp_response, get_hash(name +
"dmrpp_r"), name,
"DMRpp");
214 return(stored_dmr && stored_dmrpp);
218 DmrppMetadataStore::add_dmrpp_response(libdap::DMR *dmrpp,
const std::string &name)
220 bool stored_dmrpp =
false;
222 d_ledger_entry = string(
"add DMR++ ").append(name);
224 StreamDMRpp write_the_dmrpp_response(dmrpp);
225 stored_dmrpp = store_dap_response(write_the_dmrpp_response, get_hash(name +
"dmrpp_r"), name,
"DMRpp");
233 return(stored_dmrpp);
243 DmrppMetadataStore::get_dmr_object(
const string &name)
249 write_dmr_response(name, oss);
252 unique_ptr<DMRpp> dmrpp(
new DMRpp(&dmrpp_btf,
"mds"));
255 parser.
intern(oss.str(), dmrpp.get());
257 dmrpp->set_factory(0);
259 return dmrpp.release();
275 DmrppMetadataStore::get_dmrpp_object(
const string &name)
278 write_dmrpp_response(name, oss);
281 unique_ptr<DMRpp> dmrpp(
new DMRpp(&dmrpp_btf,
"mds"));
284 parser.
intern(oss.str(), dmrpp.get());
286 dmrpp->set_factory(0);
288 return dmrpp.release();
exception thrown if an internal error is found and is fatal to the BES
Provide a way to print the DMR++ response.
void print_dap4(libdap::XMLWriter &xml, bool constrained=false)
override DMR::print_dap4() so the chunk info will print too.
void intern(std::istream &f, libdap::DMR *dest_dmr)