2
* Copyright © 2010 Sam Spilsbury
4
* Permission to use, copy, modify, distribute, and sell this software
5
* and its documentation for any purpose is hereby granted without
6
* fee, provided that the above copyright notice appear in all copies
7
* and that both that copyright notice and this permission notice
8
* appear in supporting documentation, and that the name of
9
* Dennis Kasprzyk not be used in advertising or publicity pertaining to
10
* distribution of the software without specific, written prior permission.
11
* Dennis Kasprzyk makes no representations about the suitability of this
12
* software for any purpose. It is provided "as is" without express or
15
* DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17
* NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
* Authors: Sam Spilsbury <smspillaz@gmail.com>
26
#ifndef _COMPSERIALIZATION_H
27
#define _COMPSERIALIZATION_H
29
#include <core/core.h>
30
#include <core/timer.h>
31
#include <core/propertywriter.h>
34
#include <boost/preprocessor/cat.hpp>
36
#include <boost/archive/text_iarchive.hpp>
37
#include <boost/archive/text_oarchive.hpp>
39
#include <boost/serialization/export.hpp>
41
#include <boost/serialization/list.hpp>
42
#include <boost/serialization/vector.hpp>
49
class PluginStateWriter
57
friend class boost::serialization::access;
62
if (!screen->shouldSerializePlugins ())
65
CompOption::Vector atomTemplate = mPw.readProperty (mResource);
67
if (atomTemplate.empty ())
70
if (!(atomTemplate.at (0).value ().type () == CompOption::TypeString))
73
std::istringstream iss (atomTemplate.at (0).value ().s ());
74
boost::archive::text_iarchive ia (iss);
80
/* No need to store this data in XServer anymore, get rid of it */
82
mPw.deleteProperty (mResource);
89
template <class Archive>
90
void serialize (Archive &ar, const unsigned int version)
95
virtual void postLoad () {};
97
/* Classes get destroyed in the order of:
98
* derived -> this. Because variables might
99
* have thier destructors called, we provide
100
* a method to intercept this process
101
* and immediately serialize data such that it
102
* won't be unintentionally destroyed before the
103
* base CompPluginStateWriter destructor gets called
106
void writeSerializedData ()
108
if (!screen->shouldSerializePlugins ())
111
CompOption::Vector atomTemplate = mPw.getReadTemplate ();
113
std::ostringstream oss (str);
114
boost::archive::text_oarchive oa (oss);
116
/* Nothing was initially read from the property, which probably means that
117
* shouldSerializePlugins was turned on in between plugin load and unload
118
* so don't attempt to do anything here */
119
if (!atomTemplate.size ())
124
CompOption::Value v (oss.str ().c_str ());
125
atomTemplate.at (0).set (v);
127
mPw.updateProperty (mResource, atomTemplate, XA_STRING);
130
PluginStateWriter (T *instance,
135
if (screen->shouldSerializePlugins ())
138
CompString atomName = compPrintf ("_COMPIZ_%s_STATE",
140
CompOption::Vector o;
143
o.at (0).setName ("data", CompOption::TypeString);
145
mPw = PropertyWriter (atomName, o);
147
mTimeout.setCallback (boost::bind (&PluginStateWriter::checkTimeout,
149
mTimeout.setTimes (0, 0);
154
virtual ~PluginStateWriter () {};