The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

118 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_NAMEDPIPE_JUCEHEADER__
  19. #define __JUCE_NAMEDPIPE_JUCEHEADER__
  20. #include "../streams/juce_OutputStream.h"
  21. #include "../../threads/juce_CriticalSection.h"
  22. //==============================================================================
  23. /**
  24. A cross-process pipe that can have data written to and read from it.
  25. Two or more processes can use these for inter-process communication.
  26. @see InterprocessConnection
  27. */
  28. class JUCE_API NamedPipe
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a NamedPipe. */
  33. NamedPipe();
  34. /** Destructor. */
  35. ~NamedPipe();
  36. //==============================================================================
  37. /** Tries to open a pipe that already exists.
  38. Returns true if it succeeds.
  39. */
  40. bool openExisting (const String& pipeName);
  41. /** Tries to create a new pipe.
  42. Returns true if it succeeds.
  43. */
  44. bool createNewPipe (const String& pipeName);
  45. /** Closes the pipe, if it's open. */
  46. void close();
  47. /** True if the pipe is currently open. */
  48. bool isOpen() const;
  49. /** Returns the last name that was used to try to open this pipe. */
  50. const String getName() const;
  51. //==============================================================================
  52. /** Reads data from the pipe.
  53. This will block until another thread has written enough data into the pipe to fill
  54. the number of bytes specified, or until another thread calls the cancelPendingReads()
  55. method.
  56. If the operation fails, it returns -1, otherwise, it will return the number of
  57. bytes read.
  58. If timeOutMilliseconds is less than zero, it will wait indefinitely, otherwise
  59. this is a maximum timeout for reading from the pipe.
  60. */
  61. int read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds = 5000);
  62. /** Writes some data to the pipe.
  63. If the operation fails, it returns -1, otherwise, it will return the number of
  64. bytes written.
  65. */
  66. int write (const void* sourceBuffer, int numBytesToWrite,
  67. int timeOutMilliseconds = 2000);
  68. /** If any threads are currently blocked on a read operation, this tells them to abort.
  69. */
  70. void cancelPendingReads();
  71. //==============================================================================
  72. juce_UseDebuggingNewOperator
  73. private:
  74. void* internal;
  75. String currentPipeName;
  76. CriticalSection lock;
  77. NamedPipe (const NamedPipe&);
  78. NamedPipe& operator= (const NamedPipe&);
  79. bool openInternal (const String& pipeName, const bool createPipe);
  80. };
  81. #endif // __JUCE_NAMEDPIPE_JUCEHEADER__