Mercurial > hg > orthanc
comparison OrthancServer/OrthancInitialization.cpp @ 807:566a2fb3c1fb
update/delete modalities
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 07 May 2014 15:54:23 +0200 |
parents | 557575fd93e9 |
children | 2d9a000aa3a6 |
comparison
equal
deleted
inserted
replaced
806:557575fd93e9 | 807:566a2fb3c1fb |
---|---|
253 throw OrthancException(ErrorCode_BadFileFormat); | 253 throw OrthancException(ErrorCode_BadFileFormat); |
254 } | 254 } |
255 | 255 |
256 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; | 256 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; |
257 if (modalities.type() != Json::objectValue || | 257 if (modalities.type() != Json::objectValue || |
258 !modalities.isMember(name) || | 258 !modalities.isMember(name)) |
259 (modalities[name].size() != 3 && modalities[name].size() != 4)) | |
260 { | 259 { |
261 throw OrthancException(ErrorCode_BadFileFormat); | 260 throw OrthancException(ErrorCode_BadFileFormat); |
262 } | 261 } |
263 | 262 |
264 try | 263 try |
265 { | 264 { |
266 modality.SetApplicationEntityTitle(modalities[name].get(0u, "").asString()); | 265 modality.FromJson(modalities[name]); |
267 modality.SetHost(modalities[name].get(1u, "").asString()); | |
268 | |
269 const Json::Value& portValue = modalities[name].get(2u, ""); | |
270 try | |
271 { | |
272 modality.SetPort(portValue.asInt()); | |
273 } | |
274 catch (std::runtime_error /* error inside JsonCpp */) | |
275 { | |
276 try | |
277 { | |
278 modality.SetPort(boost::lexical_cast<int>(portValue.asString())); | |
279 } | |
280 catch (boost::bad_lexical_cast) | |
281 { | |
282 throw OrthancException(ErrorCode_BadFileFormat); | |
283 } | |
284 } | |
285 | |
286 if (modalities[name].size() == 4) | |
287 { | |
288 modality.SetManufacturer(modalities[name].get(3u, "").asString()); | |
289 } | |
290 else | |
291 { | |
292 modality.SetManufacturer(ModalityManufacturer_Generic); | |
293 } | |
294 } | 266 } |
295 catch (OrthancException& e) | 267 catch (OrthancException& e) |
296 { | 268 { |
297 LOG(ERROR) << "Syntax error in the definition of modality \"" << name | 269 LOG(ERROR) << "Syntax error in the definition of modality \"" << name |
298 << "\". Please check your configuration file."; | 270 << "\". Please check your configuration file."; |
581 else | 553 else |
582 { | 554 { |
583 throw OrthancException("Unknown modality for AET: " + aet); | 555 throw OrthancException("Unknown modality for AET: " + aet); |
584 } | 556 } |
585 } | 557 } |
558 | |
559 | |
560 void UpdateModality(const RemoteModalityParameters& modality) | |
561 { | |
562 boost::mutex::scoped_lock lock(globalMutex_); | |
563 | |
564 if (!configuration_->isMember("DicomModalities")) | |
565 { | |
566 throw OrthancException(ErrorCode_BadFileFormat); | |
567 } | |
568 | |
569 Json::Value& modalities = (*configuration_) ["DicomModalities"]; | |
570 if (modalities.type() != Json::objectValue) | |
571 { | |
572 throw OrthancException(ErrorCode_BadFileFormat); | |
573 } | |
574 | |
575 modalities.removeMember(modality.GetName().c_str()); | |
576 | |
577 Json::Value v; | |
578 modality.ToJson(v); | |
579 modalities[modality.GetName()] = v; | |
580 } | |
581 | |
582 | |
583 void RemoveModality(const std::string& symbolicName) | |
584 { | |
585 boost::mutex::scoped_lock lock(globalMutex_); | |
586 | |
587 if (!configuration_->isMember("DicomModalities")) | |
588 { | |
589 throw OrthancException(ErrorCode_BadFileFormat); | |
590 } | |
591 | |
592 Json::Value& modalities = (*configuration_) ["DicomModalities"]; | |
593 if (modalities.type() != Json::objectValue) | |
594 { | |
595 throw OrthancException(ErrorCode_BadFileFormat); | |
596 } | |
597 | |
598 modalities.removeMember(symbolicName.c_str()); | |
599 } | |
586 } | 600 } |