Jack2 1.9.12

JackWinNamedPipe.h
1 /*
2 Copyright (C) 2004-2008 Grame
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 */
19
20
21 #ifndef __JackWinNamedPipe__
22 #define __JackWinNamedPipe__
23
24 #include <windows.h>
25
26 #include "JackChannel.h"
27
28 namespace Jack
29 {
30
31 class JackWinNamedPipeAux
32 {
33
34 protected:
35
36 HANDLE fNamedPipe;
37 char fName[256];
38
39 int ReadAux(void* data, int len);
40 int WriteAux(void* data, int len);
41
42 public:
43
44 JackWinNamedPipeAux(): fNamedPipe(INVALID_HANDLE_VALUE)
45 {}
46 JackWinNamedPipeAux(HANDLE pipe): fNamedPipe(pipe)
47 {}
48 virtual ~JackWinNamedPipeAux()
49 {}
50
51 };
52
53
54 class JackWinNamedPipe : public JackWinNamedPipeAux, public detail::JackChannelTransactionInterface
55 {
56
57 public:
58
59 JackWinNamedPipe():JackWinNamedPipeAux()
60 {}
61 JackWinNamedPipe(HANDLE pipe):JackWinNamedPipeAux(pipe)
62 {}
63 virtual ~JackWinNamedPipe()
64 {}
65
66 virtual int Read(void* data, int len)
67 {
68 return ReadAux(data, len);
69 }
70 virtual int Write(void* data, int len)
71 {
72 return WriteAux(data, len);
73 }
74 };
75
80 class JackWinNamedPipeClient : public JackWinNamedPipeAux, public detail::JackClientRequestInterface
81 {
82
83 protected:
84
85 int ConnectAux();
86
87 public:
88
89 JackWinNamedPipeClient():JackWinNamedPipeAux()
90 {}
91 JackWinNamedPipeClient(HANDLE pipe, const char* name):JackWinNamedPipeAux(pipe)
92 {
93 strcpy(fName, name);
94 }
95
96 virtual ~JackWinNamedPipeClient()
97 {}
98
99 virtual int Connect(const char* dir, int which);
100 virtual int Connect(const char* dir, const char* name, int which);
101 virtual int Close();
102
103 virtual int Read(void* data, int len)
104 {
105 return ReadAux(data, len);
106 }
107 virtual int Write(void* data, int len)
108 {
109 return WriteAux(data, len);
110 }
111
112 virtual void SetReadTimeOut(long sec);
113 virtual void SetWriteTimeOut(long sec);
114
115 virtual void SetNonBlocking(bool onoff);
116 };
117
118 class JackWinAsyncNamedPipeClient : public JackWinNamedPipeClient
119 {
120 enum kIOState {kIdle = 0, kConnecting, kReading, kWriting};
121
122 private:
123
124 bool fPendingIO;
125 kIOState fIOState;
126 OVERLAPPED fOverlap;
127
128 public:
129
130 JackWinAsyncNamedPipeClient();
131 JackWinAsyncNamedPipeClient(HANDLE pipe, const char* name, bool pending);
132 virtual ~JackWinAsyncNamedPipeClient();
133
134 virtual int Read(void* data, int len);
135 virtual int Write(void* data, int len);
136
137 HANDLE GetEvent()
138 {
139 return (HANDLE)fOverlap.hEvent;
140 }
141
142 kIOState GetIOState()
143 {
144 return fIOState;
145 }
146
147 bool GetPending()
148 {
149 return fPendingIO;
150 }
151
152 int FinishIO();
153 };
154
159 class JackWinNamedPipeServer : public JackWinNamedPipe
160 {
161 private:
162
163 int BindAux();
164
165 public:
166
167 JackWinNamedPipeServer(): JackWinNamedPipe()
168 {}
169 virtual ~JackWinNamedPipeServer()
170 {}
171
172 virtual int Bind(const char* dir, int which);
173 virtual int Bind(const char* dir, const char* name, int which);
174 virtual bool Accept();
175 virtual JackWinNamedPipeClient* AcceptClient();
176 int Close();
177 };
178
183 class JackWinAsyncNamedPipeServer : public JackWinNamedPipeServer
184 {
185
186 private:
187
188 int BindAux();
189
190 public:
191
192 JackWinAsyncNamedPipeServer(): JackWinNamedPipeServer()
193 {}
194 virtual ~JackWinAsyncNamedPipeServer()
195 {}
196
197 int Bind(const char* dir, int which);
198 int Bind(const char* dir, const char* name, int which);
199 bool Accept();
200 JackWinNamedPipeClient* AcceptClient();
201 int Close();
202 };
203
204 } // end of namespace
205
206
207 #endif
208
Jack::detail::JackClientRequestInterface
Definition: JackChannel.h:68
Jack::JackWinNamedPipeAux
Definition: JackWinNamedPipe.h:31
Jack::JackWinAsyncNamedPipeServer
Server async named pipe.
Definition: JackWinNamedPipe.h:183
Jack::JackWinNamedPipeServer
Server named pipe.
Definition: JackWinNamedPipe.h:159
Jack::JackWinNamedPipeClient
Client named pipe.
Definition: JackWinNamedPipe.h:80
Jack::JackWinAsyncNamedPipeClient
Definition: JackWinNamedPipe.h:118
Jack::JackWinNamedPipe
Definition: JackWinNamedPipe.h:54
Jack::detail::JackChannelTransactionInterface
Definition: JackChannel.h:38