CameraRecorder.cc 1.8 KB

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