acq_vendor.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "acq_vendor.h"
  2. #include <communications/communication.h>
  3. #include <json/json.h>
  4. #include <settings/config_parser.h>
  5. static vendor::MyOpt myOpts_[] = {
  6. {"help", no_argument, 'h', "[options] [documents] [IPaddress][:port]..." },
  7. {"auth", required_argument, 0, "User and role configuration" },
  8. {"debug", no_argument, 0, "Run in debug mode" },
  9. {"home", required_argument, 0, "Change to directory to run" },
  10. {"log", required_argument, 0, "logFile:level, Log to file file at verbosity level"},
  11. {"route", required_argument, 0, "route file" },
  12. {"port", required_argument, 0, "set port, default: 8880" },
  13. {"delay", required_argument, 0, "delay secs to quit" },
  14. {"document", required_argument, 0, "document" },
  15. {"verbose", required_argument, 0, "Same as --log stderr:2" },
  16. {"version", no_argument, 0, "version information" }
  17. };
  18. namespace iot_acq {
  19. AcqVendor::AcqVendor():
  20. acqTask_(new AcqTask())
  21. {
  22. }
  23. AcqVendor::~AcqVendor()
  24. {
  25. }
  26. int AcqVendor::ParseCmdline(const std::string &optname, const std::string &optarg)
  27. {
  28. return 0;
  29. }
  30. vendor::MyOpt *AcqVendor::GetOpts()
  31. {
  32. return myOpts_;
  33. }
  34. int AcqVendor::GetOptSize()
  35. {
  36. return sizeof(myOpts_) / sizeof(myOpts_[0]);
  37. }
  38. void sigHandler(int sig)
  39. {
  40. HTELINK_LOG_DEBUG("sigHandler, %d", sig);
  41. }
  42. int AcqVendor::Run()
  43. {
  44. std::vector<settings::ConfigParser::DataCenter> dataCenters = configParser_.GetDataCenter();
  45. for(settings::ConfigParser::DataCenter &dc: dataCenters) {
  46. HTELINK_LOG_INFO("add rpc %s, yunId = %d", dc.name.c_str(), dc.yunID);
  47. std::shared_ptr<leoyun::YunRpc> rpc = leoyun::YunRpc::GetRpcInstance(dc.yunID);
  48. ASSERT(rpc != nullptr);
  49. rpc->SetDataCenter(dc);
  50. acqTask_->PushRpc(dc.name, rpc);
  51. }
  52. timerCheck_ = AppendTimerEvent(100, acqTask_);
  53. return 0;
  54. }
  55. std::string AcqVendor::Name()
  56. {
  57. return "iot-acq";
  58. }
  59. void AcqVendor::Stop(int signal)
  60. {
  61. HTELINK_LOG_INFO("acq exit, signal = %d", signal);
  62. StopEvent(timerCheck_);
  63. }
  64. } // namespace iot_acq