Sophie

Sophie

distrib > Mandriva > 2007.0 > i586 > by-pkgid > ad1ba1135a9c9eeffc2e538163e00373 > files > 866

libCommonC++2_1.4-devel-1.4.1-1mdv2007.0.i586.rpm

\section{serialecho.cpp}


\footnotesize\begin{verbatim}1 /**********************************************************************
2  * C/C++ Source: serialecho.cc
3  *
4  * Defines the methods for the SerialEcho class
5  *
6  * @author:  Gary Lawrence Murphy <garym@canada.com>
7  * Copyright:  2000 TeleDynamics Communications Inc (www.teledyn.com)
8  ********************************************************************
9  */
10 // Copyright (C) 1999-2000 Teledynamics Communications Inc.
11 //  
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 // 
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 // GNU General Public License for more details.
21 // 
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software 
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 
26 #include "serialecho.h"
27 
28 using namespace std;
29 
30 SerialEcho::SerialEcho(const char *device, 
31                        int priority, int stacksize) :
32   TTYSession( device, priority, stacksize ) {
33 
34   cout << "Creating SerialEcho" << endl;
35 
36   if (!(*this)) {
37     throw xError();
38     ::exit(1);
39   } else {
40     cout << "modem ready" << endl;
41   }
42 
43   interactive(false);
44 
45   if (setSpeed(38400)) cout << getErrorString() << endl;
46   if (setCharBits(8)) cout << getErrorString() << endl;
47   if (setParity(Serial::parityNone)) cout << getErrorString() << endl;
48   if (setStopBits(1)) cout << getErrorString() << endl;
49   if (setFlowControl(Serial::flowHard)) cout << getErrorString() << endl;
50 
51   cout << "config done" << endl;
52 }
53 
54 void SerialEcho::run() {
55   char* s = new char[getBufferSize()];
56 
57   cout << "start monitor" << endl;
58 
59   while (s[0] != 'X') {
60     while (isPending(Serial::pendingInput)) {
61       cout.put( TTYStream::get() );
62     } 
63     sleep(500);
64   }
65 
66   cout << "end of monitor" << endl;
67 
68   delete [] s;
69   
70   exit();
71 }
72 
\end{verbatim}
\normalsize