45 #include <libdap/D4Group.h>
46 #include <libdap/D4Attributes.h>
47 #include <libdap/BaseType.h>
48 #include <libdap/escaping.h>
50 #include <BESContextManager.h>
51 #include <BESDataDDSResponse.h>
52 #include <BESDapNames.h>
53 #include <BESDataNames.h>
61 #include <BESDapError.h>
62 #include <stringbuffer.h>
64 #include "FONcBaseType.h"
65 #include "FONcRequestHandler.h"
66 #include "FONcTransmitter.h"
67 #include "FONcTransform.h"
74 #define prolog string("FONcTransmitter::").append(__func__).append("() - ")
120 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
125 bes::TempFile temp_file(FONcRequestHandler::temp_dir +
"/ncXXXXXX");
127 BESDEBUG(MODULE, prolog <<
"Building response file " << temp_file.
get_name() << endl);
129 ostream &strm = dhi.get_output_stream();
130 if (!strm)
throw BESInternalError(
"Output stream is not set, can not return as", __FILE__, __LINE__);
132 BESDEBUG(MODULE, prolog <<
"Transmitting temp file " << temp_file.
get_name() << endl);
141 atomic<bool> file_write_done(
false);
148 std::future<uint64_t> result = task.get_future();
149 task(temp_file.
get_name(), file_write_done, strm);
152 #define TOGGLE_TASK 0
165 std::ref(file_write_done), std::ref(strm));
170 file_write_done =
true;
171 uint64_t tcount = result.get();
184 std::future<uint64_t> result = task.get_future();
185 task(temp_file.
get_name(), file_write_done, strm);
186 uint64_t tcount = result.get();
191 throw BESDapError(
"Failed to read data: " + e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
196 catch (std::exception &e) {
197 throw BESInternalError(
"Failed to read data: STL Error: " +
string(e.what()), __FILE__, __LINE__);
200 throw BESInternalError(
"Failed to get read data: Unknown exception caught", __FILE__, __LINE__);
203 BESDEBUG(MODULE, prolog <<
"END Transmitted as netcdf" << endl);
225 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
230 bes::TempFile temp_file(FONcRequestHandler::temp_dir +
"/ncXXXXXX");
232 BESDEBUG(MODULE, prolog <<
"Building response file " << temp_file.
get_name() << endl);
241 ostream &strm = dhi.get_output_stream();
245 msg << prolog <<
"Using ostream: " << (
void *) &strm << endl;
246 BESDEBUG(MODULE, msg.str());
247 INFO_LOG( msg.str());
250 if (!strm)
throw BESInternalError(
"Output stream is not set, can not return as", __FILE__, __LINE__);
252 BESDEBUG(MODULE, prolog <<
"Transmitting temp file " << temp_file.
get_name() << endl);
258 throw BESDapError(
"Failed to read data: " + e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
263 catch (std::exception &e) {
264 throw BESInternalError(
"Failed to read data: STL Error: " +
string(e.what()), __FILE__, __LINE__);
267 throw BESInternalError(
"Failed to get read data: Unknown exception caught", __FILE__, __LINE__);
270 BESDEBUG(MODULE, prolog <<
"END Transmitted as netcdf" << endl);
error object created from libdap error objects and can handle those errors
Structure storing information used by the BES to handle the request.
std::map< std::string, std::string > data
the map of string data that will be required for the current request.
Abstract exception class for the BES with basic string message.
exception thrown if internal error encountered
Abstract base class representing a specific set of information in response to a request to the BES.
static uint64_t file_to_stream_task(const std::string &file_name, std::atomic< bool > &file_write_done, std::ostream &o_strm)
static void file_to_stream(const std::string &file_name, std::ostream &o_strm)
Copies the contents of the file identified by file_name to the stream o_strm.
static void send_dap4_data(BESResponseObject *obj, BESDataHandlerInterface &dhi)
The static method registered to transmit OPeNDAP data objects as a netcdf file.
static void send_dap2_data(BESResponseObject *obj, BESDataHandlerInterface &dhi)
The static method registered to transmit OPeNDAP data objects as a netcdf file.
FONcTransmitter()
Construct the FONcTransmitter, adding it with name netcdf to be able to transmit a data response.
Get a new temporary file.
std::string get_name() const