Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/OrthancApiClient.h @ 270:2d64f4d39610 am-2
backup (work in progress)
author | am@osimis.io |
---|---|
date | Thu, 23 Aug 2018 14:45:04 +0200 |
parents | |
children | 46c5296d867e |
comparison
equal
deleted
inserted
replaced
269:0dfa83535cd7 | 270:2d64f4d39610 |
---|---|
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-2018 Osimis S.A., 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 #pragma once | |
23 | |
24 #include <boost/shared_ptr.hpp> | |
25 #include <json/json.h> | |
26 | |
27 #include "IWebService.h" | |
28 #include "../Messages/IObservable.h" | |
29 | |
30 | |
31 namespace OrthancStone | |
32 { | |
33 class OrthancApiClient: | |
34 public IObservable | |
35 { | |
36 protected: | |
37 class BaseRequest; | |
38 class GetJsonRequest; | |
39 | |
40 struct InternalGetJsonResponseReadyMessage; | |
41 struct InternalGetJsonResponseErrorMessage; | |
42 | |
43 public: | |
44 struct GetJsonResponseReadyMessage : public IMessage | |
45 { | |
46 Json::Value response_; | |
47 std::string uri_; | |
48 | |
49 GetJsonResponseReadyMessage(MessageType messageType, | |
50 const std::string& uri, | |
51 const Json::Value& response) | |
52 : IMessage(messageType), | |
53 uri_(uri), | |
54 response_(response) | |
55 { | |
56 } | |
57 }; | |
58 | |
59 public: | |
60 | |
61 enum Mode | |
62 { | |
63 Mode_GetJson | |
64 }; | |
65 | |
66 protected: | |
67 IWebService& orthanc_; | |
68 class WebCallback; | |
69 boost::shared_ptr<WebCallback> webCallback_; // This is a PImpl pattern | |
70 std::set<BaseRequest*> requestsInProgress_; | |
71 | |
72 // int ScheduleGetJsonRequest(const std::string& uri); | |
73 | |
74 void ReleaseRequest(BaseRequest* request); | |
75 | |
76 public: | |
77 OrthancApiClient(MessageBroker& broker, | |
78 IWebService& orthanc); | |
79 virtual ~OrthancApiClient() {} | |
80 | |
81 // schedule a GET request expecting a JSON request. | |
82 // once the response is ready, it will emit a OrthancApiClient::GetJsonResponseReadyMessage message whose messageType is specified in the call | |
83 void ScheduleGetJsonRequest(IObserver& responseObserver, const std::string& uri, MessageType messageToEmitWhenResponseReady); | |
84 | |
85 void ScheduleGetStudyIds(IObserver& responseObserver) {ScheduleGetJsonRequest(responseObserver, "/studies", MessageType_OrthancApi_GetStudyIds_Ready);} | |
86 void ScheduleGetStudy(IObserver& responseObserver, const std::string& studyId) {ScheduleGetJsonRequest(responseObserver, "/studies/" + studyId, MessageType_OrthancApi_GetStudy_Ready);} | |
87 void ScheduleGetSeries(IObserver& responseObserver, const std::string& seriesId) {ScheduleGetJsonRequest(responseObserver, "/series/" + seriesId, MessageType_OrthancApi_GetSeries_Ready);} | |
88 | |
89 }; | |
90 } |