OpenShot Library | libopenshot-audio  0.2.0
juce_InterprocessConnectionServer.h
1 
2 /** @weakgroup juce_events-interprocess
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  An object that waits for client sockets to connect to a port on this host, and
33  creates InterprocessConnection objects for each one.
34 
35  To use this, create a class derived from it which implements the createConnectionObject()
36  method, so that it creates suitable connection objects for each client that tries
37  to connect.
38 
39  @see InterprocessConnection
40 
41  @tags{Events}
42 */
44 {
45 public:
46  //==============================================================================
47  /** Creates an uninitialised server object.
48  */
50 
51  /** Destructor. */
52  ~InterprocessConnectionServer() override;
53 
54  //==============================================================================
55  /** Starts an internal thread which listens on the given port number.
56 
57  While this is running, if another process tries to connect with the
58  InterprocessConnection::connectToSocket() method, this object will call
59  createConnectionObject() to create a connection to that client.
60 
61  Use stop() to stop the thread running.
62 
63  @param portNumber The port on which the server will receive
64  connections
65  @param bindAddress The address on which the server will listen
66  for connections. An empty string indicates
67  that it should listen on all addresses
68  assigned to this machine.
69 
70  @see createConnectionObject, stop
71  */
72  bool beginWaitingForSocket (int portNumber, const String& bindAddress = String());
73 
74  /** Terminates the listener thread, if it's active.
75 
76  @see beginWaitingForSocket
77  */
78  void stop();
79 
80  /** Returns the local port number to which this server is currently bound.
81 
82  This is useful if you need to know to which port the OS has actually bound your
83  socket when calling beginWaitingForSocket with a port number of zero.
84 
85  Returns -1 if the function fails.
86  */
87  int getBoundPort() const noexcept;
88 
89 protected:
90  /** Creates a suitable connection object for a client process that wants to
91  connect to this one.
92 
93  This will be called by the listener thread when a client process tries
94  to connect, and must return a new InterprocessConnection object that will
95  then run as this end of the connection.
96 
97  @see InterprocessConnection
98  */
99  virtual InterprocessConnection* createConnectionObject() = 0;
100 
101 private:
102  //==============================================================================
103  std::unique_ptr<StreamingSocket> socket;
104 
105  void run() override;
106 
107  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InterprocessConnectionServer)
108 };
109 
110 } // namespace juce
111 
112 /** @}*/
#define JUCE_API
This macro is added to all JUCE public class declarations.
The JUCE String class!
Definition: juce_String.h:42
An object that waits for client sockets to connect to a port on this host, and creates InterprocessCo...
Encapsulates a thread.
Definition: juce_Thread.h:46
Manages a simple two-way messaging connection to another process, using either a socket or a named pi...