#include "API/WebAPI.h" #include #include #include #include #include #include #include #include #include #include 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 pathString = iniReader.Get("CameraRecorder", "Path", ""); if (pathString.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."); filesystem::path path(pathString); path = path.make_absolute(); ctpl::thread_pool threadPool(6); Http::HttpClient httpClient; auto callback = std::bind(&CameraRecorder::API::WebAPI::ProcessQuery, &threadPool, &httpClient, path.str(), 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; }