50 : fNotifyingOn_{Memory::MakeSharedPtr<Execution::Synchronized<
InterfacesByID>> ()}
52 Require (options.fFrequencyInfo.fRepeatInterval < options.fFrequencyInfo.fMaxAge);
57 advertisements.
Apply ([] ([[maybe_unused]]
const auto& a) { Require (not a.fTarget.empty ()); });
65 static constexpr Execution::Activity kActivity_{
"creating SSDP sockets in PeriodicNotifier"sv};
70 sockets += make_pair (s, UPnP::SSDP::V4::kSocketAddress);
75 sockets += make_pair (s, UPnP::SSDP::V6::kSocketAddress);
79 if constexpr (qStroika_Foundation_Debug_DefaultTracingOn) {
81 for ([[maybe_unused]]
const auto& a : advertisements) {
82 DbgTrace (
"(alive,usn={},...)"_f, a.fUSN);
88 if (local.GetAddressFamily () == InternetAddress::AddressFamily::V4) {
97 shared_ptr<mutex> sendingNotifies = Memory::MakeSharedPtr<mutex> ();
98 shared_ptr<Execution::Synchronized<InterfacesByID>> notifyingOn = fNotifyingOn_;
100#if USE_NOISY_TRACE_IN_THIS_MODULE_
102 for ([[maybe_unused]]
const auto& a : advertisements) {
103#if USE_NOISY_TRACE_IN_THIS_MODULE_
106 msg +=
"location=" sz + a.fLocation +
", " sz;
107 msg +=
"ST=" sz + a.fST +
", " sz;
108 msg +=
"USN=" sz + a.fUSN;
113 [[maybe_unused]] lock_guard critSec{*sendingNotifies};
118 interfaces = SSDP::Private_::GetSSDPInterfaces (interfaceFilter);
120 catch (
const Execution::Thread::AbortException&) {
124 DbgTrace (
"Ignoring inability to send SSDP notify packets: {} (try again later)"_f, current_exception ());
126 for (
unsigned int nthSet = 0; nthSet < kSetsSent_; ++nthSet) {
132 for (
const pair<ConnectionlessSocket::Ptr, SocketAddress>& s : sockets) {
135 optional<InternetAddress> local = SSDP::Server::Private_::AdvertisableAddress (i, family);
143 goOutOf (s.first, i, *local);
144 for (Advertisement a : advertisements) {
148 s.first.
SendTo (SSDP::Serialize (
"NOTIFY * HTTP/1.1"sv, SearchOrNotify::Notify, a, s.second), s.second);
152 catch (
const Execution::Thread::AbortException&) {
156 DbgTrace (
"Ignoring inability to send SSDP notify packets on {}: {} (try again later)"_f, i.fInterfaceID, current_exception ());
161 notifyingOn->store (sentOn);
164 fSayByebye_ = [sockets, advertisements, sendingNotifies, notifyingOn, goOutOf] () {
165 [[maybe_unused]] lock_guard critSec{*sendingNotifies};
167 for (
unsigned int nthSet = 0; nthSet < kSetsSent_; ++nthSet) {
171 for (
const Interface& i : notifyingOn->load ()) {
172 for (
const pair<ConnectionlessSocket::Ptr, SocketAddress>& s : sockets) {
175 optional<InternetAddress> local = SSDP::Server::Private_::AdvertisableAddress (i, family);
179 goOutOf (s.first, i, *local);
180 for (Advertisement a : advertisements) {
182 s.first.
SendTo (SSDP::Serialize (
"NOTIFY * HTTP/1.1"sv, SearchOrNotify::Notify, a, s.second), s.second);
186 DbgTrace (
"Ignoring inability to send SSDP byebye packets on {}: {}"_f, i.fInterfaceID, current_exception ());
196 fIntervalTimerAdder_ = make_unique<Execution::IntervalTimer::Adder> (callback,
Time::Duration{options.fFrequencyInfo.fRepeatInterval * 0.75},
199 if (options.fFollowNetworkChanges) {
200 fNetworkChanges_ = SSDP::Private_::FollowNetworkChanges ([callback] ()
mutable {