Initial commit
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#include "API/WebAPI.h"
|
||||
#include <ctpl_stl.h>
|
||||
#include <INIReader.h>
|
||||
#include <Logging.h>
|
||||
#include <HttpClient.h>
|
||||
#include <HttpServer.h>
|
||||
#include <functional>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
Logging::OpenLog();
|
||||
Logging::SetLogMask(Logging::Severity::Debug);
|
||||
|
||||
INIReader iniReader("CameraRecorder.ini");
|
||||
if (iniReader.ParseError() != 0)
|
||||
throw std::runtime_error("Can't read CameraRecorder.ini.");
|
||||
|
||||
Logging::Log(Logging::Severity::Info, "Starting CameraRecorder");
|
||||
|
||||
int port = iniReader.GetInteger("CameraRecorder", "Port", 0);
|
||||
if (port == 0)
|
||||
throw std::runtime_error("Port directive missing in ini file.");
|
||||
|
||||
std::string path = iniReader.Get("CameraRecorder", "Path", "");
|
||||
if (path.empty())
|
||||
throw std::runtime_error("Path directive missing in ini file.");
|
||||
|
||||
std::string ffmpeg = iniReader.Get("CameraRecorder", "FFMPEG", "");
|
||||
if (ffmpeg.empty())
|
||||
throw std::runtime_error("FFMPEG directive missing in ini file.");
|
||||
|
||||
ctpl::thread_pool threadPool(6);
|
||||
Http::HttpClient httpClient;
|
||||
auto callback = std::bind(&CameraRecorder::API::WebAPI::ProcessQuery, &threadPool, &httpClient, path, ffmpeg, std::placeholders::_1, std::placeholders::_2);
|
||||
|
||||
Http::HttpServer server(port, callback);
|
||||
Logging::Log(Logging::Severity::Info, "Startup Complete");
|
||||
server.Wait();
|
||||
|
||||
Logging::Log(Logging::Severity::Info, "Stopping CameraRecorder...");
|
||||
|
||||
Logging::CloseLog();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception caught" << std::endl;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "Type : " << typeid(e).name() << std::endl;
|
||||
ss << "ERROR: " << e.what() << std::endl;
|
||||
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
|
||||
Logging::CloseLog();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user