OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESTransmitter.cc
Go to the documentation of this file.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
37 BESTransmitter::add_method( string method_name, p_transmitter trans_method )
38 {
39  BESTransmitter::_method_citer i ;
40  i = _method_list.find( method_name ) ;
41  if( i == _method_list.end() )
42  {
43  _method_list[method_name] = trans_method ;
44  return true ;
45  }
46  return false ;
47 }
48 
49 bool
50 BESTransmitter::remove_method( string method_name )
51 {
52  BESTransmitter::_method_iter i ;
53  i = _method_list.find( method_name ) ;
54  if( i != _method_list.end() )
55  {
56  _method_list.erase( i ) ;
57  return true ;
58  }
59  return false ;
60 }
61 
63 BESTransmitter::find_method( string method_name )
64 {
65  BESTransmitter::_method_citer i ;
66  i = _method_list.find( method_name ) ;
67  if( i != _method_list.end() )
68  {
69  p_transmitter p = (*i).second ;
70  return p ;
71  }
72  return 0 ;
73 }
74 
75 void
76 BESTransmitter::send_response( const string &method_name,
77  BESResponseObject *response,
79 {
80  p_transmitter p = find_method( method_name ) ;
81  if( p )
82  {
83  p( response, dhi ) ;
84  }
85  else
86  {
87  string err = (string)"Unable to transmit response, no transmit for "
88  + method_name ;
89  throw BESInternalError( err, __FILE__, __LINE__ ) ;
90  }
91 }
92 
100 void
101 BESTransmitter::dump( ostream &strm ) const
102 {
103  strm << BESIndent::LMarg << "BESTransmitter::dump - ("
104  << (void *)this << ")" << endl ;
106  if( _method_list.size() )
107  {
108  strm << BESIndent::LMarg << "registered methods:" << endl ;
110  _method_citer i = _method_list.begin() ;
111  _method_citer ie = _method_list.end() ;
112  for( ; i != ie; i++ )
113  {
114  strm << BESIndent::LMarg << (*i).first << ": "
115  << (void *)(*i).second << endl ;
116  }
118  }
119  else
120  {
121  strm << BESIndent::LMarg << "registered methods: none" << endl ;
122  }
124 }
125