bes  Updated for version 3.20.6
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 #include <string>
32 
33 #include <BESRequestHandlerList.h>
34 #include <BESDebug.h>
35 #include <BESResponseHandlerList.h>
36 #include <BESResponseNames.h>
37 #include <BESContainerStorageList.h>
38 #include <TheBESKeys.h>
39 #include <BESSyntaxUserError.h>
40 
41 #include "GatewayModule.h"
42 #include "GatewayRequestHandler.h"
43 #include "GatewayResponseNames.h"
44 #include "GatewayContainerStorage.h"
45 #include "GatewayUtils.h"
46 #include "GatewayPathInfoResponseHandler.h"
47 #include "GatewayPathInfoCommand.h"
48 
49 using namespace std;
50 using namespace gateway;
51 
52 void GatewayModule::initialize(const string &modname)
53 {
54  BESDEBUG(modname, "Initializing Gateway Module " << modname << endl);
55 
56  BESDEBUG(modname, " adding " << modname << " request handler" << endl);
57  BESRequestHandlerList::TheList()->add_handler(modname, new GatewayRequestHandler(modname));
58 
59  BESDEBUG(modname, " adding " << modname << " container storage" << endl);
60  BESContainerStorageList::TheList()->add_persistence(new GatewayContainerStorage(modname));
61 
62  BESDEBUG(modname, " initialize the gateway utilities and params" << endl);
63  GatewayUtils::Initialize();
64 
65  BESDEBUG(modname, " adding Gateway debug context" << endl);
66  BESDebug::Register(modname);
67 
68  BESDEBUG( modname, " adding " << SHOW_GATEWAY_PATH_INFO_RESPONSE_STR << " command" << endl ) ;
69  BESXMLCommand::add_command( SHOW_GATEWAY_PATH_INFO_RESPONSE_STR, GatewayPathInfoCommand::CommandBuilder ) ;
70 
71  BESDEBUG(modname, " adding " << SHOW_GATEWAY_PATH_INFO_RESPONSE << " response handler" << endl ) ;
72  BESResponseHandlerList::TheList()->add_handler( SHOW_GATEWAY_PATH_INFO_RESPONSE, GatewayPathInfoResponseHandler::GatewayPathInfoResponseBuilder ) ;
73 
74  BESDEBUG(modname, "Done Initializing Gateway Module " << modname << endl);
75 }
76 
77 void GatewayModule::terminate(const string &modname)
78 {
79  BESDEBUG(modname, "Cleaning Gateway module " << modname << endl);
80 
81  BESResponseHandlerList::TheList()->remove_handler( SHOW_GATEWAY_PATH_INFO_RESPONSE) ;
82  BESXMLCommand::del_command( SHOW_GATEWAY_PATH_INFO_RESPONSE_STR) ;
83 
84 
85  BESDEBUG(modname, " removing " << modname << " request handler" << endl);
86  BESRequestHandler *rh = BESRequestHandlerList::TheList()->remove_handler(modname);
87  if (rh)
88  delete rh;
89 
90  BESContainerStorageList::TheList()->deref_persistence(modname);
91 
92  // TERM_END
93  BESDEBUG(modname, "Done Cleaning Gateway module " << modname << endl);
94 }
95 
96 void GatewayModule::dump(ostream &strm) const
97 {
98  strm << BESIndent::LMarg << "GatewayModule::dump - (" << (void *) this << ")" << endl;
99 }
100 
101 extern "C"
102 BESAbstractModule *maker()
103 {
104  return new GatewayModule;
105 }
106 
BESRequestHandler
Represents a specific data type request handler.
Definition: BESRequestHandler.h:74
BESRequestHandlerList::remove_handler
virtual BESRequestHandler * remove_handler(const std::string &handler_name)
remove and return the specified request handler
Definition: BESRequestHandlerList.cc:76
BESContainerStorageList::deref_persistence
virtual bool deref_persistence(const std::string &persist_name)
dereference a persistent store in the list.
Definition: BESContainerStorageList.cc:163
BESAbstractModule
Definition: BESAbstractModule.h:40
gateway::GatewayRequestHandler
Definition: GatewayRequestHandler.h:37
gateway::GatewayModule
Definition: GatewayModule.h:37
gateway::GatewayContainerStorage
implementation of BESContainerStorageVolatile that represents a list of remote requests
Definition: GatewayContainerStorage.h:49
BESContainerStorageList::add_persistence
virtual bool add_persistence(BESContainerStorage *p)
Add a persistent store to the list.
Definition: BESContainerStorageList.cc:81
BESXMLCommand::add_command
static void add_command(const std::string &cmd_str, p_xmlcmd_builder cmd)
Add a command to the possible commands allowed by this BES.
Definition: BESXMLCommand.cc:86
BESResponseHandlerList::remove_handler
virtual bool remove_handler(const std::string &handler)
removes a response handler from the list
Definition: BESResponseHandlerList.cc:74
BESRequestHandlerList::add_handler
virtual bool add_handler(const std::string &handler_name, BESRequestHandler *handler)
add a request handler to the list of registered handlers for this server
Definition: BESRequestHandlerList.cc:54
BESDebug::Register
static void Register(const std::string &flagName)
register the specified debug flag
Definition: BESDebug.h:138
BESXMLCommand::del_command
static void del_command(const std::string &cmd_str)
Deletes the command called cmd_str from the list of possible commands.
Definition: BESXMLCommand.cc:96
BESResponseHandlerList::add_handler
virtual bool add_handler(const std::string &handler, p_response_handler handler_method)
add a response handler to the list
Definition: BESResponseHandlerList.cc:55