comparison OrthancServer/OrthancInitialization.cpp @ 806:557575fd93e9

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 07 May 2014 15:22:28 +0200
parents 3bd0589af992
children 566a2fb3c1fb
comparison
equal deleted inserted replaced
805:56a813a4714d 806:557575fd93e9
48 { 48 {
49 static boost::mutex globalMutex_; 49 static boost::mutex globalMutex_;
50 static std::auto_ptr<Json::Value> configuration_; 50 static std::auto_ptr<Json::Value> configuration_;
51 static boost::filesystem::path defaultDirectory_; 51 static boost::filesystem::path defaultDirectory_;
52 52
53
53 static void ReadGlobalConfiguration(const char* configurationFile) 54 static void ReadGlobalConfiguration(const char* configurationFile)
54 { 55 {
55 configuration_.reset(new Json::Value); 56 configuration_.reset(new Json::Value);
56 57
57 std::string content; 58 std::string content;
240 } 241 }
241 242
242 243
243 244
244 245
245 void GetDicomModalityUsingSymbolicName(const std::string& name, 246 void GetDicomModalityUsingSymbolicName(RemoteModalityParameters& modality,
246 std::string& aet, 247 const std::string& name)
247 std::string& address,
248 int& port,
249 ModalityManufacturer& manufacturer)
250 { 248 {
251 boost::mutex::scoped_lock lock(globalMutex_); 249 boost::mutex::scoped_lock lock(globalMutex_);
252 250
253 if (!configuration_->isMember("DicomModalities")) 251 if (!configuration_->isMember("DicomModalities"))
254 { 252 {
263 throw OrthancException(ErrorCode_BadFileFormat); 261 throw OrthancException(ErrorCode_BadFileFormat);
264 } 262 }
265 263
266 try 264 try
267 { 265 {
268 aet = modalities[name].get(0u, "").asString(); 266 modality.SetApplicationEntityTitle(modalities[name].get(0u, "").asString());
269 address = modalities[name].get(1u, "").asString(); 267 modality.SetHost(modalities[name].get(1u, "").asString());
270 268
271 const Json::Value& portValue = modalities[name].get(2u, ""); 269 const Json::Value& portValue = modalities[name].get(2u, "");
272 try 270 try
273 { 271 {
274 port = portValue.asInt(); 272 modality.SetPort(portValue.asInt());
275 } 273 }
276 catch (std::runtime_error /* error inside JsonCpp */) 274 catch (std::runtime_error /* error inside JsonCpp */)
277 { 275 {
278 try 276 try
279 { 277 {
280 port = boost::lexical_cast<int>(portValue.asString()); 278 modality.SetPort(boost::lexical_cast<int>(portValue.asString()));
281 } 279 }
282 catch (boost::bad_lexical_cast) 280 catch (boost::bad_lexical_cast)
283 { 281 {
284 throw OrthancException(ErrorCode_BadFileFormat); 282 throw OrthancException(ErrorCode_BadFileFormat);
285 } 283 }
286 } 284 }
287 285
288 if (modalities[name].size() == 4) 286 if (modalities[name].size() == 4)
289 { 287 {
290 manufacturer = StringToModalityManufacturer(modalities[name].get(3u, "").asString()); 288 modality.SetManufacturer(modalities[name].get(3u, "").asString());
291 } 289 }
292 else 290 else
293 { 291 {
294 manufacturer = ModalityManufacturer_Generic; 292 modality.SetManufacturer(ModalityManufacturer_Generic);
295 } 293 }
296 } 294 }
297 catch (OrthancException& e) 295 catch (OrthancException& e)
298 { 296 {
299 LOG(ERROR) << "Syntax error in the definition of modality \"" << name 297 LOG(ERROR) << "Syntax error in the definition of modality \"" << name
302 } 300 }
303 } 301 }
304 302
305 303
306 304
307 void GetOrthancPeer(const std::string& name, 305 void GetOrthancPeer(OrthancPeerParameters& peer,
308 std::string& url, 306 const std::string& name)
309 std::string& username,
310 std::string& password)
311 { 307 {
312 boost::mutex::scoped_lock lock(globalMutex_); 308 boost::mutex::scoped_lock lock(globalMutex_);
313 309
314 if (!configuration_->isMember("OrthancPeers")) 310 if (!configuration_->isMember("OrthancPeers"))
315 { 311 {
323 !modalities.isMember(name)) 319 !modalities.isMember(name))
324 { 320 {
325 throw OrthancException(ErrorCode_BadFileFormat); 321 throw OrthancException(ErrorCode_BadFileFormat);
326 } 322 }
327 323
324 std::string url;
325
328 try 326 try
329 { 327 {
330 url = modalities[name].get(0u, "").asString(); 328 url = modalities[name].get(0u, "").asString();
331 329
332 if (modalities[name].size() == 1) 330 if (modalities[name].size() == 1)
333 { 331 {
334 username = ""; 332 peer.SetUsername("");
335 password = ""; 333 peer.SetPassword("");
336 } 334 }
337 else if (modalities[name].size() == 3) 335 else if (modalities[name].size() == 3)
338 { 336 {
339 username = modalities[name].get(1u, "").asString(); 337 peer.SetUsername(modalities[name].get(1u, "").asString());
340 password = modalities[name].get(2u, "").asString(); 338 peer.SetPassword(modalities[name].get(2u, "").asString());
341 } 339 }
342 else 340 else
343 { 341 {
344 throw OrthancException(ErrorCode_BadFileFormat); 342 throw OrthancException(ErrorCode_BadFileFormat);
345 } 343 }
351 349
352 if (url.size() != 0 && url[url.size() - 1] != '/') 350 if (url.size() != 0 && url[url.size() - 1] != '/')
353 { 351 {
354 url += '/'; 352 url += '/';
355 } 353 }
354
355 peer.SetUrl(url);
356 } 356 }
357 catch (OrthancException& e) 357 catch (OrthancException& e)
358 { 358 {
359 LOG(ERROR) << "Syntax error in the definition of peer \"" << name 359 LOG(ERROR) << "Syntax error in the definition of peer \"" << name
360 << "\". Please check your configuration file."; 360 << "\". Please check your configuration file.";
525 return tmp1 == tmp2; 525 return tmp1 == tmp2;
526 } 526 }
527 } 527 }
528 528
529 529
530 bool LookupDicomModalityUsingAETitle(const std::string& aet, 530 bool LookupDicomModalityUsingAETitle(RemoteModalityParameters& modality,
531 std::string& symbolicName, 531 const std::string& aet)
532 std::string& address,
533 int& port,
534 ModalityManufacturer& manufacturer)
535 { 532 {
536 std::set<std::string> modalities; 533 std::set<std::string> modalities;
537 GetListOfDicomModalities(modalities); 534 GetListOfDicomModalities(modalities);
538 535
539 for (std::set<std::string>::const_iterator 536 for (std::set<std::string>::const_iterator
540 it = modalities.begin(); it != modalities.end(); ++it) 537 it = modalities.begin(); it != modalities.end(); ++it)
541 { 538 {
542 try 539 try
543 { 540 {
544 std::string thisAet; 541 GetDicomModalityUsingSymbolicName(modality, *it);
545 GetDicomModalityUsingSymbolicName(*it, thisAet, address, port, manufacturer); 542
546 543 if (IsSameAETitle(aet, modality.GetApplicationEntityTitle()))
547 if (IsSameAETitle(aet, thisAet))
548 { 544 {
549 return true; 545 return true;
550 } 546 }
551 } 547 }
552 catch (OrthancException&) 548 catch (OrthancException&)
558 } 554 }
559 555
560 556
561 bool IsKnownAETitle(const std::string& aet) 557 bool IsKnownAETitle(const std::string& aet)
562 { 558 {
563 std::string symbolicName, address; 559 RemoteModalityParameters modality;
564 int port; 560 return LookupDicomModalityUsingAETitle(modality, aet);
565 ModalityManufacturer manufacturer;
566
567 return LookupDicomModalityUsingAETitle(aet, symbolicName, address, port, manufacturer);
568 } 561 }
569 562
570 563
571 RemoteModalityParameters GetModalityUsingSymbolicName(const std::string& name) 564 RemoteModalityParameters GetModalityUsingSymbolicName(const std::string& name)
572 { 565 {
573 std::string aet, address; 566 RemoteModalityParameters modality;
574 int port; 567 GetDicomModalityUsingSymbolicName(modality, name);
575 ModalityManufacturer manufacturer; 568
576 569 return modality;
577 GetDicomModalityUsingSymbolicName(name, aet, address, port, manufacturer);
578
579 return RemoteModalityParameters(name, aet, address, port, manufacturer);
580 } 570 }
581 571
582 572
583 RemoteModalityParameters GetModalityUsingAet(const std::string& aet) 573 RemoteModalityParameters GetModalityUsingAet(const std::string& aet)
584 { 574 {
585 std::string name, address; 575 RemoteModalityParameters modality;
586 int port; 576
587 ModalityManufacturer manufacturer; 577 if (LookupDicomModalityUsingAETitle(modality, aet))
588 578 {
589 if (LookupDicomModalityUsingAETitle(aet, name, address, port, manufacturer)) 579 return modality;
590 {
591 return RemoteModalityParameters(name, aet, address, port, manufacturer);
592 } 580 }
593 else 581 else
594 { 582 {
595 throw OrthancException("Unknown modality for AET: " + aet); 583 throw OrthancException("Unknown modality for AET: " + aet);
596 } 584 }