comparison OrthancServer/ServerJobs/OrthancPeerStoreJob.h @ 2603:988936118354 jobs

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 May 2018 17:02:25 +0200
parents c25f1a52acbc
children a21b244efb37
comparison
equal deleted inserted replaced
2602:c25f1a52acbc 2603:988936118354
34 #pragma once 34 #pragma once
35 35
36 #include "../../Core/JobsEngine/SetOfInstancesJob.h" 36 #include "../../Core/JobsEngine/SetOfInstancesJob.h"
37 #include "../../Core/HttpClient.h" 37 #include "../../Core/HttpClient.h"
38 38
39 #include "../ServerContext.h"
40
39 41
40 namespace Orthanc 42 namespace Orthanc
41 { 43 {
42 class OrthancPeerStoreJob : public SetOfInstancesJob 44 class OrthancPeerStoreJob : public SetOfInstancesJob
43 { 45 {
45 ServerContext& context_; 47 ServerContext& context_;
46 WebServiceParameters peer_; 48 WebServiceParameters peer_;
47 std::auto_ptr<HttpClient> client_; 49 std::auto_ptr<HttpClient> client_;
48 50
49 protected: 51 protected:
50 virtual bool HandleInstance(const std::string& instance) 52 virtual bool HandleInstance(const std::string& instance);
51 {
52 //boost::this_thread::sleep(boost::posix_time::milliseconds(500));
53
54 if (client_.get() == NULL)
55 {
56 client_.reset(new HttpClient(peer_, "instances"));
57 client_->SetMethod(HttpMethod_Post);
58 }
59
60 LOG(INFO) << "Sending instance " << instance << " to peer \""
61 << peer_.GetUrl() << "\"";
62
63 context_.ReadDicom(client_->GetBody(), instance);
64
65 std::string answer;
66 if (client_->Apply(answer))
67 {
68 return true;
69 }
70 else
71 {
72 throw OrthancException(ErrorCode_NetworkProtocol);
73 }
74 }
75 53
76 public: 54 public:
77 OrthancPeerStoreJob(ServerContext& context) : 55 OrthancPeerStoreJob(ServerContext& context) :
78 context_(context) 56 context_(context)
79 { 57 {
80 } 58 }
81 59
82 void SetPeer(const WebServiceParameters& peer) 60 void SetPeer(const WebServiceParameters& peer);
83 {
84 if (IsStarted())
85 {
86 throw OrthancException(ErrorCode_BadSequenceOfCalls);
87 }
88 else
89 {
90 peer_ = peer;
91 }
92 }
93 61
94 const WebServiceParameters& GetPeer() const 62 const WebServiceParameters& GetPeer() const
95 { 63 {
96 return peer_; 64 return peer_;
97 } 65 }
98 66
99 virtual void ReleaseResources() // For pausing jobs 67 virtual void ReleaseResources(); // For pausing jobs
100 {
101 client_.reset(NULL);
102 }
103 68
104 virtual void GetJobType(std::string& target) 69 virtual void GetJobType(std::string& target)
105 { 70 {
106 target = "OrthancPeerStore"; 71 target = "OrthancPeerStore";
107 } 72 }
108 73
109 virtual void GetPublicContent(Json::Value& value) 74 virtual void GetPublicContent(Json::Value& value);
110 {
111 Json::Value v;
112 peer_.ToJson(v);
113 value["Peer"] = v;
114
115 value["InstancesCount"] = static_cast<uint32_t>(GetInstances().size());
116 value["FailedInstancesCount"] = static_cast<uint32_t>(GetFailedInstances().size());
117 }
118 }; 75 };
119 } 76 }