comparison Framework/Oracle/GetOrthancImageCommand.cpp @ 1134:87fbeb823375 broker

allocating messages from oracle commands on the stack
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 06 Nov 2019 15:16:45 +0100
parents 17660df24c36
children a0a33e5ea5bb
comparison
equal deleted inserted replaced
1133:0e3a3be313fd 1134:87fbeb823375
27 #include <Core/OrthancException.h> 27 #include <Core/OrthancException.h>
28 #include <Core/Toolbox.h> 28 #include <Core/Toolbox.h>
29 29
30 namespace OrthancStone 30 namespace OrthancStone
31 { 31 {
32 GetOrthancImageCommand::SuccessMessage::SuccessMessage(const GetOrthancImageCommand& command,
33 Orthanc::ImageAccessor* image, // Takes ownership
34 Orthanc::MimeType mime) :
35 OriginMessage(command),
36 image_(image),
37 mime_(mime)
38 {
39 if (image == NULL)
40 {
41 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
42 }
43 }
44
45
46 GetOrthancImageCommand::GetOrthancImageCommand() : 32 GetOrthancImageCommand::GetOrthancImageCommand() :
47 uri_("/"), 33 uri_("/"),
48 timeout_(600), 34 timeout_(600),
49 hasExpectedFormat_(false) 35 hasExpectedFormat_(false)
50 { 36 {
80 default: 66 default:
81 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 67 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
82 } 68 }
83 } 69 }
84 70
85 IMessage* GetOrthancImageCommand::ProcessHttpAnswer(const std::string& answer, 71
86 const HttpHeaders& answerHeaders) const 72 void GetOrthancImageCommand::ProcessHttpAnswer(boost::weak_ptr<IObserver> receiver,
73 IMessageEmitter& emitter,
74 const std::string& answer,
75 const HttpHeaders& answerHeaders)
87 { 76 {
88 Orthanc::MimeType contentType = Orthanc::MimeType_Binary; 77 Orthanc::MimeType contentType = Orthanc::MimeType_Binary;
89 78
90 for (HttpHeaders::const_iterator it = answerHeaders.begin(); 79 for (HttpHeaders::const_iterator it = answerHeaders.begin();
91 it != answerHeaders.end(); ++it) 80 it != answerHeaders.end(); ++it)
143 { 132 {
144 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); 133 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
145 } 134 }
146 } 135 }
147 136
148 return new SuccessMessage(*this, image.release(), contentType); 137 SuccessMessage message(*this, *image, contentType);
138 emitter.EmitMessage(receiver, message);
149 } 139 }
150 } 140 }