annotate Plugins/Engine/PluginsJob.cpp @ 2884:497a637366b4 db-changes

integration mainline->db-changes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 12 Oct 2018 15:18:10 +0200
parents 925d8dc03a23
children bfee0b9f3209
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../../OrthancServer/PrecompiledHeadersServer.h"
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "PluginsJob.h"
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #if ORTHANC_ENABLE_PLUGINS != 1
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #error The plugin support is disabled
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #endif
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
42 #include "../../Core/Logging.h"
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include "../../Core/OrthancException.h"
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #include <json/reader.h>
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 #include <cassert>
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 namespace Orthanc
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
50 PluginsJob::PluginsJob(const _OrthancPluginCreateJob& parameters) :
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
51 parameters_(parameters)
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
53 if (parameters_.job == NULL)
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 throw OrthancException(ErrorCode_NullPointer);
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
57
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
58 if (parameters_.target == NULL ||
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
59 parameters_.finalize == NULL ||
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
60 parameters_.type == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
61 parameters_.getProgress == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
62 parameters_.getContent == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
63 parameters_.getSerialized == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
64 parameters_.step == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
65 parameters_.stop == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
66 parameters_.reset == NULL)
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
67 {
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
68 parameters_.finalize(parameters.job);
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
69 throw OrthancException(ErrorCode_NullPointer);
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
70 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
72 type_.assign(parameters.type);
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 PluginsJob::~PluginsJob()
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
77 assert(parameters_.job != NULL);
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
78 parameters_.finalize(parameters_.job);
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
81 JobStepResult PluginsJob::Step()
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
83 OrthancPluginJobStepStatus status = parameters_.step(parameters_.job);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
84
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
85 switch (status)
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
86 {
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
87 case OrthancPluginJobStepStatus_Success:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
88 return JobStepResult::Success();
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
89
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
90 case OrthancPluginJobStepStatus_Failure:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
91 return JobStepResult::Failure(ErrorCode_Plugin);
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
92
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
93 case OrthancPluginJobStepStatus_Continue:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
94 return JobStepResult::Continue();
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
95
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
96 default:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
97 throw OrthancException(ErrorCode_ParameterOutOfRange);
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
98 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
101 void PluginsJob::Reset()
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
103 parameters_.reset(parameters_.job);
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
106 void PluginsJob::Stop(JobStopReason reason)
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
108 switch (reason)
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
109 {
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
110 case JobStopReason_Success:
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
111 parameters_.stop(parameters_.job, OrthancPluginJobStopReason_Success);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
112 break;
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
113
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
114 case JobStopReason_Failure:
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
115 parameters_.stop(parameters_.job, OrthancPluginJobStopReason_Failure);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
116 break;
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
117
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
118 case JobStopReason_Canceled:
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
119 parameters_.stop(parameters_.job, OrthancPluginJobStopReason_Canceled);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
120 break;
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
121
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
122 case JobStopReason_Paused:
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
123 parameters_.stop(parameters_.job, OrthancPluginJobStopReason_Paused);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
124 break;
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
125
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
126 default:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
127 throw OrthancException(ErrorCode_ParameterOutOfRange);
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
128 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 float PluginsJob::GetProgress()
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
133 return parameters_.getProgress(parameters_.job);
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
134 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
135
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
136 void PluginsJob::GetPublicContent(Json::Value& value)
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
137 {
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
138 const char* content = parameters_.getContent(parameters_.job);
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
139
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
140 if (content == NULL)
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
141 {
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
142 value = Json::objectValue;
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
143 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
144 else
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
145 {
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
146 Json::Reader reader;
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
147
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
148 if (!reader.parse(content, value) ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
149 value.type() != Json::objectValue)
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
150 {
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
151 LOG(ERROR) << "A job plugin must provide a JSON object as its public content";
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
152 throw OrthancException(ErrorCode_Plugin);
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
153 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
154 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 bool PluginsJob::Serialize(Json::Value& value)
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
159 const char* serialized = parameters_.getSerialized(parameters_.job);
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
160
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
161 if (serialized == NULL)
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
163 return false;
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 else
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
167 Json::Reader reader;
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
168
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
169 if (!reader.parse(serialized, value) ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
170 value.type() != Json::objectValue)
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
171 {
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
172 LOG(ERROR) << "A job plugin must provide a JSON object as its serialized content";
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
173 throw OrthancException(ErrorCode_Plugin);
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
174 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
175
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
176
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
177 static const char* KEY_TYPE = "Type";
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
178
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
179 if (value.isMember(KEY_TYPE))
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
180 {
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
181 LOG(ERROR) << "The \"Type\" field is for reserved use for serialized job";
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
182 throw OrthancException(ErrorCode_Plugin);
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
183 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
184
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
185 value[KEY_TYPE] = type_;
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
186 return true;
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 }