bes  Updated for version 3.17.0
BESTransmitter.cc
1 // BESTransmitter.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 "BESTransmitter.h"
34 #include "BESInternalError.h"
35 
36 bool BESTransmitter::add_method(string method_name, p_transmitter trans_method)
37 {
38  BESTransmitter::_method_citer i;
39  i = _method_list.find(method_name);
40  if (i == _method_list.end()) {
41  _method_list[method_name] = trans_method;
42  return true;
43  }
44  return false;
45 }
46 
47 bool BESTransmitter::remove_method(string method_name)
48 {
49  BESTransmitter::_method_iter i;
50  i = _method_list.find(method_name);
51  if (i != _method_list.end()) {
52  _method_list.erase(i);
53  return true;
54  }
55  return false;
56 }
57 
58 p_transmitter BESTransmitter::find_method(string method_name)
59 {
60  BESTransmitter::_method_citer i;
61  i = _method_list.find(method_name);
62  if (i != _method_list.end()) {
63  p_transmitter p = (*i).second;
64  return p;
65  }
66  return 0;
67 }
68 
69 void BESTransmitter::send_response(const string &method_name, BESResponseObject *response, BESDataHandlerInterface &dhi)
70 {
71  p_transmitter p = find_method(method_name);
72  if (p) {
73  p(response, dhi);
74  }
75  else {
76  throw BESInternalError(string("Unable to transmit response, no transmitter for ") + method_name, __FILE__,
77  __LINE__);
78  }
79 }
80 
88 void BESTransmitter::dump(ostream &strm) const
89 {
90  strm << BESIndent::LMarg << "BESTransmitter::dump - (" << (void *) this << ")" << endl;
91  BESIndent::Indent();
92  if (_method_list.size()) {
93  strm << BESIndent::LMarg << "registered methods:" << endl;
94  BESIndent::Indent();
95  _method_citer i = _method_list.begin();
96  _method_citer ie = _method_list.end();
97  for (; i != ie; i++) {
98  strm << BESIndent::LMarg << (*i).first << ": " << (void *) (*i).second << endl;
99  }
100  BESIndent::UnIndent();
101  }
102  else {
103  strm << BESIndent::LMarg << "registered methods: none" << endl;
104  }
105  BESIndent::UnIndent();
106 }
107 
exception thrown if inernal error encountered
virtual void dump(ostream &strm) const
dumps information about this object
Structure storing information used by the BES to handle the request.
Abstract base class representing a specific set of information in response to a request to the BES...