Mercurial > hg > orthanc
comparison OrthancServer/DicomProtocol/DicomServer.cpp @ 1656:d3ba98d6b6e9
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 29 Sep 2015 15:13:34 +0200 |
parents | bd1889029cbb |
children | 131136aeeaa7 4113a9a668b1 |
comparison
equal
deleted
inserted
replaced
1655:e40fd0d925c5 | 1656:d3ba98d6b6e9 |
---|---|
40 #include "../Internals/CommandDispatcher.h" | 40 #include "../Internals/CommandDispatcher.h" |
41 #include "../OrthancInitialization.h" | 41 #include "../OrthancInitialization.h" |
42 #include "EmbeddedResources.h" | 42 #include "EmbeddedResources.h" |
43 | 43 |
44 #include <boost/thread.hpp> | 44 #include <boost/thread.hpp> |
45 #include <boost/filesystem.hpp> | |
46 #include <dcmtk/dcmdata/dcdict.h> | |
47 | 45 |
48 #if defined(__linux) | 46 #if defined(__linux) |
49 #include <cstdlib> | 47 #include <cstdlib> |
50 #endif | 48 #endif |
51 | 49 |
56 { | 54 { |
57 boost::thread thread_; | 55 boost::thread thread_; |
58 | 56 |
59 //std::set< | 57 //std::set< |
60 }; | 58 }; |
61 | |
62 | |
63 #if DCMTK_USE_EMBEDDED_DICTIONARIES == 1 | |
64 static void LoadEmbeddedDictionary(DcmDataDictionary& dictionary, | |
65 EmbeddedResources::FileResourceId resource) | |
66 { | |
67 Toolbox::TemporaryFile tmp; | |
68 | |
69 FILE* fp = fopen(tmp.GetPath().c_str(), "wb"); | |
70 fwrite(EmbeddedResources::GetFileResourceBuffer(resource), | |
71 EmbeddedResources::GetFileResourceSize(resource), 1, fp); | |
72 fclose(fp); | |
73 | |
74 if (!dictionary.loadDictionary(tmp.GetPath().c_str())) | |
75 { | |
76 throw OrthancException(ErrorCode_InternalError); | |
77 } | |
78 } | |
79 | |
80 #else | |
81 static void LoadExternalDictionary(DcmDataDictionary& dictionary, | |
82 const std::string& directory, | |
83 const std::string& filename) | |
84 { | |
85 boost::filesystem::path p = directory; | |
86 p = p / filename; | |
87 | |
88 LOG(WARNING) << "Loading the external DICOM dictionary " << p; | |
89 | |
90 if (!dictionary.loadDictionary(p.string().c_str())) | |
91 { | |
92 throw OrthancException(ErrorCode_InternalError); | |
93 } | |
94 } | |
95 | |
96 #endif | |
97 | |
98 | |
99 void DicomServer::InitializeDictionary() | |
100 { | |
101 /* Disable "gethostbyaddr" (which results in memory leaks) and use raw IP addresses */ | |
102 dcmDisableGethostbyaddr.set(OFTrue); | |
103 | |
104 dcmDataDict.clear(); | |
105 DcmDataDictionary& d = dcmDataDict.wrlock(); | |
106 | |
107 #if DCMTK_USE_EMBEDDED_DICTIONARIES == 1 | |
108 LOG(WARNING) << "Loading the embedded dictionaries"; | |
109 /** | |
110 * Do not load DICONDE dictionary, it breaks the other tags. The | |
111 * command "strace storescu 2>&1 |grep dic" shows that DICONDE | |
112 * dictionary is not loaded by storescu. | |
113 **/ | |
114 //LoadEmbeddedDictionary(d, EmbeddedResources::DICTIONARY_DICONDE); | |
115 | |
116 LoadEmbeddedDictionary(d, EmbeddedResources::DICTIONARY_DICOM); | |
117 LoadEmbeddedDictionary(d, EmbeddedResources::DICTIONARY_PRIVATE); | |
118 | |
119 #elif defined(__linux) || defined(__FreeBSD_kernel__) | |
120 std::string path = DCMTK_DICTIONARY_DIR; | |
121 | |
122 const char* env = std::getenv(DCM_DICT_ENVIRONMENT_VARIABLE); | |
123 if (env != NULL) | |
124 { | |
125 path = std::string(env); | |
126 } | |
127 | |
128 LoadExternalDictionary(d, path, "dicom.dic"); | |
129 LoadExternalDictionary(d, path, "private.dic"); | |
130 | |
131 #else | |
132 #error Support your platform here | |
133 #endif | |
134 | |
135 dcmDataDict.unlock(); | |
136 | |
137 /* make sure data dictionary is loaded */ | |
138 if (!dcmDataDict.isDictionaryLoaded()) | |
139 { | |
140 LOG(ERROR) << "No DICOM dictionary loaded, check environment variable: " << DCM_DICT_ENVIRONMENT_VARIABLE; | |
141 throw OrthancException(ErrorCode_InternalError); | |
142 } | |
143 | |
144 { | |
145 // Test the dictionary with a simple DICOM tag | |
146 DcmTag key(0x0010, 0x1030); // This is PatientWeight | |
147 if (key.getEVR() != EVR_DS) | |
148 { | |
149 LOG(ERROR) << "The DICOM dictionary has not been correctly read"; | |
150 throw OrthancException(ErrorCode_InternalError); | |
151 } | |
152 } | |
153 } | |
154 | 59 |
155 | 60 |
156 void DicomServer::ServerThread(DicomServer* server) | 61 void DicomServer::ServerThread(DicomServer* server) |
157 { | 62 { |
158 /* initialize network, i.e. create an instance of T_ASC_Network*. */ | 63 /* initialize network, i.e. create an instance of T_ASC_Network*. */ |