TDengineClient.h 1.7 KB

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