46
46
extern unsigned int pluginClassHandlerIndex;
56
* LoadedPluginClassBridge
58
* This template essentially exists so that we can reduce the
59
* scope of functions which are allowed to mark plugin classes
60
* as instantiatable as we can't really inject the interface
61
* from PluginClassHandler to do that anywhere. We also can't
62
* forward declare a nested class declaration, but we can forward
63
* declare PluginKey, which users should inherit from and take
64
* it by reference. If the class we're depending on can only be
65
* defined in one other place along with a private constructor
66
* accessible only to a friend it means that we've effectively
67
* limited the scope of users of this class.
69
template <class Tp, class Tb, int ABI = 0>
70
class LoadedPluginClassBridge
75
allowInstantiations (const PluginKey &);
78
disallowInstantiations (const PluginKey &);
48
84
template<class Tp, class Tb, int ABI = 0>
49
class PluginClassHandler {
85
class PluginClassHandler
89
typedef Tp ClassPluginType;
90
typedef Tb ClassPluginBaseType;
51
92
PluginClassHandler (Tb *);
52
93
~PluginClassHandler ();
90
131
static bool initializeIndex (Tb *base);
91
132
static inline Tp * getInstance (Tb *base);
134
static void allowInstantiations ();
135
static void disallowInstantiations ();
137
template <class Plugin, class Base, int PluginABI>
138
friend class compiz::plugin::internal::LoadedPluginClassBridge;
97
144
static PluginClassIndex mIndex;
145
static bool mPluginLoaded;
154
template <class Tp, class Tb, int ABI>
156
LoadedPluginClassBridge <Tp, Tb, ABI>::allowInstantiations (const PluginKey &)
158
PluginClassHandler <Tp, Tb, ABI>::allowInstantiations ();
161
template <class Tp, class Tb, int ABI>
163
LoadedPluginClassBridge <Tp, Tb, ABI>::disallowInstantiations (const PluginKey &)
165
PluginClassHandler <Tp, Tb, ABI>::disallowInstantiations ();
100
171
template<class Tp, class Tb, int ABI>
101
172
PluginClassIndex PluginClassHandler<Tp,Tb,ABI>::mIndex;
174
template<class Tp, class Tb, int ABI>
175
bool PluginClassHandler<Tp,Tb,ABI>::mPluginLoaded = false;
104
178
* Attaches a unique instance of the specified plugin class to a
105
179
* unique instance of a specified base class
254
328
PluginClassHandler<Tp,Tb,ABI>::get (Tb *base)
330
/* Never instantiate an instance of this class
331
* if the relevant plugin has not been loaded
256
336
/* Always ensure that the index is initialized before
257
337
* calls to ::get */
258
338
if (!mIndex.initiated)
259
339
initializeIndex (base);
260
341
/* If pluginClassHandlerIndex == mIndex.pcIndex it means that our
261
342
* mIndex.index is fresh and can be used directly without needing
262
343
* to fetch it from ValueHolder */
263
344
if (mIndex.initiated && pluginClassHandlerIndex == mIndex.pcIndex)
264
345
return getInstance (base);
265
347
/* If allocating or getting the updated index failed at any point
266
348
* then just return NULL we don't know where our private data is stored */
267
349
if (mIndex.failed && pluginClassHandlerIndex == mIndex.pcIndex)
370
template<class Tp, class Tb, int ABI>
372
PluginClassHandler<Tp, Tb, ABI>::allowInstantiations ()
374
mPluginLoaded = true;
377
template<class Tp, class Tb, int ABI>
379
PluginClassHandler<Tp, Tb, ABI>::disallowInstantiations ()
381
mPluginLoaded = false;