©2004 by Marc J. Rochkind. All rights reserved. Portions marked "Open Source" may be copied under license.

 

Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ux/uxterminal.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2003 by Marc J. Rochkind. All rights reserved.
00003     May be copied only for purposes and under conditions described
00004     on the Web page www.basepath.com/aup/copyright.htm.
00005 
00006     The Example Files are provided "as is," without any warranty;
00007     without even the implied warranty of merchantability or fitness
00008     for a particular purpose. The author and his publisher are not
00009     responsible for any damages, direct or incidental, resulting
00010     from the use or non-use of these Example Files.
00011 
00012     The Example Files may contain defects, and some contain deliberate
00013     coding mistakes that were included for educational reasons.
00014     You are responsible for determining if and how the Example Files
00015     are to be used.
00016 
00017 */
00018 #include "ux.hpp"
00019 
00020 using namespace Ux;
00021 
00022 /**
00023     Calls cfgetispeed.
00024 */
00025 speed_t Termios::cfgetispeed(void)
00026 {
00027     return ::cfgetispeed(this);
00028 }
00029 
00030 /**
00031     Calls cfgetospeed.
00032 */
00033 speed_t Termios::cfgetospeed(void)
00034 {
00035     return ::cfgetospeed(this);
00036 }
00037 
00038 /**
00039     Calls cfsetispeed.
00040 */
00041 void Termios::cfsetispeed(speed_t speed)
00042 {
00043     if (::cfsetispeed(this, speed) == -1)
00044         throw Error(errno);
00045 }
00046 
00047 /**
00048     Calls cfsetospeed.
00049 */
00050 void Termios::cfsetospeed(speed_t speed)
00051 {
00052     if (::cfsetospeed(this, speed) == -1)
00053         throw Error(errno);
00054 }
00055 
00056 /**
00057     Calls isatty and changes return value to a bool.
00058 */
00059 bool Terminal::isatty(void)
00060 {
00061     return ::isatty(fd) == 1;
00062 }
00063 
00064 /**
00065     Calls ctermid. Static because makes no reference to fd -- returns name of controlling terminal.
00066 */
00067 /* static */ char *Terminal::ctermid(char *buf)/* rtn pathname or empty string on error (errno not set) */
00068 {
00069     char *s;
00070 
00071     errno = 0;
00072     s = ::ctermid(buf);
00073     if (s[0] == '\0') {
00074         if (errno == 0)
00075             throw Error(EINVAL);
00076         else
00077             throw Error(errno);
00078     }
00079     return s;
00080 }
00081 
00082 /**
00083     Calls tcdrain.
00084 */
00085 void Terminal::tcdrain(void)
00086 {
00087     if (::tcdrain(fd) == -1)
00088         throw Error(errno);
00089 }
00090 
00091 /**
00092     Calls tcflow.
00093 */
00094 void Terminal::tcflow(int action)
00095 {
00096     if (::tcflow(fd, action) == -1)
00097         throw Error(errno);
00098 }
00099 
00100 /**
00101     Calls tcflush.
00102 */
00103 void Terminal::tcflush(int queue)
00104 {
00105     if (::tcflush(fd, queue) == -1)
00106         throw Error(errno);
00107 }
00108 
00109 /**
00110     Calls tcgetattr.
00111 */
00112 void Terminal::tcgetattr(Termios& t)
00113 {
00114     if (::tcgetattr(fd, &t) == -1)
00115         throw Error(errno);
00116 }
00117 
00118 /**
00119     Calls tcgetpgrp.
00120 */
00121 pid_t Terminal::tcgetpgrp(void)
00122 {
00123     pid_t pid;
00124     
00125     if ((pid = ::tcgetpgrp(fd)) == -1)
00126         throw Error(errno);
00127     return pid;
00128 }
00129 
00130 /**
00131     Calls tcgetsid.
00132 */
00133 pid_t Terminal::tcgetsid(void)
00134 {
00135     pid_t pid;
00136     
00137     if ((pid = ::tcgetsid(fd)) == -1)
00138         throw Error(errno);
00139     return pid;
00140 }
00141 
00142 /**
00143     Calls tcsendbreak.
00144 */
00145 void Terminal::tcsendbreak(int duration)
00146 {
00147     if (::tcsendbreak(fd, duration) == -1)
00148         throw Error(errno);
00149 }
00150 
00151 /**
00152     Calls tcsetattr.
00153 */
00154 void Terminal::tcsetattr(int actions, const Termios& t)
00155 {
00156     if (::tcsetattr(fd, actions, &t) == -1)
00157         throw Error(errno);
00158 }
00159 
00160 /**
00161     Calls tcsetpgrp.
00162 */
00163 void Terminal::tcsetpgrp(pid_t pgid)
00164 {
00165     if (::tcsetpgrp(fd, pgid) == -1)
00166         throw Error(errno);
00167 }
00168 
00169 /**
00170     Calls ttyname_r (ttyname not supported). Could be redesigned to use the path in the
00171     superclass, but this function is too rarely used for that to be worthwhile.
00172 */
00173 void Terminal::ttyname(char *buf, size_t bufsize)
00174 {
00175     int r;
00176 
00177     if ((r = ::ttyname_r(fd, buf, bufsize)) > 0)
00178         throw Error(r);
00179 }

Generated on Fri Apr 23 10:57:06 2004 for AUP2 Example Source by doxygen 1.3.1