libDwm-0.9.45
DwmTermios.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2006-2007, 2016
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
32// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
39//---------------------------------------------------------------------------
40
41#ifndef _DWMTERMIOS_HH_
42#define _DWMTERMIOS_HH_
43
44extern "C" {
45#include <inttypes.h>
46#include <termios.h>
47}
48
49#include <iostream>
50#include <string>
51#include <utility>
52
53namespace Dwm {
54
55 class Termios;
56
57 //--------------------------------------------------------------------------
59 //--------------------------------------------------------------------------
60 typedef struct {
61 tcflag_t flag;
62 tcflag_t mask;
63 const char *name;
64 const char *longName;
66
67 //--------------------------------------------------------------------------
69 //--------------------------------------------------------------------------
71 {
72 public:
73 virtual ~TermioFlags() { }
74
75 //------------------------------------------------------------------------
77 //------------------------------------------------------------------------
78 bool IsSet(const std::string & flagName) const;
79
80 //------------------------------------------------------------------------
83 //------------------------------------------------------------------------
84 bool Set(const std::string & flagName);
85
86 //------------------------------------------------------------------------
89 //------------------------------------------------------------------------
90 bool Unset(const std::string & flagName);
91
92 //------------------------------------------------------------------------
94 //------------------------------------------------------------------------
95 friend std::ostream &
96 operator << (std::ostream & os, const TermioFlags & flags);
97
98 //------------------------------------------------------------------------
100 //------------------------------------------------------------------------
101 virtual const TermioFlagInfo_t *KnownFlags() const = 0;
102
103 protected:
104 tcflag_t *_flagPtr;
105 const TermioFlagInfo_t *_flagInfo;
106
107 TermioFlags();
108 const TermioFlagInfo_t *FindFlag(const std::string & flagName) const;
109 };
110
111 //--------------------------------------------------------------------------
113 //--------------------------------------------------------------------------
115 : public TermioFlags
116 {
117 public:
118 //------------------------------------------------------------------------
120 //------------------------------------------------------------------------
121 TermioInputFlags(struct termios & t);
122
123 //------------------------------------------------------------------------
125 //------------------------------------------------------------------------
127
128 private:
129 struct termios & _termios;
130
131 static const TermioFlagInfo_t k_flags[];
132
134 };
135
136 //--------------------------------------------------------------------------
138 //--------------------------------------------------------------------------
140 : public TermioFlags
141 {
142 public:
143 //------------------------------------------------------------------------
145 //------------------------------------------------------------------------
146 TermioOutputFlags(struct termios & t);
147
148 //------------------------------------------------------------------------
150 //------------------------------------------------------------------------
152
153 private:
154 struct termios & _termios;
155
156 static const TermioFlagInfo_t k_flags[];
157
159 };
160
161 //--------------------------------------------------------------------------
163 //--------------------------------------------------------------------------
165 : public TermioFlags
166 {
167 public:
168 //------------------------------------------------------------------------
170 //------------------------------------------------------------------------
171 TermioControlFlags(struct termios & t);
172
173 //------------------------------------------------------------------------
175 //------------------------------------------------------------------------
177
178 private:
179 struct termios & _termios;
180
181 static const TermioFlagInfo_t k_flags[];
182
184 };
185
186 //--------------------------------------------------------------------------
188 //--------------------------------------------------------------------------
190 : public TermioFlags
191 {
192 public:
193 //------------------------------------------------------------------------
195 //------------------------------------------------------------------------
196 TermioLocalFlags(struct termios & t);
197
198 //------------------------------------------------------------------------
200 //------------------------------------------------------------------------
202
203 private:
204 struct termios & _termios;
205
206 static const TermioFlagInfo_t k_flags[];
207
209 };
210
211 //--------------------------------------------------------------------------
213 //--------------------------------------------------------------------------
215 {
216 public:
217 //------------------------------------------------------------------------
219 //------------------------------------------------------------------------
221
222 //------------------------------------------------------------------------
224 //------------------------------------------------------------------------
226
227 //------------------------------------------------------------------------
229 //------------------------------------------------------------------------
231
232 //------------------------------------------------------------------------
234 //------------------------------------------------------------------------
236
237 //------------------------------------------------------------------------
239 //------------------------------------------------------------------------
241
242 //------------------------------------------------------------------------
244 //------------------------------------------------------------------------
245 long InputSpeed() const;
246
247 //------------------------------------------------------------------------
249 //------------------------------------------------------------------------
250 long InputSpeed(long inputSpeed);
251
252 //------------------------------------------------------------------------
254 //------------------------------------------------------------------------
255 long OutputSpeed() const;
256
257 //------------------------------------------------------------------------
259 //------------------------------------------------------------------------
260 long OutputSpeed(long outputSpeed);
261
262 //------------------------------------------------------------------------
265 //------------------------------------------------------------------------
266 cc_t ControlChar(const std::string & ccName) const;
267
268 //------------------------------------------------------------------------
271 //------------------------------------------------------------------------
272 cc_t ControlChar(const std::string & ccName, cc_t val);
273
274 //------------------------------------------------------------------------
276 //------------------------------------------------------------------------
277 bool Get(int fd);
278
279 //------------------------------------------------------------------------
283 //------------------------------------------------------------------------
284 bool Set(int fd, int action);
285
286 //------------------------------------------------------------------------
288 //------------------------------------------------------------------------
289 friend std::ostream & operator << (std::ostream & os, const Termios & t);
290
291 //------------------------------------------------------------------------
293 //------------------------------------------------------------------------
294 bool operator == (const Termios & t) const;
295
296 private:
297 struct termios _termios;
298 TermioInputFlags _inputFlags;
299 TermioOutputFlags _outputFlags;
300 TermioControlFlags _controlFlags;
301 TermioLocalFlags _localFlags;
302
303 typedef struct {
304 uint8_t index;
305 const char *name;
306 } ControlCharName_t;
307
308 static const ControlCharName_t k_controlCharNames[];
309
310 static std::string PrintableControlChar(cc_t cc);
311
312 static const ControlCharName_t *
313 FindControlChar(const std::string & ccName);
314
315 static const ControlCharName_t *
316 FindControlChar(cc_t cc);
317 };
318
319} // namespace Dwm
320
321#endif // _DWMTERMIOS_HH_
322
323//---------------------------- emacs settings -----------------------------
324// Local Variables:
325// mode: C++
326// tab-width: 2
327// indent-tabs-mode: nil
328// c-basic-offset: 2
329// End:
330//-------------------------------------------------------------------------
Encapsulates termios control flags.
Definition DwmTermios.hh:166
const TermioFlagInfo_t * KnownFlags() const
Returns the known control flags.
TermioControlFlags(struct termios &t)
Constructor.
Base class for input, output, control and local termio flags.
Definition DwmTermios.hh:71
bool IsSet(const std::string &flagName) const
Returns true if the given flagName is set, else returns false.
bool Set(const std::string &flagName)
Sets the flag for the given flagName.
virtual const TermioFlagInfo_t * KnownFlags() const =0
Returns the known flags.
friend std::ostream & operator<<(std::ostream &os, const TermioFlags &flags)
Prints to an ostream.
bool Unset(const std::string &flagName)
Unsets the flag for the given flagName.
Encapsulates termios input flags.
Definition DwmTermios.hh:116
const TermioFlagInfo_t * KnownFlags() const
Returns the known input flags.
TermioInputFlags(struct termios &t)
Constructor.
Encapsulates termios local flags.
Definition DwmTermios.hh:191
TermioLocalFlags(struct termios &t)
Constructor.
const TermioFlagInfo_t * KnownFlags() const
Returns the known local flags.
Encapsulates termios output flags.
Definition DwmTermios.hh:141
const TermioFlagInfo_t * KnownFlags() const
Returns the known output flags.
TermioOutputFlags(struct termios &t)
Constructor.
Encapsulates a struct termios.
Definition DwmTermios.hh:215
long InputSpeed() const
Returns the input speed.
long OutputSpeed(long outputSpeed)
Sets and returns the input speed.
bool Get(int fd)
Gets the termios for the given file descriptor.
cc_t ControlChar(const std::string &ccName) const
Returns the control char value for the given control char named ccName.
Termios()
Constructor.
bool operator==(const Termios &t) const
operator ==
TermioOutputFlags & OutputFlags()
Returns a reference to the output flags.
long InputSpeed(long inputSpeed)
Sets and returns the input speed.
cc_t ControlChar(const std::string &ccName, cc_t val)
Sets and returns the control char value for the given control char named ccName.
TermioInputFlags & InputFlags()
Returns a reference to the input flags.
TermioLocalFlags & LocalFlags()
Returns a reference to the local flags.
long OutputSpeed() const
Returns the input speed.
bool Set(int fd, int action)
Applies the termios to the given file descriptor.
friend std::ostream & operator<<(std::ostream &os, const Termios &t)
Prints to an ostream.
TermioControlFlags & ControlFlags()
Returns a reference to the control flags.
Holds termios flag values and names.
Definition DwmTermios.hh:60