gsd_userApp.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * @Author: error: git config user.name && git config user.email & please set dead value or install git
  3. * @Date: 2022-07-11 00:13:35
  4. * @LastEditors: lishengyin
  5. * @LastEditTime: 2022-08-02 16:06:03
  6. * @FilePath: /gsd/plugins/gsd_userApp.cc
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. /**
  10. *
  11. * gsd_userApp.cc
  12. *
  13. */
  14. #include "gsd_userApp.h"
  15. #include <iostream>
  16. #include "Util/logger.h"
  17. #include "Util/SqlPool.h"
  18. #include "config.hpp"
  19. #include "gsd_TcpPlugin.h"
  20. #include "gsd_ExpelPlugin.h"
  21. #include "gsd_HttpPlugin.h"
  22. #include "gsd_MonitorPlugin.h"
  23. using namespace std;
  24. using namespace drogon;
  25. using namespace gsd;
  26. using namespace toolkit;
  27. void userApp::initAndStart(const Json::Value &config)
  28. {
  29. if(this->Init() != OK) {
  30. ErrorL << "userApp初始化失败" << endl;
  31. return;
  32. }
  33. this->StartTask();
  34. }
  35. void userApp::shutdown()
  36. {
  37. }
  38. /**
  39. * @description: 初始化
  40. * @return {*}
  41. */
  42. int8_t userApp::Init(){
  43. // 配置更新
  44. config::getPtr()->Update();
  45. #if defined(SUPPORT_DYNAMIC_TEMPLATE)
  46. SqlPool::Instance().Init("127.0.0.1",3306,"","root","sunwin2022"/*,character*/);
  47. #else
  48. //由于需要编译器对可变参数模板的支持,所以gcc5.0以下一般都不支持,否则编译报错
  49. ErrorL << "your compiler does not support variable parameter templates!" << endl;
  50. return -1;
  51. #endif //defined(SUPPORT_DYNAMIC_TEMPLATE)
  52. InfoL << "Starting Device, SN:" << config::getPtr()->getSimCode() << ",gsdApp:" << config::getPtr()->getApp() << ", Address:" << config::getPtr()->vpnIP << ", Version:" << config::getPtr()->getVersion() << ", Low:" << config::getPtr()->LowVersion << endl;
  53. NoticeCenter::Instance().addListener(0, NOTICE_DEVICEINFO,
  54. [&](std::string requestId,std::string json){
  55. if(app().getPlugin<TcpPlugin>()->getAlive()){
  56. json += "\r\n";
  57. app().getPlugin<TcpPlugin>()->sendRequest(requestId, NettyClientCommandEnum().device_info, json,[&](int status,std::string buf){});
  58. }
  59. });
  60. // TCP
  61. app().getPlugin<TcpPlugin>()->StartTask();
  62. app().getPlugin<ExpelPlugin>()->StartTask();
  63. app().getPlugin<MonitorPlugin>()->StartTask();
  64. app().getPlugin<HttpPlugin>()->StartTask();
  65. return OK;
  66. }
  67. /**
  68. * @description: 启动任务
  69. * @return {*}
  70. */
  71. void userApp::StartTask(){
  72. }