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