diff 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
line wrap: on
line diff
--- a/OrthancServer/ServerContext.cpp	Fri Nov 30 09:45:29 2012 +0100
+++ b/OrthancServer/ServerContext.cpp	Fri Nov 30 10:57:34 2012 +0100
@@ -36,6 +36,16 @@
 
 #include <glog/logging.h>
 
+
+/**
+ * IMPORTANT: We make the assumption that the same instance of
+ * FileStorage can be accessed from multiple threads. This seems OK
+ * since the filesystem implements the required locking mechanisms,
+ * but maybe a read-writer lock on the "FileStorage" could be
+ * useful. Conversely, "ServerIndex" already implements mutex-based
+ * locking.
+ **/
+
 namespace Orthanc
 {
   ServerContext::ServerContext(const boost::filesystem::path& path) :
@@ -44,6 +54,11 @@
   {
   }
 
+  void ServerContext::RemoveFile(const std::string& fileUuid)
+  {
+    storage_.Remove(fileUuid);
+  }
+
   StoreStatus ServerContext::Store(const char* dicomFile,
                                    size_t dicomSize,
                                    const DicomMap& dicomSummary,
@@ -102,17 +117,8 @@
   void ServerContext::ReadJson(Json::Value& result,
                                const std::string& instancePublicId)
   {
-    CompressionType compressionType;
-    std::string fileUuid;
-    if (!index_.GetFile(fileUuid, compressionType, instancePublicId, AttachedFileType_Json))
-    {
-      throw OrthancException(ErrorCode_InternalError);
-    }
-
-    assert(compressionType == CompressionType_None);
-
     std::string s;
-    storage_.ReadFile(s, fileUuid);
+    ReadFile(s, instancePublicId, AttachedFileType_Json);
 
     Json::Reader reader;
     if (!reader.parse(s, result))
@@ -120,4 +126,20 @@
       throw OrthancException("Corrupted JSON file");
     }
   }
+
+
+  void ServerContext::ReadFile(std::string& result,
+                               const std::string& instancePublicId,
+                               AttachedFileType content)
+  {
+    CompressionType compressionType;
+    std::string fileUuid;
+    if (!index_.GetFile(fileUuid, compressionType, instancePublicId, content))
+    {
+      throw OrthancException(ErrorCode_InternalError);
+    }
+
+    assert(compressionType == CompressionType_None);
+    storage_.ReadFile(result, fileUuid);    
+  }
 }