Loading...
Searching...
No Matches
juce_NetworkServiceDiscovery.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
struct NetworkServiceDiscovery
{
struct Advertiser : private Thread
{
Advertiser (const String& serviceTypeUID,
const String& serviceDescription,
int broadcastPort,
int connectionPort,
RelativeTime minTimeBetweenBroadcasts = RelativeTime::seconds (1.5));
~Advertiser() override;
private:
XmlElement message;
const int broadcastPort;
const RelativeTime minInterval;
DatagramSocket socket { true };
void run() override;
void sendBroadcast();
};
//==============================================================================
struct Service
{
String instanceID;
String description;
IPAddress address;
int port;
Time lastSeen;
};
//==============================================================================
struct AvailableServiceList : private Thread,
private AsyncUpdater
{
AvailableServiceList (const String& serviceTypeUID, int broadcastPort);
~AvailableServiceList() override;
std::function<void()> onChange;
std::vector<Service> getServices() const;
private:
DatagramSocket socket { true };
String serviceTypeUID;
CriticalSection listLock;
std::vector<Service> services;
void run() override;
void handleAsyncUpdate() override;
void handleMessage (const XmlElement&);
void handleMessage (const Service&);
void removeTimedOutServices();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AvailableServiceList)
};
};
} // namespace juce
juce::AsyncUpdater::handleAsyncUpdate
virtual void handleAsyncUpdate()=0
juce::AsyncUpdater::AsyncUpdater
AsyncUpdater()
Definition juce_AsyncUpdater.cpp:44
juce::CriticalSection
Definition juce_CriticalSection.h:43
juce::DatagramSocket
Definition juce_Socket.h:265
juce::IPAddress
Definition juce_IPAddress.h:33
juce::RelativeTime
Definition juce_RelativeTime.h:37
juce::RelativeTime::seconds
static RelativeTime seconds(double seconds) noexcept
Definition juce_RelativeTime.cpp:33
juce::String
Definition juce_String.h:53
juce::Thread::Thread
Thread(const String &threadName, size_t threadStackSize=osDefaultStackSize)
Definition juce_Thread.cpp:26
juce::Thread::run
virtual void run()=0
juce::Time
Definition juce_Time.h:37
juce::XmlElement
Definition juce_XmlElement.h:83
juce::NetworkServiceDiscovery::Advertiser::Advertiser
Advertiser(const String &serviceTypeUID, const String &serviceDescription, int broadcastPort, int connectionPort, RelativeTime minTimeBetweenBroadcasts=RelativeTime::seconds(1.5))
Definition juce_NetworkServiceDiscovery.cpp:31
juce::NetworkServiceDiscovery::Advertiser::~Advertiser
~Advertiser() override
Definition juce_NetworkServiceDiscovery.cpp:47
juce::NetworkServiceDiscovery::AvailableServiceList
Definition juce_NetworkServiceDiscovery.h:104
juce::NetworkServiceDiscovery::AvailableServiceList::AvailableServiceList
AvailableServiceList(const String &serviceTypeUID, int broadcastPort)
Definition juce_NetworkServiceDiscovery.cpp:87
juce::NetworkServiceDiscovery::AvailableServiceList::onChange
std::function< void()> onChange
Definition juce_NetworkServiceDiscovery.h:117
juce::NetworkServiceDiscovery::AvailableServiceList::~AvailableServiceList
~AvailableServiceList() override
Definition juce_NetworkServiceDiscovery.cpp:98
juce::NetworkServiceDiscovery::AvailableServiceList::getServices
std::vector< Service > getServices() const
Definition juce_NetworkServiceDiscovery.cpp:128
juce::NetworkServiceDiscovery
Definition juce_NetworkServiceDiscovery.h:35
juce::NetworkServiceDiscovery::Service::instanceID
String instanceID
Definition juce_NetworkServiceDiscovery.h:82
juce::NetworkServiceDiscovery::Service::lastSeen
Time lastSeen
Definition juce_NetworkServiceDiscovery.h:86
juce::NetworkServiceDiscovery::Service::port
int port
Definition juce_NetworkServiceDiscovery.h:85
juce::NetworkServiceDiscovery::Service::description
String description
Definition juce_NetworkServiceDiscovery.h:83
juce::NetworkServiceDiscovery::Service::address
IPAddress address
Definition juce_NetworkServiceDiscovery.h:84
juce::NetworkServiceDiscovery::Service
Definition juce_NetworkServiceDiscovery.h:81