Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/OrthancSynchronousWebService.cpp @ 70:f73aed014bde wasm
OrthancAsynchronousWebService
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 22 May 2017 21:43:49 +0200 |
parents | 1553b67b24e5 |
children |
rev | line source |
---|---|
57 | 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 | |
69
1553b67b24e5
OrthancSynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
22 #include "OrthancSynchronousWebService.h" |
57 | 23 |
24 #include "../../Resources/Orthanc/Core/OrthancException.h" | |
25 #include "../../Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.h" | |
26 | |
27 namespace OrthancStone | |
28 { | |
69
1553b67b24e5
OrthancSynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
29 OrthancSynchronousWebService::OrthancSynchronousWebService(OrthancPlugins::IOrthancConnection* orthanc) : |
57 | 30 orthanc_(orthanc) |
31 { | |
32 if (orthanc == NULL) | |
33 { | |
34 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
35 } | |
36 } | |
37 | |
69
1553b67b24e5
OrthancSynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
38 OrthancSynchronousWebService::OrthancSynchronousWebService(const Orthanc::WebServiceParameters& parameters) |
57 | 39 { |
40 orthanc_.reset(new OrthancPlugins::OrthancHttpConnection(parameters)); | |
41 } | |
42 | |
69
1553b67b24e5
OrthancSynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
43 void OrthancSynchronousWebService::ScheduleGetRequest(ICallback& callback, |
70
f73aed014bde
OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
44 const std::string& uri, |
f73aed014bde
OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
45 Orthanc::IDynamicObject* payload) |
57 | 46 { |
47 std::auto_ptr<Orthanc::IDynamicObject> tmp(payload); | |
48 | |
49 try | |
50 { | |
51 std::string answer; | |
52 orthanc_->RestApiGet(answer, uri); | |
60 | 53 callback.NotifySuccess(uri, answer.c_str(), answer.size(), tmp.release()); |
57 | 54 } |
55 catch (Orthanc::OrthancException&) | |
56 { | |
58 | 57 callback.NotifyError(uri, tmp.release()); |
57 | 58 } |
59 } | |
60 | |
69
1553b67b24e5
OrthancSynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
61 void OrthancSynchronousWebService::SchedulePostRequest(ICallback& callback, |
70
f73aed014bde
OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
62 const std::string& uri, |
f73aed014bde
OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
63 const std::string& body, |
f73aed014bde
OrthancAsynchronousWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
64 Orthanc::IDynamicObject* payload) |
57 | 65 { |
66 std::auto_ptr<Orthanc::IDynamicObject> tmp(payload); | |
67 | |
68 try | |
69 { | |
70 std::string answer; | |
71 orthanc_->RestApiPost(answer, uri, body); | |
60 | 72 callback.NotifySuccess(uri, answer.c_str(), answer.size(), tmp.release()); |
57 | 73 } |
74 catch (Orthanc::OrthancException&) | |
75 { | |
58 | 76 callback.NotifyError(uri, tmp.release()); |
57 | 77 } |
78 } | |
79 } |