comparison Plugins/Engine/OrthancPlugins.cpp @ 1800:30e97a1f4093 worklists

callback for handling worklists with plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 20 Nov 2015 13:53:20 +0100
parents 94990da8710e
children 2c60c357ee3e
comparison
equal deleted inserted replaced
1799:4f01c9d73f02 1800:30e97a1f4093
235 235
236 typedef std::pair<std::string, _OrthancPluginProperty> Property; 236 typedef std::pair<std::string, _OrthancPluginProperty> Property;
237 typedef std::list<RestCallback*> RestCallbacks; 237 typedef std::list<RestCallback*> RestCallbacks;
238 typedef std::list<OrthancPluginOnStoredInstanceCallback> OnStoredCallbacks; 238 typedef std::list<OrthancPluginOnStoredInstanceCallback> OnStoredCallbacks;
239 typedef std::list<OrthancPluginOnChangeCallback> OnChangeCallbacks; 239 typedef std::list<OrthancPluginOnChangeCallback> OnChangeCallbacks;
240 typedef std::list<OrthancPluginWorklistCallback> WorklistCallbacks;
240 typedef std::map<Property, std::string> Properties; 241 typedef std::map<Property, std::string> Properties;
241 242
242 PluginsManager manager_; 243 PluginsManager manager_;
243 ServerContext* context_; 244 ServerContext* context_;
244 RestCallbacks restCallbacks_; 245 RestCallbacks restCallbacks_;
245 OnStoredCallbacks onStoredCallbacks_; 246 OnStoredCallbacks onStoredCallbacks_;
246 OnChangeCallbacks onChangeCallbacks_; 247 OnChangeCallbacks onChangeCallbacks_;
248 WorklistCallbacks worklistCallbacks_;
247 std::auto_ptr<StorageAreaFactory> storageArea_; 249 std::auto_ptr<StorageAreaFactory> storageArea_;
248 boost::recursive_mutex restCallbackMutex_; 250 boost::recursive_mutex restCallbackMutex_;
249 boost::recursive_mutex storedCallbackMutex_; 251 boost::recursive_mutex storedCallbackMutex_;
250 boost::recursive_mutex changeCallbackMutex_; 252 boost::recursive_mutex changeCallbackMutex_;
253 boost::recursive_mutex worklistCallbackMutex_;
251 boost::recursive_mutex invokeServiceMutex_; 254 boost::recursive_mutex invokeServiceMutex_;
252 Properties properties_; 255 Properties properties_;
253 int argc_; 256 int argc_;
254 char** argv_; 257 char** argv_;
255 std::auto_ptr<OrthancPluginDatabase> database_; 258 std::auto_ptr<OrthancPluginDatabase> database_;
620 LOG(INFO) << "Plugin has registered an OnChange callback"; 623 LOG(INFO) << "Plugin has registered an OnChange callback";
621 pimpl_->onChangeCallbacks_.push_back(p.callback); 624 pimpl_->onChangeCallbacks_.push_back(p.callback);
622 } 625 }
623 626
624 627
628 void OrthancPlugins::RegisterWorklistCallback(const void* parameters)
629 {
630 const _OrthancPluginWorklistCallback& p =
631 *reinterpret_cast<const _OrthancPluginWorklistCallback*>(parameters);
632
633 LOG(INFO) << "Plugin has registered an modality worklist callback";
634 pimpl_->worklistCallbacks_.push_back(p.callback);
635 }
636
637
638
625 639
626 void OrthancPlugins::AnswerBuffer(const void* parameters) 640 void OrthancPlugins::AnswerBuffer(const void* parameters)
627 { 641 {
628 const _OrthancPluginAnswerBuffer& p = 642 const _OrthancPluginAnswerBuffer& p =
629 *reinterpret_cast<const _OrthancPluginAnswerBuffer*>(parameters); 643 *reinterpret_cast<const _OrthancPluginAnswerBuffer*>(parameters);
1399 1413
1400 case _OrthancPluginService_RegisterOnChangeCallback: 1414 case _OrthancPluginService_RegisterOnChangeCallback:
1401 RegisterOnChangeCallback(parameters); 1415 RegisterOnChangeCallback(parameters);
1402 return true; 1416 return true;
1403 1417
1418 case _OrthancPluginService_RegisterWorklistCallback:
1419 RegisterWorklistCallback(parameters);
1420 return true;
1421
1404 case _OrthancPluginService_AnswerBuffer: 1422 case _OrthancPluginService_AnswerBuffer:
1405 AnswerBuffer(parameters); 1423 AnswerBuffer(parameters);
1406 return true; 1424 return true;
1407 1425
1408 case _OrthancPluginService_CompressAndAnswerPngImage: 1426 case _OrthancPluginService_CompressAndAnswerPngImage:
1829 case _OrthancPluginService_DicomBufferToJson: 1847 case _OrthancPluginService_DicomBufferToJson:
1830 case _OrthancPluginService_DicomInstanceToJson: 1848 case _OrthancPluginService_DicomInstanceToJson:
1831 ApplyDicomToJson(service, parameters); 1849 ApplyDicomToJson(service, parameters);
1832 return true; 1850 return true;
1833 1851
1852 case _OrthancPluginService_AddWorklistAnswer:
1853 {
1854 const _OrthancPluginAddWorklistAnswer& p =
1855 *reinterpret_cast<const _OrthancPluginAddWorklistAnswer*>(parameters);
1856
1857 ParsedDicomFile answer(p.answerDicom, p.answerSize);
1858 reinterpret_cast<DicomFindAnswers*>(p.target)->Add(answer);
1859 return true;
1860 }
1861
1834 default: 1862 default:
1835 { 1863 {
1836 // This service is unknown to the Orthanc plugin engine 1864 // This service is unknown to the Orthanc plugin engine
1837 return false; 1865 return false;
1838 } 1866 }
1946 1974
1947 PluginsErrorDictionary& OrthancPlugins::GetErrorDictionary() 1975 PluginsErrorDictionary& OrthancPlugins::GetErrorDictionary()
1948 { 1976 {
1949 return pimpl_->dictionary_; 1977 return pimpl_->dictionary_;
1950 } 1978 }
1979
1980
1981 void OrthancPlugins::HandleWorklist(DicomFindAnswers& answers,
1982 ParsedDicomFile& query,
1983 const std::string& remoteIp,
1984 const std::string& remoteAet,
1985 const std::string& calledAet)
1986 {
1987 boost::recursive_mutex::scoped_lock lock(pimpl_->worklistCallbackMutex_);
1988
1989 for (PImpl::WorklistCallbacks::const_iterator
1990 callback = pimpl_->worklistCallbacks_.begin();
1991 callback != pimpl_->worklistCallbacks_.end(); ++callback)
1992 {
1993 OrthancPluginErrorCode error = (*callback)
1994 (reinterpret_cast<OrthancPluginWorklistAnswers*>(&answers),
1995 reinterpret_cast<OrthancPluginWorklistQuery*>(&query),
1996 remoteAet.c_str(),
1997 calledAet.c_str());
1998
1999 if (error != OrthancPluginErrorCode_Success)
2000 {
2001 GetErrorDictionary().LogError(error, true);
2002 throw OrthancException(static_cast<ErrorCode>(error));
2003 }
2004 }
2005 }
2006
2007
2008 class OrthancPlugins::WorklistHandler : public IWorklistRequestHandler
2009 {
2010 private:
2011 OrthancPlugins& plugins_;
2012
2013 public:
2014 WorklistHandler(OrthancPlugins& plugins) : plugins_(plugins)
2015 {
2016 }
2017
2018 virtual void Handle(DicomFindAnswers& answers,
2019 ParsedDicomFile& query,
2020 const std::string& remoteIp,
2021 const std::string& remoteAet,
2022 const std::string& calledAet)
2023 {
2024 plugins_.HandleWorklist(answers, query, remoteIp, remoteAet, calledAet);
2025 }
2026 };
2027
2028
2029 IWorklistRequestHandler* OrthancPlugins::ConstructWorklistRequestHandler()
2030 {
2031 bool hasHandler;
2032
2033 {
2034 boost::recursive_mutex::scoped_lock lock(pimpl_->worklistCallbackMutex_);
2035 hasHandler = !pimpl_->worklistCallbacks_.empty();
2036 }
2037
2038 if (hasHandler)
2039 {
2040 return new WorklistHandler(*this);
2041 }
2042 else
2043 {
2044 return NULL;
2045 }
2046 }
1951 } 2047 }