Joedb 10.3.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Server_Connection_Builder.h
Go to the documentation of this file.
1#ifndef joedb_Server_Connection_Builder_declared
2#define joedb_Server_Connection_Builder_declared
3
6
7#include <cmath>
8
9namespace joedb
10{
11 /// @ingroup ui
13 {
14 protected:
15 std::unique_ptr<Connector> connector;
16 std::unique_ptr<Connection> connection;
17
18 public:
19 virtual void build_connector(Arguments &arguments) = 0;
20 virtual std::string get_connection_parameters() const = 0;
21
22 std::string get_parameters_description() const override final
23 {
24 return "[--keep_alive <seconds>] " + get_connection_parameters();
25 }
26
28 (
29 Logger &logger,
30 Arguments &arguments,
31 Abstract_File *file
32 ) override
33 {
34 const float keep_alive_interval = arguments.next_option<float>
35 (
36 "keep_alive",
37 "<seconds>",
38 0.0f
39 );
40
41 build_connector(arguments);
42
43 if (!connector)
44 return nullptr;
45
46 connector->set_keep_alive_interval
47 (
48 std::chrono::milliseconds(std::lround(keep_alive_interval * 1000.0f))
49 );
50
51 if (file)
52 connection = std::make_unique<Robust_Connection>(*connector, logger);
53 else
54 connection = std::make_unique<Server_File>(*connector, logger);
55
56 return connection.get();
57 }
58 };
59}
60
61#endif
Class for conveniently parsing command-line arguments.
Definition Arguments.h:19
T next_option(const char *name, const char *description, T default_value)
Definition Arguments.h:117
Connection * build(Logger &logger, Arguments &arguments, Abstract_File *file) override
std::unique_ptr< Connector > connector
virtual std::string get_connection_parameters() const =0
virtual void build_connector(Arguments &arguments)=0
std::unique_ptr< Connection > connection
std::string get_parameters_description() const override final