CameraRecorder.cc 2.0 KB

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