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.

159 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 <assert.h>
  18. #include <stdio.h>
  19. #include <windows.h>
  20. namespace Jack
  21. {
  22. class JackWinNamedPipe
  23. {
  24. protected:
  25. HANDLE fNamedPipe;
  26. char fName[256];
  27. public:
  28. JackWinNamedPipe(): fNamedPipe(INVALID_HANDLE_VALUE)
  29. {}
  30. JackWinNamedPipe(HANDLE pipe): fNamedPipe(pipe)
  31. {}
  32. virtual ~JackWinNamedPipe()
  33. {}
  34. virtual int Read(void* data, int len);
  35. virtual int Write(void* data, int len);
  36. };
  37. /*!
  38. \brief Client named pipe.
  39. */
  40. class JackWinNamedPipeClient : public JackWinNamedPipe
  41. {
  42. public:
  43. JackWinNamedPipeClient(): JackWinNamedPipe()
  44. {}
  45. JackWinNamedPipeClient(HANDLE pipe): JackWinNamedPipe(pipe)
  46. {}
  47. virtual ~JackWinNamedPipeClient()
  48. {}
  49. virtual int Connect(const char* dir, int which);
  50. virtual int Connect(const char* dir, const char* name, int which);
  51. virtual int Close();
  52. virtual void SetReadTimeOut(long sec);
  53. virtual void SetWriteTimeOut(long sec);
  54. };
  55. class JackWinAsyncNamedPipeClient : public JackWinNamedPipeClient
  56. {
  57. enum kIOState {kIdle = 0, kConnecting, kReading, kWriting};
  58. private:
  59. bool fPendingIO;
  60. kIOState fIOState;
  61. OVERLAPPED fOverlap;
  62. public:
  63. JackWinAsyncNamedPipeClient();
  64. JackWinAsyncNamedPipeClient(HANDLE pipe, bool pending);
  65. virtual ~JackWinAsyncNamedPipeClient();
  66. virtual int Read(void* data, int len);
  67. virtual int Write(void* data, int len);
  68. HANDLE GetEvent()
  69. {
  70. return (HANDLE)fOverlap.hEvent;
  71. }
  72. kIOState GetIOState()
  73. {
  74. return fIOState;
  75. }
  76. bool GetPending()
  77. {
  78. return fPendingIO;
  79. }
  80. int FinishIO();
  81. };
  82. /*!
  83. \brief Server named pipe.
  84. */
  85. class JackWinNamedPipeServer : public JackWinNamedPipe
  86. {
  87. public:
  88. JackWinNamedPipeServer(): JackWinNamedPipe()
  89. {}
  90. virtual ~JackWinNamedPipeServer()
  91. {}
  92. virtual int Bind(const char* dir, int which);
  93. virtual int Bind(const char* dir, const char* name, int which);
  94. virtual bool Accept();
  95. virtual JackWinNamedPipeClient* AcceptClient();
  96. int Close();
  97. };
  98. /*!
  99. \brief Server async named pipe.
  100. */
  101. class JackWinAsyncNamedPipeServer : public JackWinNamedPipeServer
  102. {
  103. public:
  104. JackWinAsyncNamedPipeServer(): JackWinNamedPipeServer()
  105. {}
  106. virtual ~JackWinAsyncNamedPipeServer()
  107. {}
  108. int Bind(const char* dir, int which);
  109. int Bind(const char* dir, const char* name, int which);
  110. bool Accept();
  111. JackWinNamedPipeClient* AcceptClient();
  112. int Close();
  113. };
  114. } // end of namespace
  115. #endif