PluginSubscriber.hpp 981 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef __PLUGINSUBSCRIBER_HPP_
  2. #define __PLUGINSUBSCRIBER_HPP_
  3. #include <iostream>
  4. #include "PuginFactory.hpp"
  5. namespace gsd
  6. {
  7. /**
  8. * @brief PluginSubscriber
  9. *
  10. */
  11. template <typename T>
  12. class PluginSubscriber{
  13. struct Register
  14. {
  15. // Register
  16. Register(){
  17. char *Name = nullptr;
  18. Name = abi::__cxa_demangle(typeid(T).name(), nullptr, nullptr, nullptr);
  19. std::string pluginName;
  20. if(Name != nullptr){
  21. pluginName = Name;
  22. free(Name);
  23. }
  24. PuginFactory::getPtr()->Regist(pluginName, getObjectPtr);
  25. }
  26. };
  27. /**
  28. * @description:
  29. * @return {*}
  30. */
  31. static std::shared_ptr<T> getObjectPtr(){
  32. return T::getPtr();
  33. }
  34. private:
  35. Register register_;
  36. };
  37. } // namespace gsd
  38. #endif