ADTF
Loading...
Searching...
No Matches
plugin.h
Go to the documentation of this file.
1
7#ifndef _UCOM_PLUGIN_HEADER_
8#define _UCOM_PLUGIN_HEADER_
9
11extern adtf::ucom::IRuntime* _runtime;
15extern std::function<void()> _plugin_deinitialization;
16
17namespace adtf
18{
19namespace ucom
20{
21namespace ant
22{
23
24class cPlugin : public catwo::object<IPlugin,
25 IPluginLogging,
26 vision::IPluginLogging,
27 level_machine<cPlugin,
28 IPlugin::tPluginState,
29 IPlugin::tPluginState::Deinitialized>>
30{
31 public:
33 static constexpr const tChar* const DEFAULT_PLUGIN_EXTENSION = ".adtfplugin";
34
35 private:
36 tHandle m_hModule;
37 adtf::util::cString m_strLabel;
38
39 public:
40 cPlugin(const char* strLabel);
41 ~cPlugin();
42
43 protected:
44 cPlugin(cPlugin&& oPlugin) = delete;
45 cPlugin(const cPlugin& oPlugin) = delete;
46 cPlugin& operator=(cPlugin&& oPlugin) = delete;
47 cPlugin& operator=(const cPlugin& oPlugin) = delete;
48 public: // implements IPlugin
49 const char* GetLabel() const override;
51 pointer_iterator> GetVersions() const override;
52 uint32_t GetBuildType() const override;
53 tResult SetState(tPluginState eState) override;
54 tPluginState GetState() const override;
55 tResult GetClassFactory(iobject_ptr<const IClassFactory>& pClassFactory) const override;
56 void SetHandle(tHandle hModule) override;
57 tHandle GetHandle() const override;
58
59 public:
60 virtual tResult Initialize();
61 virtual tResult Deinitialize();
62
63 public: // implements IPluginLogging
64 void SetLogger(ILogger* pLogger) override;
65 void SetLogChannels(util::log::ILogChannel* pFallback, util::log::IThreadLocalLogChannelStack* pStack) noexcept override;
66};
67
68
70{
72 pointer_iterator> GetVersions()
73 {
74 static const std::array<const tNamedVersion, 1> sVersions{{UCOM_VERSION_ID, adtf::ucom::get_ucom_version_information()}};
75 return iterator_adapter<const tNamedVersion, pointer_iterator>::create(&*sVersions.begin(), &*sVersions.begin() + sVersions.size());
76 }
77};
78
79
80template<typename PLUGIN_VERSION_TYPE, typename ...CLASSES>
81class plugin_template: public cPlugin
82{
83 private:
84 object_ptr<const IClassFactory> m_pClassFactory;
85 public:
87 pointer_iterator> GetVersions() const
88 {
89 return PLUGIN_VERSION_TYPE::GetVersions();
90 }
91 public:
92 plugin_template(const char* strLabel):
93 cPlugin(strLabel),
95 {
96 }
97
98 tResult GetClassFactory(iobject_ptr<const IClassFactory>& pClassFactory) const
99 {
100 pClassFactory.Reset(m_pClassFactory);
102 }
103};
104
105template<typename PLUGIN_CLASS>
107{
108 template <typename ...Args>
109 static object_ptr<IPlugin> Get(Args&&... args)
110 {
111 // make sure the symbols are included
112 if (_runtime == reinterpret_cast<IRuntime*>(-1)) // never true, and won't be optimised away
113 {
114 UCOM_GetVersion3(nullptr, nullptr, nullptr, nullptr);
115 UCOM_LoadPlugin3(nullptr, 0, 0, 0, nullptr, 0);
116 UCOM_UnloadPlugin3();
117 }
118 return object_ptr<IPlugin>(make_object_ptr<PLUGIN_CLASS>(std::forward<Args>(args)...));
119 }
120};
121
122}
123
124using ant::cPlugin;
128
129}
130
131}
132#endif
#define UCOM_RESOLVE(...)
Resolve a path to a base class which is inherited multiple times.
Definition adtf_iid.h:46
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
Definition logger_intf.h:22
Definition object_intf.h:33
Definition plugin_intf.h:27
Definition runtime_intf.h:104
Definition plugin.h:30
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.
Definition object_ptr_intf.h:112
Definition object_ptr.h:384
Definition plugin.h:82
Definition object.h:397
Namespace for all functionality of the ADTF UCOM SDK provided since v3.0.
Definition test_runtime.h:14
object_ptr< Implementation > make_object_ptr(Args &&... args)
Create an instance of type object_ptr with Implementation as the shared resource.
Definition object_ptr_utilities.h:129
Namespace for the ADTF uCOM SDK.
Definition adtf_system.h:324
ant::iobject_ptr< T > iobject_ptr
Alias always bringing the latest version of ant::iobject_ptr into scope.
Definition object_ptr_intf.h:437
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14
std::function< tResult(adtf::ucom::iobject_ptr< adtf::ucom::IPlugin > &)> _plugin_initialization
Global Plugin initialization method.
std::function< void()> _plugin_deinitialization
Global Plugin deinitialization method.
Adapter for begin and end iterators - usable as return and parameter value in interfaces.
Definition iterator_intf.h:190
Empty struct template to specialize implementations of iterator interfaces.
Definition iterator_intf.h:28
Named version information consisting of the modules name and its adtf_util::tVersion.
Definition class_info_intf.h:22