bes  Updated for version 3.17.0
BESDapModule.cc
1 // BESDapModule.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>
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 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 
32 #include <iostream>
33 
34 using std::endl;
35 
36 #include "BESDapModule.h"
37 
38 #include "BESDapRequestHandler.h"
39 #include "BESRequestHandlerList.h"
40 
41 #include "BESDapNames.h"
42 #include "BESNames.h"
43 #include "BESResponseHandlerList.h"
44 
45 #include "BESDASResponseHandler.h"
46 #include "BESDDSResponseHandler.h"
47 #include "BESDataResponseHandler.h"
48 #include "BESDDXResponseHandler.h"
49 #include "BESDataDDXResponseHandler.h"
50 #include "BESDMRResponseHandler.h"
51 #include "BESDap4ResponseHandler.h"
52 
53 #include "BESCatalogResponseHandler.h"
54 
55 #include "BESServiceRegistry.h"
56 
57 // These I added to test the Null AggregationServer code jhrg 1/30/15
58 #include "BESDapNullAggregationServer.h"
59 // Removed jhrg 3/17/15 #include "BESDapSequenceAggregationServer.h"
60 #include "BESAggFactory.h"
61 
62 #include "BESDapTransmit.h"
63 #include "BESTransmitter.h"
64 #include "BESReturnManager.h"
65 #include "BESTransmitterNames.h"
66 
67 #include "BESDebug.h"
68 #include "BESInternalFatalError.h"
69 #include "BESExceptionManager.h"
70 #include "BESDapError.h"
71 
72 void BESDapModule::initialize(const string &modname)
73 {
74  BESDEBUG("dap", "Initializing DAP Modules:" << endl);
75 
76  BESDEBUG("dap", " adding " << modname << " request handler" << endl);
77  BESRequestHandlerList::TheList()->add_handler(modname, new BESDapRequestHandler(modname));
78 
79  BESDEBUG("dap", " adding " << DAS_RESPONSE << " response handler" << endl);
80  BESResponseHandlerList::TheList()->add_handler(DAS_RESPONSE, BESDASResponseHandler::DASResponseBuilder);
81 
82  BESDEBUG( "dap", " adding " << DDS_RESPONSE << " response handler" << endl );
83  BESResponseHandlerList::TheList()->add_handler( DDS_RESPONSE, BESDDSResponseHandler::DDSResponseBuilder );
84 
85  BESDEBUG("dap", " adding " << DDX_RESPONSE << " response handler" << endl);
86  BESResponseHandlerList::TheList()->add_handler(DDX_RESPONSE, BESDDXResponseHandler::DDXResponseBuilder);
87 
88  BESDEBUG("dap", " adding " << DATA_RESPONSE << " response handler" << endl);
89  BESResponseHandlerList::TheList()->add_handler(DATA_RESPONSE, BESDataResponseHandler::DataResponseBuilder);
90 
91  BESDEBUG("dap", " adding " << DATADDX_RESPONSE << " response handler" << endl);
92  BESResponseHandlerList::TheList()->add_handler(DATADDX_RESPONSE, BESDataDDXResponseHandler::DataDDXResponseBuilder);
93 
94  BESDEBUG("dap", " adding " << DMR_RESPONSE << " response handler" << endl);
95  BESResponseHandlerList::TheList()->add_handler(DMR_RESPONSE, BESDMRResponseHandler::DMRResponseBuilder);
96 
97  BESDEBUG("dap", " adding " << DAP4DATA_RESPONSE << " response handler" << endl);
98  BESResponseHandlerList::TheList()->add_handler(DAP4DATA_RESPONSE, BESDap4ResponseHandler::Dap4ResponseBuilder);
99 
100  BESDEBUG("dap", " adding " << CATALOG_RESPONSE << " response handler" << endl);
101  BESResponseHandlerList::TheList()->add_handler(CATALOG_RESPONSE, BESCatalogResponseHandler::CatalogResponseBuilder);
102 
103  BESDEBUG("dap", "Adding " << OPENDAP_SERVICE << " services:" << endl);
104  BESServiceRegistry *registry = BESServiceRegistry::TheRegistry();
105  registry->add_service(OPENDAP_SERVICE);
106  registry->add_to_service(OPENDAP_SERVICE, DAS_SERVICE, DAS_DESCRIPT, DAP2_FORMAT);
107  registry->add_to_service(OPENDAP_SERVICE, DDS_SERVICE, DDS_DESCRIPT, DAP2_FORMAT);
108  registry->add_to_service(OPENDAP_SERVICE, DDX_SERVICE, DDX_DESCRIPT, DAP2_FORMAT);
109  registry->add_to_service(OPENDAP_SERVICE, DATA_SERVICE, DATA_DESCRIPT, DAP2_FORMAT);
110  registry->add_to_service(OPENDAP_SERVICE, DATADDX_SERVICE, DATADDX_DESCRIPT, DAP2_FORMAT);
111 
112  registry->add_to_service(OPENDAP_SERVICE, DMR_SERVICE, DMR_DESCRIPT, DAP2_FORMAT);
113  registry->add_to_service(OPENDAP_SERVICE, DAP4DATA_SERVICE, DAP4DATA_DESCRIPT, DAP2_FORMAT);
114 
115  BESDEBUG("dap", "Initializing DAP Basic Transmitters:" << endl);
116  BESReturnManager::TheManager()->add_transmitter(DAP2_FORMAT, new BESDapTransmit());
117  // TODO ?? BESReturnManager::TheManager()->add_transmitter( DAP4_FORMAT, new BESDapTransmit( ) );
118 
119  BESDEBUG("dap", " adding dap exception handler" << endl);
120  BESExceptionManager::TheEHM()->add_ehm_callback(BESDapError::handleException);
121 
122  // Add the new 'Null' AggregationServer. jhrg 1/30/15
123  // TODO Add these names to BESDapNames.h
124  BESDEBUG("dap", " adding null aggregation handler" << endl);
125  BESAggFactory::TheFactory()->add_handler("null.aggregation", BESDapNullAggregationServer::NewBESDapNullAggregationServer);
126 #if 0
127  // Removed jhrg 3/17/15
128  BESAggFactory::TheFactory()->add_handler("sequence.aggregation", BESDapSequenceAggregationServer::NewBESDapSequenceAggregationServer);
129 #endif
130 
131  BESDEBUG("dap", " adding dap debug context" << endl);
132  BESDebug::Register("dap");
133 
134  BESDEBUG("dap", "Done Initializing DAP Modules:" << endl);
135 }
136 
137 void BESDapModule::terminate(const string &modname)
138 {
139  BESDEBUG("dap", "Removing DAP Modules:" << endl);
140 
141  BESResponseHandlerList::TheList()->remove_handler(DAS_RESPONSE);
142  BESResponseHandlerList::TheList()->remove_handler(DDS_RESPONSE);
143  BESResponseHandlerList::TheList()->remove_handler(DDX_RESPONSE);
144  BESResponseHandlerList::TheList()->remove_handler(DATA_RESPONSE);
145  BESResponseHandlerList::TheList()->remove_handler(DATADDX_RESPONSE);
146  BESResponseHandlerList::TheList()->remove_handler(CATALOG_RESPONSE);
147 
148  BESResponseHandlerList::TheList()->remove_handler(DMR_RESPONSE);
149  BESResponseHandlerList::TheList()->remove_handler(DAP4DATA_RESPONSE);
150 
151  BESResponseHandlerList::TheList()->remove_handler(CATALOG_RESPONSE);
152 
153  BESDEBUG("dap", " removing " << OPENDAP_SERVICE << " services" << endl);
154  BESServiceRegistry::TheRegistry()->remove_service(OPENDAP_SERVICE);
155 
156  BESDEBUG("dap", " removing dap Request Handler " << modname << endl);
157  BESRequestHandler *rh = BESRequestHandlerList::TheList()->remove_handler(modname);
158  if (rh) delete rh;
159 
160  BESReturnManager::TheManager()->del_transmitter(DAP2_FORMAT);
161  // TODO ?? BESReturnManager::TheManager()->del_transmitter( DAP4_FORMAT );
162 
163  BESAggFactory::TheFactory()->remove_handler("null.aggregation");
164 
165  BESDEBUG("dap", "Done Removing DAP Modules:" << endl);
166 }
167 
174 void BESDapModule::dump(ostream &strm) const
175 {
176  strm << BESIndent::LMarg << "BESDapModule::dump - (" << (void *) this << ")" << endl;
177 }
178 
179 extern "C" {
180 BESAbstractModule *maker()
181 {
182  return new BESDapModule;
183 }
184 }
185 
static BESAggregationServer * NewBESDapNullAggregationServer(const string &name)
virtual bool add_handler(const string &handler_name, BESRequestHandler *handler)
add a request handler to the list of registered handlers for this server
virtual void add_service(const string &name)
Add a service to the BES.
The service registry allows modules to register services with the BES that they provide.
virtual void add_to_service(const string &service, const string &cmd, const string &cmd_descript, const string &format)
This function allows callers to add to a service that already exists.
virtual void add_ehm_callback(p_bes_ehm ehm)
Register an exception handler with the manager.
virtual void remove_service(const string &name)
remove a service from the BES
virtual bool remove_handler(const string &handler_name)
removes a response handler from the list
virtual bool add_handler(const string &handler, p_response_handler handler_method)
add a response handler to the list
Represents a specific data type request handler.
virtual bool remove_handler(const string &handler)
removes a response handler from the list
static int handleException(BESError &e, BESDataHandlerInterface &dhi)
handles exceptions if the error context is set to dap2
Definition: BESDapError.cc:109
virtual void dump(ostream &strm) const
dumps information about this object
virtual bool add_handler(const string &handler_name, p_agg_handler handler_method)
add an aggregation handler to the list
static void Register(const string &flagName)
register the specified debug flag
Definition: BESDebug.h:145
virtual BESRequestHandler * remove_handler(const string &handler_name)
remove and return the specified request handler