ADTF  3.18.2
plugin.h
Go to the documentation of this file.
1 
7 #ifndef _UCOM_PLUGIN_HEADER_
8 #define _UCOM_PLUGIN_HEADER_
9 
15 extern std::function<void()> _plugin_deinitialization;
16 
17 namespace adtf
18 {
19 namespace ucom
20 {
21 namespace ant
22 {
23 
24 class cPlugin : public catwo::object<IPlugin,
25  IPluginLogging,
26  level_machine<cPlugin,
27  IPlugin::tPluginState,
28  IPlugin::tPluginState::Deinitialized>>
29 {
30  public:
31  UCOM_RESOLVE(IObject, IPlugin);
32  static constexpr const tChar* const DEFAULT_PLUGIN_EXTENSION = ".adtfplugin";
33 
34  private:
35  tHandle m_hModule;
36  adtf::util::cString m_strLabel;
37 
38  public:
39  cPlugin(const char* strLabel);
40  ~cPlugin();
41 
42  protected:
43  cPlugin(cPlugin&& oPlugin) = delete;
44  cPlugin(const cPlugin& oPlugin) = delete;
45  cPlugin& operator=(cPlugin&& oPlugin) = delete;
46  cPlugin& operator=(const cPlugin& oPlugin) = delete;
47  public: // implements IPlugin
48  const char* GetLabel() const override;
50  pointer_iterator> GetVersions() const override;
51  uint32_t GetBuildType() const override;
52  tResult SetState(tPluginState eState) override;
53  tPluginState GetState() const override;
54  tResult GetClassFactory(iobject_ptr<const IClassFactory>& pClassFactory) const override;
55  void SetHandle(tHandle hModule) override;
56  tHandle GetHandle() const override;
57 
58  public:
59  virtual tResult Initialize();
60  virtual tResult Deinitialize();
61 
62  public: // implements IPluginLogging
63  void SetLogger(ILogger* pLogger) override;
64 };
65 
66 
68 {
69  static iterator_adapter<const tNamedVersion,
70  pointer_iterator> GetVersions()
71  {
72  static const std::array<const tNamedVersion, 1> sVersions{{UCOM_VERSION_ID, adtf::ucom::get_ucom_version_information()}};
73  return iterator_adapter<const tNamedVersion, pointer_iterator>::create(&*sVersions.begin(), &*sVersions.begin() + sVersions.size());
74  }
75 };
76 
77 
78 template<typename PLUGIN_VERSION_TYPE, typename ...CLASSES>
79 class plugin_template: public cPlugin
80 {
81  private:
82  object_ptr<const IClassFactory> m_pClassFactory;
83  public:
85  pointer_iterator> GetVersions() const
86  {
87  return PLUGIN_VERSION_TYPE::GetVersions();
88  }
89  public:
90  plugin_template(const char* strLabel):
91  cPlugin(strLabel),
92  m_pClassFactory(make_object_ptr<class_factory<CLASSES...>>())
93  {
94  }
95 
96  tResult GetClassFactory(iobject_ptr<const IClassFactory>& pClassFactory) const
97  {
98  pClassFactory.Reset(m_pClassFactory);
100  }
101 };
102 
103 template<typename PLUGIN_CLASS>
105 {
106  template <typename ...Args>
107  static object_ptr<IPlugin> Get(Args&&... args)
108  {
109  // make sure the symbols are included
110  if (_runtime == reinterpret_cast<IRuntime*>(-1)) // never true, and won't be optimised away
111  {
112  UCOM_GetVersion3(nullptr, nullptr, nullptr, nullptr);
113  UCOM_LoadPlugin3(nullptr, 0, 0, 0, nullptr, 0);
114  UCOM_UnloadPlugin3();
115  }
116  return object_ptr<IPlugin>(make_object_ptr<PLUGIN_CLASS>(std::forward<Args>(args)...));
117  }
118 };
119 
120 }
121 
122 using ant::cPlugin;
126 
127 }
128 
129 }
130 #endif
char tChar
The tChar defines the type for platform character set (platform and compiler dependent type).
tVoid * tHandle
type definition for a handle value (platform and compiler dependent type).
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Interface for a logger.
Definition: logger_intf.h:22
Base class for every interface type within the uCOM.
Definition: object_intf.h:31
Plugin interface.
Definition: plugin_intf.h:27
The IRuntime interface controls global system startup and shutdown.
Definition: runtime_intf.h:111
The class class_factory provides a template based implementation of the IClassFactory interface,...
Definition: class_factory.h:26
virtual tResult Reset(const iobject_ptr< T > &i_oOther)=0
Reset this object_ptr<> with the content of another iobject_ptr<>
Base object pointer to realize binary compatible reference counting in interface methods.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
Use this template if you want to implement an ucom::ant::IObject based Interface and/or subclass an e...
Definition: object.h:379
string_base< cStackString > cString
cString implementation for a stack string which works on stack if string is lower than A_UTILS_DEFAUL...
Definition: string.h:2778
std::enable_if< !std::is_base_of< enable_object_ptr_from_this< typename std::remove_cv< Implementation >::type >, typename std::remove_cv< Implementation >::type >::value, object_ptr< Implementation > >::type make_object_ptr(Args &&... args)
Create an instance of type object_ptr with Implementation as the shared resource.
ant::tNamedVersion tNamedVersion
Alias alwas bringing the latest version of ant::tNamedVersion into scope.
Namespace for entire ADTF SDK.
std::function< tResult(adtf::ucom::iobject_ptr< adtf::ucom::IPlugin > &)> _plugin_initialization
Global Plugin initialization method.
adtf::ucom::IRuntime * _runtime
Global Runtime Pointer to reference to the current runtime.
std::function< void()> _plugin_deinitialization
Global Plugin deinitialization method.
Adapter for begin and end iterators - usable as return and parameter value in interfaces.
static self_type create(IteratorInterfaceType &o_oIterator)
Create the adapter by assigning iterator interface to begin and end iterators.
Empty struct template to specialize implementations of iterator interfaces.
Definition: iterator_intf.h:28