Debian Codegraph @

src/xmlrpcpp/XmlRpcSource.h

raw
1 // ----------------------------------------------------------------------------
2 //
3 // flxmlrpc Copyright (c) 2015 by W1HKJ, Dave Freese <[email protected]>
4 //
5 // XmlRpc++ Copyright (c) 2002-2008 by Chris Morley
6 //
7 // This file is part of fldigi
8 //
9 // flxmlrpc is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU Lesser General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ----------------------------------------------------------------------------
17
18 #ifndef _XMLRPCSOURCE_H_
19 #define _XMLRPCSOURCE_H_
20
21 #if defined(_MSC_VER)
22 # pragma warning(disable:4786) // identifier was truncated in debug info
23 #endif
24
25 #include "XmlRpcSocket.h"
26
27
28 namespace XmlRpc {
29
30 //! Proxy for Ssl data to avoid including headers here.
31 struct SslProxy;
32
33 //! An RPC source represents a file descriptor to monitor
34 class XmlRpcSource {
35 public:
36 //! Constructor
37 //! @param fd The socket file descriptor to monitor.
38 //! @param deleteOnClose If true, the object deletes itself when close is called.
39 XmlRpcSource(XmlRpcSocket::Socket fd = XmlRpcSocket::Invalid, bool deleteOnClose = false);
40
41 //! Destructor
42 virtual ~XmlRpcSource();
43
44 //! Return the file descriptor being monitored.
45 XmlRpcSocket::Socket getfd() const { return _fd; }
46 //! Specify the file descriptor to monitor.
47 void setfd(XmlRpcSocket::Socket fd) { _fd = fd; }
48
49 //! Return whether the file descriptor should be kept open if it is no longer monitored.
50 bool getKeepOpen() const { return _keepOpen; }
51 //! Specify whether the file descriptor should be kept open if it is no longer monitored.
52 void setKeepOpen(bool b=true) { _keepOpen = b; }
53
54 //! Return whether ssl is enabled.
55 bool getSslEnabled() const { return _sslEnabled; }
56 //! Specify whether to enable ssl. Use getSslEnabled() to verify that Ssl is available.
57 void setSslEnabled(bool b=true);
58
59 //! Close the owned fd. If deleteOnClose was specified at construction, the object is deleted.
60 virtual void close();
61
62 //! Return true to continue monitoring this source
63 virtual unsigned handleEvent(unsigned eventType) = 0;
64
65 protected:
66
67 // Execution processing helpers
68 virtual bool doConnect();
69
70 //! Read text from the source. Returns false on error.
71 bool nbRead(std::string& s, bool *eof);
72
73 //! Write text to the source. Returns false on error.
74 bool nbWrite(std::string const& s, int *bytesSoFar);
75
76 private:
77
78 // Socket. This is an int for linux/unix, and unsigned on win32, and unsigned __int64 on win64.
79 // Casting to int/long/unsigned on win64 is a bad idea.
80 XmlRpcSocket::Socket _fd;
81
82 // In the server, a new source (XmlRpcServerConnection) is created
83 // for each connected client. When each connection is closed, the
84 // corresponding source object is deleted.
85 bool _deleteOnClose;
86
87 // In the client, keep connections open if you intend to make multiple calls.
88 bool _keepOpen;
89
90 // Enable use of SSL
91 bool _sslEnabled;
92
93 // SSL data
94 SslProxy *_ssl;
95 };
96 } // namespace XmlRpc
97
98 #endif //_XMLRPCSOURCE_H_