annotate Framework/Toolbox/OrthancApiClient.cpp @ 377:8eb4fe74000f

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 05 Nov 2018 16:18:27 +0100
parents c34784e5f299
children dd4c7e82b4be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
1 /**
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
6 *
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
11 *
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
16 *
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
19 **/
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
20
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
21 #include "OrthancApiClient.h"
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
22
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
23 #include "MessagingToolbox.h"
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
24 #include "Framework/Toolbox/MessagingToolbox.h"
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
25
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
26 #include <Core/OrthancException.h>
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
27
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
28 namespace OrthancStone
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
29 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
30 const Orthanc::IDynamicObject& OrthancApiClient::JsonResponseReadyMessage::GetPayload() const
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
31 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
32 if (HasPayload())
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
33 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
34 return *payload_;
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
35 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
36 else
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
37 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
38 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
39 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
40 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
41
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
42
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
43 const Orthanc::IDynamicObject& OrthancApiClient::BinaryResponseReadyMessage::GetPayload() const
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
44 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
45 if (HasPayload())
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
46 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
47 return *payload_;
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
48 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
49 else
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
50 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
52 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
53 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
54
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
55
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
56 const Orthanc::IDynamicObject& OrthancApiClient::EmptyResponseReadyMessage::GetPayload() const
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
57 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
58 if (HasPayload())
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
59 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
60 return *payload_;
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
61 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
62 else
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
63 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
65 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
66 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
67
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
68
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
69 const Orthanc::IDynamicObject& OrthancApiClient::HttpErrorMessage::GetPayload() const
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
70 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
71 if (HasPayload())
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
72 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
73 return *payload_;
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
74 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
75 else
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
76 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
78 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
79 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
80
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
81
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
82 OrthancApiClient::OrthancApiClient(MessageBroker &broker, IWebService &orthanc) :
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
83 IObservable(broker),
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
84 orthanc_(orthanc)
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
85 {
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
86 }
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
87
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
88 // performs the translation between IWebService messages and OrthancApiClient messages
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
89 // TODO: handle destruction of this object (with shared_ptr ?::delete_later ???)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
90 class HttpResponseToJsonConverter : public IObserver, IObservable
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
91 {
334
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
92 private:
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
93 std::auto_ptr<MessageHandler<OrthancApiClient::JsonResponseReadyMessage> > orthancApiSuccessCallback_;
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
94 std::auto_ptr<MessageHandler<OrthancApiClient::HttpErrorMessage> > orthancApiFailureCallback_;
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
95
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
96 public:
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
97 HttpResponseToJsonConverter(MessageBroker& broker,
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
98 MessageHandler<OrthancApiClient::JsonResponseReadyMessage>* orthancApiSuccessCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
99 MessageHandler<OrthancApiClient::HttpErrorMessage>* orthancApiFailureCallback)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
100 : IObserver(broker),
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
101 IObservable(broker),
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
102 orthancApiSuccessCallback_(orthancApiSuccessCallback),
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
103 orthancApiFailureCallback_(orthancApiFailureCallback)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
104 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
105 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
106
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
107 void ConvertResponseToJson(const IWebService::HttpRequestSuccessMessage& message)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
108 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
109 Json::Value response;
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
110 if (MessagingToolbox::ParseJson(response, message.GetAnswer(), message.GetAnswerSize()))
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
111 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
112 if (orthancApiSuccessCallback_.get() != NULL)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
113 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
114 orthancApiSuccessCallback_->Apply(OrthancApiClient::JsonResponseReadyMessage
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
115 (message.GetUri(), response, message.GetPayloadPointer()));
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
116 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
117 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
118 else if (orthancApiFailureCallback_.get() != NULL)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
119 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
120 orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
121 (message.GetUri(), message.GetPayloadPointer()));
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
122 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
123
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
124 delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
125 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
126
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
127 void ConvertError(const IWebService::HttpRequestErrorMessage& message)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
128 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
129 if (orthancApiFailureCallback_.get() != NULL)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
130 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
131 orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage(message.GetUri(), message.GetPayloadPointer()));
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
132 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
133
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
134 delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
135 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
136 };
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
137
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
138 // performs the translation between IWebService messages and OrthancApiClient messages
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
139 // TODO: handle destruction of this object (with shared_ptr ?::delete_later ???)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
140 class HttpResponseToBinaryConverter : public IObserver, IObservable
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
141 {
334
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
142 private:
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
143 std::auto_ptr<MessageHandler<OrthancApiClient::BinaryResponseReadyMessage> > orthancApiSuccessCallback_;
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
144 std::auto_ptr<MessageHandler<OrthancApiClient::HttpErrorMessage> > orthancApiFailureCallback_;
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
145
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
146 public:
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
147 HttpResponseToBinaryConverter(MessageBroker& broker,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
148 MessageHandler<OrthancApiClient::BinaryResponseReadyMessage>* orthancApiSuccessCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
149 MessageHandler<OrthancApiClient::HttpErrorMessage>* orthancApiFailureCallback)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
150 : IObserver(broker),
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
151 IObservable(broker),
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
152 orthancApiSuccessCallback_(orthancApiSuccessCallback),
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
153 orthancApiFailureCallback_(orthancApiFailureCallback)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
154 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
155 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
156
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
157 void ConvertResponseToBinary(const IWebService::HttpRequestSuccessMessage& message)
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
158 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
159 if (orthancApiSuccessCallback_.get() != NULL)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
160 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
161 orthancApiSuccessCallback_->Apply(OrthancApiClient::BinaryResponseReadyMessage
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
162 (message.GetUri(), message.GetAnswer(),
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
163 message.GetAnswerSize(), message.GetPayloadPointer()));
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
164 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
165 else if (orthancApiFailureCallback_.get() != NULL)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
166 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
167 orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
168 (message.GetUri(), message.GetPayloadPointer()));
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
169 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
170
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
171 delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
172 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
173
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
174 void ConvertError(const IWebService::HttpRequestErrorMessage& message)
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
175 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
176 if (orthancApiFailureCallback_.get() != NULL)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
177 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
178 orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage(message.GetUri(), message.GetPayloadPointer()));
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
179 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
180
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
181 delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
182 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
183 };
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
184
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
185 // performs the translation between IWebService messages and OrthancApiClient messages
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
186 // TODO: handle destruction of this object (with shared_ptr ?::delete_later ???)
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
187 class HttpResponseToEmptyConverter : public IObserver, IObservable
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
188 {
334
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
189 private:
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
190 std::auto_ptr<MessageHandler<OrthancApiClient::EmptyResponseReadyMessage> > orthancApiSuccessCallback_;
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
191 std::auto_ptr<MessageHandler<OrthancApiClient::HttpErrorMessage> > orthancApiFailureCallback_;
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
192
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
193 public:
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
194 HttpResponseToEmptyConverter(MessageBroker& broker,
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
195 MessageHandler<OrthancApiClient::EmptyResponseReadyMessage>* orthancApiSuccessCallback,
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
196 MessageHandler<OrthancApiClient::HttpErrorMessage>* orthancApiFailureCallback)
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
197 : IObserver(broker),
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
198 IObservable(broker),
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
199 orthancApiSuccessCallback_(orthancApiSuccessCallback),
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
200 orthancApiFailureCallback_(orthancApiFailureCallback)
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
201 {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
202 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
203
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
204 void ConvertResponseToEmpty(const IWebService::HttpRequestSuccessMessage& message)
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
205 {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
206 if (orthancApiSuccessCallback_.get() != NULL)
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
207 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
208 orthancApiSuccessCallback_->Apply(OrthancApiClient::EmptyResponseReadyMessage
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
209 (message.GetUri(), message.GetPayloadPointer()));
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
210 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
211 else if (orthancApiFailureCallback_.get() != NULL)
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
212 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
213 orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
214 (message.GetUri(), message.GetPayloadPointer()));
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
215 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
216
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
217 delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
218 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
219
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
220 void ConvertError(const IWebService::HttpRequestErrorMessage& message)
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
221 {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
222 if (orthancApiFailureCallback_.get() != NULL)
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
223 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
224 orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage(message.GetUri(), message.GetPayloadPointer()));
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
225 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
226
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
227 delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
228 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
229 };
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
230
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
231
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
232 void OrthancApiClient::GetJsonAsync(const std::string& uri,
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
233 MessageHandler<JsonResponseReadyMessage>* successCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
234 MessageHandler<HttpErrorMessage>* failureCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
235 Orthanc::IDynamicObject* payload)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
236 {
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
237 HttpResponseToJsonConverter* converter = new HttpResponseToJsonConverter(broker_, successCallback, failureCallback); // it is currently deleting itself after being used
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
238 orthanc_.GetAsync(uri, IWebService::Headers(), payload,
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
239 new Callable<HttpResponseToJsonConverter, IWebService::HttpRequestSuccessMessage>(*converter, &HttpResponseToJsonConverter::ConvertResponseToJson),
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
240 new Callable<HttpResponseToJsonConverter, IWebService::HttpRequestErrorMessage>(*converter, &HttpResponseToJsonConverter::ConvertError));
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
241
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
242 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
243
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
244 void OrthancApiClient::GetBinaryAsync(const std::string& uri,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
245 const IWebService::Headers& headers,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
246 MessageHandler<BinaryResponseReadyMessage>* successCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
247 MessageHandler<HttpErrorMessage>* failureCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
248 Orthanc::IDynamicObject* payload)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
249 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
250 HttpResponseToBinaryConverter* converter = new HttpResponseToBinaryConverter(broker_, successCallback, failureCallback); // it is currently deleting itself after being used
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
251 orthanc_.GetAsync(uri, headers, payload,
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
252 new Callable<HttpResponseToBinaryConverter, IWebService::HttpRequestSuccessMessage>(*converter, &HttpResponseToBinaryConverter::ConvertResponseToBinary),
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
253 new Callable<HttpResponseToBinaryConverter, IWebService::HttpRequestErrorMessage>(*converter, &HttpResponseToBinaryConverter::ConvertError));
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
254 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
255
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
256 void OrthancApiClient::PostBinaryAsyncExpectJson(const std::string& uri,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
257 const std::string& body,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
258 MessageHandler<JsonResponseReadyMessage>* successCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
259 MessageHandler<HttpErrorMessage>* failureCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
260 Orthanc::IDynamicObject* payload)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
261 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
262 HttpResponseToJsonConverter* converter = new HttpResponseToJsonConverter(broker_, successCallback, failureCallback); // it is currently deleting itself after being used
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
263 orthanc_.PostAsync(uri, IWebService::Headers(), body, payload,
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
264 new Callable<HttpResponseToJsonConverter, IWebService::HttpRequestSuccessMessage>(*converter, &HttpResponseToJsonConverter::ConvertResponseToJson),
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
265 new Callable<HttpResponseToJsonConverter, IWebService::HttpRequestErrorMessage>(*converter, &HttpResponseToJsonConverter::ConvertError));
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
266
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
267 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
268
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
269 void OrthancApiClient::PostJsonAsyncExpectJson(const std::string& uri,
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
270 const Json::Value& data,
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
271 MessageHandler<JsonResponseReadyMessage>* successCallback,
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
272 MessageHandler<HttpErrorMessage>* failureCallback,
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
273 Orthanc::IDynamicObject* payload)
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
274 {
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
275 std::string body;
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
276 MessagingToolbox::JsonToString(body, data);
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
277 return PostBinaryAsyncExpectJson(uri, body, successCallback, failureCallback, payload);
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
278 }
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
279
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
280 void OrthancApiClient::DeleteAsync(const std::string& uri,
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
281 MessageHandler<EmptyResponseReadyMessage>* successCallback,
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
282 MessageHandler<HttpErrorMessage>* failureCallback,
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
283 Orthanc::IDynamicObject* payload)
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
284 {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
285 HttpResponseToEmptyConverter* converter = new HttpResponseToEmptyConverter(broker_, successCallback, failureCallback); // it is currently deleting itself after being used
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
286 orthanc_.DeleteAsync(uri, IWebService::Headers(), payload,
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
287 new Callable<HttpResponseToEmptyConverter, IWebService::HttpRequestSuccessMessage>(*converter, &HttpResponseToEmptyConverter::ConvertResponseToEmpty),
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
288 new Callable<HttpResponseToEmptyConverter, IWebService::HttpRequestErrorMessage>(*converter, &HttpResponseToEmptyConverter::ConvertError));
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
289 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
290
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
291
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
292 }