jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
3.5KB

  1. /*
  2. Copyright (C) 2004-2006 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #ifndef __JackWinNamedPipe__
  16. #define __JackWinNamedPipe__
  17. #include "JackChannelTransaction.h"
  18. #include <assert.h>
  19. #include <stdio.h>
  20. #include <windows.h>
  21. namespace Jack
  22. {
  23. class JackWinNamedPipe : public JackChannelTransaction
  24. {
  25. protected:
  26. HANDLE fNamedPipe;
  27. char fName[256];
  28. public:
  29. JackWinNamedPipe(): fNamedPipe(INVALID_HANDLE_VALUE)
  30. {}
  31. JackWinNamedPipe(HANDLE pipe): fNamedPipe(pipe)
  32. {}
  33. virtual ~JackWinNamedPipe()
  34. {}
  35. virtual int Read(void* data, int len);
  36. virtual int Write(void* data, int len);
  37. };
  38. /*!
  39. \brief Client named pipe.
  40. */
  41. class JackWinNamedPipeClient : public JackWinNamedPipe
  42. {
  43. public:
  44. JackWinNamedPipeClient(): JackWinNamedPipe()
  45. {}
  46. JackWinNamedPipeClient(HANDLE pipe): JackWinNamedPipe(pipe)
  47. {}
  48. virtual ~JackWinNamedPipeClient()
  49. {}
  50. virtual int Connect(const char* dir, int which);
  51. virtual int Connect(const char* dir, const char* name, int which);
  52. virtual int Close();
  53. virtual void SetReadTimeOut(long sec);
  54. virtual void SetWriteTimeOut(long sec);
  55. };
  56. class JackWinAsyncNamedPipeClient : public JackWinNamedPipeClient
  57. {
  58. enum kIOState {kIdle = 0, kConnecting, kReading, kWriting};
  59. private:
  60. bool fPendingIO;
  61. kIOState fIOState;
  62. OVERLAPPED fOverlap;
  63. public:
  64. JackWinAsyncNamedPipeClient();
  65. JackWinAsyncNamedPipeClient(HANDLE pipe, bool pending);
  66. virtual ~JackWinAsyncNamedPipeClient();
  67. virtual int Read(void* data, int len);
  68. virtual int Write(void* data, int len);
  69. HANDLE GetEvent()
  70. {
  71. return (HANDLE)fOverlap.hEvent;
  72. }
  73. kIOState GetIOState()
  74. {
  75. return fIOState;
  76. }
  77. bool GetPending()
  78. {
  79. return fPendingIO;
  80. }
  81. int FinishIO();
  82. };
  83. /*!
  84. \brief Server named pipe.
  85. */
  86. class JackWinNamedPipeServer : public JackWinNamedPipe
  87. {
  88. public:
  89. JackWinNamedPipeServer(): JackWinNamedPipe()
  90. {}
  91. virtual ~JackWinNamedPipeServer()
  92. {}
  93. virtual int Bind(const char* dir, int which);
  94. virtual int Bind(const char* dir, const char* name, int which);
  95. virtual bool Accept();
  96. virtual JackWinNamedPipeClient* AcceptClient();
  97. int Close();
  98. };
  99. /*!
  100. \brief Server async named pipe.
  101. */
  102. class JackWinAsyncNamedPipeServer : public JackWinNamedPipeServer
  103. {
  104. public:
  105. JackWinAsyncNamedPipeServer(): JackWinNamedPipeServer()
  106. {}
  107. virtual ~JackWinAsyncNamedPipeServer()
  108. {}
  109. int Bind(const char* dir, int which);
  110. int Bind(const char* dir, const char* name, int which);
  111. bool Accept();
  112. JackWinNamedPipeClient* AcceptClient();
  113. int Close();
  114. };
  115. } // end of namespace
  116. #endif