Async 1.8.0
AsyncPty.h
Go to the documentation of this file.
1
27#ifndef ASYNC_PTY_INCLUDED
28#define ASYNC_PTY_INCLUDED
29
30
31/****************************************************************************
32 *
33 * System Includes
34 *
35 ****************************************************************************/
36
37#include <unistd.h>
38#include <sigc++/sigc++.h>
39
40#include <string>
41
42
43/****************************************************************************
44 *
45 * Project Includes
46 *
47 ****************************************************************************/
48
49#include <AsyncTimer.h>
50#include <AsyncFdWatch.h>
51
52
53/****************************************************************************
54 *
55 * Local Includes
56 *
57 ****************************************************************************/
58
59
60
61/****************************************************************************
62 *
63 * Forward declarations
64 *
65 ****************************************************************************/
66
67
68
69/****************************************************************************
70 *
71 * Namespace
72 *
73 ****************************************************************************/
74
75namespace Async
76{
77
78
79/****************************************************************************
80 *
81 * Forward declarations of classes inside of the declared namespace
82 *
83 ****************************************************************************/
84
85
86
87/****************************************************************************
88 *
89 * Defines & typedefs
90 *
91 ****************************************************************************/
92
93
94
95/****************************************************************************
96 *
97 * Exported Global Variables
98 *
99 ****************************************************************************/
100
101
102
103/****************************************************************************
104 *
105 * Class definitions
106 *
107 ****************************************************************************/
108
124class Pty : public sigc::trackable
125{
126 public:
131 Pty(const std::string& slave_link="");
132
136 ~Pty(void);
137
142 void setLineBuffered(bool line_buffered)
143 {
144 m_is_line_buffered = line_buffered;
145 m_line_buffer.clear();
146 }
147
155 bool open(void);
156
163 void close(void);
164
172 bool reopen(void);
173
186 ssize_t write(const void *buf, size_t count);
187
199 ssize_t write(const std::string& str)
200 {
201 return write(str.c_str(), str.size());
202 }
203
208 bool isOpen(void) const { return m_master >= 0; }
209
214 const std::string& slavePath(void) const { return m_slave_path; }
215
221 sigc::signal<void, const void*, size_t> dataReceived;
222
223 protected:
224
225 private:
226 static const int POLLHUP_CHECK_INTERVAL = 100;
227
228 std::string m_slave_link;
229 int m_master = -1;
230 Async::FdWatch m_watch;
231 Async::Timer m_pollhup_timer;
232 bool m_is_line_buffered = false;
233 std::string m_line_buffer;
234 std::string m_slave_path;
235
236 Pty(const Pty&);
237 Pty& operator=(const Pty&);
238
239 void charactersReceived(void);
240 short pollMaster(void);
241 void checkIfSlaveEndOpen(void);
242
243}; /* class Pty */
244
245
246} /* namespace */
247
248#endif /* ASYNC_PTY_INCLUDED */
249
250
251
252/*
253 * This file has not been truncated
254 */
Contains a watch for file descriptors.
Contains a single shot or periodic timer that emits a signal on timeout.
A class for watching file descriptors.
A wrapper class for using a PTY.
Definition AsyncPty.h:125
void setLineBuffered(bool line_buffered)
Turn line buffering on or off.
Definition AsyncPty.h:142
bool isOpen(void) const
Check if the PTY is open or not.
Definition AsyncPty.h:208
const std::string & slavePath(void) const
Get the path to the slave PTS device.
Definition AsyncPty.h:214
ssize_t write(const std::string &str)
Write a string to the PTY.
Definition AsyncPty.h:199
void close(void)
Close the PTY if it's open.
bool open(void)
Open the PTY.
ssize_t write(const void *buf, size_t count)
Write data to the PTY.
bool reopen(void)
Reopen the PTY.
Pty(const std::string &slave_link="")
Constructor.
~Pty(void)
Destructor.
sigc::signal< void, const void *, size_t > dataReceived
Signal that is emitted when data has been received.
Definition AsyncPty.h:221
A class that produces timer events.
Definition AsyncTimer.h:117
Namespace for the asynchronous programming classes.