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