aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-18 21:38:13 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-18 21:38:13 +0100
commit40d750718c8e6f0d50496ddbff67d1eed1981f87 (patch)
tree8695412427e2fb9a1682af9d8c81413e88cf2582
parent399f08717ecf7c56744510e3e9643b7875bc40b5 (diff)
downloadpaludis-40d750718c8e6f0d50496ddbff67d1eed1981f87.tar.gz
paludis-40d750718c8e6f0d50496ddbff67d1eed1981f87.tar.xz
Allow states to be serialised
-rw-r--r--paludis/resolver/job.cc18
-rw-r--r--paludis/resolver/job_state.cc88
-rw-r--r--paludis/resolver/job_state.hh19
3 files changed, 122 insertions, 3 deletions
diff --git a/paludis/resolver/job.cc b/paludis/resolver/job.cc
index 75bf8c7..7bf5791 100644
--- a/paludis/resolver/job.cc
+++ b/paludis/resolver/job.cc
@@ -19,6 +19,7 @@
#include <paludis/resolver/job.hh>
#include <paludis/resolver/job_requirements.hh>
+#include <paludis/resolver/job_state.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/sequence.hh>
@@ -158,10 +159,12 @@ FetchJob::deserialise(Deserialisation & d)
requirements->push_back(vv.member<JobRequirement>(stringify(n)));
}
- return make_shared_ptr(new FetchJob(
+ std::tr1::shared_ptr<FetchJob> result(new FetchJob(
requirements,
v.member<std::tr1::shared_ptr<const PackageID> >("origin_id")
));
+ result->set_state(v.member<std::tr1::shared_ptr<JobState> >("state"));
+ return result;
}
void
@@ -170,6 +173,7 @@ FetchJob::serialise(Serialiser & s) const
s.object("FetchJob")
.member(SerialiserFlags<serialise::container, serialise::might_be_null>(), "requirements", requirements())
.member(SerialiserFlags<serialise::might_be_null>(), "origin_id", origin_id())
+ .member(SerialiserFlags<serialise::might_be_null>(), "state", state())
;
}
@@ -279,13 +283,16 @@ InstallJob::deserialise(Deserialisation & d)
requirements->push_back(vv.member<JobRequirement>(stringify(n)));
}
- return make_shared_ptr(new InstallJob(
+ std::tr1::shared_ptr<InstallJob> result(new InstallJob(
requirements,
v.member<std::tr1::shared_ptr<const PackageID> >("origin_id"),
RepositoryName(v.member<std::string>("destination_repository_name")),
destringify<DestinationType>(v.member<std::string>("destination_type")),
replacing
));
+
+ result->set_state(v.member<std::tr1::shared_ptr<JobState> >("state"));
+ return result;
}
void
@@ -297,6 +304,7 @@ InstallJob::serialise(Serialiser & s) const
.member(SerialiserFlags<>(), "destination_repository_name", stringify(destination_repository_name()))
.member(SerialiserFlags<>(), "destination_type", stringify(destination_type()))
.member(SerialiserFlags<serialise::container, serialise::might_be_null>(), "replacing", replacing())
+ .member(SerialiserFlags<serialise::might_be_null>(), "state", state())
;
}
@@ -376,10 +384,13 @@ UninstallJob::deserialise(Deserialisation & d)
requirements->push_back(vv.member<JobRequirement>(stringify(n)));
}
- return make_shared_ptr(new UninstallJob(
+ std::tr1::shared_ptr<UninstallJob> result(new UninstallJob(
requirements,
ids_to_remove
));
+
+ result->set_state(v.member<std::tr1::shared_ptr<JobState> >("state"));
+ return result;
}
void
@@ -388,6 +399,7 @@ UninstallJob::serialise(Serialiser & s) const
s.object("UninstallJob")
.member(SerialiserFlags<serialise::container, serialise::might_be_null>(), "requirements", requirements())
.member(SerialiserFlags<serialise::container, serialise::might_be_null>(), "ids_to_remove", ids_to_remove())
+ .member(SerialiserFlags<serialise::might_be_null>(), "state", state())
;
}
diff --git a/paludis/resolver/job_state.cc b/paludis/resolver/job_state.cc
index 78ae200..60f74b9 100644
--- a/paludis/resolver/job_state.cc
+++ b/paludis/resolver/job_state.cc
@@ -20,6 +20,7 @@
#include <paludis/resolver/job_state.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/serialise-impl.hh>
using namespace paludis;
using namespace paludis::resolver;
@@ -59,6 +60,51 @@ JobState::~JobState()
{
}
+const std::tr1::shared_ptr<JobState>
+JobState::deserialise(Deserialisation & d)
+{
+ if (d.class_name() == "JobPendingState")
+ return JobPendingState::deserialise(d);
+ else if (d.class_name() == "JobActiveState")
+ return JobActiveState::deserialise(d);
+ else if (d.class_name() == "JobSucceededState")
+ return JobSucceededState::deserialise(d);
+ else if (d.class_name() == "JobFailedState")
+ return JobFailedState::deserialise(d);
+ else if (d.class_name() == "JobSkippedState")
+ return JobSkippedState::deserialise(d);
+ else
+ throw InternalError(PALUDIS_HERE, "unknown class '" + stringify(d.class_name()) + "'");
+}
+
+const std::tr1::shared_ptr<JobPendingState>
+JobPendingState::deserialise(Deserialisation & d)
+{
+ Deserialisator v(d, "JobPendingState");
+ return make_shared_ptr(new JobPendingState);
+}
+
+void
+JobPendingState::serialise(Serialiser & s) const
+{
+ s.object("JobPendingState")
+ ;
+}
+
+const std::tr1::shared_ptr<JobSkippedState>
+JobSkippedState::deserialise(Deserialisation & d)
+{
+ Deserialisator v(d, "JobSkippedState");
+ return make_shared_ptr(new JobSkippedState);
+}
+
+void
+JobSkippedState::serialise(Serialiser & s) const
+{
+ s.object("JobSkippedState")
+ ;
+}
+
JobActiveState::JobActiveState() :
PrivateImplementationPattern<JobActiveState>(new Implementation<JobActiveState>)
{
@@ -86,6 +132,20 @@ JobActiveState::failed() const
return make_shared_ptr(new JobFailedState(_imp->output_manager));
}
+const std::tr1::shared_ptr<JobActiveState>
+JobActiveState::deserialise(Deserialisation & d)
+{
+ Deserialisator v(d, "JobActiveState");
+ return make_shared_ptr(new JobActiveState());
+}
+
+void
+JobActiveState::serialise(Serialiser & s) const
+{
+ s.object("JobActiveState")
+ ;
+}
+
JobSucceededState::JobSucceededState(const std::tr1::shared_ptr<OutputManager> & m) :
PrivateImplementationPattern<JobSucceededState>(new Implementation<JobSucceededState>(m))
{
@@ -101,6 +161,20 @@ JobSucceededState::output_manager() const
return _imp->output_manager;
}
+const std::tr1::shared_ptr<JobSucceededState>
+JobSucceededState::deserialise(Deserialisation & d)
+{
+ Deserialisator v(d, "JobSucceededState");
+ return make_shared_ptr(new JobSucceededState(make_null_shared_ptr()));
+}
+
+void
+JobSucceededState::serialise(Serialiser & s) const
+{
+ s.object("JobSucceededState")
+ ;
+}
+
JobFailedState::JobFailedState(const std::tr1::shared_ptr<OutputManager> & m) :
PrivateImplementationPattern<JobFailedState>(new Implementation<JobFailedState>(m))
{
@@ -116,3 +190,17 @@ JobFailedState::output_manager() const
return _imp->output_manager;
}
+const std::tr1::shared_ptr<JobFailedState>
+JobFailedState::deserialise(Deserialisation & d)
+{
+ Deserialisator v(d, "JobFailedState");
+ return make_shared_ptr(new JobFailedState(make_null_shared_ptr()));
+}
+
+void
+JobFailedState::serialise(Serialiser & s) const
+{
+ s.object("JobFailedState")
+ ;
+}
+
diff --git a/paludis/resolver/job_state.hh b/paludis/resolver/job_state.hh
index 8e3a8c0..5e001be 100644
--- a/paludis/resolver/job_state.hh
+++ b/paludis/resolver/job_state.hh
@@ -25,6 +25,7 @@
#include <paludis/util/type_list.hh>
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/output_manager-fwd.hh>
+#include <paludis/serialise-fwd.hh>
#include <tr1/memory>
namespace paludis
@@ -37,12 +38,18 @@ namespace paludis
{
public:
virtual ~JobState() = 0;
+
+ virtual void serialise(Serialiser &) const = 0;
+ static const std::tr1::shared_ptr<JobState> deserialise(Deserialisation &) PALUDIS_ATTRIBUTE((warn_unused_result));
};
class PALUDIS_VISIBLE JobPendingState :
public JobState,
public ImplementAcceptMethods<JobState, JobPendingState>
{
+ public:
+ virtual void serialise(Serialiser &) const;
+ static const std::tr1::shared_ptr<JobPendingState> deserialise(Deserialisation &) PALUDIS_ATTRIBUTE((warn_unused_result));
};
class PALUDIS_VISIBLE JobActiveState :
@@ -57,6 +64,9 @@ namespace paludis
void set_output_manager(const std::tr1::shared_ptr<OutputManager> &);
const std::tr1::shared_ptr<JobSucceededState> succeeded() const PALUDIS_ATTRIBUTE((warn_unused_result));
const std::tr1::shared_ptr<JobFailedState> failed() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual void serialise(Serialiser &) const;
+ static const std::tr1::shared_ptr<JobActiveState> deserialise(Deserialisation &) PALUDIS_ATTRIBUTE((warn_unused_result));
};
class PALUDIS_VISIBLE JobSucceededState :
@@ -69,6 +79,9 @@ namespace paludis
~JobSucceededState();
const std::tr1::shared_ptr<OutputManager> output_manager() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual void serialise(Serialiser &) const;
+ static const std::tr1::shared_ptr<JobSucceededState> deserialise(Deserialisation &) PALUDIS_ATTRIBUTE((warn_unused_result));
};
class PALUDIS_VISIBLE JobFailedState :
@@ -81,12 +94,18 @@ namespace paludis
~JobFailedState();
const std::tr1::shared_ptr<OutputManager> output_manager() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual void serialise(Serialiser &) const;
+ static const std::tr1::shared_ptr<JobFailedState> deserialise(Deserialisation &) PALUDIS_ATTRIBUTE((warn_unused_result));
};
class PALUDIS_VISIBLE JobSkippedState :
public JobState,
public ImplementAcceptMethods<JobState, JobSkippedState>
{
+ public:
+ virtual void serialise(Serialiser &) const;
+ static const std::tr1::shared_ptr<JobSkippedState> deserialise(Deserialisation &) PALUDIS_ATTRIBUTE((warn_unused_result));
};
}
}