2019-12-03 19:23:33 +00:00
|
|
|
//
|
|
|
|
// Created by loki on 5/30/19.
|
|
|
|
//
|
|
|
|
|
2020-01-01 17:47:34 +00:00
|
|
|
#include "process.h"
|
|
|
|
|
2019-12-03 19:23:33 +00:00
|
|
|
#include <thread>
|
2019-12-08 18:21:27 +00:00
|
|
|
#include <filesystem>
|
|
|
|
#include <iostream>
|
2019-12-03 19:23:33 +00:00
|
|
|
|
2020-01-09 21:02:01 +00:00
|
|
|
#include <boost/log/common.hpp>
|
|
|
|
#include <boost/log/sinks.hpp>
|
|
|
|
#include <boost/log/expressions.hpp>
|
|
|
|
#include <boost/log/sources/severity_logger.hpp>
|
|
|
|
|
2019-12-03 19:23:33 +00:00
|
|
|
#include "nvhttp.h"
|
|
|
|
#include "stream.h"
|
2019-12-15 13:30:00 +00:00
|
|
|
#include "config.h"
|
2019-12-22 22:34:12 +00:00
|
|
|
#include "thread_pool.h"
|
2019-12-03 19:23:33 +00:00
|
|
|
|
2020-01-15 17:31:28 +00:00
|
|
|
#include "platform/common.h"
|
2019-12-03 19:23:33 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <rs.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace std::literals;
|
2020-01-09 21:02:01 +00:00
|
|
|
namespace bl = boost::log;
|
2019-12-22 22:34:12 +00:00
|
|
|
|
|
|
|
util::ThreadPool task_pool;
|
2020-01-09 21:02:01 +00:00
|
|
|
bl::sources::severity_logger<int> verbose(0); // Dominating output
|
|
|
|
bl::sources::severity_logger<int> debug(1); // Follow what is happening
|
|
|
|
bl::sources::severity_logger<int> info(2); // Should be informed about
|
|
|
|
bl::sources::severity_logger<int> warning(3); // Strange events
|
|
|
|
bl::sources::severity_logger<int> error(4); // Recoverable errors
|
|
|
|
bl::sources::severity_logger<int> fatal(5); // Unrecoverable errors
|
|
|
|
|
2019-12-25 19:57:23 +00:00
|
|
|
bool display_cursor;
|
|
|
|
|
2020-01-09 21:02:01 +00:00
|
|
|
using text_sink = bl::sinks::asynchronous_sink<bl::sinks::text_ostream_backend>;
|
|
|
|
boost::shared_ptr<text_sink> sink;
|
|
|
|
|
|
|
|
struct NoDelete {
|
|
|
|
void operator()(void *) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", int)
|
|
|
|
|
|
|
|
void log_flush() {
|
|
|
|
sink->flush();
|
|
|
|
}
|
|
|
|
|
2019-12-15 13:30:00 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
2019-12-03 22:19:00 +00:00
|
|
|
if(argc > 1) {
|
2019-12-08 18:21:27 +00:00
|
|
|
if(!std::filesystem::exists(argv[1])) {
|
2020-01-09 21:02:01 +00:00
|
|
|
std::cout << "Fatal Error: Couldn't find configuration file ["sv << argv[1] << ']' << std::endl;
|
2019-12-08 18:21:27 +00:00
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
|
2019-12-03 22:19:00 +00:00
|
|
|
config::parse_file(argv[1]);
|
|
|
|
}
|
|
|
|
|
2020-01-09 21:02:01 +00:00
|
|
|
sink = boost::make_shared<text_sink>();
|
|
|
|
|
|
|
|
boost::shared_ptr<std::ostream> stream { &std::cout, NoDelete {} };
|
|
|
|
sink->locked_backend()->add_stream(stream);
|
|
|
|
sink->set_filter(severity >= config::sunshine.min_log_level);
|
|
|
|
|
|
|
|
sink->set_formatter([severity="Severity"s](const bl::record_view &view, bl::formatting_ostream &os) {
|
|
|
|
auto log_level = view.attribute_values()[severity].extract<int>().get();
|
|
|
|
|
|
|
|
std::string_view log_type;
|
|
|
|
switch(log_level) {
|
|
|
|
case 0:
|
|
|
|
log_type = "Verbose: "sv;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
log_type = "Debug: "sv;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
log_type = "Info: "sv;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
log_type = "Warning: "sv;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
log_type = "Error: "sv;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
log_type = "Fatal: "sv;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
os << log_type << view.attribute_values()["Message"].extract<std::string>();
|
|
|
|
});
|
|
|
|
|
|
|
|
bl::core::get()->add_sink(sink);
|
|
|
|
auto fg = util::fail_guard(log_flush);
|
|
|
|
|
2019-12-16 21:02:21 +00:00
|
|
|
auto proc_opt = proc::parse(config::stream.file_apps);
|
2019-12-15 18:36:22 +00:00
|
|
|
if(!proc_opt) {
|
|
|
|
return 7;
|
|
|
|
}
|
2019-12-30 18:37:12 +00:00
|
|
|
|
2019-12-15 18:36:22 +00:00
|
|
|
proc::proc = std::move(*proc_opt);
|
|
|
|
|
2019-12-03 19:23:33 +00:00
|
|
|
reed_solomon_init();
|
|
|
|
|
2019-12-22 22:34:12 +00:00
|
|
|
task_pool.start(1);
|
|
|
|
|
2019-12-03 19:23:33 +00:00
|
|
|
std::thread httpThread { nvhttp::start };
|
|
|
|
|
2019-12-22 22:34:12 +00:00
|
|
|
stream::rtpThread();
|
2019-12-03 19:23:33 +00:00
|
|
|
httpThread.join();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|