Add forgotten files 1.4.70b
[polyglot.git] / pipe.h
1 #ifndef PIPE_H
2 #define PIPE_H
3 #ifdef _WIN32
4 // includes
5
6 #include <windows.h>
7 #include <io.h>
8 #include <fcntl.h>
9 #include <stdio.h>
10
11 // constants
12
13 // This should be bigger than the maximum length of an engine output or GUI
14 // input line.
15 const int LINE_INPUT_MAX_CHAR = 40960;
16
17 // defines
18
19 #define PIPE_EOF 1
20 #define PIPE_ACTIVE 2
21
22 // types
23
24 class  PipeStruct {
25   friend DWORD WINAPI ThreadProc(LPVOID lpParam);
26  public:
27     HANDLE hProcess;
28     HANDLE hEvent;
29     bool GetBuffer(char *szLineStr);
30     void LineInput(char *szLineStr);
31     void LineOutput(const char *szLineStr) const;
32     void Open(const char *szExecFile = NULL);
33     void Close(void) const;
34     void Kill(void) const;
35     bool Active(void);
36     bool EOF_(void);
37  private:
38     HANDLE hInput, hOutput;
39     FILE *fpInput;
40     HANDLE hThread;
41     BOOL bConsole;
42     BOOL bPipe;
43
44     CRITICAL_SECTION CriticalSection;
45
46     volatile DWORD state;
47     volatile char * lpFeedEnd;
48     volatile int nReadEnd;
49     char lpBuffer[LINE_INPUT_MAX_CHAR];
50     char lpReadBuffer[LINE_INPUT_MAX_CHAR];
51
52     bool EOF_input(void);
53     void set_EOF_input(void);
54     void set_Active(void);
55     void ReadInput(void);
56     int ReadData(void);
57
58 };
59
60 // pipe
61
62 #endif
63 #endif