summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSam Spilsbury <sam.spilsbury@canonical.com>2011-07-07 03:52:01 +0800
committerSam Spilsbury <sam.spilsbury@canonical.com>2011-07-07 03:52:01 +0800
commitee98496d5d7042d4aba10d822901aac6d3b85111 (patch)
tree26319e47d850dd53e72255ff674a591a848547a3 /include
parent0550e0941017c2c7ce027ba8ba9b5e47b17e409a (diff)
parentb9d6583b26e46c6e502129d3c550a18b5a7bd4d0 (diff)
downloadmobileperf-ee98496d5d7042d4aba10d822901aac6d3b85111.tar.gz
mobileperf-ee98496d5d7042d4aba10d822901aac6d3b85111.tar.bz2
Merge in lp:~unity-team/compiz-core/compiz-core.fix_706918 and hook
PluginClassHandler tests into make test
Diffstat (limited to 'include')
-rw-r--r--include/compiz.h7
-rw-r--r--include/core/plugin.h24
-rw-r--r--include/core/pluginclasshandler.h122
-rw-r--r--include/core/privateunion.h36
-rw-r--r--include/core/screen.h1
-rw-r--r--include/core/valueholder.h53
6 files changed, 184 insertions, 59 deletions
diff --git a/include/compiz.h b/include/compiz.h
index d4b3b2e..7f1a998 100644
--- a/include/compiz.h
+++ b/include/compiz.h
@@ -72,7 +72,7 @@ typedef std::list<CompString> CompStringList;
CompString compPrintf (const char *format, ...);
CompString compPrintf (const char *format, va_list ap);
-
+extern bool debugOutput;
typedef enum {
CompLogLevelFatal = 0,
@@ -83,6 +83,11 @@ typedef enum {
} CompLogLevel;
void
+logMessage (const char *componentName,
+ CompLogLevel level,
+ const char *message);
+
+void
compLogMessage (const char *componentName,
CompLogLevel level,
const char *format,
diff --git a/include/core/plugin.h b/include/core/plugin.h
index 510f169..fad3d05 100644
--- a/include/core/plugin.h
+++ b/include/core/plugin.h
@@ -28,6 +28,7 @@
#include <compiz.h>
#include <core/option.h>
+#include <core/privateunion.h>
class CompScreen;
extern CompScreen *screen;
@@ -66,13 +67,6 @@ extern LoadPluginProc loaderLoadPlugin;
extern UnloadPluginProc loaderUnloadPlugin;
extern ListPluginsProc loaderListPlugins;
-union CompPrivate {
- void *ptr;
- long val;
- unsigned long uval;
- void *(*fptr) (void);
-};
-
/**
* Base plug-in interface for Compiz. All plugins must implement this
* interface, which provides basics for loading, unloading, options,
@@ -235,12 +229,10 @@ class CompPlugin {
template <typename T, typename T2>
bool CompPlugin::VTableForScreenAndWindow<T,T2>::initScreen (CompScreen *s)
{
- T * ps = new T (s);
- if (ps->loadFailed ())
- {
- delete ps;
+ T * ps = T::get (s);
+ if (!ps)
return false;
- }
+
return true;
}
@@ -254,12 +246,10 @@ void CompPlugin::VTableForScreenAndWindow<T,T2>::finiScreen (CompScreen *s)
template <typename T, typename T2>
bool CompPlugin::VTableForScreenAndWindow<T,T2>::initWindow (CompWindow *w)
{
- T2 * pw = new T2 (w);
- if (pw->loadFailed ())
- {
- delete pw;
+ T2 * pw = T2::get (w);
+ if (!pw)
return false;
- }
+
return true;
}
diff --git a/include/core/pluginclasshandler.h b/include/core/pluginclasshandler.h
index dde9b0d..84f77c3 100644
--- a/include/core/pluginclasshandler.h
+++ b/include/core/pluginclasshandler.h
@@ -30,8 +30,9 @@
#include <boost/preprocessor/cat.hpp>
#include <compiz.h>
-#include <core/screen.h>
+#include <core/valueholder.h>
#include <core/pluginclasses.h>
+#include <cstdio>
extern unsigned int pluginClassHandlerIndex;
@@ -53,6 +54,9 @@ class PluginClassHandler {
return compPrintf ("%s_index_%lu", typeid (Tp).name (), ABI);
}
+ static bool initializeIndex ();
+ static inline Tp * getInstance (Tb *base);
+
private:
bool mFailed;
Tb *mBase;
@@ -75,38 +79,7 @@ PluginClassHandler<Tp,Tb,ABI>::PluginClassHandler (Tb *base) :
else
{
if (!mIndex.initiated)
- {
- mIndex.index = Tb::allocPluginClassIndex ();
- if (mIndex.index != (unsigned)~0)
- {
- mIndex.initiated = true;
- mIndex.failed = false;
- mIndex.pcIndex = pluginClassHandlerIndex;
-
- CompPrivate p;
- p.uval = mIndex.index;
-
- if (!screen->hasValue (keyName ()))
- {
- screen->storeValue (keyName (), p);
- pluginClassHandlerIndex++;
- }
- else
- {
- compLogMessage ("core", CompLogLevelFatal,
- "Private index value \"%s\" already stored in screen.",
- keyName ().c_str ());
- }
- }
- else
- {
- mIndex.failed = true;
- mIndex.initiated = false;
- mIndex.pcFailed = true;
- mIndex.pcIndex = pluginClassHandlerIndex;
- mFailed = true;
- }
- }
+ mFailed = !initializeIndex ();
if (!mIndex.failed)
{
@@ -117,6 +90,44 @@ PluginClassHandler<Tp,Tb,ABI>::PluginClassHandler (Tb *base) :
}
template<class Tp, class Tb, int ABI>
+bool
+PluginClassHandler<Tp,Tb,ABI>::initializeIndex ()
+{
+ mIndex.index = Tb::allocPluginClassIndex ();
+ if (mIndex.index != (unsigned)~0)
+ {
+ mIndex.initiated = true;
+ mIndex.failed = false;
+ mIndex.pcIndex = pluginClassHandlerIndex;
+
+ CompPrivate p;
+ p.uval = mIndex.index;
+
+ if (!ValueHolder::Default ()->hasValue (keyName ()))
+ {
+ ValueHolder::Default ()->storeValue (keyName (), p);
+ pluginClassHandlerIndex++;
+ }
+ else
+ {
+ compLogMessage ("core", CompLogLevelFatal,
+ "Private index value \"%s\" already stored in screen.",
+ keyName ().c_str ());
+ }
+ return true;
+ }
+ else
+ {
+ mIndex.index = 0;
+ mIndex.failed = true;
+ mIndex.initiated = false;
+ mIndex.pcFailed = true;
+ mIndex.pcIndex = pluginClassHandlerIndex;
+ return false;
+ }
+}
+
+template<class Tp, class Tb, int ABI>
PluginClassHandler<Tp,Tb,ABI>::~PluginClassHandler ()
{
if (!mIndex.pcFailed)
@@ -129,7 +140,7 @@ PluginClassHandler<Tp,Tb,ABI>::~PluginClassHandler ()
mIndex.initiated = false;
mIndex.failed = false;
mIndex.pcIndex = pluginClassHandlerIndex;
- screen->eraseValue (keyName ());
+ ValueHolder::Default ()->eraseValue (keyName ());
pluginClassHandlerIndex++;
}
}
@@ -137,23 +148,52 @@ PluginClassHandler<Tp,Tb,ABI>::~PluginClassHandler ()
template<class Tp, class Tb, int ABI>
Tp *
-PluginClassHandler<Tp,Tb,ABI>::get (Tb *base)
+PluginClassHandler<Tp,Tb,ABI>::getInstance (Tb *base)
{
- if (mIndex.initiated && pluginClassHandlerIndex == mIndex.pcIndex)
+ if (base->pluginClasses[mIndex.index])
+ return static_cast<Tp *> (base->pluginClasses[mIndex.index]);
+ else
{
- return static_cast<Tp *>
- (base->pluginClasses[mIndex.index]);
+ /* mIndex.index will be implicitly set by
+ * the constructor */
+ Tp *pc = new Tp (base);
+
+ if (!pc)
+ return NULL;
+
+ /* FIXME: If a plugin class fails to load for
+ * whatever reason, then ::get is going to return
+ * NULL, which is unsafe in cases that aren't
+ * initScreen and initWindow */
+ if (pc->loadFailed ())
+ {
+ delete pc;
+ return NULL;
+ }
+
+ return static_cast<Tp *> (base->pluginClasses[mIndex.index]);
}
+}
+
+template<class Tp, class Tb, int ABI>
+Tp *
+PluginClassHandler<Tp,Tb,ABI>::get (Tb *base)
+{
+ if (!mIndex.initiated)
+ initializeIndex ();
+ if (mIndex.initiated && pluginClassHandlerIndex == mIndex.pcIndex)
+ return getInstance (base);
if (mIndex.failed && pluginClassHandlerIndex == mIndex.pcIndex)
return NULL;
- if (screen->hasValue (keyName ()))
+ if (ValueHolder::Default ()->hasValue (keyName ()))
{
- mIndex.index = screen->getValue (keyName ()).uval;
+ mIndex.index = ValueHolder::Default ()->getValue (keyName ()).uval;
mIndex.initiated = true;
mIndex.failed = false;
mIndex.pcIndex = pluginClassHandlerIndex;
- return static_cast<Tp *> (base->pluginClasses[mIndex.index]);
+
+ return getInstance (base);
}
else
{
diff --git a/include/core/privateunion.h b/include/core/privateunion.h
new file mode 100644
index 0000000..ae78e18
--- /dev/null
+++ b/include/core/privateunion.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Novell, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Novell, Inc. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: David Reveman <davidr@novell.com>
+ */
+
+#ifndef _COMPIZ_PRIVATEUNION_H
+#define _COMPIZ_PRIVATEUNION_H
+
+union CompPrivate {
+ void *ptr;
+ long val;
+ unsigned long uval;
+ void *(*fptr) (void);
+};
+
+#endif \ No newline at end of file
diff --git a/include/core/screen.h b/include/core/screen.h
index 6f4ef01..4c7b2be 100644
--- a/include/core/screen.h
+++ b/include/core/screen.h
@@ -36,6 +36,7 @@
#include <core/pluginclasses.h>
#include <core/region.h>
#include <core/modifierhandler.h>
+#include <core/valueholder.h>
class CompScreen;
class PrivateScreen;
diff --git a/include/core/valueholder.h b/include/core/valueholder.h
new file mode 100644
index 0000000..ab04006
--- /dev/null
+++ b/include/core/valueholder.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2010 Canonical Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Canonical Ltd. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Canonical Ltd. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
+ */
+
+#ifndef _COMPIZ_VALUEHOLDER_H
+#define _COMPIZ_VALUEHOLDER_H
+
+#include <compiz.h>
+#include <core/privateunion.h>
+
+class PrivateValueHolder;
+
+class ValueHolder
+{
+ public:
+
+ ValueHolder ();
+
+ void eraseValue (CompString key);
+ bool hasValue (CompString key);
+ void storeValue (CompString key, CompPrivate value);
+ CompPrivate getValue (CompString key);
+
+ static ValueHolder * Default ();
+ static void SetDefault (ValueHolder *);
+
+ private:
+
+ PrivateValueHolder *priv;
+};
+
+#endif \ No newline at end of file