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