bes  Updated for version 3.20.6
BESUsageModule.cc
1 // BESUsageModule.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,2005 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 using std::ostream;
36 using std::string;
37 
38 #include "BESUsageModule.h"
39 
40 #include "BESUsageNames.h"
41 #include "BESDapNames.h"
42 #include "BESResponseNames.h"
43 #include "BESResponseHandlerList.h"
44 
45 #include "BESUsageRequestHandler.h"
46 #include "BESRequestHandlerList.h"
47 
48 #include "BESUsageResponseHandler.h"
49 
50 #include "BESDapService.h"
51 
52 #include "BESUsageTransmit.h"
53 #include "BESTransmitter.h"
54 #include "BESReturnManager.h"
55 #include "BESTransmitterNames.h"
56 
57 #include "BESDebug.h"
58 
59 
60 void
61 BESUsageModule::initialize( const string &modname )
62 {
63  BESDEBUG( "usage", "Initializing OPeNDAP Usage module "
64  << modname << endl ) ;
65 
66  BESDEBUG( "usage", " adding " << modname <<
67  " request handler" << endl ) ;
68  BESRequestHandler *handler = new BESUsageRequestHandler( modname ) ;
69  BESRequestHandlerList::TheList()->add_handler( modname, handler ) ;
70 
71  BESDEBUG( "usage", " adding " << Usage_RESPONSE
72  << " response handler" << endl ) ;
73  BESResponseHandlerList::TheList()->add_handler( Usage_RESPONSE, BESUsageResponseHandler::UsageResponseBuilder ) ;
74 
75  BESDEBUG( "usage", "Adding to dap services" << endl ) ;
76  BESDapService::add_to_dap_service( Usage_SERVICE,
77  "OPeNDAP Data Information Page" ) ;
78 
79  BESTransmitter *t = BESReturnManager::TheManager()->find_transmitter( DAP2_FORMAT ) ;
80  if( t )
81  {
82  BESDEBUG( "usage", " adding basic " << Usage_TRANSMITTER
83  << " transmitter" << endl ) ;
84  t->add_method( Usage_TRANSMITTER, BESUsageTransmit::send_basic_usage ) ;
85  }
86 
87  BESDEBUG( "usage", " adding usage debug context" << endl ) ;
88  BESDebug::Register( "usage" ) ;
89 
90  BESDEBUG( "usage", "Done Initializing OPeNDAP Usage module"
91  << modname << endl ) ;
92 }
93 
94 void
95 BESUsageModule::terminate( const string &modname )
96 {
97  BESDEBUG( "usage", "Cleaning OPeNDAP usage module " << modname << endl ) ;
98 
99  BESDEBUG( "usage", " removing " << modname << " request handler "
100  << endl ) ;
101  BESRequestHandler *rh =
102  BESRequestHandlerList::TheList()->remove_handler( modname ) ;
103  if( rh ) delete rh ;
104 
105  BESDEBUG( "usage", " removing " << Usage_RESPONSE
106  << " response handler " << endl ) ;
107  BESResponseHandlerList::TheList()->remove_handler( Usage_RESPONSE ) ;
108 
109  BESTransmitter *t =
110  BESReturnManager::TheManager()->find_transmitter( DAP2_FORMAT ) ;
111  if( t )
112  {
113  BESDEBUG( "usage", " removing basic " << Usage_TRANSMITTER
114  << " transmitter" << endl ) ;
115  t->remove_method( Usage_TRANSMITTER ) ;
116  }
117 
118  t = BESReturnManager::TheManager()->find_transmitter( DAP2_FORMAT ) ;
119  if( t )
120  {
121  BESDEBUG( "usage", " removing http " << Usage_TRANSMITTER
122  << " transmitter" << endl ) ;
123  t->remove_method( Usage_TRANSMITTER ) ;
124  }
125 
126  BESDEBUG( "usage", "Done Cleaning OPeNDAP usage module "
127  << modname << endl ) ;
128 }
129 
136 void
137 BESUsageModule::dump( ostream &strm ) const
138 {
139  strm << BESIndent::LMarg << "BESUsageModule::dump - ("
140  << (void *)this << ")" << endl ;
141 }
142 
143 extern "C"
144 {
145  BESAbstractModule *maker()
146  {
147  return new BESUsageModule ;
148  }
149 }
150 
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
BESAbstractModule
Definition: BESAbstractModule.h:40
BESDapService::add_to_dap_service
static void add_to_dap_service(const std::string &cmd, const std::string &desc)
static function to add commands to the dap service
Definition: BESDapService.cc:47
BESResponseHandlerList::remove_handler
virtual bool remove_handler(const std::string &handler)
removes a response handler from the list
Definition: BESResponseHandlerList.cc:74
BESUsageModule
Definition: BESUsageModule.h:37
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
BESTransmitter
Definition: BESTransmitter.h:47
BESUsageRequestHandler
Definition: BESUsageRequestHandler.h:39
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
BESUsageModule::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESUsageModule.cc:137