4#include "Stroika/Frameworks/StroikaPreComp.h"
12#include "Stroika/Foundation/Execution/CommandLine.h"
13#include "Stroika/Foundation/Execution/SignalHandlers.h"
14#include "Stroika/Foundation/Execution/TimeOutException.h"
15#include "Stroika/Foundation/Execution/WaitableEvent.h"
16#include "Stroika/Foundation/IO/Network/HTTP/Headers.h"
17#include "Stroika/Foundation/IO/Network/Listener.h"
19#include "Stroika/Frameworks/UPnP/SSDP/Server/BasicServer.h"
20#include "Stroika/Frameworks/WebServer/ConnectionManager.h"
27using namespace Stroika::Foundation::IO;
29using namespace Stroika::Frameworks;
30using namespace Stroika::Frameworks::UPnP;
31using namespace Stroika::Frameworks::UPnP::SSDP;
39 static inline const HTTP::Headers kDefaultResponseHeaders_{[] () {
41 h.
server =
"stroika-ssdp-server-demo"sv;
44 WebServerForDeviceDescription_ (uint16_t webServerPortNumber,
const DeviceDescription& dd)
49 Response& response = m.rwResponse ();
50 response.contentType = DataExchange::InternetMediaTypes::kXML;
51 response.write (Stroika::Frameworks::UPnP::Serialize (dd));
54 Options{.
fMaxConnections = 3, .fDefaultResponseHeaders = kDefaultResponseHeaders_}}
60int main ([[maybe_unused]]
int argc, [[maybe_unused]]
const char* argv[])
66#if qStroika_Foundation_Common_Platform_POSIX
71 uint16_t portForOurWS = 8080;
73 const CommandLine::Option kQuitAfterO_{.fLongName =
"quit-after"sv, .fSupportsArgument =
true};
76 if (
auto o = cmdLine.GetArgument (kQuitAfterO_)) {
77 quitAfter =
Time::DurationSeconds{Characters::FloatConversion::ToFloat<Time::DurationSeconds::rep> (*o)};
80 if (cmdLine.Has (StandardCommandLineOptions::kHelp)) {
81 cerr << cmdLine.GenerateUsage (kAllOptions_) << endl;
91 d.fServer = UPnP::SSDP::MakeServerHeaderValue (
"MyStroikaBasedSampleProduct/1.0"sv);
92 d.fDeviceID = UPnP::MungePrimaryMacAddrIntoBaseDeviceID (
"315CAAE0-1335-57BF-A178-24C9EE756627"sv);
95 deviceInfo.fPresentationURL =
URI{
"http://www.sophists.com/"sv};
96 deviceInfo.fDeviceType =
"urn:sophists.com:device:deviceType:1.0"sv;
97 deviceInfo.fManufactureName =
"Sophist Solutions, Inc."sv;
98 deviceInfo.fFriendlyName =
"Sophist Solutions fake device"sv;
99 deviceInfo.fManufacturingURL =
URI{
"http://www.sophists.com/"sv};
100 deviceInfo.fModelDescription =
"long user-friendly title"sv;
101 deviceInfo.fModelName =
"model name"sv;
102 deviceInfo.fModelNumber =
"model number"sv;
103 deviceInfo.fModelURL =
URI{
"http://www.sophists.com/"sv};
104 deviceInfo.fSerialNumber =
"manufacturer's serial number"sv;
105 deviceInfo.
fUDN =
"uuid:" + d.fDeviceID;
107 WebServerForDeviceDescription_ deviceWS{portForOurWS, deviceInfo};
108 BasicServer b{d, deviceInfo};
112 cerr <<
"Timed out - so - exiting..." << endl;
116 cerr <<
"Exception - " << Characters::ToString (current_exception ()) <<
" - terminating..." << endl;
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
#define Stroika_Foundation_Debug_OptionalizeTraceArgs(...)
A generalization of a vector: a container whose elements are keyed by the natural numbers.
nonvirtual void SetSignalHandlers(SignalID signal)
static const SignalHandler kIGNORED
static SignalHandlerRegistry sThe
nonvirtual void Wait(Time::DurationSeconds timeout=Time::kInfinity)
nonvirtual void SetScheme(const optional< SchemeType > &scheme)
handle the multicast part of UPnP SSDP - listening for searches and sending periodic notifications
Traversal::Iterable< SocketAddress > SocketAddresses(const Traversal::Iterable< InternetAddress > &internetAddresses, PortType portNumber)
Traversal::Iterable< InternetAddress > InternetAddresses_Any(InternetProtocol::IP::IPVersionSupport ipSupport=InternetProtocol::IP::IPVersionSupport::eDEFAULT)
Having explicit activator object allows for users to control the starting/stopping of facility in a m...
optional< unsigned int > fMaxConnections