comparison OrthancServer/main.cpp @ 224:4eb0c7ce86c9

refactoring for store
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Nov 2012 22:22:00 +0100
parents 96b7918a6a18
children 1af3bc092db8
comparison
equal deleted inserted replaced
223:6f0e4a8ebb0f 224:4eb0c7ce86c9
40 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" 40 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h"
41 #include "../Core/HttpServer/FilesystemHttpHandler.h" 41 #include "../Core/HttpServer/FilesystemHttpHandler.h"
42 #include "../Core/HttpServer/MongooseServer.h" 42 #include "../Core/HttpServer/MongooseServer.h"
43 #include "DicomProtocol/DicomServer.h" 43 #include "DicomProtocol/DicomServer.h"
44 #include "OrthancInitialization.h" 44 #include "OrthancInitialization.h"
45 45 #include "ServerContext.h"
46 46
47 using namespace Orthanc; 47 using namespace Orthanc;
48 48
49 49
50
50 class MyDicomStore : public IStoreRequestHandler 51 class MyDicomStore : public IStoreRequestHandler
51 { 52 {
52 private: 53 private:
53 ServerIndex& index_; 54 ServerContext& context_;
54 FileStorage storage_;
55 55
56 public: 56 public:
57 MyDicomStore(ServerIndex& index, 57 MyDicomStore(ServerContext& context) :
58 const std::string& path) : 58 context_(context)
59 index_(index),
60 storage_(path)
61 { 59 {
62 } 60 }
63 61
64 virtual void Handle(const std::vector<uint8_t>& dicomFile, 62 virtual void Handle(const std::vector<uint8_t>& dicomFile,
65 const DicomMap& dicomSummary, 63 const DicomMap& dicomSummary,
66 const Json::Value& dicomJson, 64 const Json::Value& dicomJson,
67 const std::string& remoteAet) 65 const std::string& remoteAet)
68 { 66 {
69 if (dicomFile.size() > 0) 67 if (dicomFile.size() > 0)
70 { 68 {
71 index_.Store(storage_, 69 context_.Store(reinterpret_cast<const char*>(&dicomFile[0]), dicomFile.size(),
72 reinterpret_cast<const char*>(&dicomFile[0]), dicomFile.size(), 70 dicomSummary, dicomJson, remoteAet);
73 dicomSummary, dicomJson, remoteAet);
74 } 71 }
75 } 72 }
76 }; 73 };
77 74
78 75
79 class MyDicomStoreFactory : public IStoreRequestHandlerFactory 76 class MyDicomStoreFactory : public IStoreRequestHandlerFactory
80 { 77 {
81 private: 78 private:
82 ServerIndex& index_; 79 ServerContext& context_;
83 std::string path_;
84 80
85 public: 81 public:
86 MyDicomStoreFactory(ServerIndex& index, 82 MyDicomStoreFactory(ServerContext& context) : context_(context)
87 const std::string& path) :
88 index_(index),
89 path_(path)
90 { 83 {
91 } 84 }
92 85
93 virtual IStoreRequestHandler* ConstructStoreRequestHandler() 86 virtual IStoreRequestHandler* ConstructStoreRequestHandler()
94 { 87 {
95 return new MyDicomStore(index_, path_); 88 return new MyDicomStore(context_);
96 } 89 }
97 90
98 void Done() 91 void Done()
99 { 92 {
100 //index_.db().Execute("DELETE FROM Studies"); 93 //index_.db().Execute("DELETE FROM Studies");
217 { 210 {
218 OrthancInitialize(); 211 OrthancInitialize();
219 } 212 }
220 213
221 boost::filesystem::path storageDirectory = GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); 214 boost::filesystem::path storageDirectory = GetGlobalStringParameter("StorageDirectory", "OrthancStorage");
222 FileStorage storage(storageDirectory.string()); 215 ServerContext context(storageDirectory);
223 ServerIndex index(storage, storageDirectory.string()); 216 MyDicomStoreFactory storeScp(context);
224 MyDicomStoreFactory storeScp(index, storageDirectory.string());
225 217
226 { 218 {
227 // DICOM server 219 // DICOM server
228 DicomServer dicomServer; 220 DicomServer dicomServer;
229 dicomServer.SetCalledApplicationEntityTitleCheck(GetGlobalBoolParameter("DicomCheckCalledAet", false)); 221 dicomServer.SetCalledApplicationEntityTitleCheck(GetGlobalBoolParameter("DicomCheckCalledAet", false));
257 httpServer.RegisterHandler(new EmbeddedResourceHttpHandler("/app", EmbeddedResources::ORTHANC_EXPLORER)); 249 httpServer.RegisterHandler(new EmbeddedResourceHttpHandler("/app", EmbeddedResources::ORTHANC_EXPLORER));
258 #else 250 #else
259 httpServer.RegisterHandler(new FilesystemHttpHandler("/app", ORTHANC_PATH "/OrthancExplorer")); 251 httpServer.RegisterHandler(new FilesystemHttpHandler("/app", ORTHANC_PATH "/OrthancExplorer"));
260 #endif 252 #endif
261 253
262 httpServer.RegisterHandler(new OrthancRestApi2(index, storageDirectory.string())); 254 httpServer.RegisterHandler(new OrthancRestApi2(context));
263 httpServer.RegisterHandler(new OrthancRestApi(index, storageDirectory.string())); 255 httpServer.RegisterHandler(new OrthancRestApi(context.GetIndex(), storageDirectory.string()));
264 256
265 // GO !!! 257 // GO !!!
266 httpServer.Start(); 258 httpServer.Start();
267 dicomServer.Start(); 259 dicomServer.Start();
268 260