writecore.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "writecore.h"
  2. WriteCore::WriteCore(QObject *parent) : QObject(parent)
  3. {
  4. dbthread = new DatabaseThread(this);
  5. dbthread->start();
  6. connect(dbthread,&DatabaseThread::mqtt_conf,this,&WriteCore::mqtt_data);
  7. connect(dbthread,&DatabaseThread::dbdata_log,this,&WriteCore::dbdata_log);
  8. logthread = new LogThread(this);
  9. logthread->start();
  10. mqthread = new MqttDataThread(this);
  11. connect(mqthread,&MqttDataThread::mq_log,this,&WriteCore::mq_log);
  12. connect(mqthread,&MqttDataThread::sendMqttData,this,&WriteCore::sendMqttData);
  13. dealmqthread = new DealMqttThread(this);
  14. connect(dealmqthread,&DealMqttThread::dmq_log,this,&WriteCore::dmq_log);
  15. connect(dealmqthread,&DealMqttThread::dmqSql,this,&WriteCore::appendSql);
  16. connect(dealmqthread,&DealMqttThread::dmqAlarm,this,&WriteCore::appendAlarm);
  17. }
  18. WriteCore::~WriteCore()
  19. {
  20. dbthread->stop();
  21. logthread->stop();
  22. dealmqthread->stop();
  23. }
  24. void WriteCore::start()
  25. {
  26. mqthread->start();
  27. dealmqthread->start();
  28. }
  29. void WriteCore::mqtt_data(QString ip,QString port,QString username,QString password)
  30. {
  31. mqthread->mqtt_conf(ip,port,username,password);
  32. }
  33. void WriteCore::dbdata_log(QString log)
  34. {
  35. logthread->appendData(log);
  36. }
  37. void WriteCore::mq_log(QString log)
  38. {
  39. logthread->appendData(log);
  40. }
  41. void WriteCore::sendMqttData(QString topic,QByteArray data)
  42. {
  43. dealmqthread->appendMqttData(MqttData(topic,data));
  44. }
  45. void WriteCore::dmq_log(QString log)
  46. {
  47. logthread->appendData(log);
  48. }
  49. void WriteCore::appendSql(QString sql)
  50. {
  51. dbthread->appendSql(sql);
  52. }
  53. void WriteCore::appendAlarm(QString sql)
  54. {
  55. dbthread->appendAlarm(sql);
  56. }