# HG changeset patch # User Sebastien Jodogne # Date 1581350188 -3600 # Node ID 08eb0f93c491becb2a3f8478ac506687250cc115 # Parent 2d90dd30858c8724d7280e9a4b4718f4801ecdd4 setup step in StorageCommitmentScpJob diff -r 2d90dd30858c -r 08eb0f93c491 OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp --- a/OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp Mon Feb 10 16:44:26 2020 +0100 +++ b/OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp Mon Feb 10 16:56:28 2020 +0100 @@ -46,6 +46,7 @@ static const char* CALLED_AET = "CalledAet"; static const char* LOOKUP = "Lookup"; static const char* REMOTE_MODALITY = "RemoteModality"; +static const char* SETUP = "Setup"; static const char* SOP_CLASS_UID = "SopClassUid"; static const char* SOP_INSTANCE_UID = "SopInstanceUid"; static const char* TRANSACTION_UID = "TransactionUid"; @@ -58,10 +59,39 @@ class StorageCommitmentScpJob::StorageCommitmentCommand : public SetOfCommandsJob::ICommand { public: - virtual bool IsAnswer() const = 0; + virtual CommandType GetType() const = 0; }; + class StorageCommitmentScpJob::SetupCommand : public StorageCommitmentCommand + { + private: + ServerContext& context_; + + public: + SetupCommand(ServerContext& context) : + context_(context) + { + } + + virtual CommandType GetType() const + { + return CommandType_Setup; + } + + virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE + { + return true; + } + + virtual void Serialize(Json::Value& target) const + { + target = Json::objectValue; + target[TYPE] = SETUP; + } + }; + + class StorageCommitmentScpJob::LookupCommand : public StorageCommitmentCommand { private: @@ -82,9 +112,9 @@ { } - virtual bool IsAnswer() const + virtual CommandType GetType() const { - return false; + return CommandType_Lookup; } virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE @@ -184,9 +214,9 @@ } } - virtual bool IsAnswer() const + virtual CommandType GetType() const { - return true; + return CommandType_Answer; } virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE @@ -222,7 +252,11 @@ { const std::string type = SerializationToolbox::ReadString(source, TYPE); - if (type == LOOKUP) + if (type == SETUP) + { + return new SetupCommand(context_); + } + else if (type == LOOKUP) { return new LookupCommand(context_, SerializationToolbox::ReadString(source, SOP_CLASS_UID), @@ -246,7 +280,7 @@ const size_t n = GetCommandsCount(); - if (n == 0) + if (n <= 1) { throw OrthancException(ErrorCode_InternalError); } @@ -260,24 +294,18 @@ for (size_t i = 0; i < n; i++) { - const StorageCommitmentCommand& command = dynamic_cast(GetCommand(i)); - - if (i == n - 1) + const CommandType type = dynamic_cast(GetCommand(i)).GetType(); + + if ((i == 0 && type != CommandType_Setup) || + (i >= 1 && i < n - 1 && type != CommandType_Lookup) || + (i == n - 1 && type != CommandType_Answer)) { - if (!command.IsAnswer()) - { - throw OrthancException(ErrorCode_InternalError); - } + throw OrthancException(ErrorCode_InternalError); } - else - { - if (command.IsAnswer()) - { - throw OrthancException(ErrorCode_InternalError); - } - const LookupCommand& lookup = dynamic_cast(command); - + if (type == CommandType_Lookup) + { + const LookupCommand& lookup = dynamic_cast(GetCommand(i)); sopClassUids.push_back(lookup.GetSopClassUid()); sopInstanceUids.push_back(lookup.GetSopInstanceUid()); failureReasons.push_back(lookup.GetFailureReason()); @@ -306,6 +334,8 @@ "Unknown remote modality for storage commitment SCP: " + remoteAet); } } + + AddCommand(new SetupCommand(context)); } diff -r 2d90dd30858c -r 08eb0f93c491 OrthancServer/ServerJobs/StorageCommitmentScpJob.h --- a/OrthancServer/ServerJobs/StorageCommitmentScpJob.h Mon Feb 10 16:44:26 2020 +0100 +++ b/OrthancServer/ServerJobs/StorageCommitmentScpJob.h Mon Feb 10 16:56:28 2020 +0100 @@ -45,7 +45,15 @@ class StorageCommitmentScpJob : public SetOfCommandsJob { private: + enum CommandType + { + CommandType_Setup, + CommandType_Lookup, + CommandType_Answer + }; + class StorageCommitmentCommand; + class SetupCommand; class LookupCommand; class AnswerCommand; class Unserializer;