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");
33 throw RuntimeException(boost::str(boost::format(
"The dynamic backend %1% (version %2%) is not compatible" 34 "with the current Backend API (vesion %3%)")
43 if (m_BackendIdFunction ==
nullptr)
48 const char* backendId = m_BackendIdFunction();
49 if (backendId ==
nullptr)
59 if (m_BackendVersionFunction ==
nullptr)
66 m_BackendVersionFunction(&major, &minor);
74 return CreateBackend();
79 if (m_BackendFactoryFunction ==
nullptr)
81 throw RuntimeException(
"GetFactoryFunction error: invalid function pointer");
87 return CreateBackend();
91 template<
typename BackendFunctionType>
92 BackendFunctionType DynamicBackend::SetFunctionPointer(
const std::string& backendFunctionName)
94 if (m_Handle ==
nullptr)
96 throw RuntimeException(
"SetFunctionPointer error: invalid shared object handle");
99 if (backendFunctionName.empty())
101 throw RuntimeException(
"SetFunctionPointer error: backend function name must not be empty");
105 auto functionPointer = DynamicBackendUtils::GetEntryPoint<BackendFunctionType>(m_Handle.get(),
106 backendFunctionName.c_str());
107 if (!functionPointer)
109 throw RuntimeException(
"SetFunctionPointer error: invalid backend function pointer returned");
112 return functionPointer;
117 if (m_BackendFactoryFunction ==
nullptr)
122 auto backendPointer =
reinterpret_cast<IBackendInternal*
>(m_BackendFactoryFunction());
123 if (backendPointer ==
nullptr)
125 throw RuntimeException(
"CreateBackend error: backend instance must not be null");
128 return std::unique_ptr<IBackendInternal>(backendPointer);
std::function< PointerType()> FactoryFunction
static bool IsBackendCompatible(const BackendVersion &backendVersion)
Copyright (c) 2020 ARM Limited.
static constexpr BackendVersion GetApiVersion()
Returns the version of the Backend API.
BackendRegistry::FactoryFunction GetFactoryFunction()
DynamicBackend(const void *sharedObjectHandle)
BackendId GetBackendId()
Public dynamic backend functions.
IBackendInternalUniquePtr GetBackend()
std::unique_ptr< IBackendInternal > IBackendInternalUniquePtr
BackendVersion GetBackendVersion()