-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
56 lines (43 loc) · 1.13 KB
/
main.cpp
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
#include <fstream>
#include <iostream>
#include <string>
#include <nlohmann/json.hpp>
#include "commandline.hpp"
#include "logging.hpp"
#include "manager.hpp"
using namespace std;
using namespace nlohmann;
namespace dsmq {
static Logger logger( "main" );
json readProperties( string const& fileName )
{
ifstream ifs { fileName, ios::in };
if ( !ifs ) {
throw system_error( errno, system_category(), "couldn't open " + fileName );
}
json props;
ifs >> props;
return props;
}
void run( int argc, char* const argv[] )
{
try {
Logger::threshold( Logger::Level::debug );
CommandLine args { argv, argc };
if ( !args.logFile().empty()) {
Logger::output( args.logFile().c_str());
}
logger.info( "dsmqbridge starting" );
Manager manager { readProperties( args.propertiesFile()) };
manager.run();
} catch ( CommandLineError const& e ) {
std::cerr << e.what();
} catch ( exception const& e ) {
logger.error( e.what() );
}
}
} // namespace dsmq
int main( int argc, char* const argv[] )
{
dsmq::run( argc, argv );
}