comparison Plugins/Engine/OrthancPlugins.cpp @ 1452:b737acb13da5

refactoring of the main function
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 02 Jul 2015 11:35:41 +0200
parents 5ba7471780ae
children 0cd0f2ad3599
comparison
equal deleted inserted replaced
1451:538fc8359a9a 1452:b737acb13da5
31 31
32 32
33 #include "OrthancPlugins.h" 33 #include "OrthancPlugins.h"
34 34
35 #include "../../Core/ChunkedBuffer.h" 35 #include "../../Core/ChunkedBuffer.h"
36 #include "../../Core/HttpServer/StringHttpOutput.h" 36 #include "../../Core/HttpServer/HttpToolbox.h"
37 #include "../../Core/ImageFormats/PngWriter.h" 37 #include "../../Core/ImageFormats/PngWriter.h"
38 #include "../../Core/OrthancException.h" 38 #include "../../Core/OrthancException.h"
39 #include "../../Core/Toolbox.h" 39 #include "../../Core/Toolbox.h"
40 #include "../../OrthancServer/OrthancInitialization.h" 40 #include "../../OrthancServer/OrthancInitialization.h"
41 #include "../../OrthancServer/OrthancRestApi/OrthancRestApi.h"
42 #include "../../OrthancServer/ServerContext.h" 41 #include "../../OrthancServer/ServerContext.h"
43 #include "../../OrthancServer/ServerToolbox.h" 42 #include "../../OrthancServer/ServerToolbox.h"
44 43
45 #include <boost/regex.hpp> 44 #include <boost/regex.hpp>
46 #include <glog/logging.h> 45 #include <glog/logging.h>
121 typedef std::map<Property, std::string> Properties; 120 typedef std::map<Property, std::string> Properties;
122 121
123 PluginsManager manager_; 122 PluginsManager manager_;
124 ServerContext* context_; 123 ServerContext* context_;
125 RestCallbacks restCallbacks_; 124 RestCallbacks restCallbacks_;
126 OrthancRestApi* restApi_;
127 OnStoredCallbacks onStoredCallbacks_; 125 OnStoredCallbacks onStoredCallbacks_;
128 OnChangeCallbacks onChangeCallbacks_; 126 OnChangeCallbacks onChangeCallbacks_;
129 bool hasStorageArea_; 127 bool hasStorageArea_;
130 _OrthancPluginRegisterStorageArea storageArea_; 128 _OrthancPluginRegisterStorageArea storageArea_;
131 boost::recursive_mutex callbackMutex_; 129 boost::recursive_mutex callbackMutex_;
134 char** argv_; 132 char** argv_;
135 std::auto_ptr<OrthancPluginDatabase> database_; 133 std::auto_ptr<OrthancPluginDatabase> database_;
136 134
137 PImpl() : 135 PImpl() :
138 context_(NULL), 136 context_(NULL),
139 restApi_(NULL),
140 hasStorageArea_(false), 137 hasStorageArea_(false),
141 argc_(1), 138 argc_(1),
142 argv_(NULL) 139 argv_(NULL)
143 { 140 {
144 memset(&storageArea_, 0, sizeof(storageArea_)); 141 memset(&storageArea_, 0, sizeof(storageArea_));
598 } 595 }
599 596
600 597
601 void OrthancPlugins::GetDicomForInstance(const void* parameters) 598 void OrthancPlugins::GetDicomForInstance(const void* parameters)
602 { 599 {
603 CheckContextAvailable();
604
605 const _OrthancPluginGetDicomForInstance& p = 600 const _OrthancPluginGetDicomForInstance& p =
606 *reinterpret_cast<const _OrthancPluginGetDicomForInstance*>(parameters); 601 *reinterpret_cast<const _OrthancPluginGetDicomForInstance*>(parameters);
607 602
608 std::string dicom; 603 std::string dicom;
604
605 CheckContextAvailable();
609 pimpl_->context_->ReadFile(dicom, p.instanceId, FileContentType_Dicom); 606 pimpl_->context_->ReadFile(dicom, p.instanceId, FileContentType_Dicom);
607
610 CopyToMemoryBuffer(*p.target, dicom); 608 CopyToMemoryBuffer(*p.target, dicom);
611 } 609 }
612 610
613 611
614 void OrthancPlugins::RestApiGet(const void* parameters, 612 void OrthancPlugins::RestApiGet(const void* parameters,
1117 return false; 1115 return false;
1118 } 1116 }
1119 } 1117 }
1120 1118
1121 1119
1122 void OrthancPlugins::SetOrthancRestApi(OrthancRestApi& restApi)
1123 {
1124 pimpl_->restApi_ = &restApi;
1125 }
1126
1127
1128 void OrthancPlugins::ResetOrthancRestApi()
1129 {
1130 pimpl_->restApi_ = NULL;
1131 }
1132
1133
1134 bool OrthancPlugins::HasStorageArea() const 1120 bool OrthancPlugins::HasStorageArea() const
1135 { 1121 {
1136 return pimpl_->hasStorageArea_; 1122 return pimpl_->hasStorageArea_;
1137 } 1123 }
1138 1124
1229 } 1215 }
1230 }; 1216 };
1231 } 1217 }
1232 1218
1233 1219
1234 IStorageArea* OrthancPlugins::GetStorageArea() 1220 IStorageArea* OrthancPlugins::CreateStorageArea()
1235 { 1221 {
1236 if (!HasStorageArea()) 1222 if (!HasStorageArea())
1237 { 1223 {
1238 throw OrthancException(ErrorCode_BadSequenceOfCalls); 1224 throw OrthancException(ErrorCode_BadSequenceOfCalls);
1239 } 1225 }