comparison Framework/Toolbox/OrthancWebService.cpp @ 57:d20e25cfcf3a wasm

IWebService
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 May 2017 14:45:21 +0200
parents
children 468c48eaa01c
comparison
equal deleted inserted replaced
56:9e3c2e75b870 57:d20e25cfcf3a
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 "OrthancWebService.h"
23
24 #include "../../Resources/Orthanc/Core/OrthancException.h"
25 #include "../../Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.h"
26
27 namespace OrthancStone
28 {
29 OrthancWebService::OrthancWebService(OrthancPlugins::IOrthancConnection* orthanc) :
30 orthanc_(orthanc)
31 {
32 if (orthanc == NULL)
33 {
34 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
35 }
36 }
37
38 OrthancWebService::OrthancWebService(const Orthanc::WebServiceParameters& parameters)
39 {
40 orthanc_.reset(new OrthancPlugins::OrthancHttpConnection(parameters));
41 }
42
43 void OrthancWebService::ScheduleGetRequest(IRequestObserver& observer,
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 observer.NotifyAnswer(answer, tmp.release());
54 }
55 catch (Orthanc::OrthancException&)
56 {
57 observer.NotifyError(tmp.release());
58 }
59 }
60
61 void OrthancWebService::SchedulePostRequest(IRequestObserver& observer,
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 observer.NotifyAnswer(answer, tmp.release());
73 }
74 catch (Orthanc::OrthancException&)
75 {
76 observer.NotifyError(tmp.release());
77 }
78 }
79 }