Joedb 10.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Connection.h
Go to the documentation of this file.
1#ifndef joedb_Connection_declared
2#define joedb_Connection_declared
3
6
7#include <chrono>
8
9namespace joedb
10{
11 /// @ingroup concurrency
13 {
14 public:
16 };
17
18 /// @ingroup concurrency
19 enum class Content_Check
20 {
24 };
25
26 /// @ingroup concurrency
27 enum class Data_Transfer
28 {
31 };
32
33 /// @ingroup concurrency
34 enum class Lock_Action
35 {
38 };
39
40 /// @ingroup concurrency
41 enum class Unlock_Action
42 {
45 };
46
47 /// @ingroup concurrency
49 {
50 protected:
51 /// Called by @ref handshake when the file and the connection do not match
52 static void content_mismatch();
53
54 Connection() = default; // Force using Connection::dummy
55
56 public:
57 /// Called during Client construction
58 ///
59 /// @param client_journal may be used to check matching content
60 /// @param content_check indicates how matching content is tested
61 ///
62 /// @return connection checkpoint
63 virtual int64_t handshake
64 (
65 const Readonly_Journal &client_journal,
66 Content_Check content_check
67 );
68
69 /// Compare content of file and connection. Throw if mismatch.
70 virtual void check_matching_content
71 (
72 const Readonly_Journal &client_journal,
73 Content_Check content_check,
74 int64_t from,
75 int64_t until
76 );
77
78 /// Pull from the connection
79 ///
80 /// @param lock_action whether the connection should be locked before pulling
81 /// @param data_transfer whether data should be transferred
82 /// @param client_journal journal to pull into
83 /// @param wait duration during which the connection may wait
84 /// for new data if the pull would otherwise be empty
85 ///
86 /// @return connection checkpoint
87 virtual int64_t pull
88 (
89 Lock_Action lock_action,
90 Data_Transfer data_transfer,
91 Writable_Journal &client_journal,
92 std::chrono::milliseconds wait = std::chrono::milliseconds(0)
93 );
94
95 /// Push new data to the connection
96 ///
97 /// @return connection checkpoint
98 virtual int64_t push
99 (
100 const Readonly_Journal &client_journal,
101 int64_t from,
102 int64_t until,
103 Unlock_Action unlock_action
104 );
105
106 /// Unlock the connection
107 virtual void unlock();
108
109 virtual bool is_pullonly() const;
110
111 virtual ~Connection();
112
113 /// Since this class has no internal state, this global variable
114 /// can be used instead of creating an instance.
115 /// The default constructor is protected to force using it.
117 };
118}
119
120#endif
virtual bool is_pullonly() const
virtual void check_matching_content(const Readonly_Journal &client_journal, Content_Check content_check, int64_t from, int64_t until)
Compare content of file and connection. Throw if mismatch.
static Connection dummy
Since this class has no internal state, this global variable can be used instead of creating an insta...
Definition Connection.h:116
virtual int64_t push(const Readonly_Journal &client_journal, int64_t from, int64_t until, Unlock_Action unlock_action)
Push new data to the connection.
virtual void unlock()
Unlock the connection.
virtual ~Connection()
virtual int64_t pull(Lock_Action lock_action, Data_Transfer data_transfer, Writable_Journal &client_journal, std::chrono::milliseconds wait=std::chrono::milliseconds(0))
Pull from the connection.
Connection()=default
static void content_mismatch()
Called by handshake when the file and the connection do not match.
Definition Connection.cpp:9
virtual int64_t handshake(const Readonly_Journal &client_journal, Content_Check content_check)
Called during Client construction.
Disconnection(const char *what_arg)
Data_Transfer
Definition Connection.h:28
Lock_Action
Definition Connection.h:35
Content_Check
Definition Connection.h:20
Unlock_Action
Definition Connection.h:42