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.

96 lines
3.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCE_INTERPROCESSCONNECTIONSERVER_JUCEHEADER__
  18. #define __JUCE_INTERPROCESSCONNECTIONSERVER_JUCEHEADER__
  19. #include "juce_InterprocessConnection.h"
  20. //==============================================================================
  21. /**
  22. An object that waits for client sockets to connect to a port on this host, and
  23. creates InterprocessConnection objects for each one.
  24. To use this, create a class derived from it which implements the createConnectionObject()
  25. method, so that it creates suitable connection objects for each client that tries
  26. to connect.
  27. @see InterprocessConnection
  28. */
  29. class JUCE_API InterprocessConnectionServer : private Thread
  30. {
  31. public:
  32. //==============================================================================
  33. /** Creates an uninitialised server object.
  34. */
  35. InterprocessConnectionServer();
  36. /** Destructor. */
  37. ~InterprocessConnectionServer();
  38. //==============================================================================
  39. /** Starts an internal thread which listens on the given port number.
  40. While this is running, in another process tries to connect with the
  41. InterprocessConnection::connectToSocket() method, this object will call
  42. createConnectionObject() to create a connection to that client.
  43. Use stop() to stop the thread running.
  44. @see createConnectionObject, stop
  45. */
  46. bool beginWaitingForSocket (int portNumber);
  47. /** Terminates the listener thread, if it's active.
  48. @see beginWaitingForSocket
  49. */
  50. void stop();
  51. protected:
  52. /** Creates a suitable connection object for a client process that wants to
  53. connect to this one.
  54. This will be called by the listener thread when a client process tries
  55. to connect, and must return a new InterprocessConnection object that will
  56. then run as this end of the connection.
  57. @see InterprocessConnection
  58. */
  59. virtual InterprocessConnection* createConnectionObject() = 0;
  60. private:
  61. //==============================================================================
  62. ScopedPointer <StreamingSocket> socket;
  63. void run() override;
  64. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InterprocessConnectionServer)
  65. };
  66. #endif // __JUCE_INTERPROCESSCONNECTIONSERVER_JUCEHEADER__