bes  Updated for version 3.20.6
Connection.h
1 // Connection.h
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 #ifndef Connection_h
34 #define Connection_h 1
35 
36 #include <iostream>
37 #include <string>
38 #include <map>
39 
40 #include "BESObj.h"
41 #include "Socket.h"
42 
43 class Connection: public BESObj {
44 protected:
45  Socket *_mySock;
46  std::ostream *_out;
47  bool _brokenPipe;
48 
49  Connection() :
50  _mySock(0), _out(0), _brokenPipe(false)
51  {
52  }
53 
54  virtual void send(const std::string &buffer) = 0;
55  virtual void sendChunk(const std::string &buffer, std::map<std::string, std::string> &extensions) = 0;
56 
57 public:
58  virtual ~Connection()
59  {
60  }
61 
62  virtual void initConnection() = 0;
63  virtual void closeConnection() = 0;
64 
65  virtual std::string exit() = 0;
66 
67  virtual void send(const std::string &buffer, std::map<std::string, std::string> &extensions) = 0;
68  virtual void sendExtensions(std::map<std::string, std::string> &extensions) = 0;
69  virtual void sendExit() = 0;
70  virtual bool receive(std::map<std::string, std::string> &extensions, std::ostream *strm = 0) = 0;
71 
72  virtual Socket * getSocket()
73  {
74  return _mySock;
75  }
76 
77  virtual bool isConnected()
78  {
79  if (_mySock) return _mySock->isConnected();
80  return false;
81  }
82 
83  virtual void setOutputStream(std::ostream *strm)
84  {
85  _out = strm;
86  }
87  virtual std::ostream * getOutputStream()
88  {
89  return _out;
90  }
91 
92  virtual void brokenPipe()
93  {
94  _brokenPipe = true;
95  }
96 
97  virtual unsigned int getRecvChunkSize() = 0;
98  virtual unsigned int getSendChunkSize() = 0;
99 
100  virtual void dump(std::ostream &strm) const;
101 };
102 
103 #endif // Connection_h
Connection::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: Connection.cc:44
Socket
Definition: Socket.h:42
Connection
Definition: Connection.h:43
BESObj
top level BES object to house generic methods
Definition: BESObj.h:49