comparison Plugins/Engine/OrthancPlugins.cpp @ 2815:925d8dc03a23

unserialization of jobs from plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Sep 2018 16:34:21 +0200
parents 7d1d3136f6cf
children 3e048b243d20
comparison
equal deleted inserted replaced
2814:7d1d3136f6cf 2815:925d8dc03a23
2874 2874
2875 case _OrthancPluginService_CallPeerApi: 2875 case _OrthancPluginService_CallPeerApi:
2876 CallPeerApi(parameters); 2876 CallPeerApi(parameters);
2877 return true; 2877 return true;
2878 2878
2879 case _OrthancPluginService_CreateJob:
2880 {
2881 const _OrthancPluginCreateJob& p =
2882 *reinterpret_cast<const _OrthancPluginCreateJob*>(parameters);
2883 *(p.target) = reinterpret_cast<OrthancPluginJob*>(new PluginsJob(p));
2884 return true;
2885 }
2886
2887 case _OrthancPluginService_FreeJob:
2888 {
2889 const _OrthancPluginFreeJob& p =
2890 *reinterpret_cast<const _OrthancPluginFreeJob*>(parameters);
2891
2892 if (p.job != NULL)
2893 {
2894 delete reinterpret_cast<PluginsJob*>(p.job);
2895 }
2896
2897 return true;
2898 }
2899
2879 case _OrthancPluginService_SubmitJob: 2900 case _OrthancPluginService_SubmitJob:
2880 { 2901 {
2881 const _OrthancPluginSubmitJob& p = 2902 const _OrthancPluginSubmitJob& p =
2882 *reinterpret_cast<const _OrthancPluginSubmitJob*>(parameters); 2903 *reinterpret_cast<const _OrthancPluginSubmitJob*>(parameters);
2883 2904
2884 std::string uuid; 2905 std::string uuid;
2885 2906
2886 PImpl::ServerContextLock lock(*pimpl_); 2907 PImpl::ServerContextLock lock(*pimpl_);
2887 lock.GetContext().GetJobsEngine().GetRegistry().Submit(uuid, new PluginsJob(p), p.priority); 2908 lock.GetContext().GetJobsEngine().GetRegistry().Submit
2909 (uuid, reinterpret_cast<PluginsJob*>(p.job), p.priority);
2888 2910
2889 *p.resultId = CopyString(uuid); 2911 *p.resultId = CopyString(uuid);
2890 2912
2891 return true; 2913 return true;
2892 } 2914 }
3432 3454
3433 return true; 3455 return true;
3434 } 3456 }
3435 3457
3436 3458
3437 bool OrthancPlugins::UnserializeJob(const Json::Value& value) 3459 IJob* OrthancPlugins::UnserializeJob(const std::string& type,
3438 { 3460 const Json::Value& value)
3439 const std::string type = SerializationToolbox::ReadString(value, "Type"); 3461 {
3440 const std::string serialized = value.toStyledString(); 3462 const std::string serialized = value.toStyledString();
3441 3463
3442 boost::mutex::scoped_lock lock(pimpl_->jobsUnserializersMutex_); 3464 boost::mutex::scoped_lock lock(pimpl_->jobsUnserializersMutex_);
3443 3465
3444 for (PImpl::JobsUnserializers::iterator 3466 for (PImpl::JobsUnserializers::iterator
3445 unserializer = pimpl_->jobsUnserializers_.begin(); 3467 unserializer = pimpl_->jobsUnserializers_.begin();
3446 unserializer != pimpl_->jobsUnserializers_.end(); ++unserializer) 3468 unserializer != pimpl_->jobsUnserializers_.end(); ++unserializer)
3447 { 3469 {
3448 if ((*unserializer) (type.c_str(), serialized.c_str()) == OrthancPluginErrorCode_Success) 3470 OrthancPluginJob* job = (*unserializer) (type.c_str(), serialized.c_str());
3449 { 3471 if (job != NULL)
3450 return true; 3472 {
3451 } 3473 return reinterpret_cast<PluginsJob*>(job);
3452 } 3474 }
3453 3475 }
3454 return false; 3476
3477 return NULL;
3455 } 3478 }
3456 } 3479 }