TDengineClient.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. //#include "MWareInterface.h"
  3. #include "taos.h"
  4. #include <QtCore/QObject>
  5. #include <QtCore/QDebug>
  6. #include "libaray_symbols.h"
  7. #include <functional>
  8. #include <QFuture>
  9. class TDENGINECLIENT_EXPORT TDengineClient : public QObject
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit TDengineClient(QObject *parent = 0);
  14. TDengineClient(QString password,
  15. std::function<void(const char *, const char *, void*)> callback)
  16. : password(std::move(password)), callback(std::move(callback)) {}
  17. ~TDengineClient();
  18. void exec(QString sql);
  19. public:
  20. int32_t msgProcess(TAOS_RES* msg); //消息处理
  21. tmq_t* buildConsumer(); //构建消费者
  22. tmq_list_t* buildTopicList(); //构建主题
  23. void topicLoop(); //轮询主题
  24. signals:
  25. public slots:
  26. private:
  27. QString host = "192.168.9.6";
  28. uint16_t port = 6030;
  29. QString user = "root";
  30. QString dbName = "lanpengdb";
  31. QString password = "x=gheLw7QMAD4zjQh3d9";
  32. TAOS* pConn = NULL;
  33. std::function<void(const char* topic, const char* data, void*usr)> callback;
  34. //TAOS* pConn = NULL;
  35. //EventSubInterface* g_pSubCB; // 订阅回调
  36. std::list<std::string> topicList;
  37. void * usrData;
  38. QFuture<void> future;
  39. public:
  40. //void Setup(tagSetup ts);
  41. void Setup(const char* host, const char* user, const char* passwd, uint16_t port);
  42. void subscribe(QString ch, std::function<void(const char* topic, const char* data, void*usr)> fn, void* usrdata); // 订阅
  43. void psubscribe(QString ch, std::function<void(const char* topic, const char* data, void*usr)> fn, void*usrdata); // 订阅:模式匹配
  44. void start();
  45. };