comparison Plugins/Engine/PluginsJob.cpp @ 2810:1e8c4ecd02f4

missing files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Sep 2018 11:06:54 +0200
parents
children 7cfc8d266f41
comparison
equal deleted inserted replaced
2809:b509d9a4958b 2810:1e8c4ecd02f4
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
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 General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #include "../../OrthancServer/PrecompiledHeadersServer.h"
35 #include "PluginsJob.h"
36
37 #if ORTHANC_ENABLE_PLUGINS != 1
38 #error The plugin support is disabled
39 #endif
40
41
42 #include "../../Core/OrthancException.h"
43
44 #include <json/reader.h>
45 #include <cassert>
46
47 namespace Orthanc
48 {
49 PluginsJob::PluginsJob(const _OrthancPluginSubmitJob& parameters) :
50 job_(parameters.job_),
51 free_(parameters.free_),
52 getProgress_(parameters.getProgress_),
53 step_(parameters.step_),
54 releaseResources_(parameters.releaseResources_),
55 reset_(parameters.reset_)
56 {
57 if (job_ == NULL ||
58 parameters.type_ == NULL ||
59 free_ == NULL ||
60 getProgress_ == NULL ||
61 step_ == NULL ||
62 releaseResources_ == NULL ||
63 reset_ == NULL)
64 {
65 throw OrthancException(ErrorCode_NullPointer);
66 }
67
68 type_.assign(parameters.type_);
69
70 if (parameters.content_ == NULL)
71 {
72 publicContent_ = Json::objectValue;
73 }
74 else
75 {
76 Json::Reader reader;
77 if (!reader.parse(parameters.content_, publicContent_) ||
78 publicContent_.type() != Json::objectValue)
79 {
80 free_(job_);
81 throw OrthancException(ErrorCode_BadFileFormat);
82 }
83 }
84
85 if (parameters.serialized_ == NULL)
86 {
87 hasSerialized_ = false;
88 }
89 else
90 {
91 hasSerialized_ = true;
92
93 Json::Reader reader;
94 if (!reader.parse(parameters.serialized_, serialized_) ||
95 serialized_.type() != Json::objectValue ||
96 !serialized_.isMember("Type") ||
97 serialized_["Type"].type() != Json::stringValue)
98 {
99 free_(job_);
100 throw OrthancException(ErrorCode_BadFileFormat);
101 }
102 }
103 }
104
105 PluginsJob::~PluginsJob()
106 {
107 assert(job_ != NULL);
108 free_(job_);
109 }
110
111 JobStepResult PluginsJob::ExecuteStep()
112 {
113
114 }
115
116 void PluginsJob::SignalResubmit()
117 {
118 reset_(job_);
119 }
120
121 void PluginsJob::ReleaseResources()
122 {
123 releaseResources_(job_);
124 }
125
126 float PluginsJob::GetProgress()
127 {
128 return getProgress_(job_);
129 }
130
131 bool PluginsJob::Serialize(Json::Value& value)
132 {
133 if (hasSerialized_)
134 {
135 value = serialized_;
136 return true;
137 }
138 else
139 {
140 return false;
141 }
142 }
143 }