bes  Updated for version 3.20.8
GatewayModule.cc
1 // GatewayModule.cc
2 
3 // -*- mode: c++; c-basic-offset:4 -*-
4 
5 // This file is part of gateway_module, A C++ module that can be loaded in to
6 // the OPeNDAP Back-End Server (BES) and is able to handle remote requests.
7 
8 // Copyright (c) 2002,2003 OPeNDAP, Inc.
9 // Author: Patrick West <pwest@ucar.edu>
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
26 
27 #include "config.h"
28 
29 #include <iostream>
30 #include <vector>
31 
32 #include <BESRequestHandlerList.h>
33 #include <BESDebug.h>
34 #include <BESResponseHandlerList.h>
35 #include <BESContainerStorageList.h>
36 
37 #include "GatewayModule.h"
38 #include "GatewayRequestHandler.h"
39 #include "GatewayContainerStorage.h"
40 #include "GatewayPathInfoResponseHandler.h"
41 #include "GatewayPathInfoCommand.h"
42 
43 using namespace std;
44 using namespace gateway;
45 
46 void GatewayModule::initialize(const string &modname)
47 {
48  BESDEBUG(modname, "Initializing Gateway Module " << modname << endl);
49 
50  BESDEBUG(modname, " adding " << modname << " request handler" << endl);
51  BESRequestHandlerList::TheList()->add_handler(modname, new GatewayRequestHandler(modname));
52 
53  BESDEBUG(modname, " adding " << modname << " container storage" << endl);
54  BESContainerStorageList::TheList()->add_persistence(new GatewayContainerStorage(modname));
55 
56  // BESDEBUG(modname, " initialize the gateway utilities and params" << endl);
57  // THis called used to set up HTTP cache proxies, etc now that's done in http - ndp 7/6/20
58  // GatewayUtils::Initialize();
59 
60  BESDEBUG(modname, " adding Gateway debug context" << endl);
61  BESDebug::Register(modname);
62 
63  BESDEBUG( modname, " adding " << SHOW_GATEWAY_PATH_INFO_RESPONSE_STR << " command" << endl ) ;
64  BESXMLCommand::add_command( SHOW_GATEWAY_PATH_INFO_RESPONSE_STR, GatewayPathInfoCommand::CommandBuilder ) ;
65 
66  BESDEBUG(modname, " adding " << SHOW_GATEWAY_PATH_INFO_RESPONSE << " response handler" << endl ) ;
67  BESResponseHandlerList::TheList()->add_handler( SHOW_GATEWAY_PATH_INFO_RESPONSE, GatewayPathInfoResponseHandler::GatewayPathInfoResponseBuilder ) ;
68 
69  BESDEBUG(modname, "Done Initializing Gateway Module " << modname << endl);
70 }
71 
72 void GatewayModule::terminate(const string &modname)
73 {
74  BESDEBUG(modname, "Cleaning Gateway module " << modname << endl);
75 
76  BESResponseHandlerList::TheList()->remove_handler( SHOW_GATEWAY_PATH_INFO_RESPONSE) ;
77  BESXMLCommand::del_command( SHOW_GATEWAY_PATH_INFO_RESPONSE_STR) ;
78 
79 
80  BESDEBUG(modname, " removing " << modname << " request handler" << endl);
81  BESRequestHandler *rh = BESRequestHandlerList::TheList()->remove_handler(modname);
82  if (rh)
83  delete rh;
84 
85  BESContainerStorageList::TheList()->deref_persistence(modname);
86 
87  // TERM_END
88  BESDEBUG(modname, "Done Cleaning Gateway module " << modname << endl);
89 }
90 
91 void GatewayModule::dump(ostream &strm) const
92 {
93  strm << BESIndent::LMarg << "GatewayModule::dump - (" << (void *) this << ")" << endl;
94 }
95 
96 extern "C"
97 BESAbstractModule *maker()
98 {
99  return new GatewayModule;
100 }
101 
virtual bool add_persistence(BESContainerStorage *p)
Add a persistent store to the list.
virtual bool deref_persistence(const std::string &persist_name)
dereference a persistent store in the list.
static void Register(const std::string &flagName)
register the specified debug flag
Definition: BESDebug.h:141
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.
virtual bool remove_handler(const std::string &handler)
removes a response handler from the list
virtual bool add_handler(const std::string &handler, p_response_handler handler_method)
add a response handler to the list
static void del_command(const std::string &cmd_str)
Deletes the command called cmd_str from the list of possible commands.
static void add_command(const std::string &cmd_str, p_xmlcmd_builder cmd)
Add a command to the possible commands allowed by this BES.
implementation of BESContainerStorageVolatile that represents a list of remote requests