comparison Framework/StatefulOrthancJob.h @ 0:95226b754d9e

initial release
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Sep 2018 11:34:55 +0200
parents
children 7e207ade2f1a
comparison
equal deleted inserted replaced
-1:000000000000 0:95226b754d9e
1 /**
2 * Transfers accelerator plugin for Orthanc
3 * Copyright (C) 2018 Osimis, Belgium
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 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h>
23
24 #include <memory>
25
26
27 namespace OrthancPlugins
28 {
29 class StatefulOrthancJob : public OrthancJob
30 {
31 protected:
32 class IState;
33
34
35 class JobInfo : public boost::noncopyable
36 {
37 private:
38 StatefulOrthancJob& job_;
39 bool updated_;
40 Json::Value content_;
41
42 public:
43 JobInfo(StatefulOrthancJob& job);
44
45 void SetProgress(float progress)
46 {
47 job_.UpdateProgress(progress);
48 }
49
50 void SetContent(const std::string& key,
51 const Json::Value& value);
52
53 void Update();
54 };
55
56
57
58 class StateUpdate : public boost::noncopyable
59 {
60 private:
61 OrthancPluginJobStepStatus status_;
62 std::auto_ptr<IState> state_;
63
64 StateUpdate(OrthancPluginJobStepStatus status) :
65 status_(status)
66 {
67 }
68
69 StateUpdate(IState* state);
70
71 public:
72 static StateUpdate* Next(IState* state) // Takes ownsership
73 {
74 return new StateUpdate(state);
75 }
76
77 static StateUpdate* Continue()
78 {
79 return new StateUpdate(OrthancPluginJobStepStatus_Continue);
80 }
81
82 static StateUpdate* Success()
83 {
84 return new StateUpdate(OrthancPluginJobStepStatus_Success);
85 }
86
87 static StateUpdate* Failure()
88 {
89 return new StateUpdate(OrthancPluginJobStepStatus_Failure);
90 }
91
92 OrthancPluginJobStepStatus GetStatus() const
93 {
94 return status_;
95 }
96
97 bool IsOtherState() const
98 {
99 return state_.get() != NULL;
100 }
101
102 IState* ReleaseOtherState();
103 };
104
105
106 class IState : public boost::noncopyable
107 {
108 public:
109 virtual ~IState()
110 {
111 }
112
113 virtual StateUpdate* Step() = 0;
114
115 virtual void Stop(OrthancPluginJobStopReason reason) = 0;
116 };
117
118
119 virtual StateUpdate* CreateInitialState(JobInfo& info) = 0;
120
121
122 private:
123 std::auto_ptr<IState> state_;
124 JobInfo info_;
125
126
127 public:
128 StatefulOrthancJob(const std::string& jobType);
129
130 virtual OrthancPluginJobStepStatus Step();
131
132 virtual void Stop(OrthancPluginJobStopReason reason);
133
134 virtual void Reset();
135 };
136 }