Leosac
0.8.0
Open Source Access Control
main.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2014-2016 Leosac
3
4
This file is part of Leosac.
5
6
Leosac is free software: you can redistribute it and/or modify
7
it under the terms of the GNU Affero General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
Leosac is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU Affero General Public License for more details.
15
16
You should have received a copy of the GNU Affero General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
26
#include "
core/kernel.hpp
"
27
#include "
exception/ExceptionsTools.hpp
"
28
#include "
tools/ThreadUtils.hpp
"
29
#include "
tools/log.hpp
"
30
#include "
tools/unixshellscript.hpp
"
31
#include "
tools/version.hpp
"
32
#include <iostream>
33
#include <tclap/CmdLine.h>
// Could be replaced by boost::program_options
34
#include <unistd.h>
35
36
using namespace
Leosac::Tools
;
37
using namespace
Leosac
;
38
39
static
int
set_working_directory(
RuntimeOptions
&opts) noexcept
40
{
41
int
ret = 0;
42
if
(opts.has_param(
"working_directory"
) &&
43
!opts.get_param(
"working_directory"
).empty())
44
{
45
ret = chdir(opts.get_param(
"working_directory"
).c_str());
46
if
(ret != 0)
47
perror(
"Cannot change working directory"
);
48
}
49
return
ret;
50
}
51
52
int
main
(
int
argc,
const
char
**argv)
53
{
54
RuntimeOptions
options;
55
int
relaunch = 1;
56
57
std::cout <<
"Running Leosac version "
<<
Version::get_full_version
()
58
<< std::endl;
59
60
Leosac::set_thread_name
(
"main"
);
61
try
62
{
63
TCLAP::CmdLine cmd(
"Open Source Access Controller"
,
' '
,
64
Version::get_full_version
());
65
TCLAP::SwitchArg strict(
"s"
,
"strict"
,
66
"Be strict regarding configuration error"
,
67
false
);
// assert on configuration error.
68
TCLAP::ValueArg<std::string> kernelFile(
69
"k"
,
"kernel-cfg"
,
"Kernel Configuration file"
,
true
,
""
,
"config_file"
);
70
TCLAP::ValueArg<std::string> working_directory(
71
"d"
,
"working-directory"
,
"Leosac's working directory"
,
false
,
""
,
72
"working_directory"
);
73
74
cmd.add(strict);
75
cmd.add(kernelFile);
76
cmd.add(working_directory);
77
cmd.parse(argc, argv);
78
options.
set_param
(
"kernel-cfg"
, kernelFile.getValue());
79
options.
set_param
(
"working_directory"
, working_directory.getValue());
80
options.
set_strict
(strict.getValue());
81
}
82
catch
(
const
TCLAP::ArgException &e)
83
{
84
Leosac::print_exception
(e);
85
return
1;
86
}
87
88
if
(set_working_directory(options) != 0)
89
return
1;
90
91
while
(relaunch)
92
{
93
try
94
{
95
INFO
(
"Creating Leosac Kernel..."
);
96
Kernel
kernel(
Kernel::make_config
(options), options.
is_strict
());
97
relaunch = kernel.
run
();
98
}
99
catch
(
const
std::exception &e)
100
{
101
std::cerr <<
"Exception propagated to main(). Will now exit."
102
<< std::endl;
103
Leosac::print_exception
(e);
104
return
1;
105
}
106
catch
(...)
107
{
108
std::cerr <<
"Unknown exception in main"
<< std::endl;
109
return
1;
110
}
111
}
112
INFO
(
"Bye."
);
113
return
(0);
114
}
Leosac::print_exception
void print_exception(const std::exception &e, int level=0)
Recursively print the exception trace to std::cerr.
Definition:
ExceptionsTools.cpp:44
Leosac::Tools::Version::get_full_version
static std::string get_full_version()
Returns the complete version string.
Definition:
version.cpp:80
unixshellscript.hpp
UnixShellScript class declaration.
Leosac::Kernel::run
bool run()
Main loop of the main thread.
Definition:
kernel.cpp:151
INFO
@ INFO
Definition:
log.hpp:34
version.hpp
version handling
ExceptionsTools.hpp
Leosac::set_thread_name
void set_thread_name(const std::string &name)
Set the name of the current thread.
Definition:
ThreadUtils.cpp:37
ThreadUtils.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition:
APIStatusCode.hpp:22
kernel.hpp
Leosac::Tools::RuntimeOptions::set_strict
void set_strict(bool v)
Definition:
runtimeoptions.cpp:60
Leosac::Tools::RuntimeOptions::is_strict
bool is_strict() const
Definition:
runtimeoptions.cpp:55
Leosac::Kernel::make_config
static boost::property_tree::ptree make_config(const Leosac::Tools::RuntimeOptions &opt)
Build a property tree from a runtime object object.
Definition:
kernel.cpp:128
Leosac::Tools::RuntimeOptions::set_param
void set_param(const std::string &key, const std::string &value)
Definition:
runtimeoptions.cpp:36
Leosac::Kernel
Core of Leosac.
Definition:
kernel.hpp:73
log.hpp
Leosac::Tools::RuntimeOptions
Holds informations about runtime options, such as "is this a verbose run" or path to configurations f...
Definition:
runtimeoptions.hpp:42
Leosac::Tools
Definition:
DatabaseLogSink.hpp:27
main
int main(int argc, const char **argv)
Definition:
main.cpp:52
src
main.cpp
Generated on Tue Mar 22 2022 10:48:23 for Leosac by
1.8.17