comparison Plugins/Engine/OrthancPlugins.cpp @ 2012:50b9bc19dc62

More than one custom image decoder can be installed (e.g. to handle different transfer syntaxes)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 10 Jun 2016 17:54:26 +0200
parents e2dd40abce72
children 9c9332e486ca
comparison
equal deleted inserted replaced
2011:5b3b2de4e018 2012:50b9bc19dc62
342 typedef std::pair<std::string, _OrthancPluginProperty> Property; 342 typedef std::pair<std::string, _OrthancPluginProperty> Property;
343 typedef std::list<RestCallback*> RestCallbacks; 343 typedef std::list<RestCallback*> RestCallbacks;
344 typedef std::list<OrthancPluginOnStoredInstanceCallback> OnStoredCallbacks; 344 typedef std::list<OrthancPluginOnStoredInstanceCallback> OnStoredCallbacks;
345 typedef std::list<OrthancPluginOnChangeCallback> OnChangeCallbacks; 345 typedef std::list<OrthancPluginOnChangeCallback> OnChangeCallbacks;
346 typedef std::list<OrthancPluginIncomingHttpRequestFilter> IncomingHttpRequestFilters; 346 typedef std::list<OrthancPluginIncomingHttpRequestFilter> IncomingHttpRequestFilters;
347 typedef std::list<OrthancPluginDecodeImageCallback> DecodeImageCallbacks;
347 typedef std::map<Property, std::string> Properties; 348 typedef std::map<Property, std::string> Properties;
348 349
349 PluginsManager manager_; 350 PluginsManager manager_;
350 351
351 RestCallbacks restCallbacks_; 352 RestCallbacks restCallbacks_;
352 OnStoredCallbacks onStoredCallbacks_; 353 OnStoredCallbacks onStoredCallbacks_;
353 OnChangeCallbacks onChangeCallbacks_; 354 OnChangeCallbacks onChangeCallbacks_;
354 OrthancPluginFindCallback findCallback_; 355 OrthancPluginFindCallback findCallback_;
355 OrthancPluginWorklistCallback worklistCallback_; 356 OrthancPluginWorklistCallback worklistCallback_;
356 OrthancPluginDecodeImageCallback decodeImageCallback_; 357 DecodeImageCallbacks decodeImageCallbacks_;
357 _OrthancPluginMoveCallback moveCallbacks_; 358 _OrthancPluginMoveCallback moveCallbacks_;
358 IncomingHttpRequestFilters incomingHttpRequestFilters_; 359 IncomingHttpRequestFilters incomingHttpRequestFilters_;
359 std::auto_ptr<StorageAreaFactory> storageArea_; 360 std::auto_ptr<StorageAreaFactory> storageArea_;
360 361
361 boost::recursive_mutex restCallbackMutex_; 362 boost::recursive_mutex restCallbackMutex_;
374 375
375 PImpl() : 376 PImpl() :
376 context_(NULL), 377 context_(NULL),
377 findCallback_(NULL), 378 findCallback_(NULL),
378 worklistCallback_(NULL), 379 worklistCallback_(NULL),
379 decodeImageCallback_(NULL),
380 argc_(1), 380 argc_(1),
381 argv_(NULL) 381 argv_(NULL)
382 { 382 {
383 memset(&moveCallbacks_, 0, sizeof(moveCallbacks_)); 383 memset(&moveCallbacks_, 0, sizeof(moveCallbacks_));
384 } 384 }
1102 const _OrthancPluginDecodeImageCallback& p = 1102 const _OrthancPluginDecodeImageCallback& p =
1103 *reinterpret_cast<const _OrthancPluginDecodeImageCallback*>(parameters); 1103 *reinterpret_cast<const _OrthancPluginDecodeImageCallback*>(parameters);
1104 1104
1105 boost::mutex::scoped_lock lock(pimpl_->decodeImageCallbackMutex_); 1105 boost::mutex::scoped_lock lock(pimpl_->decodeImageCallbackMutex_);
1106 1106
1107 if (pimpl_->decodeImageCallback_ != NULL) 1107 pimpl_->decodeImageCallbacks_.push_back(p.callback);
1108 { 1108 LOG(INFO) << "Plugin has registered a callback to decode DICOM images ("
1109 LOG(ERROR) << "Can only register one plugin to handle the decompression of DICOM images"; 1109 << pimpl_->decodeImageCallbacks_.size() << " decoder(s) now active)";
1110 throw OrthancException(ErrorCode_Plugin);
1111 }
1112 else
1113 {
1114 LOG(INFO) << "Plugin has registered a callback to decode DICOM images";
1115 pimpl_->decodeImageCallback_ = p.callback;
1116 }
1117 } 1110 }
1118 1111
1119 1112
1120 void OrthancPlugins::RegisterIncomingHttpRequestFilter(const void* parameters) 1113 void OrthancPlugins::RegisterIncomingHttpRequestFilter(const void* parameters)
1121 { 1114 {
2966 2959
2967 2960
2968 bool OrthancPlugins::HasCustomImageDecoder() 2961 bool OrthancPlugins::HasCustomImageDecoder()
2969 { 2962 {
2970 boost::mutex::scoped_lock lock(pimpl_->decodeImageCallbackMutex_); 2963 boost::mutex::scoped_lock lock(pimpl_->decodeImageCallbackMutex_);
2971 return (pimpl_->decodeImageCallback_ != NULL); 2964 return !pimpl_->decodeImageCallbacks_.empty();
2972 } 2965 }
2973 2966
2974 2967
2975 ImageAccessor* OrthancPlugins::Decode(const void* dicom, 2968 ImageAccessor* OrthancPlugins::DecodeUnsafe(const void* dicom,
2976 size_t size, 2969 size_t size,
2977 unsigned int frame) 2970 unsigned int frame)
2978 { 2971 {
2979 { 2972 boost::mutex::scoped_lock lock(pimpl_->decodeImageCallbackMutex_);
2980 boost::mutex::scoped_lock lock(pimpl_->decodeImageCallbackMutex_); 2973
2981 if (pimpl_->decodeImageCallback_ != NULL) 2974 for (PImpl::DecodeImageCallbacks::const_iterator
2982 { 2975 decoder = pimpl_->decodeImageCallbacks_.begin();
2983 OrthancPluginImage* pluginImage = NULL; 2976 decoder != pimpl_->decodeImageCallbacks_.end(); ++decoder)
2984 if (pimpl_->decodeImageCallback_(&pluginImage, dicom, size, frame) == OrthancPluginErrorCode_Success && 2977 {
2985 pluginImage != NULL) 2978 OrthancPluginImage* pluginImage = NULL;
2986 { 2979 if ((*decoder) (&pluginImage, dicom, size, frame) == OrthancPluginErrorCode_Success &&
2987 return reinterpret_cast<ImageAccessor*>(pluginImage); 2980 pluginImage != NULL)
2988 } 2981 {
2989 2982 return reinterpret_cast<ImageAccessor*>(pluginImage);
2990 LOG(INFO) << "The installed image decoding plugins cannot handle an image, fallback to the built-in decoder"; 2983 }
2991 } 2984 }
2992 } 2985
2993 2986 return NULL;
2994 DefaultDicomImageDecoder defaultDecoder; 2987 }
2995 return defaultDecoder.Decode(dicom, size, frame); // TODO RETURN NULL ??? 2988
2989
2990 ImageAccessor* OrthancPlugins::Decode(const void* dicom,
2991 size_t size,
2992 unsigned int frame)
2993 {
2994 ImageAccessor* result = DecodeUnsafe(dicom, size, frame);
2995
2996 if (result != NULL)
2997 {
2998 return result;
2999 }
3000 else
3001 {
3002 LOG(INFO) << "The installed image decoding plugins cannot handle an image, fallback to the built-in decoder";
3003 DefaultDicomImageDecoder defaultDecoder;
3004 return defaultDecoder.Decode(dicom, size, frame);
3005 }
2996 } 3006 }
2997 3007
2998 3008
2999 bool OrthancPlugins::IsAllowed(HttpMethod method, 3009 bool OrthancPlugins::IsAllowed(HttpMethod method,
3000 const char* uri, 3010 const char* uri,