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.

95 lines
3.4KB

  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. #pragma once
  18. //==============================================================================
  19. /**
  20. An object that waits for client sockets to connect to a port on this host, and
  21. creates InterprocessConnection objects for each one.
  22. To use this, create a class derived from it which implements the createConnectionObject()
  23. method, so that it creates suitable connection objects for each client that tries
  24. to connect.
  25. @see InterprocessConnection
  26. */
  27. class JUCE_API InterprocessConnectionServer : private Thread
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates an uninitialised server object.
  32. */
  33. InterprocessConnectionServer();
  34. /** Destructor. */
  35. ~InterprocessConnectionServer();
  36. //==============================================================================
  37. /** Starts an internal thread which listens on the given port number.
  38. While this is running, in another process tries to connect with the
  39. InterprocessConnection::connectToSocket() method, this object will call
  40. createConnectionObject() to create a connection to that client.
  41. Use stop() to stop the thread running.
  42. @param portNumber The port on which the server will receive
  43. connections
  44. @param bindAddress The address on which the server will listen
  45. for connections. An empty string indicates
  46. that it should listen on all addresses
  47. assigned to this machine.
  48. @see createConnectionObject, stop
  49. */
  50. bool beginWaitingForSocket (int portNumber, const String& bindAddress = String());
  51. /** Terminates the listener thread, if it's active.
  52. @see beginWaitingForSocket
  53. */
  54. void stop();
  55. protected:
  56. /** Creates a suitable connection object for a client process that wants to
  57. connect to this one.
  58. This will be called by the listener thread when a client process tries
  59. to connect, and must return a new InterprocessConnection object that will
  60. then run as this end of the connection.
  61. @see InterprocessConnection
  62. */
  63. virtual InterprocessConnection* createConnectionObject() = 0;
  64. private:
  65. //==============================================================================
  66. ScopedPointer<StreamingSocket> socket;
  67. void run() override;
  68. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InterprocessConnectionServer)
  69. };