OpenShot Audio Library | OpenShotAudio: juce_InterprocessConnectionServer.cpp Source File

OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_InterprocessConnectionServer.cpp
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26InterprocessConnectionServer::InterprocessConnectionServer() : Thread ("JUCE IPC server")
27{
28}
29
30InterprocessConnectionServer::~InterprocessConnectionServer()
31{
32 stop();
33}
34
35//==============================================================================
36 bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber, const String& bindAddress)
37{
38 stop();
39
40 socket.reset (new StreamingSocket());
41
42 if (socket->createListener (portNumber, bindAddress))
43 {
44 startThread();
45 return true;
46 }
47
48 socket.reset();
49 return false;
50}
51
52 void InterprocessConnectionServer::stop()
53{
54 signalThreadShouldExit();
55
56 if (socket != nullptr)
57 socket->close();
58
59 stopThread (4000);
60 socket.reset();
61}
62
63 int InterprocessConnectionServer::getBoundPort() const noexcept
64{
65 return (socket == nullptr) ? -1 : socket->getBoundPort();
66}
67
68void InterprocessConnectionServer::run()
69{
70 while ((! threadShouldExit()) && socket != nullptr)
71 {
72 std::unique_ptr<StreamingSocket> clientSocket (socket->waitForNextConnection());
73
74 if (clientSocket != nullptr)
75 if (auto* newConnection = createConnectionObject())
76 newConnection->initialiseWithSocket (clientSocket.release());
77 }
78}
79
80} // namespace juce
juce::InterprocessConnectionServer::getBoundPort
int getBoundPort() const noexcept
Definition: juce_InterprocessConnectionServer.cpp:63
juce::InterprocessConnectionServer::beginWaitingForSocket
bool beginWaitingForSocket(int portNumber, const String &bindAddress=String())
Definition: juce_InterprocessConnectionServer.cpp:36
juce::InterprocessConnectionServer::createConnectionObject
virtual InterprocessConnection * createConnectionObject()=0
juce::InterprocessConnectionServer::InterprocessConnectionServer
InterprocessConnectionServer()
Definition: juce_InterprocessConnectionServer.cpp:26
juce::InterprocessConnectionServer::~InterprocessConnectionServer
~InterprocessConnectionServer() override
Definition: juce_InterprocessConnectionServer.cpp:30
juce::InterprocessConnectionServer::stop
void stop()
Definition: juce_InterprocessConnectionServer.cpp:52
juce::StreamingSocket
Definition: juce_Socket.h:38
juce::String
Definition: juce_String.h:39
juce::Thread
Definition: juce_Thread.h:43
juce::Thread::startThread
void startThread()
Definition: juce_Thread.cpp:122
juce::Thread::threadShouldExit
bool threadShouldExit() const
Definition: juce_Thread.cpp:182
juce::Thread::stopThread
bool stopThread(int timeOutMilliseconds)
Definition: juce_Thread.cpp:213
juce::Thread::signalThreadShouldExit
void signalThreadShouldExit()
Definition: juce_Thread.cpp:176