terminator_emqx.h 916 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 "emqx/paho_client.h"
  8. #include "emqx/message.grpc.pb.h"
  9. typedef void (*Callback)(const MqttMsg& msg,void* context);
  10. typedef struct{
  11. Callback func;
  12. void* contextx;
  13. }CallBackInfo;
  14. class Terminator_emqx {
  15. public:
  16. Terminator_emqx(std::string nodeId);
  17. virtual ~Terminator_emqx();
  18. bool Connect(std::string ip,int port);
  19. bool AddCallback(std::string topic,Callback callback,void* context);
  20. void Publish(std::string topic,const MqttMsg& statu);
  21. protected:
  22. static void MessageArrivedCallback(std::string topic,int QOS,MqttMsg& msg,void* context);
  23. std::mutex mtx_;
  24. Paho_client* client_;
  25. bool connected_;
  26. std::string nodeId_;
  27. public:
  28. std::map<std::string,CallBackInfo> sub_topic_callbacks_;
  29. };
  30. #endif //NAVIGATION_TERMINATOR_EMQX_H