1 // *************************************************************************
2 // * GSM TA/ME library
3 // *
4 // * File:    gsm_port.h
5 // *
6 // * Purpose: Abstract port definition
7 // *
8 // * Author:  Peter Hofmann (software@pxh.de)
9 // *
10 // * Created: 3.5.1999
11 // *************************************************************************
12 
13 #ifndef GSM_PORT_H
14 #define GSM_PORT_H
15 
16 #include <gsmlib/gsm_error.h>
17 #include <gsmlib/gsm_util.h>
18 #include <string>
19 
20 using namespace std;
21 
22 namespace gsmlib
23 {
24   // TA defaults
25   const int TIMEOUT_SECS = 60;
26   const char DEFAULT_INIT_STRING[] = "E0";
27   const int DEFAULT_BAUD_RATE = 38400;
28 
29   class Port : public RefBase
30   {
31   public:
32     // read line from port(including eol characters)
33     virtual string getLine() throw(GsmException) =0;
34 
35     // write line to port
36     virtual void putLine(string line,
37                          bool carriageReturn = true) throw(GsmException) =0;
38 
39     // wait for new data to become available, return after timeout
40     // if timeout == 0, wait forever
41     // return true if data available
42     virtual bool wait(GsmTime timeout) throw(GsmException) =0;
43 
44     // put back one byte that can be read by a subsequent call to readByte()
45     virtual void putBack(unsigned char c) =0;
46 
47     // read a single byte, return -1 if error or file closed
48     virtual int readByte() throw(GsmException) =0;
49 
50     // set timeout for the readByte(), getLine(), and putLine() functions
51     // (globally for ALL ports)
52     virtual void setTimeOut(unsigned int timeout) =0;
53 
~Port()54     virtual ~Port() {}
55   };
56 };
57 
58 #endif // GSM_PORT_H
59