acq_vendor.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. std::shared_ptr<leoyun::YunRpc> rpc = leoyun::YunRpc::GetRpcInstance(dc.yunID);
  47. rpc->SetDataCenter(dc);
  48. acqTask_->PushRpc(dc.name, rpc);
  49. }
  50. timerCheck_ = AppendTimerEvent(100, acqTask_);
  51. return 0;
  52. }
  53. std::string AcqVendor::Name()
  54. {
  55. return "iot-acq";
  56. }
  57. void AcqVendor::Stop(int signal)
  58. {
  59. HTELINK_LOG_INFO("acq exit, signal = %d", signal);
  60. StopEvent(timerCheck_);
  61. }
  62. } // namespace iot_acq