bes  Updated for version 3.20.8
DapFunctions.cc
1 // DapFunctions.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) 2013 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 #include "config.h"
26 
27 #include <iostream>
28 
29 #include <gdal.h> // needed for scale_{grid,array}
30 
31 #include <ServerFunctionsList.h>
32 
33 #include <BESRequestHandlerList.h>
34 #include <TheBESKeys.h>
35 #include <BESDebug.h>
36 
37 #include "GeoGridFunction.h"
38 #include "GridFunction.h"
39 #include "LinearScaleFunction.h"
40 #include "VersionFunction.h"
41 #include "MakeArrayFunction.h"
42 #include "MakeMaskFunction.h"
43 #include "BindNameFunction.h"
44 #include "BindShapeFunction.h"
45 #include "TabularFunction.h"
46 #include "BBoxFunction.h"
47 #include "RoiFunction.h"
48 #include "BBoxUnionFunction.h"
49 #include "MaskArrayFunction.h"
50 #include "DilateArrayFunction.h"
51 #include "RangeFunction.h"
52 #include "BBoxCombFunction.h"
53 #include "ScaleGrid.h"
54 #include "TestFunction.h"
55 
56 #if HAVE_STARE
57 #include "stare/StareFunctions.h"
58 #endif
59 
60 #include "DapFunctionsRequestHandler.h"
61 #include "DapFunctions.h"
62 
63 using std::endl;
64 using std::ostream;
65 using std::string;
66 
67 namespace functions {
68 
69 void DapFunctions::initialize(const string &modname)
70 {
71  BESDEBUG( "dap_functions", "Initializing DAP Functions:" << endl );
72 
73  // Add this module to the Request Handler List so that it can respond
74  // to version and help requests. Note the matching code to remove the
75  // handler from the list in the terminate() method.
76  BESRequestHandlerList::TheList()->add_handler(modname, new DapFunctionsRequestHandler(modname));
77 
78  libdap::ServerFunctionsList::TheList()->add_function(new GridFunction());
79  libdap::ServerFunctionsList::TheList()->add_function(new GeoGridFunction());
80  libdap::ServerFunctionsList::TheList()->add_function(new LinearScaleFunction());
81 
82  libdap::ServerFunctionsList::TheList()->add_function(new MakeArrayFunction());
83  libdap::ServerFunctionsList::TheList()->add_function(new MakeMaskFunction());
84  libdap::ServerFunctionsList::TheList()->add_function(new BindNameFunction());
85  libdap::ServerFunctionsList::TheList()->add_function(new BindShapeFunction());
86 
87  libdap::ServerFunctionsList::TheList()->add_function(new VersionFunction());
88 
89  libdap::ServerFunctionsList::TheList()->add_function(new TabularFunction());
90  libdap::ServerFunctionsList::TheList()->add_function(new BBoxFunction());
91  libdap::ServerFunctionsList::TheList()->add_function(new RoiFunction());
92  libdap::ServerFunctionsList::TheList()->add_function(new BBoxUnionFunction());
93  libdap::ServerFunctionsList::TheList()->add_function(new BBoxCombFunction());
94 
95  libdap::ServerFunctionsList::TheList()->add_function(new MaskArrayFunction());
96  libdap::ServerFunctionsList::TheList()->add_function(new DilateArrayFunction());
97 
98  libdap::ServerFunctionsList::TheList()->add_function(new RangeFunction());
99 
100  libdap::ServerFunctionsList::TheList()->add_function(new ScaleArray());
101  libdap::ServerFunctionsList::TheList()->add_function(new ScaleGrid());
102  libdap::ServerFunctionsList::TheList()->add_function(new Scale3DArray());
103 
104  libdap::ServerFunctionsList::TheList()->add_function(new TestFunction());
105 
106 #if HAVE_STARE
107  libdap::ServerFunctionsList::TheList()->add_function(new StareIntersectionFunction());
108  libdap::ServerFunctionsList::TheList()->add_function(new StareCountFunction());
109  libdap::ServerFunctionsList::TheList()->add_function(new StareSubsetFunction());
110  libdap::ServerFunctionsList::TheList()->add_function(new StareSubsetArrayFunction());
111 
112  // The key names and module variables used here are defined in StareFunctions.cc
113  // jhrg 5/21/20
114  stare_storage_path = TheBESKeys::TheKeys()->read_string_key(STARE_STORAGE_PATH_KEY, stare_storage_path);
115  stare_sidecar_suffix = TheBESKeys::TheKeys()->read_string_key(STARE_SIDECAR_SUFFIX_KEY, stare_sidecar_suffix);
116 #endif
117 
118  GDALAllRegister();
119  OGRRegisterAll();
120 
121  // What to do with the orig error handler? Pitch it. jhrg 10/17/16
122  /*CPLErrorHandler orig_err_handler =*/ (void) CPLSetErrorHandler(CPLQuietErrorHandler);
123 
124  BESDEBUG( "dap_functions", "Done initializing DAP Functions" << endl );
125 }
126 
127 void DapFunctions::terminate(const string &modname)
128 {
129  BESDEBUG( "dap_functions", "Removing DAP Functions." << endl );
130 
131  BESRequestHandler *rh = BESRequestHandlerList::TheList()->remove_handler(modname);
132  delete rh;
133 }
134 
141 void DapFunctions::dump(ostream &strm) const
142 {
143  strm << BESIndent::LMarg << "DapFunctions::dump - (" << (void *) this << ")" << endl;
144 }
145 
146 extern "C" {
147 BESAbstractModule *maker()
148 {
149  return new DapFunctions;
150 }
151 }
152 
153 } // namespace functions
virtual bool add_handler(const std::string &handler_name, BESRequestHandler *handler)
add a request handler to the list of registered handlers for this server
virtual BESRequestHandler * remove_handler(const std::string &handler_name)
remove and return the specified request handler
Represents a specific data type request handler.
A Request Handler for the DAP Functions module.
static TheBESKeys * TheKeys()
Definition: TheBESKeys.cc:71
std::string read_string_key(const std::string &key, const std::string &default_value)
Read a string-valued key from the bes.conf file.
Definition: TheBESKeys.cc:422
virtual void dump(std::ostream &strm) const
dumps information about this object