5 #ifndef CVMFS_UTIL_PLUGIN_H_
6 #define CVMFS_UTIL_PLUGIN_H_
16 #ifdef CVMFS_NAMESPACE_GUARD
17 namespace CVMFS_NAMESPACE_GUARD {
32 template <
class AbstractProductT,
typename ParameterT,
typename InfoT>
38 virtual bool WillHandle(
const ParameterT ¶m)
const = 0;
39 virtual AbstractProductT* Construct(
const ParameterT ¶m)
const = 0;
40 virtual InfoT Introspect()
const = 0;
57 template <
class ConcreteProductT,
58 class AbstractProductT,
67 return ConcreteProductT::WillHandle(param);
69 inline AbstractProductT*
Construct(
const ParameterT ¶m)
const {
70 AbstractProductT* product =
new ConcreteProductT(param);
82 template <
class ConcreteProductT,
83 class AbstractProductT,
93 return ConcreteProductT::GetInfo();
101 template <
class ConcreteProductT,
102 class AbstractProductT,
179 template <
class AbstractProductT,
typename ParameterT,
typename InfoT>
188 static AbstractProductT*
Construct(
const ParameterT ¶m) {
189 LazilyRegisterPlugins();
193 typename RegisteredPlugins::const_iterator i = registered_plugins_.begin();
194 typename RegisteredPlugins::const_iterator iend = registered_plugins_.end();
195 for (; i != iend; ++i) {
196 if ((*i)->WillHandle(param)) {
198 AbstractProductT *product = (*i)->Construct(param);
199 if (!product->Initialize()) {
220 if (atomic_read32(&needs_init_)) {
222 if (atomic_read32(&needs_init_)) {
223 AbstractProductT::RegisterPlugins();
224 atomic_dec32(&needs_init_);
228 assert(!registered_plugins_.empty());
234 friend class PolymorphicConstructionUnittestAdapter;
247 template <
class ConcreteProductT>
249 registered_plugins_.push_back(
271 registered_plugins_.clear();
291 template <
class AbstractProductT,
typename ParameterT,
typename InfoT =
void>
303 introspection_data.reserve(T::registered_plugins_.
size());
306 T::LazilyRegisterPlugins();
307 typename RegisteredPlugins::const_iterator i = plugins.begin();
308 typename RegisteredPlugins::const_iterator iend = plugins.end();
309 for (; i != iend; ++i) {
310 introspection_data.push_back((*i)->Introspect());
313 return introspection_data;
321 template <
class AbstractProductT,
typename ParameterT>
327 template <
class AbstractProductT,
typename ParameterT,
typename InfoT>
332 template <
class AbstractProductT,
typename ParameterT,
typename InfoT>
335 PTHREAD_MUTEX_INITIALIZER;
339 template <
class AbstractProductT,
typename ParameterT,
typename InfoT>
346 #ifdef CVMFS_NAMESPACE_GUARD
350 #endif // CVMFS_UTIL_PLUGIN_H_
virtual bool Initialize()
static IntrospectionData Introspect()
virtual ~PolymorphicConstructionImpl()
virtual ~AbstractFactory()
AbstractFactory< AbstractProductT, ParameterT, InfoT > Factory
assert((mem||(size==0))&&"Out Of Memory")
static RegisteredPlugins registered_plugins_
static AbstractProductT * Construct(const ParameterT ¶m)
std::vector< InfoT > IntrospectionData
static void UnregisterAllPlugins()
PolymorphicConstructionImpl< AbstractProductT, ParameterT, InfoT > T
std::vector< Factory * > RegisteredPlugins
static atomic_int32 needs_init_
bool WillHandle(const ParameterT ¶m) const
static void LazilyRegisterPlugins()
T::RegisteredPlugins RegisteredPlugins
static void RegisterPlugin()
static pthread_mutex_t init_mutex_
AbstractProductT * Construct(const ParameterT ¶m) const