Joedb 10.2.1
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 <iostream>
8#include <cmath>
9
10namespace joedb
11{
12 /// @ingroup ui
14 {
15 protected:
16 std::unique_ptr<Connector> connector;
17 std::unique_ptr<Connection> connection;
18
19 public:
20 virtual void build_connector(Arguments &arguments) = 0;
21 virtual std::string get_connection_parameters() const = 0;
22
23 std::string get_parameters_description() const override final
24 {
25 return "[--keep_alive <seconds>] " + get_connection_parameters();
26 }
27
28 Connection *build(Arguments &arguments, Abstract_File *file) override
29 {
30 const float keep_alive_interval = arguments.next_option<float>
31 (
32 "keep_alive",
33 "<seconds>",
34 0.0f
35 );
36
37 build_connector(arguments);
38
39 if (!connector)
40 return nullptr;
41
42 connector->set_keep_alive_interval
43 (
44 std::chrono::milliseconds(std::lround(keep_alive_interval * 1000.0f))
45 );
46
47 if (file)
48 connection = std::make_unique<Robust_Connection>(*connector, &std::cerr);
49 else
50 connection = std::make_unique<Server_File>(*connector, &std::cerr);
51
52 return connection.get();
53 }
54 };
55}
56
57#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
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
Connection * build(Arguments &arguments, Abstract_File *file) override