bes  Updated for version 3.17.0
SampleModule.cc
1 // SampleModule.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> and Jose Garcia <jgarcia@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 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include <iostream>
34 
35 using std::endl ;
36 
37 #include "SampleModule.h"
38 #include "BESRequestHandlerList.h"
39 #include "SampleRequestHandler.h"
40 #include "BESDebug.h"
41 #include "BESResponseHandlerList.h"
42 #include "BESResponseNames.h"
43 #include "BESXMLCommand.h"
44 #include "SampleResponseNames.h"
45 #include "SampleSayResponseHandler.h"
46 #include "SampleSayXMLCommand.h"
47 #include "BESReporterList.h"
48 #include "SayReporter.h"
49 
50 void
51 SampleModule::initialize( const string &modname )
52 {
53  BESDEBUG( modname, "Initializing Sample Module " << modname << endl ) ;
54 
55  BESDEBUG( modname, " adding " << modname << " request handler" << endl );
56  BESRequestHandlerList::TheList()->add_handler( modname, new SampleRequestHandler( modname ) ) ;
57 
58  // If new commands are needed, then let's declare this once here. If
59  // not, then you can remove this line.
60  string cmd_name ;
61 
62  BESDEBUG( modname, " adding " << SAY_RESPONSE
63  << " response handler" << endl ) ;
64  BESResponseHandlerList::TheList()->add_handler( SAY_RESPONSE, SampleSayResponseHandler::SampleSayResponseBuilder ) ;
65 
66  cmd_name = SAY_RESPONSE ;
67  BESDEBUG( modname, " adding " << cmd_name << " command" << endl ) ;
68  BESXMLCommand::add_command( cmd_name, SampleSayXMLCommand::CommandBuilder ) ;
69 
70  BESDEBUG( "say", " adding Say reporter" << endl ) ;
71  BESReporterList::TheList()->add_reporter( modname, new SayReporter ) ;
72 
73  // INIT_END
74 
75  BESDEBUG( modname, " adding Sample debug context" << endl ) ;
76  BESDebug::Register( modname ) ;
77 
78  BESDEBUG( modname, "Done Initializing Sample Module " << modname << endl ) ;
79 }
80 
81 void
82 SampleModule::terminate( const string &modname )
83 {
84  BESDEBUG( modname, "Cleaning Sample module " << modname << endl ) ;
85 
86  BESDEBUG( modname, " removing " << modname
87  << " request handler" << endl ) ;
88  BESRequestHandler *rh = BESRequestHandlerList::TheList()->remove_handler( modname ) ;
89  if( rh ) delete rh ;
90 
91  // If new commands are needed, then let's declare this once here. If
92  // not, then you can remove this line.
93  string cmd_name ;
94 
95  BESDEBUG( modname, " removing " << SAY_RESPONSE
96  << " response handler" << endl ) ;
97  BESResponseHandlerList::TheList()->remove_handler( SAY_RESPONSE ) ;
98 
99  cmd_name = SAY_RESPONSE ;
100  BESDEBUG( modname, " removing " << cmd_name << " command" << endl ) ;
101  BESXMLCommand::del_command( cmd_name ) ;
102 
103  // TERM_END
104  BESDEBUG( modname, "Done Cleaning Sample module " << modname << endl ) ;
105 }
106 
107 extern "C"
108 {
109  BESAbstractModule *maker()
110  {
111  return new SampleModule ;
112  }
113 }
114 
115 void
116 SampleModule::dump( ostream &strm ) const
117 {
118  strm << BESIndent::LMarg << "SampleModule::dump - ("
119  << (void *)this << ")" << endl ;
120 }
121 
static bool del_command(const string &cmd_str)
Deletes the command called cmd_str from the list of possible commands.
static void add_command(const string &cmd_str, p_xmlcmd_builder cmd)
Add a command to the possible commands allowed by this BES.
virtual bool add_handler(const string &handler_name, BESRequestHandler *handler)
add a request handler to the list of registered handlers for this server
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 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
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream