1 | //-----------------------------------------------------------------------------
|
---|
2 | // ------------------
|
---|
3 | // File ....: gcomm.h
|
---|
4 | // ------------------
|
---|
5 | // Author...: Gus J Grubba
|
---|
6 | // Date ....: September 1995
|
---|
7 | // O.S. ....: Windows NT 3.51
|
---|
8 | //
|
---|
9 | // Note ....: Copyright 1991, 1995 Gus J Grubba
|
---|
10 | //
|
---|
11 | // History .: Sep, 03 1995 - Ported to C++ / WinNT
|
---|
12 | //
|
---|
13 | //-----------------------------------------------------------------------------
|
---|
14 |
|
---|
15 | #ifndef _GCOMMINCLUDE_
|
---|
16 | #define _GCOMMINCLUDE_
|
---|
17 |
|
---|
18 | //-----------------------------------------------------------------------------
|
---|
19 | //-- Common Error Codes
|
---|
20 |
|
---|
21 | typedef unsigned int GCRES;
|
---|
22 |
|
---|
23 | #define GCRES_SUCCESS 0x0000
|
---|
24 |
|
---|
25 | //-----------------------------------------------------------------------------
|
---|
26 | //-- Error Handler
|
---|
27 |
|
---|
28 | typedef void (WINAPI *PERROR_HANDLER)(
|
---|
29 | int ErrorCode,
|
---|
30 | const TCHAR *ErrorMessage
|
---|
31 | );
|
---|
32 |
|
---|
33 | //-----------------------------------------------------------------------------
|
---|
34 | //-- Client Types
|
---|
35 |
|
---|
36 | #define gcTCP 1 //-- 0x1000 ... 0x1FFF
|
---|
37 | #define gcUART 2 //-- 0x2000 ... 0x2FFF
|
---|
38 | #define gcSCSI 3 //-- 0x3000 ... 0x3FFF
|
---|
39 | #define gcCENTRONICS 4 //-- 0x4000 ... 0x4FFF
|
---|
40 | #define gcIPX 5 //-- 0x5000 ... 0x5FFF
|
---|
41 | #define gcNETBIOS 6 //-- 0x6000 ... 0x6FFF
|
---|
42 |
|
---|
43 | //-----------------------------------------------------------------------------
|
---|
44 | //-- Error Types (for logging)
|
---|
45 |
|
---|
46 | #define ERR_FATAL 0 // Fatal Error, won't procede
|
---|
47 | #define ERR_WARN 1 // Warning Error, will procede with defaults (No Error Dialogue)
|
---|
48 | #define ERR_INFO 2 // Not an error, just a logging message (No Error Dialogue)
|
---|
49 | #define ERR_DEBUG 3 // Not an error, just debugging information (No Error Dialogue)
|
---|
50 |
|
---|
51 | //-----------------------------------------------------------------------------
|
---|
52 | //-- Timer Class Definition --------------------------------------------------
|
---|
53 | //-----------------------------------------------------------------------------
|
---|
54 | // #> Timer
|
---|
55 | //
|
---|
56 |
|
---|
57 | class Timer {
|
---|
58 |
|
---|
59 | float timer,count;
|
---|
60 |
|
---|
61 | public:
|
---|
62 |
|
---|
63 | //-- Timer methods ----------------------------------------------------
|
---|
64 | //
|
---|
65 | // Timers are kept in fractional units of seconds with a resolution
|
---|
66 | // no less than 10ms.
|
---|
67 |
|
---|
68 | GCOMMEXPORT Timer ( float t = 2.0f ) { timer = t; Start(); }
|
---|
69 | GCOMMEXPORT void Set ( float t = 2.0f ) { timer = t; }
|
---|
70 | GCOMMEXPORT void Start ( );
|
---|
71 | GCOMMEXPORT BOOL IsTimeout ( );
|
---|
72 | GCOMMEXPORT float Elapsed ( );
|
---|
73 |
|
---|
74 | };
|
---|
75 |
|
---|
76 | //-----------------------------------------------------------------------------
|
---|
77 | //-- Base Class Definition ---------------------------------------------------
|
---|
78 | //-----------------------------------------------------------------------------
|
---|
79 | // #> tcCOMM
|
---|
80 | //
|
---|
81 |
|
---|
82 | class tcCOMM {
|
---|
83 |
|
---|
84 | private:
|
---|
85 |
|
---|
86 | //-- Windows Specific -------------------------------------------------
|
---|
87 |
|
---|
88 | HINSTANCE tcphInst;
|
---|
89 | HWND hWnd;
|
---|
90 |
|
---|
91 | //-- System -----------------------------------------------------------
|
---|
92 |
|
---|
93 | BOOL silentmode;
|
---|
94 | PERROR_HANDLER errorhandler;
|
---|
95 | TCHAR error_title[64];
|
---|
96 |
|
---|
97 | public:
|
---|
98 |
|
---|
99 | //-- Constructors/Destructors -----------------------------------------
|
---|
100 |
|
---|
101 | GCOMMEXPORT tcCOMM ( );
|
---|
102 | GCOMMEXPORT ~tcCOMM ( );
|
---|
103 |
|
---|
104 | //-- Initialization process -------------------------------------------
|
---|
105 | //
|
---|
106 |
|
---|
107 | virtual BOOL Init ( HWND hWnd )=0;
|
---|
108 | virtual BOOL Setup ( void *setupdata )=0;
|
---|
109 | virtual void Close ( )=0;
|
---|
110 |
|
---|
111 | //-- Application provided hooks for saving/restoring session ----------
|
---|
112 | //
|
---|
113 | // If the application wants to save and restore session data, such
|
---|
114 | // as numbers, names, addresses, etc., it should use these methods.
|
---|
115 | // Each subclassed object should implement a method for saving and
|
---|
116 | // restoring its own session data.
|
---|
117 | //
|
---|
118 | // The host will issue a LoadSession() with previously saved data
|
---|
119 | // before issuing an Init() call. At the end of a session, it will
|
---|
120 | // issue the SaveSession() before calling Close();
|
---|
121 | //
|
---|
122 | // The host will use EvaluateDataSize() to find out the size of the
|
---|
123 | // buffer needed (called prior to SaveSession()).
|
---|
124 | //
|
---|
125 |
|
---|
126 | virtual BOOL SaveSession ( void *ptr )=0;
|
---|
127 | virtual BOOL LoadSession ( void *ptr )=0;
|
---|
128 | virtual DWORD EvaluateDataSize ( )=0;
|
---|
129 |
|
---|
130 | //-- Services ---------------------------------------------------------
|
---|
131 | //
|
---|
132 | // If you want your own error handler, use this function to register
|
---|
133 | // one. Whenever an error occurs, it will be called with an error
|
---|
134 | // code and with an optional error string message. The function
|
---|
135 | // prototype is:
|
---|
136 | //
|
---|
137 | // void WINAPI ErrorHandler (int ErrorCode, TCHAR *ErrorMessage);
|
---|
138 | //
|
---|
139 | // ErrorCode is one of the defined error codes above.
|
---|
140 | // ErrorMessage, if not NULL, contains a textual description of the
|
---|
141 | // error and can be used directly.
|
---|
142 | //
|
---|
143 | // Note that only ERR_FATAL warrants a mandatory action. All other
|
---|
144 | // error types are handled as you please. The idea is to provide
|
---|
145 | // ongoing messages for logging purposes and debugging. Internally,
|
---|
146 | // only ERR_FATAL will generate a dialogue message (provided the
|
---|
147 | // silence flag is set to FALSE);
|
---|
148 | //
|
---|
149 |
|
---|
150 | GCOMMEXPORT void RegisterErrorHandler (PERROR_HANDLER handler);
|
---|
151 |
|
---|
152 | //-- If you do not provide an error handler, the driver will produce
|
---|
153 | // its own error messages. If you don't pass a Window handler, the
|
---|
154 | // driver will use the system window (root) as the parent window.
|
---|
155 | //
|
---|
156 | // You can set the driver not to produce any error message at all
|
---|
157 | // by setting the Silent flag to TRUE. Simple use SetSilentMode().
|
---|
158 |
|
---|
159 |
|
---|
160 | HWND GethWnd ( ) { return hWnd; }
|
---|
161 | void SethWnd ( HWND hwnd ) { hWnd = hwnd; }
|
---|
162 | BOOL SilentMode ( ) { return silentmode; }
|
---|
163 | void SetSilentMode ( BOOL v ) { silentmode = v; }
|
---|
164 |
|
---|
165 | //-- Error Dialogue Title ---------------------------------------------
|
---|
166 | //
|
---|
167 | // If you let the driver produce its own error dialogue boxes, you
|
---|
168 | // still can set the Window title if you want something other than
|
---|
169 | // the default "Transport Error".
|
---|
170 |
|
---|
171 | void SetErrorTitle ( TCHAR *t ) {_tcscpy(error_title,t);}
|
---|
172 |
|
---|
173 | //-- Internal Services ------------------------------------------------
|
---|
174 | //
|
---|
175 |
|
---|
176 | void SetInstance ( HINSTANCE hi ) { tcphInst = hi; }
|
---|
177 | HINSTANCE GetInstance ( ) { return (tcphInst); }
|
---|
178 | TCHAR *GetLastErrorText ( TCHAR *buf, DWORD size );
|
---|
179 | void Error ( int type, const TCHAR *message );
|
---|
180 |
|
---|
181 | };
|
---|
182 |
|
---|
183 | //-----------------------------------------------------------------------------
|
---|
184 | //-- Interface
|
---|
185 |
|
---|
186 | GCOMMEXPORT void *gcommCreate ( int type );
|
---|
187 | GCOMMEXPORT void gcommDestroy ( void *ptr );
|
---|
188 |
|
---|
189 | #include "tcp.h"
|
---|
190 |
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | //-- EOF: gcomm.h -------------------------------------------------------------
|
---|