VStarCamFinder.cc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "VStarCam/Finder.h"
  2. #include <INIReader.h>
  3. #include <Logging.h>
  4. #include <sstream>
  5. #include <string>
  6. int main(int argc, char** argv)
  7. {
  8. try
  9. {
  10. Logging::OpenLog();
  11. Logging::SetLogMask(Logging::Severity::Info);
  12. if (argc != 2)
  13. {
  14. std::stringstream ss;
  15. ss << "Usage: " << argv[0] << " <ipaddress>";
  16. Logging::Log(Logging::Severity::Error, ss.str());
  17. return 1;
  18. }
  19. INIReader iniReader("VStarCamFinder.ini");
  20. if (iniReader.ParseError() != 0)
  21. {
  22. Logging::Log(Logging::Severity::Error, "Can't read VStarCamFinder.ini");
  23. return 1;
  24. }
  25. std::string ipAddress(argv[1]);
  26. std::string listenAddress = iniReader.Get("VStarCamFinder", "ListenAddress", "0.0.0.0");
  27. int port = 0;
  28. VStarCam::Finder finder(listenAddress);
  29. port = finder.GetPort(ipAddress);
  30. if (port != 0)
  31. {
  32. std::stringstream ss;
  33. ss << port;
  34. Logging::Log(Logging::Severity::Error, ss.str());
  35. return 0;
  36. }
  37. return 1;
  38. }
  39. catch (const std::exception& e)
  40. {
  41. std::stringstream ss;
  42. ss << "ERROR: " << e.what() << std::endl;
  43. Logging::Log(Logging::Severity::Error, ss.str());
  44. return 1;
  45. }
  46. }