CameraRecorder.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "API/WebAPI.h"
  2. #include <ctpl_stl.h>
  3. #include <INIReader.h>
  4. #include <Logging.h>
  5. #include <HttpClient.h>
  6. #include <HttpServer.h>
  7. #include <filesystem/path.h>
  8. #include <functional>
  9. #include <fstream>
  10. #include <iostream>
  11. #include <sstream>
  12. int main(int argc, char** argv)
  13. {
  14. try
  15. {
  16. Logging::OpenLog();
  17. Logging::SetLogMask(Logging::Severity::Debug);
  18. INIReader iniReader("CameraRecorder.ini");
  19. if (iniReader.ParseError() != 0)
  20. throw std::runtime_error("Can't read CameraRecorder.ini.");
  21. Logging::Log(Logging::Severity::Info, "Starting CameraRecorder");
  22. int port = iniReader.GetInteger("CameraRecorder", "Port", 0);
  23. if (port == 0)
  24. throw std::runtime_error("Port directive missing in ini file.");
  25. std::string pathString = iniReader.Get("CameraRecorder", "Path", "");
  26. if (pathString.empty())
  27. throw std::runtime_error("Path directive missing in ini file.");
  28. std::string ffmpeg = iniReader.Get("CameraRecorder", "FFMPEG", "");
  29. if (ffmpeg.empty())
  30. throw std::runtime_error("FFMPEG directive missing in ini file.");
  31. filesystem::path path(pathString);
  32. path = path.make_absolute();
  33. ctpl::thread_pool threadPool(6);
  34. Http::HttpClient httpClient;
  35. auto callback = std::bind(&CameraRecorder::API::WebAPI::ProcessQuery, &threadPool, &httpClient, path.str(), ffmpeg, std::placeholders::_1, std::placeholders::_2);
  36. Http::HttpServer server(port, callback);
  37. Logging::Log(Logging::Severity::Info, "Startup Complete");
  38. server.Wait();
  39. Logging::Log(Logging::Severity::Info, "Stopping CameraRecorder...");
  40. Logging::CloseLog();
  41. }
  42. catch (const std::exception& e)
  43. {
  44. std::cerr << "Exception caught" << std::endl;
  45. std::stringstream ss;
  46. ss << "Type : " << typeid(e).name() << std::endl;
  47. ss << "ERROR: " << e.what() << std::endl;
  48. Logging::Log(Logging::Severity::Error, ss.str());
  49. Logging::CloseLog();
  50. return -1;
  51. }
  52. return 0;
  53. }