Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
BasicServer.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#ifndef _Stroika_Frameworks_UPnP_SSDP_Server_BasicServer_h_
5#define _Stroika_Frameworks_UPnP_SSDP_Server_BasicServer_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
10#include "Stroika/Foundation/Common/Common.h"
11
12#include "Stroika/Frameworks/UPnP/Device.h"
13#include "Stroika/Frameworks/UPnP/DeviceDescription.h"
14#include "Stroika/Frameworks/UPnP/SSDP/Server/PeriodicNotifier.h"
15#include "Stroika/Frameworks/UPnP/SSDP/Server/SearchResponder.h"
16
17/*
18 * \file
19 *
20 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
21 */
22
23namespace Stroika::Frameworks::UPnP::SSDP::Server {
24
25 /**
26 * \brief SSDP Server Implementation: handle the multicast part of UPnP SSDP - listening for searches and sending periodic notifications
27 *
28 * When this object is instantiated, it fires off threads to notify and respond to
29 * searches. When it is destroyed, it stops doing that, and says ssdp:byebye - so control points drop the device at once,
30 * rather than when its announcements' max-age runs out.
31 *
32 * \note Caller must separately handle the HTTP requests for device discovery (see SSDP server sample)
33 *
34 * \note (since Stroika v3)requires Execution::IntervalTimer::Manager::Activator intervalTimerMgrActivator
35 */
37 public:
39
40 public:
41 /**
42 * \par Example Usage
43 * \code
44 * BasicServer server{device, deviceDescription, LocationFromBindings (deviceWS.bindings ()),
45 * BasicServer::Options{.fIPVersion = IPVersionSupport::eIPV4Only}};
46 * \endcode
47 */
48 struct Options {
49 /**
50 * How often to send the NOTIFYs, and how long they - and the answers to searches - say they are good for (as
51 * PeriodicNotifier::FrequencyInfo describes).
52 */
54
55 /**
56 * Which SSDP channels to use: IPv4 (239.255.255.250) and/or IPv6 (ff02::c). Each LOCATION is of the same family as
57 * its channel.
58 */
59 IO::Network::InternetProtocol::IP::IPVersionSupport fIPVersion{IO::Network::InternetProtocol::IP::IPVersionSupport::eDEFAULT};
60
61 /**
62 * The TTL (IPv6: hop limit) of each NOTIFY: how many routers it may cross (@see kDefaultMulticastTTL). Answers to
63 * searches are unicast, and not limited.
64 */
66
67 /**
68 * Which network interfaces to advertise, and answer searches, on - asked each time SSDP lists them (@see
69 * SSDP::InterfaceFilter). To advertise there with no LOCATION, or some other one, @see LocationProvider.
70 */
72
73 /**
74 * When a network appears, advertise there right away, and listen for searches there too.
75 * It costs a LinkMonitor (all share one thread, waiting on the OS's address-change notifications) - and, only while
76 * a burst of changes settles and is acted on, a thread of its own. Where the OS cannot tell (e.g. some containers),
77 * it is just not done. (Two of each: one for the NOTIFYs, one for the answers.)
78 */
80 };
81 static const Options kDefaultOptions;
82
83 public:
84 /**
85 * Advertise the device on every network interface, each with the LOCATION location gives for it: where its device
86 * description is to be found, from that network (@see LocationProvider). For a Stroika web server, that is usually
87 * LocationFromBindings (theWebServer.bindings ()). d.fLocation is not used.
88 *
89 * It is advertised - so a search for any of these finds it - as a root device (upnp:rootdevice), by its UDN ("uuid:" and
90 * d.fDeviceID), by its device type (dd.fDeviceType), and by each of its service types (dd.fServices' - once, however many
91 * of its services are of it): the advertisements the UPnP Device Architecture (1.1, section 1.1.2) lists for a root device.
92 */
93 BasicServer (const Device& d, const DeviceDescription& dd, const LocationProvider& location, const Options& options = kDefaultOptions);
94 BasicServer (const BasicServer&) = delete;
95 const BasicServer& operator= (const BasicServer&) = delete;
96
97 public:
98 /**
99 * \brief The network interfaces it is advertising on now: those its NOTIFYs last went out of, and those it listens for
100 * searches on. One on both is listed once (matched by fInterfaceID). Safe to call from any thread.
101 */
103
104 private:
105 class Rep_;
106 shared_ptr<Rep_> fRep_;
107 };
108
109}
110
111/*
112 ********************************************************************************
113 ***************************** Implementation Details ***************************
114 ********************************************************************************
115 */
116#include "BasicServer.inl"
117
118#endif /*_Stroika_Frameworks_UPnP_SSDP_Server_BasicServer_h_*/
bool DefaultInterfaceFilter(const Foundation::IO::Network::Interface &i)
SSDP's default InterfaceFilter: an interface that is running, and not loopback (whose multicast suppo...
constexpr uint8_t kDefaultMulticastTTL
The TTL (IPv6: hop limit) multicast SSDP packets - NOTIFYs and M-SEARCHes - go out with,...
function< bool(const Foundation::IO::Network::Interface &i)> InterfaceFilter
Which network interfaces SSDP is to talk on - asked of each interface every time SSDP lists them,...
a cross between Mapping<KEY, T> and Collection<T> and Set<T>
SSDP Server Implementation: handle the multicast part of UPnP SSDP - listening for searches and sendi...
Definition BasicServer.h:36
nonvirtual IO::Network::InterfacesByID GetNetworkInterfaces() const
The network interfaces it is advertising on now: those its NOTIFYs last went out of,...
IO::Network::InternetProtocol::IP::IPVersionSupport fIPVersion
Definition BasicServer.h:59