nidas  v1.2-1520
PSQLChannel.h
Go to the documentation of this file.
1 /* vim: set shiftwidth=4 softtabstop=4 expandtab: */
2 // -*- mode: c++; c-basic-offset: 4; -*-
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2005, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program 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
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 
27 #ifndef NIDAS_DYNLD_PSQL_PSQLCHANNEL_H
28 #define NIDAS_DYNLD_PSQL_PSQLCHANNEL_H
29 
30 #include <libpq-fe.h> // PostgreSQL front end
31 
32 #include <nidas/core/IOChannel.h>
33 
34 namespace nidas { namespace dynld { namespace psql {
35 
36 using namespace nidas::core;
37 
38 class PSQLChannel : public IOChannel
39 {
40 public:
41 
42  PSQLChannel();
43 
47  PSQLChannel(const PSQLChannel&);
48 
49  virtual ~PSQLChannel();
50 
54  PSQLChannel* clone() const;
55 
56  void setName(const std::string& val) { name = val; }
57 
58  const std::string& getName() const { return name; }
59 
60  void requestConnection(ConnectionRequester*)
61  throw(nidas::util::IOException);
62 
63  IOChannel* connect() throw(nidas::util::IOException);
64 
68  size_t read(void* buf, size_t len) throw(nidas::util::IOException)
69  {
70  throw nidas::util::IOException(getName(),"read","not supported");
71  }
72 
76  size_t write(const void* buf, size_t len)
78 
79  void flush() throw(nidas::util::IOException);
80 
81  void close() throw(nidas::util::IOException);
82 
83  int getFd() const { return -1; }
84 
85  void setHost(const std::string& val);
86 
87  const std::string& getHost() const { return host; }
88 
89  void setDBName(const std::string& val);
90 
91  const std::string& getDBName() const { return dbname; }
92 
93  void setUser(const std::string& val);
94 
95  const std::string& getUser() const { return user; }
96 
97  void fromDOMElement(const xercesc::DOMElement*)
98  throw(nidas::util::InvalidParameterException);
99 
100 protected:
101 
102  void
103  connectDatabase();
104 
105  std::string name;
106 
107  std::string host;
108 
109  std::string dbname;
110 
111  std::string user;
112 
116  PGconn *_conn;
117 
118  char* lastCommand;
119  size_t lastNchars;
120 };
121 
122 }}}
123 
124 #endif // NIDAS_DYNLD_PSQL_PSQLCHANNEL_H
125 
const std::string & getHost() const
Definition: PSQLChannel.h:87
Definition: PSQLChannel.h:38
const std::string & getUser() const
Definition: PSQLChannel.h:95
const std::string & getName() const
Definition: PSQLChannel.h:58
A channel for Input or Output of data.
Definition: IOChannel.h:64
const std::string & getDBName() const
Definition: PSQLChannel.h:91
int len
Definition: sing.cc:934
Definition: IOException.h:37
Definition: InvalidParameterException.h:35
void setName(const std::string &val)
Definition: PSQLChannel.h:56