summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSam Spilsbury <SmSpillaz@gmail.com>2010-06-12 15:43:36 +0800
committerSam Spilsbury <SmSpillaz@gmail.com>2010-06-12 15:43:36 +0800
commitad81a6e7b48ce68e893b4c0b13080b198f37634c (patch)
tree24f4887e8d7169563af96224d9b6990cfe651913 /include
parenta9e34d283827f5bd956ae45339ac95a96e9f64ae (diff)
downloadzcomp-ad81a6e7b48ce68e893b4c0b13080b198f37634c.tar.gz
zcomp-ad81a6e7b48ce68e893b4c0b13080b198f37634c.tar.bz2
A few big changes:
* Rewrite PropertyWriter, move it out of compiztoolbox * Added CompPluginStateWriter, a serialization interface, which plugins inherit, and specify how to serialize their class members, which will be automatically unloaded and reloaded as plugins unload and reload. * Currently there are bugs with this interface, so it is disabled by default (mostly bugs to do with boost and libdl) * Depend on libboost-serialization * A few bugfixes
Diffstat (limited to 'include')
-rw-r--r--include/core/CMakeLists.txt2
-rw-r--r--include/core/propertywriter.h54
-rw-r--r--include/core/screen.h2
-rw-r--r--include/core/serialization.h150
4 files changed, 208 insertions, 0 deletions
diff --git a/include/core/CMakeLists.txt b/include/core/CMakeLists.txt
index eac25a6..f541c9c 100644
--- a/include/core/CMakeLists.txt
+++ b/include/core/CMakeLists.txt
@@ -12,9 +12,11 @@ set (_headers
point.h
pluginclasshandler.h
pluginclasses.h
+ propertywriter.h
rect.h
region.h
screen.h
+ serialization.h
session.h
size.h
timer.h
diff --git a/include/core/propertywriter.h b/include/core/propertywriter.h
new file mode 100644
index 0000000..80ce5d2
--- /dev/null
+++ b/include/core/propertywriter.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright © 2010 Sam Spilsbury
+ *
+ * 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
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK 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.
+ *
+ * Authors: Sam Spilsbury <smspillaz@gmail.com>
+ */
+
+#ifndef _COMPPROPERTYWRITER_H
+#define _COMPPROPERTYWRITER_H
+
+#include "core.h"
+#include <X11/Xatom.h>
+
+static const CompOption::Vector nilValues;
+
+class PropertyWriter
+{
+ public:
+
+ PropertyWriter ();
+ PropertyWriter (CompString propName,
+ CompOption::Vector &readTemplate);
+
+ bool updateProperty (Window, CompOption::Vector &, int);
+ void deleteProperty (Window);
+ const CompOption::Vector & readProperty (Window);
+ void setReadTemplate (const CompOption::Vector &);
+ const CompOption::Vector & getReadTemplate ();
+
+ private:
+
+ CompOption::Vector mPropertyValues;
+ Atom mAtom;
+};
+
+#endif
diff --git a/include/core/screen.h b/include/core/screen.h
index 4d1e2f1..f107bb3 100644
--- a/include/core/screen.h
+++ b/include/core/screen.h
@@ -321,6 +321,8 @@ class CompScreen :
unsigned int nDesktop ();
CompActiveWindowHistory *currentHistory ();
+
+ bool shouldSerializePlugins () ;
const CompRegion & region () const;
diff --git a/include/core/serialization.h b/include/core/serialization.h
new file mode 100644
index 0000000..cb9ea1a
--- /dev/null
+++ b/include/core/serialization.h
@@ -0,0 +1,150 @@
+/*
+ * Copyright © 2010 Sam Spilsbury
+ *
+ * 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
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK 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.
+ *
+ * Authors: Sam Spilsbury <smspillaz@gmail.com>
+ */
+
+#ifndef _COMPSERIALIZATION_H
+#define _COMPSERIALIZATION_H
+
+#include <core/core.h>
+#include <core/timer.h>
+#include <core/propertywriter.h>
+
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/archive/text_oarchive.hpp>
+
+#include <boost/serialization/export.hpp>
+
+#include <boost/serialization/list.hpp>
+#include <boost/serialization/vector.hpp>
+
+#include <sstream>
+#include <fstream>
+
+
+template <class T>
+class PluginStateWriter
+{
+ private:
+ PropertyWriter mPw;
+ Window mResource;
+ T *mClassPtr;
+ CompTimer mTimeout;
+
+ friend class boost::serialization::access;
+
+ bool
+ checkTimeout ()
+ {
+ if (!screen->shouldSerializePlugins ())
+ return false;
+
+ CompOption::Vector atomTemplate = mPw.readProperty (mResource);
+
+ if (atomTemplate.empty ())
+ return false;
+
+ if (!(atomTemplate.at (0).value ().type () == CompOption::TypeString))
+ return false;
+
+ std::istringstream iss (atomTemplate.at (0).value ().s ());
+ boost::archive::text_iarchive ia (iss);
+
+ ia >> *this;
+
+ postLoad ();
+
+ /* No need to store this data in XServer anymore, get rid of it */
+
+ mPw.deleteProperty (mResource);
+
+ return false;
+ };
+
+ public:
+
+ template <class Archive>
+ void serialize (Archive &ar, const unsigned int version)
+ {
+ ar & *mClassPtr;;
+ };
+
+ virtual void postLoad () {};
+
+ /* Classes get destroyed in the order of:
+ * derived -> this. Because variables might
+ * have thier destructors called, we provide
+ * a method to intercept this process
+ * and immediately serialize data such that it
+ * won't be unintentionally destroyed before the
+ * base CompPluginStateWriter destructor gets called
+ */
+
+ void writeSerializedData ()
+ {
+ if (!screen->shouldSerializePlugins ())
+ return;
+
+ CompOption::Vector atomTemplate = mPw.getReadTemplate ();
+ std::string str;
+ std::ostringstream oss (str);
+ boost::archive::text_oarchive oa (oss);
+
+ oa << *this;
+
+ CompOption::Value v (oss.str ().c_str ());
+ atomTemplate.at (0).set (v);
+
+ mPw.updateProperty (mResource, atomTemplate, XA_STRING);
+ }
+
+ PluginStateWriter (T *instance,
+ CompString pluginName,
+ Window xid) :
+ mResource (xid),
+ mClassPtr (instance)
+ {
+ if (screen->shouldSerializePlugins ())
+
+ {
+ CompString atomName = CompString ("_COMPIZ_") + pluginName +
+ CompString ("_STATE");
+ CompOption::Vector o;
+
+ o.resize (1);
+ o.at (0).setName ("data", CompOption::TypeString);
+
+ mPw = PropertyWriter (atomName, o);
+
+ mTimeout.setCallback (boost::bind (&PluginStateWriter::checkTimeout,
+ this));
+ mTimeout.setTimes (0, 0);
+ mTimeout.start ();
+ }
+ }
+
+ virtual ~PluginStateWriter () {};
+
+};
+
+#endif