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.

158 lines
3.5KB

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