Jack2  1.9.8
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 namespace Jack
27 {
28 
30 {
31 
32  protected:
33 
34  HANDLE fNamedPipe;
35  char fName[256];
36 
37  public:
38 
39  JackWinNamedPipe(): fNamedPipe(INVALID_HANDLE_VALUE)
40  {}
41  JackWinNamedPipe(HANDLE pipe): fNamedPipe(pipe)
42  {}
43  virtual ~JackWinNamedPipe()
44  {}
45 
46  virtual int Read(void* data, int len);
47  virtual int Write(void* data, int len);
48 };
49 
55 {
56 
57  private:
58 
59  int ConnectAux();
60 
61  public:
62 
64  {}
65  JackWinNamedPipeClient(HANDLE pipe, const char* name): JackWinNamedPipe(pipe)
66  {
67  strcpy(fName, name);
68  }
69 
70  virtual ~JackWinNamedPipeClient()
71  {}
72 
73  virtual int Connect(const char* dir, int which);
74  virtual int Connect(const char* dir, const char* name, int which);
75  virtual int Close();
76  virtual void SetReadTimeOut(long sec);
77  virtual void SetWriteTimeOut(long sec);
78 };
79 
81 {
82  enum kIOState {kIdle = 0, kConnecting, kReading, kWriting};
83 
84  private:
85 
86  bool fPendingIO;
87  kIOState fIOState;
88  OVERLAPPED fOverlap;
89 
90  public:
91 
93  JackWinAsyncNamedPipeClient(HANDLE pipe, const char* name, bool pending);
94  virtual ~JackWinAsyncNamedPipeClient();
95 
96  virtual int Read(void* data, int len);
97  virtual int Write(void* data, int len);
98 
99  HANDLE GetEvent()
100  {
101  return (HANDLE)fOverlap.hEvent;
102  }
103 
104  kIOState GetIOState()
105  {
106  return fIOState;
107  }
108 
109  bool GetPending()
110  {
111  return fPendingIO;
112  }
113 
114  int FinishIO();
115 };
116 
122 {
123  private:
124 
125  int BindAux();
126 
127  public:
128 
130  {}
131  virtual ~JackWinNamedPipeServer()
132  {}
133 
134  virtual int Bind(const char* dir, int which);
135  virtual int Bind(const char* dir, const char* name, int which);
136  virtual bool Accept();
137  virtual JackWinNamedPipeClient* AcceptClient();
138  int Close();
139 };
140 
146 {
147 
148  private:
149 
150  int BindAux();
151 
152  public:
153 
155  {}
156  virtual ~JackWinAsyncNamedPipeServer()
157  {}
158 
159  int Bind(const char* dir, int which);
160  int Bind(const char* dir, const char* name, int which);
161  bool Accept();
162  JackWinNamedPipeClient* AcceptClient();
163  int Close();
164 };
165 
166 } // end of namespace
167 
168 
169 #endif
170