Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
212 dhylands 1
/****************************************************************************
2
*
3
*     Copyright (c) 2003 Dave Hylands
4
*           All Rights Reserved
5
*
6
*   Permission is granted to any individual or institution to use, copy, or
7
*   redistribute this software so long as it is not sold for profit, and that
8
*   this copyright notice is retained.
9
*
10
****************************************************************************/
11
/**
12
*
13
*   @file   ConsoleComm.h
14
*
15
*   @brief  Implements the abstract communications device using a serial port.
16
*
17
****************************************************************************/
18
/**
19
*  @defgroup    ConsoleComm  Serial Communications Device
20
*  @ingroup     CommDev
21
*
22
*  @brief   Implements the abstract communications device using a serial port.
23
*/
24
 
25
#if !defined( CONSOLECOMM_H )
26
#define CONSOLECOMM_H                   ///< Include Guard
27
 
28
// ---- Include Files -------------------------------------------------------
29
 
30
#include "CommDev.h"
31
 
32
#if !defined( _WINDOWS_ )
33
#   define WIN32_LEAN_AND_MEAN  ///< Trim it down as much as we can
34
#   include <windows.h>
35
#endif
36
 
37
/**
38
 * @addtogroup ConsoleComm
39
 * @{
40
 */
41
 
42
//---------------------------------------------------------------------------
43
/**
44
*  The ConsoleComm class implements the serial communications device.
45
*/
46
 
47
class ConsoleComm : public CommDev
48
{
49
public:
50
 
51
    //------------------------------------------------------------------------
52
    // Default constructor
53
 
54
    ConsoleComm();
55
 
56
    //------------------------------------------------------------------------
57
    // Destructor
58
 
59
    virtual ~ConsoleComm();
60
 
61
    //------------------------------------------------------------------------
62
    // Aborts a read, if one is pending.
63
 
64
    virtual void AbortRead();
65
 
66
    //------------------------------------------------------------------------
67
    // Close a previsouly opened device.
68
 
69
    virtual void Close();
70
 
71
    //------------------------------------------------------------------------
72
    // Enable line input/editing mode, if supported by the device.
73
 
74
    virtual void EnableLineMode( bool enable = true );
75
 
76
    //------------------------------------------------------------------------
77
    // Open a communication device. This provides a generic interface,
78
    // but a derived class may choose to provide a more specialized version.
79
 
80
    virtual bool Open( const char *openStr );
81
 
82
    //------------------------------------------------------------------------
83
    // Returns true if the device has detected a quit indication. This is
84
    // typically only implemented by a console device.
85
 
86
    virtual bool QuitDetected() const;
87
 
88
    //------------------------------------------------------------------------
89
    // Read data from the communication device.
90
 
91
    virtual bool Read( void *buf, size_t bufSize, size_t *bytesRead );
92
 
93
    //------------------------------------------------------------------------
94
    // Write data to the communication device.
95
 
96
    virtual bool Write( const void *buf, size_t bufSize, size_t *bytesWritten );
97
 
98
private:
99
 
100
    //------------------------------------------------------------------------
101
    // The copy constructor and assignment operator are not need for this
102
    // class so we declare them private and don't provide an implementation.
103
 
104
    ConsoleComm( const ConsoleComm & copy );
105
    ConsoleComm &operator =( const ConsoleComm &rhs );
106
 
107
    //------------------------------------------------------------------------
108
 
109
    HANDLE          m_stdin;
110
    HANDLE          m_stdout;
111
    INPUT_RECORD    m_inputRec;
112
    HANDLE          m_abortEvent;
113
    bool            m_quitDetected;
114
};
115
 
116
// ---- Inline Functions ----------------------------------------------------
117
 
118
/** @} */
119
 
120
#endif // CONSOLECOMM_H
121