Audio plugin host https://kx.studio/carla
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.

105 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. //==============================================================================
  20. /**
  21. An object that waits for client sockets to connect to a port on this host, and
  22. creates InterprocessConnection objects for each one.
  23. To use this, create a class derived from it which implements the createConnectionObject()
  24. method, so that it creates suitable connection objects for each client that tries
  25. to connect.
  26. @see InterprocessConnection
  27. */
  28. class JUCE_API InterprocessConnectionServer : private Thread
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates an uninitialised server object.
  33. */
  34. InterprocessConnectionServer();
  35. /** Destructor. */
  36. ~InterprocessConnectionServer();
  37. //==============================================================================
  38. /** Starts an internal thread which listens on the given port number.
  39. While this is running, in another process tries to connect with the
  40. InterprocessConnection::connectToSocket() method, this object will call
  41. createConnectionObject() to create a connection to that client.
  42. Use stop() to stop the thread running.
  43. @param portNumber The port on which the server will receive
  44. connections
  45. @param bindAddress The address on which the server will listen
  46. for connections. An empty string indicates
  47. that it should listen on all addresses
  48. assigned to this machine.
  49. @see createConnectionObject, stop
  50. */
  51. bool beginWaitingForSocket (int portNumber, const String& bindAddress = String());
  52. /** Terminates the listener thread, if it's active.
  53. @see beginWaitingForSocket
  54. */
  55. void stop();
  56. /** Returns the local port number to which this server is currently bound.
  57. This is useful if you need to know to which port the OS has actually bound your
  58. socket when calling beginWaitingForSocket with a port number of zero.
  59. Returns -1 if the function fails.
  60. */
  61. int getBoundPort() const noexcept;
  62. protected:
  63. /** Creates a suitable connection object for a client process that wants to
  64. connect to this one.
  65. This will be called by the listener thread when a client process tries
  66. to connect, and must return a new InterprocessConnection object that will
  67. then run as this end of the connection.
  68. @see InterprocessConnection
  69. */
  70. virtual InterprocessConnection* createConnectionObject() = 0;
  71. private:
  72. //==============================================================================
  73. ScopedPointer<StreamingSocket> socket;
  74. void run() override;
  75. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InterprocessConnectionServer)
  76. };
  77. } // namespace juce