13 : m_BackendIdFunction(nullptr)
14 , m_BackendVersionFunction(nullptr)
15 , m_BackendFactoryFunction(nullptr)
18 if (m_Handle ==
nullptr)
24 m_BackendIdFunction = SetFunctionPointer<IdFunctionType>(
"GetBackendId");
25 m_BackendVersionFunction = SetFunctionPointer<VersionFunctionType>(
"GetVersion");
26 m_BackendFactoryFunction = SetFunctionPointer<FactoryFunctionType>(
"BackendFactory");
34 std::stringstream message;
35 message <<
"The dynamic backend " << backendId <<
" (version " << backendVersion <<
44 if (m_BackendIdFunction ==
nullptr)
49 const char* backendId = m_BackendIdFunction();
50 if (backendId ==
nullptr)
60 if (m_BackendVersionFunction ==
nullptr)
67 m_BackendVersionFunction(&major, &minor);
75 return CreateBackend();
80 if (m_BackendFactoryFunction ==
nullptr)
82 throw RuntimeException(
"GetFactoryFunction error: invalid function pointer");
88 return CreateBackend();
92 template<
typename BackendFunctionType>
93 BackendFunctionType DynamicBackend::SetFunctionPointer(
const std::string& backendFunctionName)
95 if (m_Handle ==
nullptr)
97 throw RuntimeException(
"SetFunctionPointer error: invalid shared object handle");
100 if (backendFunctionName.empty())
102 throw RuntimeException(
"SetFunctionPointer error: backend function name must not be empty");
106 auto functionPointer = DynamicBackendUtils::GetEntryPoint<BackendFunctionType>(m_Handle.get(),
107 backendFunctionName.c_str());
108 if (!functionPointer)
110 throw RuntimeException(
"SetFunctionPointer error: invalid backend function pointer returned");
113 return functionPointer;
118 if (m_BackendFactoryFunction ==
nullptr)
120 throw RuntimeException(
"CreateBackend error: invalid function pointer");
123 auto backendPointer =
reinterpret_cast<IBackendInternal*
>(m_BackendFactoryFunction());
124 if (backendPointer ==
nullptr)
126 throw RuntimeException(
"CreateBackend error: backend instance must not be null");
129 return std::unique_ptr<IBackendInternal>(backendPointer);