DataSubscribe.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "DataSubscribe.h"
  2. #include <QVariant>
  3. #include "LibraryLoader.h"
  4. #include "Publisher.h"
  5. #include <QDebug>
  6. DataSubscribe::DataSubscribe()
  7. {
  8. //shares = new SharedData();
  9. }
  10. DataSubscribe::~DataSubscribe()
  11. {
  12. //delete shares;
  13. }
  14. void DataSubscribe::Setup(ModuleInfo &mi)
  15. {
  16. std::string assemblyName = mi.AssemblyName;
  17. dataName = mi.Name;
  18. Publisher* pModule = nullptr;// = (BaseModule)Assembly.LoadFile(Path.GetFullPath(@".\" + assemblyName)).CreateInstance(className);
  19. pModule = LibraryLoader::load<Publisher>(assemblyName);
  20. if( pModule == nullptr )
  21. {
  22. // qCritical() << LOG_HEADER << " load " << szPlugin.c_str() << " failed.";
  23. return;
  24. }
  25. if( pModule == nullptr )
  26. {
  27. qCritical() << __FILE__ << __LINE__ << " " << assemblyName.c_str() << " load failed.";
  28. return;
  29. }
  30. {
  31. Publisher* runable = dynamic_cast<Publisher*>(pModule);
  32. //runable->shares(shares);
  33. connect(runable, SIGNAL(pubData(const QString& ,const QString& ,const QVariant& )), this, SLOT(OnData(const QString& ,const QString& ,const QVariant&)));
  34. // ------------- 由于tdengine订阅模块是单例运行,消息发送是广播发送 -------------
  35. // for(auto it = dataConsumerList.begin(); it != dataConsumerList.end(); it++){
  36. // connect(runable, SIGNAL(pubData(const QString& ,const QString& ,const QVariant& )), *it, SLOT(OnData(const QString& ,const QString& ,const QVariant&)));
  37. // }
  38. // ______________
  39. runable->Run(mi);
  40. }
  41. }
  42. std::string DataSubscribe::getTypeList()
  43. {
  44. return "DataStorage::RunnableModule";
  45. }
  46. // void DataSubscribe::setLoader(QLibrary *)
  47. // {
  48. // }
  49. void DataSubscribe::regConsumer(DataConsumer *dc)
  50. {
  51. dataConsumerList.append(dc);
  52. }
  53. void DataSubscribe::OnData(const QString &user, const QString &key, const QVariant &val)
  54. {
  55. for(auto it = dataConsumerList.begin(); it != dataConsumerList.end(); it++){
  56. if((*it)->topicsMap.count(key.toStdString().c_str()) ){
  57. (*it)->OnData(user, key, val);
  58. }
  59. }
  60. }