changeset 3639:0c9a8f6d2349 storage-commitment

better unserialization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 31 Jan 2020 17:01:55 +0100
parents ae866fc06df5
children f6a73611ec5c
files OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp
diffstat 1 files changed, 11 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp	Fri Jan 31 16:53:23 2020 +0100
+++ b/OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp	Fri Jan 31 17:01:55 2020 +0100
@@ -101,6 +101,14 @@
     AnswerCommand(StorageCommitmentScpJob& that) :
       that_(that)
     {
+      if (that_.ready_)
+      {
+        throw OrthancException(ErrorCode_BadSequenceOfCalls);
+      }
+      else
+      {
+        that_.ready_ = true;
+      }
     }
 
     virtual bool Execute()
@@ -126,6 +134,7 @@
     Unserializer(StorageCommitmentScpJob&  that) :
       that_(that)
     {
+      that_.ready_ = false;
     }
 
     virtual ICommand* Unserialize(const Json::Value& source) const
@@ -243,15 +252,7 @@
 
   void StorageCommitmentScpJob::MarkAsReady()
   {
-    if (ready_)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-    else
-    {
-      AddCommand(new AnswerCommand(*this));
-      ready_ = true;
-    }
+    AddCommand(new AnswerCommand(*this));
   }
 
 
@@ -269,8 +270,7 @@
   StorageCommitmentScpJob::StorageCommitmentScpJob(ServerContext& context,
                                                    const Json::Value& serialized) :
     SetOfCommandsJob(new Unserializer(*this), serialized),
-    context_(context),
-    ready_(false)
+    context_(context)
   {
     transactionUid_ = SerializationToolbox::ReadString(serialized, TRANSACTION_UID);
     remoteModality_ = RemoteModalityParameters(serialized[REMOTE_MODALITY]);
@@ -279,8 +279,6 @@
     SerializationToolbox::ReadListOfStrings(successSopInstanceUids_, serialized, SUCCESS_SOP_INSTANCE_UIDS);
     SerializationToolbox::ReadListOfStrings(failedSopClassUids_, serialized, FAILED_SOP_CLASS_UIDS);
     SerializationToolbox::ReadListOfStrings(failedSopInstanceUids_, serialized, FAILED_SOP_INSTANCE_UIDS);
-
-    MarkAsReady();
   }