Mercurial > hg > orthanc-transfers
annotate Framework/StatefulOrthancJob.h @ 73:0a18367a3358 OrthancTransfers-1.5
1.5
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 26 Mar 2024 11:06:52 +0100 |
parents | 44a0430d7899 |
children | 1e396fb509ca |
rev | line source |
---|---|
0 | 1 /** |
2 * Transfers accelerator plugin for Orthanc | |
33
44a0430d7899
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
3 * Copyright (C) 2018-2021 Osimis S.A., Belgium |
0 | 4 * |
5 * This program is free software: you can redistribute it and/or | |
6 * modify it under the terms of the GNU Affero General Public License | |
7 * as published by the Free Software Foundation, either version 3 of | |
8 * the License, or (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, but | |
11 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Affero General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Affero General Public License | |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 **/ | |
18 | |
19 | |
20 #pragma once | |
21 | |
22 | 22 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
0 | 23 |
25
dfc43678aecb
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
24 #include <Compatibility.h> // For std::unique_ptr |
dfc43678aecb
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
25 |
0 | 26 #include <memory> |
27 | |
28 | |
29 namespace OrthancPlugins | |
30 { | |
31 class StatefulOrthancJob : public OrthancJob | |
32 { | |
33 protected: | |
34 class IState; | |
35 | |
36 | |
37 class JobInfo : public boost::noncopyable | |
38 { | |
39 private: | |
40 StatefulOrthancJob& job_; | |
41 bool updated_; | |
42 Json::Value content_; | |
43 | |
44 public: | |
12 | 45 explicit JobInfo(StatefulOrthancJob& job); |
0 | 46 |
47 void SetProgress(float progress) | |
48 { | |
49 job_.UpdateProgress(progress); | |
50 } | |
51 | |
52 void SetContent(const std::string& key, | |
53 const Json::Value& value); | |
54 | |
55 void Update(); | |
56 }; | |
57 | |
58 | |
59 | |
60 class StateUpdate : public boost::noncopyable | |
61 { | |
62 private: | |
63 OrthancPluginJobStepStatus status_; | |
25
dfc43678aecb
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
64 std::unique_ptr<IState> state_; |
0 | 65 |
12 | 66 explicit StateUpdate(OrthancPluginJobStepStatus status) : |
0 | 67 status_(status) |
68 { | |
69 } | |
70 | |
12 | 71 explicit StateUpdate(IState* state); |
0 | 72 |
73 public: | |
74 static StateUpdate* Next(IState* state) // Takes ownsership | |
75 { | |
76 return new StateUpdate(state); | |
77 } | |
78 | |
79 static StateUpdate* Continue() | |
80 { | |
81 return new StateUpdate(OrthancPluginJobStepStatus_Continue); | |
82 } | |
83 | |
84 static StateUpdate* Success() | |
85 { | |
86 return new StateUpdate(OrthancPluginJobStepStatus_Success); | |
87 } | |
88 | |
89 static StateUpdate* Failure() | |
90 { | |
91 return new StateUpdate(OrthancPluginJobStepStatus_Failure); | |
92 } | |
93 | |
94 OrthancPluginJobStepStatus GetStatus() const | |
95 { | |
96 return status_; | |
97 } | |
98 | |
99 bool IsOtherState() const | |
100 { | |
101 return state_.get() != NULL; | |
102 } | |
103 | |
104 IState* ReleaseOtherState(); | |
105 }; | |
106 | |
107 | |
108 class IState : public boost::noncopyable | |
109 { | |
110 public: | |
111 virtual ~IState() | |
112 { | |
113 } | |
114 | |
115 virtual StateUpdate* Step() = 0; | |
116 | |
117 virtual void Stop(OrthancPluginJobStopReason reason) = 0; | |
118 }; | |
119 | |
120 | |
121 virtual StateUpdate* CreateInitialState(JobInfo& info) = 0; | |
122 | |
123 | |
124 private: | |
25
dfc43678aecb
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
125 std::unique_ptr<IState> state_; |
0 | 126 JobInfo info_; |
127 | |
128 | |
129 public: | |
130 StatefulOrthancJob(const std::string& jobType); | |
131 | |
132 virtual OrthancPluginJobStepStatus Step(); | |
133 | |
134 virtual void Stop(OrthancPluginJobStopReason reason); | |
135 | |
136 virtual void Reset(); | |
137 }; | |
138 } |