~mc-return/compiz/compiz.merge-src-header-files-cleanup

« back to all changes in this revision

Viewing changes to include/core/plugin.h

  • Committer: MC Return
  • Date: 2013-06-20 05:56:13 UTC
  • mfrom: (3724.2.16 0.9.10)
  • Revision ID: mc.return@gmx.net-20130620055613-8dp00nmw2jpm3ptu
Merged latest lp:compiz and fixed conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <core/string.h>
30
30
#include <core/option.h>
31
31
#include <core/privateunion.h>
 
32
#include <core/pluginclasshandler.h>
32
33
 
33
34
#include <string.h>
34
35
 
70
71
extern UnloadPluginProc loaderUnloadPlugin;
71
72
extern ListPluginsProc  loaderListPlugins;
72
73
 
 
74
namespace compiz
 
75
{
 
76
namespace plugin
 
77
{
 
78
namespace internal
 
79
{
 
80
class VTableBase;
 
81
 
 
82
/**
 
83
 * Provide a definition for PluginKey, with a protected
 
84
 * constructor which is a friend of VTableBase */
 
85
class PluginKey
 
86
{
 
87
    protected:
 
88
 
 
89
        PluginKey () {}
 
90
 
 
91
        friend class VTableBase;
 
92
};
 
93
 
 
94
class VTableBase :
 
95
    public PluginKey
 
96
{
 
97
    public:
 
98
 
 
99
        virtual ~VTableBase () {};
 
100
};
 
101
}
 
102
}
 
103
}
 
104
 
73
105
/**
74
106
 * Base plug-in interface for Compiz. All plugins must implement this
75
107
 * interface, which provides basics for loading, unloading, options,
77
109
 */
78
110
class CompPlugin {
79
111
    public:
80
 
        class VTable {
 
112
        class VTable :
 
113
            public compiz::plugin::internal::VTableBase
 
114
        {
81
115
            public:
 
116
 
82
117
                VTable ();
83
118
                virtual ~VTable ();
84
119
 
91
126
                const CompString &name () const;
92
127
 
93
128
                virtual bool init () = 0;
94
 
 
95
129
                virtual void fini ();
96
130
 
 
131
                /* Mark the plugin as ready to be instantiated */
 
132
                virtual void markReadyToInstantiate () = 0;
 
133
 
 
134
                /* Mark the plugin as disallowing further instantiation */
 
135
                virtual void markNoFurtherInstantiation () = 0;
 
136
 
97
137
                virtual bool initScreen (CompScreen *s);
98
138
 
99
139
                virtual void finiScreen (CompScreen *s);
111
151
                VTable       **mSelf;
112
152
        };
113
153
 
114
 
    /**
115
 
     * TODO (or not?)
116
 
     */
117
 
        template <typename T, typename T2>
118
 
        class VTableForScreenAndWindow : public VTable {
119
 
            bool initScreen (CompScreen *s);
120
 
 
121
 
            void finiScreen (CompScreen *s);
122
 
 
123
 
            bool initWindow (CompWindow *w);
124
 
 
125
 
            void finiWindow (CompWindow *w);
126
 
 
127
 
            CompOption::Vector & getOptions ();
128
 
 
129
 
            bool setOption (const CompString &name, CompOption::Value &value);
 
154
        /**
 
155
         * TODO (or not?)
 
156
         */
 
157
        template <typename T, typename T2, int ABI = 0>
 
158
        class VTableForScreenAndWindow :
 
159
            public VTable
 
160
        {
 
161
            public:
 
162
 
 
163
                bool initScreen (CompScreen *s);
 
164
                void finiScreen (CompScreen *s);
 
165
                bool initWindow (CompWindow *w);
 
166
                void finiWindow (CompWindow *w);
 
167
                CompOption::Vector & getOptions ();
 
168
                bool setOption (const CompString &name,
 
169
                                CompOption::Value &value);
 
170
 
 
171
            private:
 
172
 
 
173
                /* Mark the plugin as ready to be instantiated */
 
174
                void markReadyToInstantiate ();
 
175
 
 
176
                /* Mark the plugin as disallowing further instantiation */
 
177
                void markNoFurtherInstantiation ();
130
178
        };
131
179
 
132
 
    /**
133
 
     * TODO (or not?)
134
 
     */
135
 
        template <typename T>
136
 
        class VTableForScreen : public VTable {
137
 
            bool initScreen (CompScreen *s);
138
 
 
139
 
            void finiScreen (CompScreen *s);
140
 
 
141
 
            CompOption::Vector & getOptions ();
142
 
 
143
 
            bool setOption (const CompString &name, CompOption::Value &value);
 
180
        /**
 
181
         * TODO (or not?)
 
182
         */
 
183
        template <typename T, int ABI = 0>
 
184
        class VTableForScreen :
 
185
            public VTable
 
186
        {
 
187
            public:
 
188
 
 
189
                bool initScreen (CompScreen *s);
 
190
                void finiScreen (CompScreen *s);
 
191
                CompOption::Vector & getOptions ();
 
192
                bool setOption (const CompString &name, CompOption::Value &value);
 
193
 
 
194
            private:
 
195
 
 
196
                /* Mark the plugin as ready to be instantiated */
 
197
                void markReadyToInstantiate ();
 
198
 
 
199
                /* Mark the plugin as disallowing further instantiation */
 
200
                void markNoFurtherInstantiation ();
144
201
        };
145
202
        
146
203
        typedef std::map<CompString, CompPlugin *> Map;
211
268
 
212
269
};
213
270
 
214
 
 
215
 
template <typename T, typename T2>
216
 
bool CompPlugin::VTableForScreenAndWindow<T,T2>::initScreen (CompScreen *s)
 
271
/**
 
272
 * Mark the plugin class handlers as ready to be initialized
 
273
 */
 
274
template <typename T, typename T2, int ABI>
 
275
void
 
276
CompPlugin::VTableForScreenAndWindow<T, T2, ABI>::markReadyToInstantiate ()
 
277
{
 
278
    namespace cpi = compiz::plugin::internal;
 
279
 
 
280
    typedef typename T::ClassPluginBaseType ScreenBase;
 
281
    typedef typename T2::ClassPluginBaseType WindowBase;
 
282
 
 
283
    typedef cpi::LoadedPluginClassBridge <T, ScreenBase, ABI> ScreenBridge;
 
284
    typedef cpi::LoadedPluginClassBridge <T2, WindowBase, ABI> WindowBridge;
 
285
 
 
286
    ScreenBridge::allowInstantiations (*this);
 
287
    WindowBridge::allowInstantiations (*this);
 
288
}
 
289
 
 
290
/**
 
291
 * Allow no further class handler initialization
 
292
 */
 
293
template <typename T, typename T2, int ABI>
 
294
void
 
295
CompPlugin::VTableForScreenAndWindow<T, T2, ABI>::markNoFurtherInstantiation ()
 
296
{
 
297
    namespace cpi = compiz::plugin::internal;
 
298
 
 
299
    typedef typename T::ClassPluginBaseType ScreenBase;
 
300
    typedef typename T2::ClassPluginBaseType WindowBase;
 
301
 
 
302
    typedef cpi::LoadedPluginClassBridge <T, ScreenBase, ABI> ScreenBridge;
 
303
    typedef cpi::LoadedPluginClassBridge <T2, WindowBase, ABI> WindowBridge;
 
304
 
 
305
    ScreenBridge::disallowInstantiations (*this);
 
306
    WindowBridge::disallowInstantiations (*this);
 
307
}
 
308
 
 
309
template <typename T, typename T2, int ABI>
 
310
bool
 
311
CompPlugin::VTableForScreenAndWindow<T, T2, ABI>::initScreen (CompScreen *s)
217
312
{
218
313
    T * ps = T::get (s);
219
314
    if (!ps)
222
317
    return true;
223
318
}
224
319
 
225
 
template <typename T, typename T2>
226
 
void CompPlugin::VTableForScreenAndWindow<T,T2>::finiScreen (CompScreen *s)
 
320
template <typename T, typename T2, int ABI>
 
321
void
 
322
CompPlugin::VTableForScreenAndWindow<T, T2, ABI>::finiScreen (CompScreen *s)
227
323
{
228
324
    T * ps = T::get (s);
229
325
    delete ps;
230
326
}
231
327
 
232
 
template <typename T, typename T2>
233
 
bool CompPlugin::VTableForScreenAndWindow<T,T2>::initWindow (CompWindow *w)
 
328
template <typename T, typename T2, int ABI>
 
329
bool
 
330
CompPlugin::VTableForScreenAndWindow<T, T2, ABI>::initWindow (CompWindow *w)
234
331
{
235
332
    T2 * pw = T2::get (w);
236
333
    if (!pw)
239
336
    return true;
240
337
}
241
338
 
242
 
template <typename T, typename T2>
243
 
void CompPlugin::VTableForScreenAndWindow<T,T2>::finiWindow (CompWindow *w)
 
339
template <typename T, typename T2, int ABI>
 
340
void
 
341
CompPlugin::VTableForScreenAndWindow<T, T2, ABI>::finiWindow (CompWindow *w)
244
342
{
245
343
    T2 * pw = T2::get (w);
246
344
    delete pw;
247
345
}
248
346
 
249
 
template <typename T, typename T2>
250
 
CompOption::Vector & CompPlugin::VTableForScreenAndWindow<T,T2>::getOptions ()
 
347
template <typename T, typename T2, int ABI>
 
348
CompOption::Vector & CompPlugin::VTableForScreenAndWindow<T, T2, ABI>::getOptions ()
251
349
{
252
350
    CompOption::Class *oc = dynamic_cast<CompOption::Class *> (T::get (screen));
253
351
    if (!oc)
255
353
    return oc->getOptions ();
256
354
}
257
355
 
258
 
template <typename T, typename T2>
259
 
bool CompPlugin::VTableForScreenAndWindow<T,T2>::setOption (const CompString  &name,
260
 
                                                            CompOption::Value &value)
 
356
template <typename T, typename T2, int ABI>
 
357
bool
 
358
CompPlugin::VTableForScreenAndWindow<T, T2, ABI>::setOption (const CompString  &name,
 
359
                                                             CompOption::Value &value)
261
360
{
262
361
    CompOption::Class *oc = dynamic_cast<CompOption::Class *> (T::get (screen));
263
362
    if (!oc)
265
364
    return oc->setOption (name, value);
266
365
}
267
366
 
268
 
template <typename T>
269
 
bool CompPlugin::VTableForScreen<T>::initScreen (CompScreen *s)
 
367
/**
 
368
 * Mark the plugin class handlers as ready to be initialized
 
369
 */
 
370
template <typename T, int ABI>
 
371
void
 
372
CompPlugin::VTableForScreen<T, ABI>::markReadyToInstantiate ()
 
373
{
 
374
    namespace cpi = compiz::plugin::internal;
 
375
 
 
376
    typedef typename T::ClassPluginBaseType ScreenBase;
 
377
    typedef cpi::LoadedPluginClassBridge <T, ScreenBase, ABI> ScreenBridge;
 
378
 
 
379
    ScreenBridge::allowInstantiations (*this);
 
380
}
 
381
 
 
382
/**
 
383
 * Allow no further class handler initialization
 
384
 */
 
385
template <typename T, int ABI>
 
386
void
 
387
CompPlugin::VTableForScreen<T, ABI>::markNoFurtherInstantiation ()
 
388
{
 
389
    namespace cpi = compiz::plugin::internal;
 
390
 
 
391
    typedef typename T::ClassPluginBaseType ScreenBase;
 
392
    typedef cpi::LoadedPluginClassBridge <T, ScreenBase, ABI> ScreenBridge;
 
393
 
 
394
    ScreenBridge::disallowInstantiations (*this);
 
395
}
 
396
 
 
397
template <typename T, int ABI>
 
398
bool
 
399
CompPlugin::VTableForScreen<T, ABI>::initScreen (CompScreen *s)
270
400
{
271
401
    T * ps = new T (s);
272
402
    if (ps->loadFailed ())
277
407
    return true;
278
408
}
279
409
 
280
 
template <typename T>
281
 
void CompPlugin::VTableForScreen<T>::finiScreen (CompScreen *s)
 
410
template <typename T, int ABI>
 
411
void CompPlugin::VTableForScreen<T, ABI>::finiScreen (CompScreen *s)
282
412
{
283
413
    T * ps = T::get (s);
284
414
    delete ps;
285
415
}
286
416
 
287
 
template <typename T>
288
 
CompOption::Vector & CompPlugin::VTableForScreen<T>::getOptions ()
 
417
template <typename T, int ABI>
 
418
CompOption::Vector &
 
419
CompPlugin::VTableForScreen<T, ABI>::getOptions ()
289
420
{
290
421
    CompOption::Class *oc = dynamic_cast<CompOption::Class *> (T::get (screen));
291
422
    if (!oc)
293
424
    return oc->getOptions ();
294
425
}
295
426
 
296
 
template <typename T>
297
 
bool CompPlugin::VTableForScreen<T>::setOption (const CompString  &name,
 
427
template <typename T, int ABI>
 
428
bool
 
429
CompPlugin::VTableForScreen<T, ABI>::setOption (const CompString  &name,
298
430
                                                CompOption::Value &value)
299
431
{
300
432
    CompOption::Class *oc = dynamic_cast<CompOption::Class *> (T::get (screen));