Jack2  1.9.9
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 
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 
55 {
56 
57  public:
58 
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 
81 {
82 
83  protected:
84 
85  int ConnectAux();
86 
87  public:
88 
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 
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 
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 
160 {
161  private:
162 
163  int BindAux();
164 
165  public:
166 
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 
184 {
185 
186  private:
187 
188  int BindAux();
189 
190  public:
191 
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 
Server async named pipe.