terminator_emqx.h 867 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // Created by zx on 23-4-11.
  3. //
  4. #ifndef NAVIGATION_TERMINATOR_EMQX_H
  5. #define NAVIGATION_TERMINATOR_EMQX_H
  6. #include <mutex>
  7. #include "paho_client.h"
  8. typedef void (*Callback)(const MqttMsg& msg,void* context);
  9. typedef struct{
  10. Callback func;
  11. void* contextx;
  12. }CallBackInfo;
  13. class Terminator_emqx {
  14. public:
  15. Terminator_emqx(std::string nodeId);
  16. ~Terminator_emqx();
  17. bool Connect(std::string ip,int port);
  18. bool AddCallback(std::string topic,Callback callback,void* context);
  19. void Publish(std::string topic,const MqttMsg& statu);
  20. protected:
  21. static void StatuArrivedCallback(std::string topic,int QOS,MqttMsg& msg,void* context);
  22. std::mutex mtx_;
  23. Paho_client* client_;
  24. bool connected_;
  25. std::string nodeId_;
  26. public:
  27. std::map<std::string,CallBackInfo> sub_topic_callbacks_;
  28. };
  29. #endif //NAVIGATION_TERMINATOR_EMQX_H