Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_push.cpp
Go to the documentation of this file.
5#include "joedb/Signal.h"
6
7#include <iostream>
8#include <limits>
9#include <thread>
10#include <chrono>
11#include <cstring>
12#include <cstdlib>
13
14namespace joedb
15{
16 ////////////////////////////////////////////////////////////////////////////
17 static int push(Arguments &arguments)
18 ////////////////////////////////////////////////////////////////////////////
19 {
20 const bool follow = arguments.has_flag("follow");
21 const int64_t until_checkpoint = arguments.get_option<int64_t>
22 (
23 "until",
24 "checkpoint",
25 std::numeric_limits<int64_t>::max()
26 );
27
28 Client_Parser client_parser
29 (
32 arguments
33 );
34
35 if (!client_parser.get())
36 {
37 arguments.print_help(std::cerr) << '\n';
38 client_parser.print_help(std::cerr);
39 return 1;
40 }
41
42 Client &client = *client_parser.get();
43 Readonly_Client *readonly_client = dynamic_cast<Readonly_Client*>(&client);
44 JOEDB_RELEASE_ASSERT(readonly_client);
45
46 if (follow)
47 {
49
50 while
51 (
52 client.get_connection_checkpoint() < until_checkpoint &&
53 Signal::get_signal() != SIGINT
54 )
55 {
56 std::this_thread::sleep_for(std::chrono::seconds(1));
57 client.push_if_ahead();
58 }
59 }
60
61 return 0;
62 }
63}
64
65/////////////////////////////////////////////////////////////////////////////
66int main(int argc, char **argv)
67/////////////////////////////////////////////////////////////////////////////
68{
69 return joedb::main_wrapper(joedb::push, argc, argv);
70}
static int get_signal()
Definition Signal.cpp:27
static void start()
Definition Signal.cpp:34
int main()
#define JOEDB_RELEASE_ASSERT(x)
always-tested assertion (release and debug mode)
Definition assert.h:24
@ read_existing
fails if does not exist
int main_wrapper(int(*main)(Arguments &), int argc, char **argv)
Process command-line arguments and catch exceptions from main.
Definition Blob.h:7