bes  Updated for version 3.20.5
BESDapResponseBuilder.h
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
4 // Access Protocol.
5 
6 // Copyright (c) 2011 OPeNDAP, Inc.
7 // Author: James Gallagher <jgallagher@opendap.org>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 #ifndef _response_builder_h
26 #define _response_builder_h
27 
28 #include <string>
29 
30 #define DAP_PROTOCOL_VERSION "3.2"
31 
32 #undef DAP2_STORED_RESULTS
33 
36 class BESResponseObject;
37 
38 namespace libdap {
39  class ConstraintEvaluator;
40  class DDS;
41  class DAS;
42 }
43 
52 public:
53  friend class ResponseBuilderTest;
54 
55 protected:
56  std::string d_dataset;
57  std::string d_dap2ce;
58  std::string d_dap4ce;
59  std::string d_dap4function;
60  std::string d_btp_func_ce;
61  int d_timeout;
62  std::string d_default_protocol;
63 
65 
70  std::string d_async_accepted;
71 
78  std::string d_store_result;
79 
80  void initialize();
81 
82 #ifdef DAP2_STORED_RESULTS
83  bool store_dap2_result(ostream &out, libdap::DDS &dds, libdap::ConstraintEvaluator &eval);
84 #endif
85 
86  void send_dap4_data_using_ce(std::ostream &out, libdap::DMR &dmr, bool with_mime_headersr);
87 
88 public:
89 
93  BESDapResponseBuilder(): d_dataset(""), d_dap2ce(""), d_dap4ce(""), d_dap4function(""),
94  d_btp_func_ce(""), d_timeout(0), d_default_protocol(DAP_PROTOCOL_VERSION),
96  {
97  initialize();
98  }
99 
100  virtual ~BESDapResponseBuilder();
101 
102  virtual std::string get_ce() const;
103  virtual void set_ce(std::string _ce);
104 
105  virtual std::string get_dap4ce() const;
106  virtual void set_dap4ce(std::string _ce);
107 
108  virtual std::string get_dap4function() const;
109  virtual void set_dap4function(std::string _func);
110 
111  virtual std::string get_store_result() const;
112  virtual void set_store_result(std::string _sr);
113 
114  virtual std::string get_async_accepted() const;
115  virtual void set_async_accepted(std::string _aa);
116 
117  virtual std::string get_btp_func_ce() const
118  {
119  return d_btp_func_ce;
120  }
121  virtual void set_btp_func_ce(std::string _ce)
122  {
123  d_btp_func_ce = _ce;
124  }
125 
126  virtual std::string get_dataset_name() const;
127  virtual void set_dataset_name(const std::string _dataset);
128 
133  void register_timeout() const;
135  void set_timeout(int timeout = 0);
136  int get_timeout() const;
137  void timeout_on() const;
138  void timeout_off();
139 
140  virtual void establish_timeout(std::ostream &stream) const;
141  virtual void remove_timeout() const;
143 
145 
146  virtual void split_ce(libdap::ConstraintEvaluator &eval, const std::string &expr = "");
147 
148  virtual void send_das(std::ostream &out, libdap::DAS &das, bool with_mime_headers = true) const;
149  virtual void send_das(std::ostream &out, libdap::DDS **dds, libdap::ConstraintEvaluator &eval, bool constrained =
150  false, bool with_mime_headers = true);
151 
152  virtual void send_dds(std::ostream &out, libdap::DDS **dds, libdap::ConstraintEvaluator &eval, bool constrained =
153  false, bool with_mime_headers = true);
154 
155  virtual void serialize_dap2_data_dds(std::ostream &out, libdap::DDS **dds, libdap::ConstraintEvaluator &eval,
156  bool ce_eval = true);
157  virtual void send_dap2_data(std::ostream &data_stream, libdap::DDS **dds, libdap::ConstraintEvaluator &eval,
158  bool with_mime_headers = true);
159 
160  // Added jhrg 9/1/16
161  virtual libdap::DDS *intern_dap2_data(BESResponseObject *obj, BESDataHandlerInterface &dhi);
162  virtual libdap::DDS *process_dap2_dds(BESResponseObject *obj, BESDataHandlerInterface &dhi);
163 
164  // TODO jhrg 9/6/16
165  //
166  // virtual libdap::DMR *intern_dap4_data(BESResponseObject *obj, BESDataHandlerInterface &dhi);
167 
168  virtual void send_ddx(std::ostream &out, libdap::DDS **dds, libdap::ConstraintEvaluator &eval,
169  bool with_mime_headers = true);
170 
171 #ifdef DAP2_STORED_RESULTS
172  virtual void serialize_dap2_data_ddx(std::ostream &out, libdap::DDS **dds, libdap::ConstraintEvaluator & eval,
173  const std::string &boundary, const std::string &start, bool ce_eval = true);
174 #endif
175  virtual void send_dmr(std::ostream &out, libdap::DMR &dmr, bool with_mime_headers = true);
176 
177  virtual void send_dap4_data(std::ostream &out, libdap::DMR & dmr, bool with_mime_headers = true);
178 
179  virtual void serialize_dap4_data(std::ostream &out, libdap::DMR &dmr, bool with_mime_headers = true);
180 
181  virtual bool store_dap4_result(ostream &out, libdap::DMR &dmr);
182 };
183 
184 #endif // _response_builder_h
virtual libdap::DDS * intern_dap2_data(BESResponseObject *obj, BESDataHandlerInterface &dhi)
std::string d_dap4function
DAP4 Constraint expression.
virtual void send_dds(std::ostream &out, libdap::DDS **dds, libdap::ConstraintEvaluator &eval, bool constrained=false, bool with_mime_headers=true)
Transmit a DDS.
std::string d_async_accepted
Should a timeout be cancelled once transmission starts?
std::string d_default_protocol
Response timeout after N seconds.
virtual void serialize_dap2_data_dds(std::ostream &out, libdap::DDS **dds, libdap::ConstraintEvaluator &eval, bool ce_eval=true)
virtual std::string get_dataset_name() const
Get the dataset name.
virtual void remove_timeout() const
Transmit data.
int d_timeout
The BTP functions, extracted from the CE.
std::string d_dap4ce
DAP2 Constraint expression.
virtual void split_ce(libdap::ConstraintEvaluator &eval, const std::string &expr="")
virtual void establish_timeout(std::ostream &stream) const
std::string d_btp_func_ce
DAP4 Server Side Function expression.
void set_timeout(int timeout=0)
virtual void set_dataset_name(const std::string _dataset)
Set the dataset pathname.
virtual void set_dap4function(std::string _func)
bool d_cancel_timeout_on_send
Version string for the library's default protocol version.
Structure storing information used by the BES to handle the request.
virtual std::string get_ce() const
Get the constraint expression.
virtual void send_dap2_data(std::ostream &data_stream, libdap::DDS **dds, libdap::ConstraintEvaluator &eval, bool with_mime_headers=true)
virtual std::string get_dap4function() const
Get the DAP4 server side function expression.
virtual void set_ce(std::string _ce)
std::string d_dap2ce
Name of the dataset/database.
Cache the results from server functions.
Abstract base class representing a specific set of information in response to a request to the BES.
virtual void send_ddx(std::ostream &out, libdap::DDS **dds, libdap::ConstraintEvaluator &eval, bool with_mime_headers=true)
virtual bool store_dap4_result(ostream &out, libdap::DMR &dmr)
virtual std::string get_dap4ce() const
Get the DAP4 constraint expression.
virtual void set_dap4ce(std::string _ce)
virtual void serialize_dap4_data(std::ostream &out, libdap::DMR &dmr, bool with_mime_headers=true)
virtual libdap::DDS * process_dap2_dds(BESResponseObject *obj, BESDataHandlerInterface &dhi)
Process a DDS (i.e., apply a constraint) for a non-DAP transmitter.