Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/OrthancSynchronousWebService.cpp @ 69:1553b67b24e5 wasm
OrthancSynchronousWebService
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 22 May 2017 20:35:11 +0200 |
parents | Framework/Toolbox/OrthancWebService.cpp@288c948199e5 |
children | f73aed014bde |
comparison
equal
deleted
inserted
replaced
68:1526d38ef6da | 69:1553b67b24e5 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017 Osimis, Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "OrthancSynchronousWebService.h" | |
23 | |
24 #include "../../Resources/Orthanc/Core/OrthancException.h" | |
25 #include "../../Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.h" | |
26 | |
27 namespace OrthancStone | |
28 { | |
29 OrthancSynchronousWebService::OrthancSynchronousWebService(OrthancPlugins::IOrthancConnection* orthanc) : | |
30 orthanc_(orthanc) | |
31 { | |
32 if (orthanc == NULL) | |
33 { | |
34 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
35 } | |
36 } | |
37 | |
38 OrthancSynchronousWebService::OrthancSynchronousWebService(const Orthanc::WebServiceParameters& parameters) | |
39 { | |
40 orthanc_.reset(new OrthancPlugins::OrthancHttpConnection(parameters)); | |
41 } | |
42 | |
43 void OrthancSynchronousWebService::ScheduleGetRequest(ICallback& callback, | |
44 const std::string& uri, | |
45 Orthanc::IDynamicObject* payload) | |
46 { | |
47 std::auto_ptr<Orthanc::IDynamicObject> tmp(payload); | |
48 | |
49 try | |
50 { | |
51 std::string answer; | |
52 orthanc_->RestApiGet(answer, uri); | |
53 callback.NotifySuccess(uri, answer.c_str(), answer.size(), tmp.release()); | |
54 } | |
55 catch (Orthanc::OrthancException&) | |
56 { | |
57 callback.NotifyError(uri, tmp.release()); | |
58 } | |
59 } | |
60 | |
61 void OrthancSynchronousWebService::SchedulePostRequest(ICallback& callback, | |
62 const std::string& uri, | |
63 const std::string& body, | |
64 Orthanc::IDynamicObject* payload) | |
65 { | |
66 std::auto_ptr<Orthanc::IDynamicObject> tmp(payload); | |
67 | |
68 try | |
69 { | |
70 std::string answer; | |
71 orthanc_->RestApiPost(answer, uri, body); | |
72 callback.NotifySuccess(uri, answer.c_str(), answer.size(), tmp.release()); | |
73 } | |
74 catch (Orthanc::OrthancException&) | |
75 { | |
76 callback.NotifyError(uri, tmp.release()); | |
77 } | |
78 } | |
79 } |