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.

103 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #pragma once
  24. //==============================================================================
  25. /**
  26. An object that waits for client sockets to connect to a port on this host, and
  27. creates InterprocessConnection objects for each one.
  28. To use this, create a class derived from it which implements the createConnectionObject()
  29. method, so that it creates suitable connection objects for each client that tries
  30. to connect.
  31. @see InterprocessConnection
  32. */
  33. class JUCE_API InterprocessConnectionServer : private Thread
  34. {
  35. public:
  36. //==============================================================================
  37. /** Creates an uninitialised server object.
  38. */
  39. InterprocessConnectionServer();
  40. /** Destructor. */
  41. ~InterprocessConnectionServer();
  42. //==============================================================================
  43. /** Starts an internal thread which listens on the given port number.
  44. While this is running, in another process tries to connect with the
  45. InterprocessConnection::connectToSocket() method, this object will call
  46. createConnectionObject() to create a connection to that client.
  47. Use stop() to stop the thread running.
  48. @param portNumber The port on which the server will receive
  49. connections
  50. @param bindAddress The address on which the server will listen
  51. for connections. An empty string indicates
  52. that it should listen on all addresses
  53. assigned to this machine.
  54. @see createConnectionObject, stop
  55. */
  56. bool beginWaitingForSocket (int portNumber, const String& bindAddress = String());
  57. /** Terminates the listener thread, if it's active.
  58. @see beginWaitingForSocket
  59. */
  60. void stop();
  61. protected:
  62. /** Creates a suitable connection object for a client process that wants to
  63. connect to this one.
  64. This will be called by the listener thread when a client process tries
  65. to connect, and must return a new InterprocessConnection object that will
  66. then run as this end of the connection.
  67. @see InterprocessConnection
  68. */
  69. virtual InterprocessConnection* createConnectionObject() = 0;
  70. private:
  71. //==============================================================================
  72. ScopedPointer<StreamingSocket> socket;
  73. void run() override;
  74. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InterprocessConnectionServer)
  75. };