Mercurial > hg > orthanc
comparison OrthancServer/ServerContext.cpp @ 227:209ca3f6db62
dicom-scu from rest
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 30 Nov 2012 10:57:34 +0100 |
parents | 8a26a8e85edf |
children | 5368bbe813cf |
comparison
equal
deleted
inserted
replaced
226:8a26a8e85edf | 227:209ca3f6db62 |
---|---|
34 | 34 |
35 #include "../Core/HttpServer/FilesystemHttpSender.h" | 35 #include "../Core/HttpServer/FilesystemHttpSender.h" |
36 | 36 |
37 #include <glog/logging.h> | 37 #include <glog/logging.h> |
38 | 38 |
39 | |
40 /** | |
41 * IMPORTANT: We make the assumption that the same instance of | |
42 * FileStorage can be accessed from multiple threads. This seems OK | |
43 * since the filesystem implements the required locking mechanisms, | |
44 * but maybe a read-writer lock on the "FileStorage" could be | |
45 * useful. Conversely, "ServerIndex" already implements mutex-based | |
46 * locking. | |
47 **/ | |
48 | |
39 namespace Orthanc | 49 namespace Orthanc |
40 { | 50 { |
41 ServerContext::ServerContext(const boost::filesystem::path& path) : | 51 ServerContext::ServerContext(const boost::filesystem::path& path) : |
42 storage_(path.string()), | 52 storage_(path.string()), |
43 index_(*this, path.string()) | 53 index_(*this, path.string()) |
44 { | 54 { |
55 } | |
56 | |
57 void ServerContext::RemoveFile(const std::string& fileUuid) | |
58 { | |
59 storage_.Remove(fileUuid); | |
45 } | 60 } |
46 | 61 |
47 StoreStatus ServerContext::Store(const char* dicomFile, | 62 StoreStatus ServerContext::Store(const char* dicomFile, |
48 size_t dicomSize, | 63 size_t dicomSize, |
49 const DicomMap& dicomSummary, | 64 const DicomMap& dicomSummary, |
100 | 115 |
101 | 116 |
102 void ServerContext::ReadJson(Json::Value& result, | 117 void ServerContext::ReadJson(Json::Value& result, |
103 const std::string& instancePublicId) | 118 const std::string& instancePublicId) |
104 { | 119 { |
105 CompressionType compressionType; | |
106 std::string fileUuid; | |
107 if (!index_.GetFile(fileUuid, compressionType, instancePublicId, AttachedFileType_Json)) | |
108 { | |
109 throw OrthancException(ErrorCode_InternalError); | |
110 } | |
111 | |
112 assert(compressionType == CompressionType_None); | |
113 | |
114 std::string s; | 120 std::string s; |
115 storage_.ReadFile(s, fileUuid); | 121 ReadFile(s, instancePublicId, AttachedFileType_Json); |
116 | 122 |
117 Json::Reader reader; | 123 Json::Reader reader; |
118 if (!reader.parse(s, result)) | 124 if (!reader.parse(s, result)) |
119 { | 125 { |
120 throw OrthancException("Corrupted JSON file"); | 126 throw OrthancException("Corrupted JSON file"); |
121 } | 127 } |
122 } | 128 } |
129 | |
130 | |
131 void ServerContext::ReadFile(std::string& result, | |
132 const std::string& instancePublicId, | |
133 AttachedFileType content) | |
134 { | |
135 CompressionType compressionType; | |
136 std::string fileUuid; | |
137 if (!index_.GetFile(fileUuid, compressionType, instancePublicId, content)) | |
138 { | |
139 throw OrthancException(ErrorCode_InternalError); | |
140 } | |
141 | |
142 assert(compressionType == CompressionType_None); | |
143 storage_.ReadFile(result, fileUuid); | |
144 } | |
123 } | 145 } |