libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
libdap::D4ResponseBuilder Class Reference

#include <D4ResponseBuilder.h>

Collaboration diagram for libdap::D4ResponseBuilder:
Collaboration graph

Public Member Functions

virtual void cache_data_ddx (const string &cache_file_name, DDS &dds)
 Cache data.
 
virtual string ce () const
 
 D4ResponseBuilder ()
 
virtual void dataset_constraint (ostream &out, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true)
 
virtual void dataset_constraint_ddx (ostream &out, DDS &dds, ConstraintEvaluator &eval, const string &boundary, const string &start, bool ce_eval=true)
 
virtual string dataset_name () const
 
virtual void establish_timeout (ostream &stream) const
 
virtual string get_btp_func_ce () const
 
virtual DDSget_cached_data_ddx (const string &cache_file_name, BaseTypeFactory *factory)
 
virtual bool is_valid (const string &cache_file_name)
 
virtual DDSread_cached_dataset (DDS &dds, ConstraintEvaluator &eval, string &cache_token)
 
virtual void read_data_from_cache (FILE *data, DDS *fdds)
 
virtual void remove_timeout () const
 
virtual void send_data (ostream &data_stream, DDS &dds, ConstraintEvaluator &eval, bool with_mime_headers=true)
 Transmit data.
 
virtual void send_data_ddx (ostream &data_stream, DDS &dds, ConstraintEvaluator &eval, const string &start, const string &boundary, bool with_mime_headers=true)
 Transmit data.
 
virtual void send_dds (ostream &out, DDS &dds, ConstraintEvaluator &eval, bool constrained=false, bool with_mime_headers=true)
 Transmit a DDS.
 
virtual void send_ddx (ostream &out, DDS &dds, ConstraintEvaluator &eval, bool with_mime_headers=true)
 
virtual void set_btp_func_ce (string _ce)
 
virtual void set_ce (const string &ce)
 
virtual void set_dataset_name (const string &ds)
 
void set_mime_binary (ostream &out, ObjectType type=unknown_type, EncodingType enc=x_plain, const time_t last_modified=0, const string &protocol="") const
 
void set_mime_data_boundary (ostream &out, const string &boundary, const string &cid, const string &endian, unsigned long long len) const
 
void set_mime_ddx_boundary (ostream &out, const string &boundary, const string &start) const
 
void set_mime_error (ostream &out, int code=404, const string &reason="Dataset not found", const string &protocol="") const
 
void set_mime_html (ostream &out, ObjectType type=unknown_type, EncodingType enc=x_plain, const time_t last_modified=0, const string &protocol="") const
 
void set_mime_multipart (ostream &out, const string &boundary, const string &start, ObjectType type=unknown_type, EncodingType enc=x_plain, const time_t last_modified=0, const string &protocol="", const string &url="") const
 
void set_mime_text (ostream &out, ObjectType type=unknown_type, EncodingType enc=x_plain, const time_t last_modified=0, const string &protocol="") const
 
void set_timeout (int t=0)
 
virtual void split_ce (ConstraintEvaluator &eval, const string &expr="")
 
int timeout () const
 
virtual ~D4ResponseBuilder ()
 

Protected Member Functions

void initialize ()
 

Protected Attributes

string d_btp_func_ce
 Constraint expression.
 
DAPCache3d_cache
 Version string for the library's default protocol version.
 
string d_ce
 Name of the dataset/database.
 
string d_dataset
 
string d_default_protocol
 Response timeout after N seconds.
 
int d_timeout
 The BTP functions, extracted from the CE.
 

Friends

class ResponseBuilderTest
 

Detailed Description

This class is used to build responses for/by the BES. This class replaces DODSFilter (although DODSFilter is still included in the library, its use is deprecated). and it does not have a provision for command line arguments.

Author
jhrg 1/28/2011

Definition at line 68 of file D4ResponseBuilder.h.

Constructor & Destructor Documentation

◆ D4ResponseBuilder()

libdap::D4ResponseBuilder::D4ResponseBuilder ( )
inline

Make an empty instance. Use the set_*() methods to load with needed values. You must call at least set_dataset_name() or be requesting version information.

Definition at line 89 of file D4ResponseBuilder.h.

◆ ~D4ResponseBuilder()

libdap::D4ResponseBuilder::~D4ResponseBuilder ( )
virtual

Definition at line 84 of file D4ResponseBuilder.cc.

Member Function Documentation

◆ cache_data_ddx()

void libdap::D4ResponseBuilder::cache_data_ddx ( const string & cache_file_name,
DDS & dds )
virtual

Cache data.

Write a DDS to an output stream. This method is intended to be used to write to a cache so that interim results can be reused w/o needing to be recomputed. I chose the 'data ddx' response because it combines the syntax and semantic metadata along with the data and all three DAP2 requests can be satisfied using it.

Parameters
cache_file_namePut the data here
ddsA DDS object containing the data to be sent.
Returns
void

Definition at line 1231 of file D4ResponseBuilder.cc.

◆ ce()

virtual string libdap::D4ResponseBuilder::ce ( ) const
inlinevirtual

Get the complete constraint expression.

Definition at line 96 of file D4ResponseBuilder.h.

◆ dataset_constraint()

void libdap::D4ResponseBuilder::dataset_constraint ( ostream & out,
DDS & dds,
ConstraintEvaluator & eval,
bool ce_eval = true )
virtual

Build/return the BLOB part of the DAP2 data response.

Definition at line 741 of file D4ResponseBuilder.cc.

◆ dataset_constraint_ddx()

void libdap::D4ResponseBuilder::dataset_constraint_ddx ( ostream & out,
DDS & dds,
ConstraintEvaluator & eval,
const string & boundary,
const string & start,
bool ce_eval = true )
virtual

Build/return the DDX and the BLOB part of the DAP4 data response.

Definition at line 783 of file D4ResponseBuilder.cc.

◆ dataset_name()

virtual string libdap::D4ResponseBuilder::dataset_name ( ) const
inlinevirtual

Get the dataset name - often a pathname to a file.

Definition at line 104 of file D4ResponseBuilder.h.

◆ establish_timeout()

void libdap::D4ResponseBuilder::establish_timeout ( ostream & stream) const
virtual

Use values of this instance to establish a timeout alarm for the server. If the timeout value is zero, do nothing.

Todo
When the alarm handler is called, two CRLF pairs are dumped to the stream and then an Error object is sent. Replace this with code that uses the new chunking protocol to insert an error message that can be read.

Definition at line 188 of file D4ResponseBuilder.cc.

◆ get_btp_func_ce()

virtual string libdap::D4ResponseBuilder::get_btp_func_ce ( ) const
inlinevirtual

Definition at line 100 of file D4ResponseBuilder.h.

◆ get_cached_data_ddx()

DDS * libdap::D4ResponseBuilder::get_cached_data_ddx ( const string & cache_file_name,
BaseTypeFactory * factory )
virtual

Read data from cache. Allocates a new DDS using the given factory.

Definition at line 1326 of file D4ResponseBuilder.cc.

◆ initialize()

void libdap::D4ResponseBuilder::initialize ( )
protected

Called when initializing a D4ResponseBuilder that's not going to be passed command line arguments.

Definition at line 90 of file D4ResponseBuilder.cc.

◆ is_valid()

bool libdap::D4ResponseBuilder::is_valid ( const string & cache_file_name)
virtual

Is the item named by cache_entry_name valid? This code tests that the cache entry is non-zero in size (returns false if that is the case, although that might not be correct) and that the dataset associated with this ResponseBulder instance is at least as old as the cached entry.

Parameters
cache_file_nameFile name of the cached entry
Returns
True if the thing is valid, false otherwise.

Definition at line 306 of file D4ResponseBuilder.cc.

◆ read_cached_dataset()

DDS * libdap::D4ResponseBuilder::read_cached_dataset ( DDS & dds,
ConstraintEvaluator & eval,
string & cache_token )
virtual

Get the cache DDS pointer - which will contain both attributes and data values.

Note
Do not call this when d_cache is null or when d_dap4_btp_func_expr is empty!
Parameters
ddsThe DDS of the dataset referenced by the URL
Returns
The cached DDS that resulted from calling the server functions in the original CE.
Parameters
cache_tokenA value-result parameter that contains the name of the file in the cache. Used to release the lock on the cached file.

Definition at line 354 of file D4ResponseBuilder.cc.

◆ read_data_from_cache()

void libdap::D4ResponseBuilder::read_data_from_cache ( FILE * data,
DDS * fdds )
virtual

Read the data from the saved response document.

Note
this method is made of code copied from Connect (process_data(0) but this copy assumes ot is reading a DDX with data written using the code in D4ResponseBuilder::cache_data_ddx().
I put this code here instead of using what was in Connect because I did not want all of the handlers to be modified to inlcude libdapclient and thus libcurl and libuuid.
Todo
Maybe move this code into libdap as a general 'get it from disk' method. Use that code in libdapclient.
Parameters
dataThe input stream @parma fdds Load this DDS object with the variables, attributes and data values from the cached DDS.

Definition at line 1280 of file D4ResponseBuilder.cc.

◆ remove_timeout()

void libdap::D4ResponseBuilder::remove_timeout ( ) const
virtual

Remove the timeout alarm.

Definition at line 203 of file D4ResponseBuilder.cc.

◆ send_data()

void libdap::D4ResponseBuilder::send_data ( ostream & data_stream,
DDS & dds,
ConstraintEvaluator & eval,
bool with_mime_headers = true )
virtual

Transmit data.

Send the data in the DDS object back to the client program. The data is encoded using a Marshaller, and enclosed in a MIME document which is all sent to data_stream.

Note
This is the DAP2 data response.
Parameters
ddsA DDS object containing the data to be sent.
evalA reference to the ConstraintEvaluator to use.
data_streamWrite the response to this stream.
anc_locationA directory to search for ancillary files (in addition to the CWD). This is used in a call to get_data_last_modified_time().
with_mime_headersIf true, include the MIME headers in the response. Defaults to true.
Returns
void

Definition at line 853 of file D4ResponseBuilder.cc.

◆ send_data_ddx()

void libdap::D4ResponseBuilder::send_data_ddx ( ostream & data_stream,
DDS & dds,
ConstraintEvaluator & eval,
const string & start,
const string & boundary,
bool with_mime_headers = true )
virtual

Transmit data.

Send the data in the DDS object back to the client program. The data is encoded using a Marshaller, and enclosed in a MIME document which is all sent to data_stream.

Note
This is the DAP4 data response.

FIXME!!!

Todo
I am broken WRT the other code here for sending data and DDS responses
Parameters
ddsA DDS object containing the data to be sent.
evalA reference to the ConstraintEvaluator to use.
data_streamWrite the response to this stream.
anc_locationA directory to search for ancillary files (in addition to the CWD). This is used in a call to get_data_last_modified_time().
with_mime_headersIf true, include the MIME headers in the response. Defaults to true.
Returns
void

Definition at line 1142 of file D4ResponseBuilder.cc.

◆ send_dds()

void libdap::D4ResponseBuilder::send_dds ( ostream & out,
DDS & dds,
ConstraintEvaluator & eval,
bool constrained = false,
bool with_mime_headers = true )
virtual

Transmit a DDS.

This function formats and prints an ASCII representation of a DDS on stdout. Either an entire DDS or a constrained DDS may be sent. This function looks in the local cache and uses a DDS object there if it's valid. Otherwise, if the request CE contains server functions that build data for the response, the resulting DDS will be cached.

Parameters
outThe output stream to which the DAS is to be sent.
ddsThe DDS to send back to a client.
evalA reference to the ConstraintEvaluator to use.
constrainedIf this argument is true, evaluate the current constraint expression and send the ‘constrained DDS’ back to the client.
anc_locationThe directory in which the external DAS file resides.
with_mime_headersIf true (default) send MIME headers.
Returns
void
See also
DDS

Definition at line 606 of file D4ResponseBuilder.cc.

◆ send_ddx()

void libdap::D4ResponseBuilder::send_ddx ( ostream & out,
DDS & dds,
ConstraintEvaluator & eval,
bool with_mime_headers = true )
virtual

Send the DDX response. The DDX never contains data, instead it holds a reference to a Blob response which is used to get the data values. The DDS and DAS objects are built using code that already exists in the servers.

Note
This is the DAP4 metadata response; it is supported by most DAP2 servers as well, although the DAP4 DDX will contain types not present in DAP2.

FIXME!!!

Todo
I am broken WRT the other code here for sending data and DDS responses
Parameters
ddsThe dataset's DDS with attributes in the variables.
evalA reference to the ConstraintEvaluator to use.
outDestination
with_mime_headersIf true, include the MIME headers in the response. Defaults to true.

Definition at line 1106 of file D4ResponseBuilder.cc.

◆ set_btp_func_ce()

virtual void libdap::D4ResponseBuilder::set_btp_func_ce ( string _ce)
inlinevirtual

Definition at line 101 of file D4ResponseBuilder.h.

◆ set_ce()

virtual void libdap::D4ResponseBuilder::set_ce ( const string & ce)
inlinevirtual

Set the constraint expression to use for this response.

Definition at line 98 of file D4ResponseBuilder.h.

◆ set_dataset_name()

virtual void libdap::D4ResponseBuilder::set_dataset_name ( const string & ds)
inlinevirtual

Set the dataset name, removing any escaping except spaces

Definition at line 106 of file D4ResponseBuilder.h.

◆ set_mime_binary()

void libdap::D4ResponseBuilder::set_mime_binary ( ostream & out,
ObjectType type = unknown_type,
EncodingType enc = x_plain,
const time_t last_modified = 0,
const string & protocol = "" ) const

Write an HTTP 1.0 response header for our binary response document (i.e., the DataDDS object).

Parameters
strmWrite the MIME header to this stream.
typeThe type of this this response. Defaults to application/octet-stream.
verThe version string; denotes the libdap implementation version.
encHow is this response encoded? Can be plain or deflate or the x_... versions of those. Default is x_plain.
last_modifiedThe time to use for the Last-Modified header value. Default is zero which means use the current time.

Definition at line 1542 of file D4ResponseBuilder.cc.

◆ set_mime_data_boundary()

void libdap::D4ResponseBuilder::set_mime_data_boundary ( ostream & out,
const string & boundary,
const string & cid,
const string & endian,
unsigned long long len ) const

Definition at line 1623 of file D4ResponseBuilder.cc.

◆ set_mime_ddx_boundary()

void libdap::D4ResponseBuilder::set_mime_ddx_boundary ( ostream & out,
const string & boundary,
const string & start ) const

Definition at line 1612 of file D4ResponseBuilder.cc.

◆ set_mime_error()

void libdap::D4ResponseBuilder::set_mime_error ( ostream & out,
int code = 404,
const string & reason = "Dataset not found",
const string & protocol = "" ) const

Generate an HTTP 1.0 response header for an Error object.

Parameters
strmWrite the MIME header to this stream.
codeHTTP 1.0 response code. Should be 400, ... 500, ...
reasonReason string of the HTTP 1.0 response header.
versionThe version string; denotes the DAP spec and implementation version.

Definition at line 1642 of file D4ResponseBuilder.cc.

◆ set_mime_html()

void libdap::D4ResponseBuilder::set_mime_html ( ostream & out,
ObjectType type = unknown_type,
EncodingType enc = x_plain,
const time_t last_modified = 0,
const string & protocol = "" ) const

Generate an HTTP 1.0 response header for a html document.

Parameters
strmWrite the MIME header to this stream.
typeThe type of this this response.
verThe version string; denotes the libdap implementation version.
encHow is this response encoded? Can be plain or deflate or the x_... versions of those. Default is x_plain.
last_modifiedThe time to use for the Last-Modified header value. Default is zero which means use the current time.

Definition at line 1495 of file D4ResponseBuilder.cc.

◆ set_mime_multipart()

void libdap::D4ResponseBuilder::set_mime_multipart ( ostream & out,
const string & boundary,
const string & start,
ObjectType type = unknown_type,
EncodingType enc = x_plain,
const time_t last_modified = 0,
const string & protocol = "",
const string & url = "" ) const

Build the initial headers for the DAP4 data response

Definition at line 1574 of file D4ResponseBuilder.cc.

◆ set_mime_text()

void libdap::D4ResponseBuilder::set_mime_text ( ostream & out,
ObjectType type = unknown_type,
EncodingType enc = x_plain,
const time_t last_modified = 0,
const string & protocol = "" ) const

Generate an HTTP 1.0 response header for a text document. This is used when returning a serialized DAS or DDS object.

Note
In Hyrax these headers are not used. Instead the front end of the server will build the response headers
Parameters
strmWrite the MIME header to this stream.
typeThe type of this this response. Defaults to application/octet-stream.
verThe version string; denotes the libdap implementation version.
encHow is this response encoded? Can be plain or deflate or the x_... versions of those. Default is x_plain.
last_modifiedThe time to use for the Last-Modified header value. Default is zero which means use the current time.

Definition at line 1446 of file D4ResponseBuilder.cc.

◆ set_timeout()

void libdap::D4ResponseBuilder::set_timeout ( int t = 0)
inline

Set the time out for requests in seconds. Zero means no timeout

Definition at line 109 of file D4ResponseBuilder.h.

◆ split_ce()

void libdap::D4ResponseBuilder::split_ce ( ConstraintEvaluator & eval,
const string & expr = "" )
virtual

Split the CE so that the server functions that compute new values are separated into their own string and can be evaluated separately from the rest of the CE (which can contain simple and slicing projection as well as other types of function calls).

Definition at line 218 of file D4ResponseBuilder.cc.

◆ timeout()

int libdap::D4ResponseBuilder::timeout ( ) const
inline

Get the current request timeout value in seconds.

Definition at line 111 of file D4ResponseBuilder.h.

Friends And Related Symbol Documentation

◆ ResponseBuilderTest

friend class ResponseBuilderTest
friend

Definition at line 71 of file D4ResponseBuilder.h.

Member Data Documentation

◆ d_btp_func_ce

string libdap::D4ResponseBuilder::d_btp_func_ce
protected

Constraint expression.

Definition at line 76 of file D4ResponseBuilder.h.

◆ d_cache

DAPCache3* libdap::D4ResponseBuilder::d_cache
protected

Version string for the library's default protocol version.

Definition at line 80 of file D4ResponseBuilder.h.

◆ d_ce

string libdap::D4ResponseBuilder::d_ce
protected

Name of the dataset/database.

Definition at line 75 of file D4ResponseBuilder.h.

◆ d_dataset

string libdap::D4ResponseBuilder::d_dataset
protected

Definition at line 74 of file D4ResponseBuilder.h.

◆ d_default_protocol

string libdap::D4ResponseBuilder::d_default_protocol
protected

Response timeout after N seconds.

Definition at line 78 of file D4ResponseBuilder.h.

◆ d_timeout

int libdap::D4ResponseBuilder::d_timeout
protected

The BTP functions, extracted from the CE.

Definition at line 77 of file D4ResponseBuilder.h.


The documentation for this class was generated from the following files: