Jack2 1.9.6

JackWinNamedPipe.h

00001 /*
00002  Copyright (C) 2004-2008 Grame
00003  
00004  This program is free software; you can redistribute it and/or modify
00005  it under the terms of the GNU Lesser General Public License as published by
00006  the Free Software Foundation; either version 2.1 of the License, or
00007  (at your option) any later version.
00008  
00009  This program is distributed in the hope that it will be useful,
00010  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  GNU Lesser General Public License for more details.
00013  
00014  You should have received a copy of the GNU Lesser General Public License
00015  along with this program; if not, write to the Free Software
00016  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  
00018  */
00019 
00020 
00021 #ifndef __JackWinNamedPipe__
00022 #define __JackWinNamedPipe__
00023 
00024 #include <windows.h>
00025 
00026 namespace Jack
00027 {
00028 
00029 class JackWinNamedPipe
00030 {
00031 
00032     protected:
00033 
00034         HANDLE fNamedPipe;
00035         char fName[256];
00036 
00037     public:
00038 
00039         JackWinNamedPipe(): fNamedPipe(INVALID_HANDLE_VALUE)
00040         {}
00041         JackWinNamedPipe(HANDLE pipe): fNamedPipe(pipe)
00042         {}
00043         virtual ~JackWinNamedPipe()
00044         {}
00045 
00046         virtual int Read(void* data, int len);
00047         virtual int Write(void* data, int len);
00048 };
00049 
00054 class JackWinNamedPipeClient : public JackWinNamedPipe
00055 {
00056 
00057     public:
00058 
00059         JackWinNamedPipeClient(): JackWinNamedPipe()
00060         {}
00061         JackWinNamedPipeClient(HANDLE pipe): JackWinNamedPipe(pipe)
00062         {}
00063 
00064         virtual ~JackWinNamedPipeClient()
00065         {}
00066 
00067         virtual int Connect(const char* dir, int which);
00068         virtual int Connect(const char* dir, const char* name, int which);
00069         virtual int Close();
00070         virtual void SetReadTimeOut(long sec);
00071         virtual void SetWriteTimeOut(long sec);
00072 };
00073 
00074 class JackWinAsyncNamedPipeClient : public JackWinNamedPipeClient
00075 {
00076         enum kIOState {kIdle = 0, kConnecting, kReading, kWriting};
00077 
00078     private:
00079 
00080         bool fPendingIO;
00081         kIOState fIOState;
00082         OVERLAPPED fOverlap;
00083 
00084     public:
00085 
00086         JackWinAsyncNamedPipeClient();
00087         JackWinAsyncNamedPipeClient(HANDLE pipe, bool pending);
00088         virtual ~JackWinAsyncNamedPipeClient();
00089 
00090         virtual int Read(void* data, int len);
00091         virtual int Write(void* data, int len);
00092 
00093         HANDLE GetEvent()
00094         {
00095             return (HANDLE)fOverlap.hEvent;
00096         }
00097 
00098         kIOState GetIOState()
00099         {
00100             return fIOState;
00101         }
00102 
00103         bool GetPending()
00104         {
00105             return fPendingIO;
00106         }
00107 
00108         int FinishIO();
00109 };
00110 
00115 class JackWinNamedPipeServer : public JackWinNamedPipe
00116 {
00117 
00118     public:
00119 
00120         JackWinNamedPipeServer(): JackWinNamedPipe()
00121         {}
00122         virtual ~JackWinNamedPipeServer()
00123         {}
00124 
00125         virtual int Bind(const char* dir, int which);
00126         virtual int Bind(const char* dir, const char* name, int which);
00127         virtual bool Accept();
00128         virtual JackWinNamedPipeClient* AcceptClient();
00129         int Close();
00130 };
00131 
00136 class JackWinAsyncNamedPipeServer : public JackWinNamedPipeServer
00137 {
00138 
00139     public:
00140 
00141         JackWinAsyncNamedPipeServer(): JackWinNamedPipeServer()
00142         {}
00143         virtual ~JackWinAsyncNamedPipeServer()
00144         {}
00145 
00146         int Bind(const char* dir, int which);
00147         int Bind(const char* dir, const char* name, int which);
00148         bool Accept();
00149         JackWinNamedPipeClient* AcceptClient();
00150         int Close();
00151 };
00152 
00153 } // end of namespace
00154 
00155 
00156 #endif
00157