Stroika Library 3.0d21
 
Loading...
Searching...
No Matches
Samples/WebService/Sources/Main.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Frameworks/StroikaPreComp.h"
5
6#include <iostream>
7
8#include "Stroika/Foundation/Characters/String2Int.h"
10#include "Stroika/Foundation/Containers/Sequence.h"
12#include "Stroika/Foundation/Execution/CommandLine.h"
13#include "Stroika/Foundation/Execution/Module.h"
14#include "Stroika/Foundation/Execution/SignalHandlers.h"
15#include "Stroika/Foundation/Execution/TimeOutException.h"
16#include "Stroika/Foundation/Execution/WaitableEvent.h"
17
18#include "WSImpl.h"
19#include "WebServer.h"
20
21#include "AppVersion.h"
22
23using namespace std;
24
25using namespace Stroika::Foundation;
27using namespace Stroika::Foundation::Execution;
28
31
32using namespace StroikaSample::WebServices;
33
34int main (int argc, const char* argv[])
35{
36 CommandLine cmdLine{argc, argv};
37 Debug::TraceContextBumper ctx{"main", "argv={}"_f, cmdLine};
39#if qStroika_Foundation_Common_Platform_POSIX
41#endif
42 uint16_t portNumber = 8080;
43 Time::DurationSeconds quitAfter = Time::kInfinity;
44
45 const CommandLine::Option kPortO_{.fLongName = "port"sv, .fSupportsArgument = true};
46 const CommandLine::Option kQuitAfterO_{.fLongName = "quit-after"sv, .fSupportsArgument = true};
47
48 try {
49 cmdLine.Validate ({kPortO_, kQuitAfterO_});
50
51 if (auto o = cmdLine.GetArgument (kPortO_)) {
52 portNumber = Characters::String2Int<uint16_t> (*o);
53 }
54 if (auto o = cmdLine.GetArgument (kQuitAfterO_)) {
55 quitAfter = Time::DurationSeconds{Characters::FloatConversion::ToFloat<Time::DurationSeconds::rep> (*o)};
56 }
57
58 WebServer myWebServer{portNumber, make_shared<WSImpl> ()}; // listen and dispatch while this object exists
59 WaitableEvent{}.Wait (quitAfter); // wait quitAfter seconds, or til user hits ctrl-c
60 }
61 catch (const TimeOutException&) {
62 cerr << "Timed out - so - exiting..." << endl;
63 return EXIT_SUCCESS;
64 }
65 catch (...) {
66 cerr << "Error encountered: " << Characters::ToString (current_exception ()) << " - terminating..." << endl;
67 return EXIT_FAILURE;
68 }
69 return EXIT_SUCCESS;
70}
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
Definition Realtime.h:57
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
A generalization of a vector: a container whose elements are keyed by the natural numbers.
nonvirtual void Wait(Time::DurationSeconds timeout=Time::kInfinity)
Create a format-string (see std::wformat_string or Stroika FormatString, or python 'f' strings.
STL namespace.