comparison OrthancServer/OrthancInitialization.cpp @ 810:401a9633e492

configuration into a namespace
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 07 May 2014 16:47:56 +0200
parents 2d9a000aa3a6
children 8a36c947490c
comparison
equal deleted inserted replaced
809:8ce2f69436ca 810:401a9633e492
192 configuration_.reset(NULL); 192 configuration_.reset(NULL);
193 } 193 }
194 194
195 195
196 196
197 std::string GetGlobalStringParameter(const std::string& parameter, 197 std::string Configuration::GetGlobalStringParameter(const std::string& parameter,
198 const std::string& defaultValue) 198 const std::string& defaultValue)
199 { 199 {
200 boost::mutex::scoped_lock lock(globalMutex_); 200 boost::mutex::scoped_lock lock(globalMutex_);
201 201
202 if (configuration_->isMember(parameter)) 202 if (configuration_->isMember(parameter))
203 { 203 {
208 return defaultValue; 208 return defaultValue;
209 } 209 }
210 } 210 }
211 211
212 212
213 int GetGlobalIntegerParameter(const std::string& parameter, 213 int Configuration::GetGlobalIntegerParameter(const std::string& parameter,
214 int defaultValue) 214 int defaultValue)
215 { 215 {
216 boost::mutex::scoped_lock lock(globalMutex_); 216 boost::mutex::scoped_lock lock(globalMutex_);
217 217
218 if (configuration_->isMember(parameter)) 218 if (configuration_->isMember(parameter))
219 { 219 {
223 { 223 {
224 return defaultValue; 224 return defaultValue;
225 } 225 }
226 } 226 }
227 227
228 bool GetGlobalBoolParameter(const std::string& parameter, 228
229 bool defaultValue) 229 bool Configuration::GetGlobalBoolParameter(const std::string& parameter,
230 bool defaultValue)
230 { 231 {
231 boost::mutex::scoped_lock lock(globalMutex_); 232 boost::mutex::scoped_lock lock(globalMutex_);
232 233
233 if (configuration_->isMember(parameter)) 234 if (configuration_->isMember(parameter))
234 { 235 {
239 return defaultValue; 240 return defaultValue;
240 } 241 }
241 } 242 }
242 243
243 244
244 245 void Configuration::GetDicomModalityUsingSymbolicName(RemoteModalityParameters& modality,
245 246 const std::string& name)
246 void GetDicomModalityUsingSymbolicName(RemoteModalityParameters& modality,
247 const std::string& name)
248 { 247 {
249 boost::mutex::scoped_lock lock(globalMutex_); 248 boost::mutex::scoped_lock lock(globalMutex_);
250 249
251 if (!configuration_->isMember("DicomModalities")) 250 if (!configuration_->isMember("DicomModalities"))
252 { 251 {
272 } 271 }
273 } 272 }
274 273
275 274
276 275
277 void GetOrthancPeer(OrthancPeerParameters& peer, 276 void Configuration::GetOrthancPeer(OrthancPeerParameters& peer,
278 const std::string& name) 277 const std::string& name)
279 { 278 {
280 boost::mutex::scoped_lock lock(globalMutex_); 279 boost::mutex::scoped_lock lock(globalMutex_);
281 280
282 if (!configuration_->isMember("OrthancPeers")) 281 if (!configuration_->isMember("OrthancPeers"))
283 { 282 {
342 341
343 return true; 342 return true;
344 } 343 }
345 344
346 345
347 void GetListOfDicomModalities(std::set<std::string>& target) 346 void Configuration::GetListOfDicomModalities(std::set<std::string>& target)
348 { 347 {
349 if (!ReadKeys(target, "DicomModalities", true)) 348 if (!ReadKeys(target, "DicomModalities", true))
350 { 349 {
351 throw OrthancException("Only alphanumeric and dash characters are allowed in the names of the modalities"); 350 throw OrthancException("Only alphanumeric and dash characters are allowed in the names of the modalities");
352 } 351 }
353 } 352 }
354 353
355 354
356 void GetListOfOrthancPeers(std::set<std::string>& target) 355 void Configuration::GetListOfOrthancPeers(std::set<std::string>& target)
357 { 356 {
358 if (!ReadKeys(target, "OrthancPeers", true)) 357 if (!ReadKeys(target, "OrthancPeers", true))
359 { 358 {
360 throw OrthancException("Only alphanumeric and dash characters are allowed in the names of Orthanc peers"); 359 throw OrthancException("Only alphanumeric and dash characters are allowed in the names of Orthanc peers");
361 } 360 }
362 } 361 }
363 362
364 363
365 364
366 void SetupRegisteredUsers(MongooseServer& httpServer) 365 void Configuration::SetupRegisteredUsers(MongooseServer& httpServer)
367 { 366 {
368 boost::mutex::scoped_lock lock(globalMutex_); 367 boost::mutex::scoped_lock lock(globalMutex_);
369 368
370 httpServer.ClearUsers(); 369 httpServer.ClearUsers();
371 370
388 httpServer.RegisterUser(username.c_str(), password.c_str()); 387 httpServer.RegisterUser(username.c_str(), password.c_str());
389 } 388 }
390 } 389 }
391 390
392 391
393 std::string InterpretRelativePath(const std::string& baseDirectory, 392 std::string Configuration::InterpretRelativePath(const std::string& baseDirectory,
394 const std::string& relativePath) 393 const std::string& relativePath)
395 { 394 {
396 boost::filesystem::path base(baseDirectory); 395 boost::filesystem::path base(baseDirectory);
397 boost::filesystem::path relative(relativePath); 396 boost::filesystem::path relative(relativePath);
398 397
399 /** 398 /**
414 { 413 {
415 return (base / relative).string(); 414 return (base / relative).string();
416 } 415 }
417 } 416 }
418 417
419 std::string InterpretStringParameterAsPath(const std::string& parameter) 418 std::string Configuration::InterpretStringParameterAsPath(const std::string& parameter)
420 { 419 {
421 boost::mutex::scoped_lock lock(globalMutex_); 420 boost::mutex::scoped_lock lock(globalMutex_);
422 return InterpretRelativePath(defaultDirectory_.string(), parameter); 421 return InterpretRelativePath(defaultDirectory_.string(), parameter);
423 } 422 }
424 423
425 424
426 void GetGlobalListOfStringsParameter(std::list<std::string>& target, 425 void Configuration::GetGlobalListOfStringsParameter(std::list<std::string>& target,
427 const std::string& key) 426 const std::string& key)
428 { 427 {
429 boost::mutex::scoped_lock lock(globalMutex_); 428 boost::mutex::scoped_lock lock(globalMutex_);
430 429
431 target.clear(); 430 target.clear();
432 431
447 target.push_back(lst[i].asString()); 446 target.push_back(lst[i].asString());
448 } 447 }
449 } 448 }
450 449
451 450
452 bool IsSameAETitle(const std::string& aet1, 451 bool Configuration::IsSameAETitle(const std::string& aet1,
453 const std::string& aet2) 452 const std::string& aet2)
454 { 453 {
455 if (GetGlobalBoolParameter("StrictAetComparison", false)) 454 if (GetGlobalBoolParameter("StrictAetComparison", false))
456 { 455 {
457 // Case-sensitive matching 456 // Case-sensitive matching
458 return aet1 == aet2; 457 return aet1 == aet2;
466 return tmp1 == tmp2; 465 return tmp1 == tmp2;
467 } 466 }
468 } 467 }
469 468
470 469
471 bool LookupDicomModalityUsingAETitle(RemoteModalityParameters& modality, 470 bool Configuration::LookupDicomModalityUsingAETitle(RemoteModalityParameters& modality,
472 const std::string& aet) 471 const std::string& aet)
473 { 472 {
474 std::set<std::string> modalities; 473 std::set<std::string> modalities;
475 GetListOfDicomModalities(modalities); 474 GetListOfDicomModalities(modalities);
476 475
477 for (std::set<std::string>::const_iterator 476 for (std::set<std::string>::const_iterator
493 492
494 return false; 493 return false;
495 } 494 }
496 495
497 496
498 bool IsKnownAETitle(const std::string& aet) 497 bool Configuration::IsKnownAETitle(const std::string& aet)
499 { 498 {
500 RemoteModalityParameters modality; 499 RemoteModalityParameters modality;
501 return LookupDicomModalityUsingAETitle(modality, aet); 500 return LookupDicomModalityUsingAETitle(modality, aet);
502 } 501 }
503 502
504 503
505 RemoteModalityParameters GetModalityUsingSymbolicName(const std::string& name) 504 RemoteModalityParameters Configuration::GetModalityUsingSymbolicName(const std::string& name)
506 { 505 {
507 RemoteModalityParameters modality; 506 RemoteModalityParameters modality;
508 GetDicomModalityUsingSymbolicName(modality, name); 507 GetDicomModalityUsingSymbolicName(modality, name);
509 508
510 return modality; 509 return modality;
511 } 510 }
512 511
513 512
514 RemoteModalityParameters GetModalityUsingAet(const std::string& aet) 513 RemoteModalityParameters Configuration::GetModalityUsingAet(const std::string& aet)
515 { 514 {
516 RemoteModalityParameters modality; 515 RemoteModalityParameters modality;
517 516
518 if (LookupDicomModalityUsingAETitle(modality, aet)) 517 if (LookupDicomModalityUsingAETitle(modality, aet))
519 { 518 {
524 throw OrthancException("Unknown modality for AET: " + aet); 523 throw OrthancException("Unknown modality for AET: " + aet);
525 } 524 }
526 } 525 }
527 526
528 527
529 void UpdateModality(const RemoteModalityParameters& modality) 528 void Configuration::UpdateModality(const RemoteModalityParameters& modality)
530 { 529 {
531 boost::mutex::scoped_lock lock(globalMutex_); 530 boost::mutex::scoped_lock lock(globalMutex_);
532 531
533 if (!configuration_->isMember("DicomModalities")) 532 if (!configuration_->isMember("DicomModalities"))
534 { 533 {
547 modality.ToJson(v); 546 modality.ToJson(v);
548 modalities[modality.GetName()] = v; 547 modalities[modality.GetName()] = v;
549 } 548 }
550 549
551 550
552 void RemoveModality(const std::string& symbolicName) 551 void Configuration::RemoveModality(const std::string& symbolicName)
553 { 552 {
554 boost::mutex::scoped_lock lock(globalMutex_); 553 boost::mutex::scoped_lock lock(globalMutex_);
555 554
556 if (!configuration_->isMember("DicomModalities")) 555 if (!configuration_->isMember("DicomModalities"))
557 { 556 {
566 565
567 modalities.removeMember(symbolicName.c_str()); 566 modalities.removeMember(symbolicName.c_str());
568 } 567 }
569 568
570 569
571 void UpdatePeer(const OrthancPeerParameters& peer) 570 void Configuration::UpdatePeer(const OrthancPeerParameters& peer)
572 { 571 {
573 boost::mutex::scoped_lock lock(globalMutex_); 572 boost::mutex::scoped_lock lock(globalMutex_);
574 573
575 if (!configuration_->isMember("OrthancPeers")) 574 if (!configuration_->isMember("OrthancPeers"))
576 { 575 {
589 peer.ToJson(v); 588 peer.ToJson(v);
590 peers[peer.GetName()] = v; 589 peers[peer.GetName()] = v;
591 } 590 }
592 591
593 592
594 void RemovePeer(const std::string& symbolicName) 593 void Configuration::RemovePeer(const std::string& symbolicName)
595 { 594 {
596 boost::mutex::scoped_lock lock(globalMutex_); 595 boost::mutex::scoped_lock lock(globalMutex_);
597 596
598 if (!configuration_->isMember("OrthancPeers")) 597 if (!configuration_->isMember("OrthancPeers"))
599 { 598 {