libdap++  Updated for version 3.11.7
ResponseBuilder.h
Go to the documentation of this file.
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2011 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 #ifndef _response_builder_h
27 #define _response_builder_h
28 
29 #include <string>
30 #include <set>
31 
32 #ifndef _das_h
33 #include "DAS.h"
34 #endif
35 
36 #ifndef _dds_h
37 #include "DDS.h"
38 #endif
39 
40 #ifndef constraint_evaluator_h
41 #include "ConstraintEvaluator.h"
42 #endif
43 
44 #ifndef _object_type_h
45 #include "ObjectType.h"
46 #endif
47 
48 #ifndef _encodingtype_h
49 #include "EncodingType.h"
50 #endif
51 
52 class DAPCache3;
53 
54 namespace libdap
55 {
56 
63 {
64 public:
65  friend class ResponseBuilderTest;
66 
67 protected:
68  string d_dataset;
69  string d_ce;
70  string d_btp_func_ce;
71  int d_timeout;
73 
75 
76 #if 0 // Keyword support moved to Keywords class
77  set<string> d_keywords;
78  set<string> d_known_keywords;
79 #endif
80  void initialize();
81 
82 public:
83 
88  initialize();
89  }
90 
91  virtual ~ResponseBuilder();
92 #if 0
93  virtual void add_keyword(const string &kw);
94  virtual bool is_keyword(const string &kw) const;
95  virtual list<string> get_keywords() const;
96  // This method holds all of the keywords that this version of libdap groks
97  virtual bool is_known_keyword(const string &w) const;
98 #endif
99 
100  virtual string get_ce() const;
101  virtual void set_ce(string _ce);
102 
103  virtual string get_btp_func_ce() const { return d_btp_func_ce; }
104  virtual void set_btp_func_ce(string _ce) { d_btp_func_ce = _ce; }
105 
106  virtual string get_dataset_name() const;
107  virtual void set_dataset_name(const string _dataset);
108 
109  void set_timeout(int timeout = 0);
110  int get_timeout() const;
111 
112  virtual void establish_timeout(ostream &stream) const;
113 
114  virtual void split_ce(ConstraintEvaluator &eval, const string &expr = "");
115  virtual bool is_valid(const string &cache_file_name);
116 
117  virtual void send_das(ostream &out, DAS &das, bool with_mime_headers = true);
118  virtual void send_das(ostream &out, DDS &dds, ConstraintEvaluator &eval,
119  bool constrained = false, bool with_mime_headers = true);
120 
121  virtual void send_dds(ostream &out, DDS &dds, ConstraintEvaluator &eval,
122  bool constrained = false, bool with_mime_headers = true);
123 
124  virtual void dataset_constraint(ostream &out, DDS &dds, ConstraintEvaluator &eval,
125  bool ce_eval = true) const;
126  virtual void dataset_constraint_ddx(ostream &out, DDS & dds, ConstraintEvaluator & eval,
127  const string &boundary, const string &start,
128  bool ce_eval = true) const;
129 
130  virtual void send_data(ostream &data_stream, DDS &dds, ConstraintEvaluator &eval, bool with_mime_headers = true);
131 
132  virtual void send_ddx(ostream &out, DDS &dds, ConstraintEvaluator &eval,
133  bool with_mime_headers = true);
134 
135  virtual void send_data_ddx(ostream &data_stream, DDS &dds, ConstraintEvaluator &eval,
136  const string &start, const string &boundary,
137  bool with_mime_headers = true);
138 
139  virtual void cache_data_ddx(const string &cache_file_name, DDS &dds);
140  virtual void read_data_from_cache(FILE *data, DDS *fdds);
141  virtual DDS *get_cached_data_ddx(const string &cache_file_name, BaseTypeFactory *factory);
142 
143  // This method is uses the above three and is used by send_das(), send_dds(), and send_data().
144  virtual DDS *read_cached_dataset(DDS &dds, ConstraintEvaluator & eval, string &cache_token);
145 
146  // These functions are used both by the methods above and by other code
147 
148  void set_mime_text(ostream &out, ObjectType type = unknown_type,
149  EncodingType enc = x_plain,
150  const time_t last_modified = 0,
151  const string &protocol = "") const;
152 
153  void set_mime_html(ostream &out, ObjectType type = unknown_type,
154  EncodingType enc = x_plain,
155  const time_t last_modified = 0,
156  const string &protocol = "") const;
157 
158  void set_mime_binary(ostream &out, ObjectType type = unknown_type,
159  EncodingType enc = x_plain,
160  const time_t last_modified = 0,
161  const string &protocol = "") const;
162 
163  void set_mime_multipart(ostream &out, const string &boundary,
164  const string &start, ObjectType type = unknown_type,
165  EncodingType enc = x_plain,
166  const time_t last_modified = 0,
167  const string &protocol = "") const;
168 
169  void set_mime_ddx_boundary(ostream &out, const string &boundary,
170  const string &start, ObjectType type = unknown_type,
171  EncodingType enc = x_plain) const;
172 
173  void set_mime_data_boundary(ostream &out, const string &boundary,
174  const string &cid, ObjectType type = unknown_type,
175  EncodingType enc = x_plain) const;
176 
177  void set_mime_error(ostream &out, int code = 404,
178  const string &reason = "Dataset not found",
179  const string &protocol = "") const;
180 };
181 
182 } // namespace libdap
183 
184 #endif // _response_builder_h
void set_mime_html(ostream &out, ObjectType type=unknown_type, EncodingType enc=x_plain, const time_t last_modified=0, const string &protocol="") const
int d_timeout
The BTP functions, extracted from the CE.
Build responses for Hyrax server modules/handlers.
virtual void set_btp_func_ce(string _ce)
void set_mime_text(ostream &out, ObjectType type=unknown_type, EncodingType enc=x_plain, const time_t last_modified=0, const string &protocol="") const
virtual void set_dataset_name(const string _dataset)
Implementation of a caching mechanism for compressed data. This cache uses simple advisory locking fo...
Definition: DAPCache3.h:80
virtual void set_ce(string _ce)
string d_default_protocol
Response timeout after N seconds.
virtual void send_data(ostream &data_stream, DDS &dds, ConstraintEvaluator &eval, bool with_mime_headers=true)
Transmit data.
virtual bool is_valid(const string &cache_file_name)
ObjectType
The type of object in the stream coming from the data server.
Definition: ObjectType.h:57
virtual void send_das(ostream &out, DAS &das, bool with_mime_headers=true)
Transmit a DAS.
virtual void send_ddx(ostream &out, DDS &dds, ConstraintEvaluator &eval, bool with_mime_headers=true)
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 establish_timeout(ostream &stream) const
string d_ce
Name of the dataset/database.
string d_btp_func_ce
Constraint expression.
void set_mime_data_boundary(ostream &out, const string &boundary, const string &cid, ObjectType type=unknown_type, EncodingType enc=x_plain) const
void set_mime_ddx_boundary(ostream &out, const string &boundary, const string &start, ObjectType type=unknown_type, EncodingType enc=x_plain) const
virtual DDS * read_cached_dataset(DDS &dds, ConstraintEvaluator &eval, string &cache_token)
DAPCache3 * d_cache
Version string for the library's default protocol version.
virtual string get_dataset_name() const
Get the dataset name.
virtual string get_btp_func_ce() const
virtual void split_ce(ConstraintEvaluator &eval, const string &expr="")
friend class ResponseBuilderTest
virtual DDS * get_cached_data_ddx(const string &cache_file_name, BaseTypeFactory *factory)
Evaluate a constraint expression.
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
void set_timeout(int timeout=0)
bool is_keyword(string id, const string &keyword)
Definition: parser-util.cc:175
virtual void dataset_constraint_ddx(ostream &out, DDS &dds, ConstraintEvaluator &eval, const string &boundary, const string &start, bool ce_eval=true) const
Hold attribute data for a DAP2 dataset.
Definition: DAS.h:121
EncodingType
The type of encoding used on the current stream.
Definition: EncodingType.h:48
virtual void read_data_from_cache(FILE *data, DDS *fdds)
virtual void cache_data_ddx(const string &cache_file_name, DDS &dds)
Cache data.
virtual void dataset_constraint(ostream &out, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true) const
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_error(ostream &out, int code=404, const string &reason="Dataset not found", const string &protocol="") const
virtual string get_ce() const
Get the constraint expression.
virtual void send_dds(ostream &out, DDS &dds, ConstraintEvaluator &eval, bool constrained=false, bool with_mime_headers=true)
Transmit a DDS.