annotate OrthancServer/Plugins/Engine/PluginsJob.cpp @ 5294:e0e2aee4453e

Modality worklists plugin: allow searching on private tags (exact match only)
author Alain Mazy <am@osimis.io>
date Wed, 10 May 2023 12:52:35 +0200
parents 0ea402b4d901
children 48b8dae6dc77
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
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5138
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5138
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * General Public License for more details.
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
23 #include "../../Sources/PrecompiledHeadersServer.h"
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "PluginsJob.h"
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #if ORTHANC_ENABLE_PLUGINS != 1
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #error The plugin support is disabled
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #endif
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
31 #include "../../../OrthancFramework/Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
32 #include "../../../OrthancFramework/Sources/OrthancException.h"
4392
3af1d763763a confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
33 #include "../../../OrthancFramework/Sources/Toolbox.h"
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include <cassert>
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 namespace Orthanc
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
39 void PluginsJob::Setup()
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
41 if (parameters_.job == NULL)
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 throw OrthancException(ErrorCode_NullPointer);
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 }
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
45
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
46 if (parameters_.target == NULL ||
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
47 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
48 parameters_.type == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
49 parameters_.getProgress == NULL ||
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
50 (parameters_.getContent == NULL && deprecatedGetContent_ == NULL) ||
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
51 (parameters_.getSerialized == NULL && deprecatedGetSerialized_ == NULL) ||
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
52 parameters_.step == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
53 parameters_.stop == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
54 parameters_.reset == NULL)
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
55 {
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
56 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
57 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
58 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
60 type_.assign(parameters_.type);
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
61 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
62
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
63 PluginsJob::PluginsJob(const _OrthancPluginCreateJob2& parameters) :
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
64 parameters_(parameters),
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
65 deprecatedGetContent_(NULL),
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
66 deprecatedGetSerialized_(NULL)
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
67 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
68 Setup();
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
69 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
70
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
71 PluginsJob::PluginsJob(const _OrthancPluginCreateJob& parameters)
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
72 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
73 LOG(WARNING) << "Your plugin is using the deprecated OrthancPluginCreateJob() function";
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
74
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
75 memset(&parameters_, 0, sizeof(parameters_));
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
76 parameters_.target = parameters.target;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
77 parameters_.job = parameters.job;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
78 parameters_.finalize = parameters.finalize;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
79 parameters_.type = parameters.type;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
80 parameters_.getProgress = parameters.getProgress;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
81 parameters_.getContent = NULL;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
82 parameters_.getSerialized = NULL;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
83 parameters_.step = parameters.step;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
84 parameters_.stop = parameters.stop;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
85 parameters_.reset = parameters.reset;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
86
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
87 deprecatedGetContent_ = parameters.getContent;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
88 deprecatedGetSerialized_ = parameters.getSerialized;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
89
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
90 Setup();
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 PluginsJob::~PluginsJob()
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
95 assert(parameters_.job != NULL);
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
96 parameters_.finalize(parameters_.job);
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
99 JobStepResult PluginsJob::Step(const std::string& jobId)
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
101 OrthancPluginJobStepStatus status = parameters_.step(parameters_.job);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
102
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
103 switch (status)
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
104 {
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
105 case OrthancPluginJobStepStatus_Success:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
106 return JobStepResult::Success();
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
107
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
108 case OrthancPluginJobStepStatus_Failure:
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
109 return JobStepResult::Failure(ErrorCode_Plugin, NULL);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
110
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
111 case OrthancPluginJobStepStatus_Continue:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
112 return JobStepResult::Continue();
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
113
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
114 default:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
115 throw OrthancException(ErrorCode_ParameterOutOfRange);
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
116 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
119 void PluginsJob::Reset()
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
121 parameters_.reset(parameters_.job);
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
124 void PluginsJob::Stop(JobStopReason reason)
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
126 switch (reason)
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
127 {
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
128 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
129 parameters_.stop(parameters_.job, OrthancPluginJobStopReason_Success);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
130 break;
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
131
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
132 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
133 parameters_.stop(parameters_.job, OrthancPluginJobStopReason_Failure);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
134 break;
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
135
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
136 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
137 parameters_.stop(parameters_.job, OrthancPluginJobStopReason_Canceled);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
138 break;
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
139
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
140 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
141 parameters_.stop(parameters_.job, OrthancPluginJobStopReason_Paused);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
142 break;
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
143
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
144 default:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
145 throw OrthancException(ErrorCode_ParameterOutOfRange);
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
146 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 float PluginsJob::GetProgress()
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
151 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
152 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
153
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
154
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
155 namespace
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
156 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
157 class MemoryBufferRaii : public boost::noncopyable
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
158 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
159 private:
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
160 OrthancPluginMemoryBuffer buffer_;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
161
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
162 public:
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
163 MemoryBufferRaii()
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
164 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
165 buffer_.size = 0;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
166 buffer_.data = NULL;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
167 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
168
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
169 ~MemoryBufferRaii()
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
170 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
171 if (buffer_.size != 0)
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
172 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
173 free(buffer_.data);
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
174 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
175 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
176
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
177 OrthancPluginMemoryBuffer* GetObject()
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
178 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
179 return &buffer_;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
180 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
181
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
182 void ToJsonObject(Json::Value& target) const
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
183 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
184 if ((buffer_.data == NULL && buffer_.size != 0) ||
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
185 (buffer_.data != NULL && buffer_.size == 0) ||
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
186 !Toolbox::ReadJson(target, buffer_.data, buffer_.size) ||
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
187 target.type() != Json::objectValue)
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
188 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
189 throw OrthancException(ErrorCode_Plugin,
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
190 "A job plugin must provide a JSON object as its public content and as its serialization");
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
191 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
192 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
193 };
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
194 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
195
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
196 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
197 {
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
198 if (parameters_.getContent != NULL)
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
199 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
200 MemoryBufferRaii target;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
201
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
202 OrthancPluginErrorCode code = parameters_.getContent(target.GetObject(), parameters_.job);
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
203
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
204 if (code != OrthancPluginErrorCode_Success)
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
205 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
206 throw OrthancException(static_cast<ErrorCode>(code));
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
207 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
208 else
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
209 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
210 target.ToJsonObject(value);
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
211 }
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
212 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
213 else
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
214 {
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
215 // This was the source code in Orthanc <= 1.11.2
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
216 const char* content = deprecatedGetContent_(parameters_.job);
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
217
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
218 if (content == NULL)
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
219 {
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
220 value = Json::objectValue;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
221 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
222 else
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
223 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
224 if (!Toolbox::ReadJson(value, content) ||
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
225 value.type() != Json::objectValue)
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
226 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
227 throw OrthancException(ErrorCode_Plugin,
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
228 "A job plugin must provide a JSON object as its public content");
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
229 }
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
230 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
231 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 bool PluginsJob::Serialize(Json::Value& value)
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
236 if (parameters_.getSerialized != NULL)
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
237 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
238 MemoryBufferRaii target;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
239
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
240 int32_t code = parameters_.getContent(target.GetObject(), parameters_.job);
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
241
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
242 if (code < 0)
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
243 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
244 throw OrthancException(ErrorCode_Plugin, "Error during the serialization of a job");
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
245 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
246 else if (code == 0)
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
247 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
248 return false; // Serialization is not implemented
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
249 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
250 else
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
251 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
252 target.ToJsonObject(value);
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
253
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
254 static const char* KEY_TYPE = "Type";
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
255
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
256 if (value.isMember(KEY_TYPE))
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
257 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
258 throw OrthancException(ErrorCode_Plugin,
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
259 "The \"Type\" field is for reserved use for serialized job");
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
260 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
261
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
262 value[KEY_TYPE] = type_;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
263 return true;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
264 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 else
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 {
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
268 // This was the source code in Orthanc <= 1.11.2
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
269 const char* serialized = deprecatedGetSerialized_(parameters_.job);
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
270
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
271 if (serialized == NULL)
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
272 {
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
273 return false;
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
274 }
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
275 else
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
276 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
277 if (!Toolbox::ReadJson(value, serialized) ||
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
278 value.type() != Json::objectValue)
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
279 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
280 throw OrthancException(ErrorCode_Plugin,
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
281 "A job plugin must provide a JSON object as its serialized content");
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
282 }
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
283
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
284
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
285 static const char* KEY_TYPE = "Type";
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
286
5138
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
287 if (value.isMember(KEY_TYPE))
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
288 {
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
289 throw OrthancException(ErrorCode_Plugin,
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
290 "The \"Type\" field is for reserved use for serialized job");
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
291 }
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
292
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
293 value[KEY_TYPE] = type_;
d00db9fb48fb added OrthancPluginCreateJob2() in the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
294 return true;
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
295 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 }