bes  Updated for version 3.20.10
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 <libdap/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 #include "IdentityFunction.h"
56 
57 #if HAVE_STARE
58 #include "stare/StareFunctions.h"
59 #endif
60 
61 #include "DapFunctionsRequestHandler.h"
62 #include "DapFunctions.h"
63 
64 using std::endl;
65 using std::ostream;
66 using std::string;
67 
68 namespace functions {
69 
70 void DapFunctions::initialize(const string &modname)
71 {
72  BESDEBUG( "dap_functions", "Initializing DAP Functions:" << endl );
73 
74  // Add this module to the Request Handler List so that it can respond
75  // to version and help requests. Note the matching code to remove the
76  // handler from the list in the terminate() method.
77  BESRequestHandlerList::TheList()->add_handler(modname, new DapFunctionsRequestHandler(modname));
78 
79  libdap::ServerFunctionsList::TheList()->add_function(new GridFunction());
80  libdap::ServerFunctionsList::TheList()->add_function(new GeoGridFunction());
81  libdap::ServerFunctionsList::TheList()->add_function(new LinearScaleFunction());
82 
83  libdap::ServerFunctionsList::TheList()->add_function(new MakeArrayFunction());
84  libdap::ServerFunctionsList::TheList()->add_function(new MakeMaskFunction());
85  libdap::ServerFunctionsList::TheList()->add_function(new BindNameFunction());
86  libdap::ServerFunctionsList::TheList()->add_function(new BindShapeFunction());
87 
88  libdap::ServerFunctionsList::TheList()->add_function(new VersionFunction());
89 
90  libdap::ServerFunctionsList::TheList()->add_function(new TabularFunction());
91  libdap::ServerFunctionsList::TheList()->add_function(new BBoxFunction());
92  libdap::ServerFunctionsList::TheList()->add_function(new RoiFunction());
93  libdap::ServerFunctionsList::TheList()->add_function(new BBoxUnionFunction());
94  libdap::ServerFunctionsList::TheList()->add_function(new BBoxCombFunction());
95 
96  libdap::ServerFunctionsList::TheList()->add_function(new MaskArrayFunction());
97  libdap::ServerFunctionsList::TheList()->add_function(new DilateArrayFunction());
98 
99  libdap::ServerFunctionsList::TheList()->add_function(new RangeFunction());
100 
101  libdap::ServerFunctionsList::TheList()->add_function(new ScaleArray());
102  libdap::ServerFunctionsList::TheList()->add_function(new ScaleGrid());
103  libdap::ServerFunctionsList::TheList()->add_function(new Scale3DArray());
104 
105  libdap::ServerFunctionsList::TheList()->add_function(new TestFunction());
106 
107  libdap::ServerFunctionsList::TheList()->add_function(new IdentityFunction());
108 
109 #if HAVE_STARE
110  libdap::ServerFunctionsList::TheList()->add_function(new StareIntersectionFunction());
111  libdap::ServerFunctionsList::TheList()->add_function(new StareCountFunction());
112  libdap::ServerFunctionsList::TheList()->add_function(new StareSubsetFunction());
113  libdap::ServerFunctionsList::TheList()->add_function(new StareSubsetArrayFunction());
114  libdap::ServerFunctionsList::TheList()->add_function(new StareBoxFunction());
115 
116  // The key names and module variables used here are defined in StareFunctions.cc
117  // jhrg 5/21/20
118  stare_storage_path = TheBESKeys::TheKeys()->read_string_key(STARE_STORAGE_PATH_KEY, stare_storage_path);
119  stare_sidecar_suffix = TheBESKeys::TheKeys()->read_string_key(STARE_SIDECAR_SUFFIX_KEY, stare_sidecar_suffix);
120 #endif
121 
122  GDALAllRegister();
123  OGRRegisterAll();
124 
125  // What to do with the orig error handler? Pitch it. jhrg 10/17/16
126  /*CPLErrorHandler orig_err_handler =*/ (void) CPLSetErrorHandler(CPLQuietErrorHandler);
127 
128  BESDEBUG( "dap_functions", "Done initializing DAP Functions" << endl );
129 }
130 
131 void DapFunctions::terminate(const string &modname)
132 {
133  BESDEBUG( "dap_functions", "Removing DAP Functions." << endl );
134 
135  BESRequestHandler *rh = BESRequestHandlerList::TheList()->remove_handler(modname);
136  delete rh;
137 }
138 
145 void DapFunctions::dump(ostream &strm) const
146 {
147  strm << BESIndent::LMarg << "DapFunctions::dump - (" << (void *) this << ")" << endl;
148 }
149 
150 extern "C" {
151 BESAbstractModule *maker()
152 {
153  return new DapFunctions;
154 }
155 }
156 
157 } // 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:423
virtual void dump(std::ostream &strm) const
dumps information about this object