Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sshstream.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_CORE_SSHSTREAM_H_)
21 #define __MITSUBA_CORE_SSHSTREAM_H_
22 
23 #include <mitsuba/mitsuba.h>
24 #include <boost/scoped_ptr.hpp>
25 
27 
28 
29 /** \brief Stream implementation based on an encrypted SSH tunnel
30  *
31  * This class remotely starts a program and exposes its stdin/stdout
32  * streams through an instance of \ref Stream. To make all
33  * of this work, passwordless authentication must be enabled (for
34  * example by using public key authentication in addition to a
35  * running ssh-agent, which stores the decrypted private key).
36  *
37  * On Windows, things are implemented a bit differently: Instead
38  * of OpenSSH, plink.exe (from PUTTY) is used and must be available
39  * in $PATH. For passwordless authentication, convert your private
40  * key to PuTTY's format (with the help of puttygen.exe). Afterwards,
41  * pageant.exe is required to load and authenticate the key.
42  *
43  * Note: SSH streams are set to use network byte order by default.
44  *
45  * \ingroup libcore
46  * \ingroup libpython
47  */
49 public:
50  // =============================================================
51  //! @{ \name Constructors
52  // =============================================================
53 
54  /**
55  * \brief Create a new SSH stream.
56  *
57  * The timeout parameter specifies specifies the maximum amount of
58  * time that can be spent before failing to create the initial
59  * connection. This feature is unsupported (and ignored) on Windows.
60  *
61  * \param userName Username to use for the authentication
62  * \param hostName Destination host name
63  * \param cmdLine Command (with arguments) to be executed on the remote side
64  * \param port Destination port
65  * \param timeout Maximum time to use for the connection attempt (in seconds)
66  */
67  SSHStream(const std::string &userName,
68  const std::string &hostName,
69  const std::vector<std::string> &cmdLine,
70  int port = 22, int timeout = 10
71  );
72 
73  //! @}
74  // =============================================================
75 
76  // =============================================================
77  //! @{ \name SSH stream-specific features
78  // =============================================================
79 
80  /// Return the destination machine's host name
81  const std::string &getHostName() const;
82 
83  /// Return the user name used for authentication
84  const std::string &getUserName() const;
85 
86  /// Return the number of received bytes
87  size_t getReceivedBytes() const;
88 
89  /// Return the number of sent bytes
90  size_t getSentBytes() const;
91 
92  //! @}
93  // =============================================================
94 
95  // =============================================================
96  //! @{ \name Implementation of the Stream interface
97  // =============================================================
98 
99  void read(void *ptr, size_t size);
100  void write(const void *ptr, size_t size);
101  void seek(size_t pos);
102  size_t getPos() const;
103  size_t getSize() const;
104  void truncate(size_t size);
105  void flush();
106  bool canWrite() const;
107  bool canRead() const;
108 
109  //! @}
110  // =============================================================
111 
112 
113  /// Return a string representation
114  std::string toString() const;
115 
117 protected:
118  /** \brief Virtual destructor
119  *
120  * The destructor frees all resources and closes
121  * the socket if it is still open
122  */
123  virtual ~SSHStream();
124 private:
125  struct SSHStreamPrivate;
126  boost::scoped_ptr<SSHStreamPrivate> d;
127 };
128 
130 
131 #endif /* __MITSUBA_CORE_SSHSTREAM_H_ */
virtual void flush()=0
Flush the stream&#39;s buffers.
virtual bool canRead() const =0
Can we read from the stream?
#define MTS_EXPORT_CORE
Definition: getopt.h:29
virtual bool canWrite() const =0
Can we write to the stream?
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
virtual void read(void *ptr, size_t size)=0
Read a specified amount of data from the stream.
Stream implementation based on an encrypted SSH tunnel.
Definition: sshstream.h:48
Abstract seekable stream class.
Definition: stream.h:58
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
virtual void write(const void *ptr, size_t size)=0
Write a specified amount of data into the stream.
MTS_EXPORT_CORE std::string getHostName()
Return the host name of this machine.
virtual size_t getPos() const =0
Get the current position inside the stream.
#define MTS_NAMESPACE_END
Definition: platform.h:138
virtual std::string toString() const
Return a string representation.
virtual void seek(size_t pos)=0
Seek to a position inside the stream.
virtual size_t getSize() const =0
Return the size of the stream.
virtual void truncate(size_t size)=0
Truncate the stream to a given size.