JackWinNamedPipe.h

00001 /*
00002 Copyright (C) 2004-2006 Grame  
00003 
00004 This program is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 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 General Public License for more details.
00013 
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 
00018 */
00019 
00020 #ifndef __JackWinNamedPipe__
00021 #define __JackWinNamedPipe__
00022 
00023 #include "JackChannelTransaction.h"
00024 #include <assert.h>
00025 #include <stdio.h>
00026 #include <windows.h>
00027 
00028 namespace Jack
00029 {
00030 
00031 class JackWinNamedPipe : public JackChannelTransaction
00032 {
00033 
00034     protected:
00035 
00036         HANDLE fNamedPipe;
00037         char fName[256];
00038 
00039     public:
00040 
00041         JackWinNamedPipe(): fNamedPipe(INVALID_HANDLE_VALUE)
00042         {}
00043         JackWinNamedPipe(HANDLE pipe): fNamedPipe(pipe)
00044         {}
00045         virtual ~JackWinNamedPipe()
00046         {}
00047 
00048         virtual int Read(void* data, int len);
00049         virtual int Write(void* data, int len);
00050 };
00051 
00056 class JackWinNamedPipeClient : public JackWinNamedPipe
00057 {
00058 
00059     public:
00060 
00061         JackWinNamedPipeClient(): JackWinNamedPipe()
00062         {}
00063         JackWinNamedPipeClient(HANDLE pipe): JackWinNamedPipe(pipe)
00064         {}
00065 
00066         virtual ~JackWinNamedPipeClient()
00067         {}
00068 
00069         virtual int Connect(const char* dir, int which);
00070         virtual int Connect(const char* dir, const char* name, int which);
00071         virtual int Close();
00072         virtual void SetReadTimeOut(long sec);
00073         virtual void SetWriteTimeOut(long sec);
00074 };
00075 
00076 class JackWinAsyncNamedPipeClient : public JackWinNamedPipeClient
00077 {
00078         enum kIOState {kIdle = 0, kConnecting, kReading, kWriting};
00079 
00080     private:
00081 
00082         bool fPendingIO;
00083         kIOState fIOState;
00084         OVERLAPPED fOverlap;
00085 
00086     public:
00087 
00088         JackWinAsyncNamedPipeClient();
00089         JackWinAsyncNamedPipeClient(HANDLE pipe, bool pending);
00090         virtual ~JackWinAsyncNamedPipeClient();
00091 
00092         virtual int Read(void* data, int len);
00093         virtual int Write(void* data, int len);
00094 
00095         HANDLE GetEvent()
00096         {
00097             return fOverlap.hEvent;
00098         }
00099 
00100         kIOState GetIOState()
00101         {
00102             return fIOState;
00103         }
00104 
00105         bool GetPending()
00106         {
00107             return fPendingIO;
00108         }
00109 
00110         int FinishIO();
00111 };
00112 
00117 class JackWinNamedPipeServer : public JackWinNamedPipe
00118 {
00119 
00120     public:
00121 
00122         JackWinNamedPipeServer(): JackWinNamedPipe()
00123         {}
00124         virtual ~JackWinNamedPipeServer()
00125         {}
00126 
00127         virtual int Bind(const char* dir, int which);
00128         virtual int Bind(const char* dir, const char* name, int which);
00129         virtual bool Accept();
00130         virtual JackWinNamedPipeClient* AcceptClient();
00131         int Close();
00132 };
00133 
00138 class JackWinAsyncNamedPipeServer : public JackWinNamedPipeServer
00139 {
00140 
00141     public:
00142 
00143         JackWinAsyncNamedPipeServer(): JackWinNamedPipeServer()
00144         {}
00145         virtual ~JackWinAsyncNamedPipeServer()
00146         {}
00147 
00148         int Bind(const char* dir, int which);
00149         int Bind(const char* dir, const char* name, int which);
00150         bool Accept();
00151         JackWinNamedPipeClient* AcceptClient();
00152         int Close();
00153 };
00154 
00155 } // end of namespace
00156 
00157 
00158 #endif
00159 

Generated on Thu Feb 14 11:16:02 2008 for Jackdmp by  doxygen 1.5.1