OPeNDAP Hyrax Back End Server (BES)
Updated for version 3.8.3
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
BESBasicInterface.cc
Go to the documentation of this file.
1
// BESBasicInterface.cc
2
3
// This file is part of bes, A C++ back-end server implementation framework
4
// for the OPeNDAP Data Access Protocol.
5
6
// Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7
// Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
//
23
// You can contact University Corporation for Atmospheric Research at
24
// 3080 Center Green Drive, Boulder, CO 80301
25
26
// (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27
// Please read the full copyright statement in the file COPYRIGHT_UCAR.
28
//
29
// Authors:
30
// pwest Patrick West <pwest@ucar.edu>
31
// jgarcia Jose Garcia <jgarcia@ucar.edu>
32
33
#include <iostream>
34
#include <sstream>
35
36
using
std::endl ;
37
using
std::stringstream ;
38
39
#include "
BESBasicInterface.h
"
40
#include "
BESInterface.h
"
41
#include "
BESLog.h
"
42
#include "
BESDebug.h
"
43
#include "
BESReturnManager.h
"
44
#include "
BESSyntaxUserError.h
"
45
#include "
BESInternalError.h
"
46
#include "
BESAggFactory.h
"
47
#include "
BESAggregationServer.h
"
48
#include "
BESTransmitterNames.h
"
49
#include "
BESDataNames.h
"
50
57
BESBasicInterface::BESBasicInterface
( ostream *strm )
58
:
BESInterface
( strm )
59
{
60
}
61
62
BESBasicInterface::~BESBasicInterface
()
63
{
64
}
65
74
int
75
BESBasicInterface::execute_request
(
const
string
&from )
76
{
77
return
BESInterface::execute_request
( from ) ;
78
}
79
89
void
90
BESBasicInterface::initialize
()
91
{
92
// dhi has not been filled in at this point, so let's set a default
93
// transmitter given the protocol. The transmitter might change after
94
// parsing a request and given a return manager to use. This is done in
95
// build_data_plan.
96
//
97
// The reason I moved this from the build_data_plan method is because a
98
// registered initialization routine might throw an exception and we
99
// will need to transmit the exception info, which needs a transmitter.
100
// If an exception happens before this then the exception info is just
101
// printed to cout (see BESInterface::transmit_data()). -- pcw 09/05/06
102
BESDEBUG
(
"bes"
,
"Finding "
<<
BASIC_TRANSMITTER
<<
" transmitter ... "
<< endl ) ;
103
_transmitter
=
BESReturnManager::TheManager
()->
find_transmitter
(
BASIC_TRANSMITTER
) ;
104
if
( !
_transmitter
)
105
{
106
string
s = (string)
"Unable to find transmitter "
107
+
BASIC_TRANSMITTER
;
108
throw
BESInternalError
( s, __FILE__, __LINE__ ) ;
109
}
110
BESDEBUG
(
"bes"
,
"OK"
<< endl ) ;
111
112
BESInterface::initialize
() ;
113
}
114
117
void
118
BESBasicInterface::validate_data_request
()
119
{
120
BESInterface::validate_data_request
() ;
121
}
122
127
void
128
BESBasicInterface::build_data_request_plan
()
129
{
130
// The derived class build_data_request_plan should be run first to
131
// parse the incoming request. Once parsed we can determine if there is
132
// a return command
133
134
// The default _transmitter (either basic or http depending on the
135
// protocol passed) has been set in initialize. If the parsed command
136
// sets a RETURN_CMD (a different transmitter) then look it up here. If
137
// it's set but not found then this is an error. If it's not set then
138
// just use the defaults.
139
if
(
_dhi
->
data
[
RETURN_CMD
] !=
""
)
140
{
141
BESDEBUG
(
"bes"
,
"Finding transmitter: "
<<
_dhi
->
data
[
RETURN_CMD
] <<
" ... "
<< endl ) ;
142
_transmitter
=
BESReturnManager::TheManager
()->
find_transmitter
(
_dhi
->
data
[
RETURN_CMD
] ) ;
143
if
( !
_transmitter
)
144
{
145
string
s = (string)
"Unable to find transmitter "
146
+
_dhi
->
data
[
RETURN_CMD
] ;
147
throw
BESSyntaxUserError
( s, __FILE__, __LINE__ ) ;
148
}
149
BESDEBUG
(
"bes"
,
"OK"
<< endl ) ;
150
}
151
}
152
160
void
161
BESBasicInterface::execute_data_request_plan
()
162
{
163
if
(
BESLog::TheLog
()->is_verbose() )
164
{
165
*(
BESLog::TheLog
()) <<
_dhi
->
data
[
SERVER_PID
]
166
<<
" from "
<<
_dhi
->
data
[
REQUEST_FROM
]
167
<<
" ["
<<
_dhi
->
data
[
DATA_REQUEST
] <<
"] executing"
168
<< endl ;
169
}
170
BESInterface::execute_data_request_plan
() ;
171
}
172
180
void
181
BESBasicInterface::invoke_aggregation
()
182
{
183
if
(
_dhi
->
data
[
AGG_CMD
] ==
""
)
184
{
185
if
(
BESLog::TheLog
()->is_verbose() )
186
{
187
*(
BESLog::TheLog
()) <<
_dhi
->
data
[
SERVER_PID
]
188
<<
" from "
<<
_dhi
->
data
[
REQUEST_FROM
]
189
<<
" ["
<<
_dhi
->
data
[
DATA_REQUEST
] <<
"]"
190
<<
" not aggregating, command empty"
191
<< endl ;
192
}
193
}
194
else
195
{
196
BESAggregationServer
*agg =
BESAggFactory::TheFactory
()->
find_handler
(
_dhi
->
data
[
AGG_HANDLER
] ) ;
197
if
( !agg )
198
{
199
if
(
BESLog::TheLog
()->is_verbose() )
200
{
201
*(
BESLog::TheLog
()) <<
_dhi
->
data
[
SERVER_PID
]
202
<<
" from "
<<
_dhi
->
data
[
REQUEST_FROM
]
203
<<
" ["
<<
_dhi
->
data
[
DATA_REQUEST
] <<
"]"
204
<<
" not aggregating, no handler"
205
<< endl ;
206
}
207
}
208
else
209
{
210
if
(
BESLog::TheLog
()->
is_verbose
() )
211
{
212
*(
BESLog::TheLog
()) <<
_dhi
->
data
[
SERVER_PID
]
213
<<
" from "
<<
_dhi
->
data
[
REQUEST_FROM
]
214
<<
" ["
<<
_dhi
->
data
[
DATA_REQUEST
]
215
<<
"] aggregating"
<< endl ;
216
}
217
}
218
}
219
BESInterface::invoke_aggregation
() ;
220
}
221
229
void
230
BESBasicInterface::transmit_data
()
231
{
232
if
(
BESLog::TheLog
()->is_verbose() )
233
{
234
*(
BESLog::TheLog
()) <<
_dhi
->
data
[
SERVER_PID
]
235
<<
" from "
<<
_dhi
->
data
[
REQUEST_FROM
]
236
<<
" ["
<<
_dhi
->
data
[
DATA_REQUEST
]
237
<<
"] transmitting"
<< endl ;
238
}
239
BESInterface::transmit_data
() ;
240
}
241
246
void
247
BESBasicInterface::log_status
()
248
{
249
string
result =
"completed"
;
250
if
(
_dhi
->
error_info
)
251
result =
"failed"
;
252
if
(
BESLog::TheLog
()->is_verbose() )
253
{
254
*(
BESLog::TheLog
()) <<
_dhi
->
data
[
SERVER_PID
]
255
<<
" from "
<<
_dhi
->
data
[
REQUEST_FROM
]
256
<<
" ["
<<
_dhi
->
data
[
DATA_REQUEST
] <<
"] "
257
<< result << endl ;
258
}
259
}
260
269
void
270
BESBasicInterface::clean
()
271
{
272
BESInterface::clean
() ;
273
if
(
BESLog::TheLog
()->is_verbose() )
274
{
275
*(
BESLog::TheLog
()) <<
_dhi
->
data
[
SERVER_PID
]
276
<<
" from "
<<
_dhi
->
data
[
REQUEST_FROM
]
277
<<
" ["
<<
_dhi
->
data
[
DATA_REQUEST
] <<
"] cleaning"
278
<< endl ;
279
}
280
}
281
288
void
289
BESBasicInterface::dump
( ostream &strm )
const
290
{
291
strm <<
BESIndent::LMarg
<<
"BESBasicInterface::dump - ("
292
<< (
void
*)
this
<<
")"
<< endl ;
293
BESIndent::Indent
() ;
294
BESInterface::dump
( strm ) ;
295
BESIndent::UnIndent
() ;
296
297
298
}
299
dispatch
BESBasicInterface.cc
Generated by
1.8.4