| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include "API/WebAPI.h"
- #include <ctpl_stl.h>
- #include <INIReader.h>
- #include <Logging.h>
- #include <HttpClient.h>
- #include <HttpServer.h>
- #include <filesystem/path.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 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;
- Http::HttpServer::CallbackMethod 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;
- }
|