Jack2 1.9.8

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     private:
00058 
00059         int ConnectAux();
00060 
00061     public:
00062 
00063         JackWinNamedPipeClient(): JackWinNamedPipe()
00064         {}
00065         JackWinNamedPipeClient(HANDLE pipe, const char* name): JackWinNamedPipe(pipe)
00066         {
00067             strcpy(fName, name);
00068         }
00069 
00070         virtual ~JackWinNamedPipeClient()
00071         {}
00072 
00073         virtual int Connect(const char* dir, int which);
00074         virtual int Connect(const char* dir, const char* name, int which);
00075         virtual int Close();
00076         virtual void SetReadTimeOut(long sec);
00077         virtual void SetWriteTimeOut(long sec);
00078 };
00079 
00080 class JackWinAsyncNamedPipeClient : public JackWinNamedPipeClient
00081 {
00082         enum kIOState {kIdle = 0, kConnecting, kReading, kWriting};
00083 
00084     private:
00085 
00086         bool fPendingIO;
00087         kIOState fIOState;
00088         OVERLAPPED fOverlap;
00089 
00090     public:
00091 
00092         JackWinAsyncNamedPipeClient();
00093         JackWinAsyncNamedPipeClient(HANDLE pipe, const char* name, bool pending);
00094         virtual ~JackWinAsyncNamedPipeClient();
00095 
00096         virtual int Read(void* data, int len);
00097         virtual int Write(void* data, int len);
00098 
00099         HANDLE GetEvent()
00100         {
00101             return (HANDLE)fOverlap.hEvent;
00102         }
00103 
00104         kIOState GetIOState()
00105         {
00106             return fIOState;
00107         }
00108 
00109         bool GetPending()
00110         {
00111             return fPendingIO;
00112         }
00113 
00114         int FinishIO();
00115 };
00116 
00121 class JackWinNamedPipeServer : public JackWinNamedPipe
00122 {
00123     private:
00124 
00125         int BindAux();
00126 
00127     public:
00128 
00129         JackWinNamedPipeServer(): JackWinNamedPipe()
00130         {}
00131         virtual ~JackWinNamedPipeServer()
00132         {}
00133 
00134         virtual int Bind(const char* dir, int which);
00135         virtual int Bind(const char* dir, const char* name, int which);
00136         virtual bool Accept();
00137         virtual JackWinNamedPipeClient* AcceptClient();
00138         int Close();
00139 };
00140 
00145 class JackWinAsyncNamedPipeServer : public JackWinNamedPipeServer
00146 {
00147 
00148     private:
00149 
00150         int BindAux();
00151 
00152     public:
00153 
00154         JackWinAsyncNamedPipeServer(): JackWinNamedPipeServer()
00155         {}
00156         virtual ~JackWinAsyncNamedPipeServer()
00157         {}
00158 
00159         int Bind(const char* dir, int which);
00160         int Bind(const char* dir, const char* name, int which);
00161         bool Accept();
00162         JackWinNamedPipeClient* AcceptClient();
00163         int Close();
00164 };
00165 
00166 } // end of namespace
00167 
00168 
00169 #endif
00170