TDengineClient.h 1.6 KB

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