-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_server.cpp
More file actions
69 lines (52 loc) · 1.55 KB
/
database_server.cpp
File metadata and controls
69 lines (52 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <example/Database.h>
#include <vnx/Config.h>
#include <vnx/Process.h>
#include <vnx/Terminal.h>
#include <vnx/Server.h>
int main(int argc, char** argv) {
std::map<std::string, std::string> options;
options["n"] = "node"; // we declare -n is the same as --node
options["node"] = "server url"; // we declare --node means "server url"
vnx::init("database_server", argc, argv, options);
/*
* By default we create a local UNIX node for this example.
*/
std::string node = "database_server.sock";
vnx::read_config("node", node);
{
/*
* Start a Terminal to display log messages for us.
*/
vnx::Handle<vnx::Terminal> terminal = new vnx::Terminal("Terminal");
terminal.start_detached();
}
{
/*
* The Server will listen on and accept client connections to this process,
* depending on the type of Endpoint either on a TCP port or on a UNIX domain socket.
*/
vnx::Handle<vnx::Server> server = new vnx::Server("Server", vnx::Endpoint::from_url(node));
server.start_detached();
}
{
/*
* Create a new instance of our Database module.
*/
vnx::Handle<example::Database> module = new example::Database("Database");
// Set configuration variables
if(!module->input) {
module->input = example::transactions;
}
// Start module in the background
module.start_detached();
/*
* After the module has been started any attempt to access it will cause an exception.
*
* For example: module->input = "something.else"; // throws exception
*/
}
/*
* Wait until shutdown.
*/
vnx::wait();
}