Mercurial > hg > orthanc
comparison OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 5138:d00db9fb48fb
added OrthancPluginCreateJob2() in the plugin SDK
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Jan 2023 19:04:13 +0100 |
parents | fcb2ed6c88ff |
children | 688b83f915bc |
comparison
equal
deleted
inserted
replaced
5137:15109c3f0f7d | 5138:d00db9fb48fb |
---|---|
2170 return 0; | 2170 return 0; |
2171 } | 2171 } |
2172 } | 2172 } |
2173 | 2173 |
2174 | 2174 |
2175 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3) | |
2176 static OrthancPluginErrorCode CopyStringToMemoryBuffer(OrthancPluginMemoryBuffer* target, | |
2177 const std::string& source) | |
2178 { | |
2179 if (OrthancPluginCreateMemoryBuffer(globalContext_, target, source.size()) != OrthancPluginErrorCode_Success) | |
2180 { | |
2181 return OrthancPluginErrorCode_NotEnoughMemory; | |
2182 } | |
2183 else | |
2184 { | |
2185 if (!source.empty()) | |
2186 { | |
2187 memcpy(target->data, source.c_str(), source.size()); | |
2188 } | |
2189 | |
2190 return OrthancPluginErrorCode_Success; | |
2191 } | |
2192 } | |
2193 #endif | |
2194 | |
2195 | |
2196 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3) | |
2197 OrthancPluginErrorCode OrthancJob::CallbackGetContent(OrthancPluginMemoryBuffer* target, | |
2198 void* job) | |
2199 { | |
2200 assert(job != NULL); | |
2201 OrthancJob& that = *reinterpret_cast<OrthancJob*>(job); | |
2202 return CopyStringToMemoryBuffer(target, that.content_); | |
2203 } | |
2204 #else | |
2175 const char* OrthancJob::CallbackGetContent(void* job) | 2205 const char* OrthancJob::CallbackGetContent(void* job) |
2176 { | 2206 { |
2177 assert(job != NULL); | 2207 assert(job != NULL); |
2178 | 2208 |
2179 try | 2209 try |
2183 catch (...) | 2213 catch (...) |
2184 { | 2214 { |
2185 return 0; | 2215 return 0; |
2186 } | 2216 } |
2187 } | 2217 } |
2188 | 2218 #endif |
2189 | 2219 |
2220 | |
2221 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3) | |
2222 int32_t OrthancJob::CallbackGetSerialized(OrthancPluginMemoryBuffer* target, | |
2223 void* job) | |
2224 { | |
2225 assert(job != NULL); | |
2226 OrthancJob& that = *reinterpret_cast<OrthancJob*>(job); | |
2227 | |
2228 if (that.hasSerialized_) | |
2229 { | |
2230 if (CopyStringToMemoryBuffer(target, that.serialized_) == OrthancPluginErrorCode_Success) | |
2231 { | |
2232 return 1; | |
2233 } | |
2234 else | |
2235 { | |
2236 return -1; | |
2237 } | |
2238 } | |
2239 else | |
2240 { | |
2241 return 0; | |
2242 } | |
2243 } | |
2244 #else | |
2190 const char* OrthancJob::CallbackGetSerialized(void* job) | 2245 const char* OrthancJob::CallbackGetSerialized(void* job) |
2191 { | 2246 { |
2192 assert(job != NULL); | 2247 assert(job != NULL); |
2193 | 2248 |
2194 try | 2249 try |
2207 catch (...) | 2262 catch (...) |
2208 { | 2263 { |
2209 return 0; | 2264 return 0; |
2210 } | 2265 } |
2211 } | 2266 } |
2267 #endif | |
2212 | 2268 |
2213 | 2269 |
2214 OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job) | 2270 OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job) |
2215 { | 2271 { |
2216 assert(job != NULL); | 2272 assert(job != NULL); |
2338 if (job == NULL) | 2394 if (job == NULL) |
2339 { | 2395 { |
2340 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); | 2396 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); |
2341 } | 2397 } |
2342 | 2398 |
2343 OrthancPluginJob* orthanc = OrthancPluginCreateJob( | 2399 OrthancPluginJob* orthanc = |
2344 GetGlobalContext(), job, CallbackFinalize, job->jobType_.c_str(), | 2400 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3) |
2345 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized, | 2401 OrthancPluginCreateJob2 |
2346 CallbackStep, CallbackStop, CallbackReset); | 2402 #else |
2403 OrthancPluginCreateJob | |
2404 #endif | |
2405 (GetGlobalContext(), job, CallbackFinalize, job->jobType_.c_str(), | |
2406 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized, | |
2407 CallbackStep, CallbackStop, CallbackReset); | |
2347 | 2408 |
2348 if (orthanc == NULL) | 2409 if (orthanc == NULL) |
2349 { | 2410 { |
2350 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | 2411 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
2351 } | 2412 } |