Mercurial > hg > orthanc-transfers
comparison Plugin/Plugin.cpp @ 5:5e6de82bb10f
use of user properties instead of BidirectionalPeers option
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 18 Sep 2018 15:39:02 +0200 |
parents | 1ed03945c057 |
children | 4c3437217518 |
comparison
equal
deleted
inserted
replaced
4:1ed03945c057 | 5:5e6de82bb10f |
---|---|
436 return; | 436 return; |
437 } | 437 } |
438 | 438 |
439 OrthancPlugins::TransferQuery query(body); | 439 OrthancPlugins::TransferQuery query(body); |
440 | 440 |
441 OrthancPlugins::OrthancPeers peers(context.GetOrthanc()); | |
442 | |
441 std::string remoteSelf; // For pull mode | 443 std::string remoteSelf; // For pull mode |
442 bool pullMode = context.LookupBidirectionalPeer(remoteSelf, query.GetPeer()); | 444 bool pullMode = peers.LookupUserProperty(remoteSelf, query.GetPeer(), KEY_REMOTE_SELF); |
443 | 445 |
444 LOG(INFO) << "Sending resources to peer \"" << query.GetPeer() << "\" using " | 446 LOG(INFO) << "Sending resources to peer \"" << query.GetPeer() << "\" using " |
445 << (pullMode ? "pull" : "push") << " mode"; | 447 << (pullMode ? "pull" : "push") << " mode"; |
446 | 448 |
447 if (pullMode) | 449 if (pullMode) |
448 { | 450 { |
449 OrthancPlugins::OrthancPeers peers(context.GetOrthanc()); | |
450 | |
451 Json::Value lookup = Json::objectValue; | 451 Json::Value lookup = Json::objectValue; |
452 lookup[KEY_RESOURCES] = query.GetResources(); | 452 lookup[KEY_RESOURCES] = query.GetResources(); |
453 lookup[KEY_COMPRESSION] = OrthancPlugins::EnumerationToString(query.GetCompression()); | 453 lookup[KEY_COMPRESSION] = OrthancPlugins::EnumerationToString(query.GetCompression()); |
454 lookup[KEY_ORIGINATOR_UUID] = context.GetPluginUuid(); | 454 lookup[KEY_ORIGINATOR_UUID] = context.GetPluginUuid(); |
455 lookup[KEY_PEER] = remoteSelf; | 455 lookup[KEY_PEER] = remoteSelf; |
577 { | 577 { |
578 OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "GET"); | 578 OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "GET"); |
579 return; | 579 return; |
580 } | 580 } |
581 | 581 |
582 OrthancPlugins::DetectTransferPlugin::Peers peers; | 582 OrthancPlugins::DetectTransferPlugin::Result detection; |
583 OrthancPlugins::DetectTransferPlugin::Apply | 583 OrthancPlugins::DetectTransferPlugin::Apply |
584 (peers, context.GetOrthanc(), context.GetThreadsCount(), 2 /* timeout */); | 584 (detection, context.GetOrthanc(), context.GetThreadsCount(), 2 /* timeout */); |
585 | 585 |
586 Json::Value result = Json::objectValue; | 586 Json::Value result = Json::objectValue; |
587 | 587 |
588 for (OrthancPlugins::DetectTransferPlugin::Peers::const_iterator | 588 OrthancPlugins::OrthancPeers peers(context.GetOrthanc()); |
589 it = peers.begin(); it != peers.end(); ++it) | 589 |
590 { | 590 for (OrthancPlugins::DetectTransferPlugin::Result::const_iterator |
591 switch (it->second) | 591 it = detection.begin(); it != detection.end(); ++it) |
592 { | 592 { |
593 case OrthancPlugins::PeerCapabilities_Disabled: | 593 if (it->second) |
594 result[it->first] = "disabled"; | 594 { |
595 break; | 595 std::string remoteSelf; |
596 | 596 |
597 case OrthancPlugins::PeerCapabilities_Installed: | 597 if (peers.LookupUserProperty(remoteSelf, it->first, KEY_REMOTE_SELF)) |
598 { | 598 { |
599 std::string remoteSelf; | 599 result[it->first] = "bidirectional"; |
600 | 600 } |
601 if (context.LookupBidirectionalPeer(remoteSelf, it->first)) | 601 else |
602 { | 602 { |
603 result[it->first] = "installed"; | 603 result[it->first] = "installed"; |
604 } | 604 } |
605 else | 605 } |
606 { | 606 else |
607 result[it->first] = "bidirectional"; | 607 { |
608 } | 608 result[it->first] = "disabled"; |
609 break; | |
610 } | |
611 | |
612 default: | |
613 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
614 } | 609 } |
615 } | 610 } |
616 | 611 |
617 std::string s = result.toStyledString(); | 612 std::string s = result.toStyledString(); |
618 OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json"); | 613 OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json"); |
656 if (config.IsSection(KEY_PLUGIN_CONFIGURATION)) | 651 if (config.IsSection(KEY_PLUGIN_CONFIGURATION)) |
657 { | 652 { |
658 OrthancPlugins::OrthancConfiguration plugin; | 653 OrthancPlugins::OrthancConfiguration plugin; |
659 config.GetSection(plugin, KEY_PLUGIN_CONFIGURATION); | 654 config.GetSection(plugin, KEY_PLUGIN_CONFIGURATION); |
660 | 655 |
661 plugin.GetDictionary(bidirectionalPeers, KEY_BIDIRECTIONAL_PEERS); | |
662 threadsCount = plugin.GetUnsignedIntegerValue("Threads", threadsCount); | 656 threadsCount = plugin.GetUnsignedIntegerValue("Threads", threadsCount); |
663 targetBucketSize = plugin.GetUnsignedIntegerValue("BucketSize", targetBucketSize); | 657 targetBucketSize = plugin.GetUnsignedIntegerValue("BucketSize", targetBucketSize); |
664 memoryCacheSize = plugin.GetUnsignedIntegerValue("CacheSize", memoryCacheSize); | 658 memoryCacheSize = plugin.GetUnsignedIntegerValue("CacheSize", memoryCacheSize); |
665 maxPushTransactions = plugin.GetUnsignedIntegerValue | 659 maxPushTransactions = plugin.GetUnsignedIntegerValue |
666 ("MaxPushTransactions", maxPushTransactions); | 660 ("MaxPushTransactions", maxPushTransactions); |
667 } | 661 } |
668 } | 662 } |
669 | 663 |
670 OrthancPlugins::PluginContext::Initialize | 664 OrthancPlugins::PluginContext::Initialize |
671 (context, threadsCount, targetBucketSize * KB, maxPushTransactions, memoryCacheSize * MB); | 665 (context, threadsCount, targetBucketSize * KB, maxPushTransactions, memoryCacheSize * MB); |
672 OrthancPlugins::PluginContext::GetInstance().LoadBidirectionalPeers(bidirectionalPeers); | |
673 | 666 |
674 OrthancPlugins::RegisterRestCallback<ServeChunks> | 667 OrthancPlugins::RegisterRestCallback<ServeChunks> |
675 (context, std::string(URI_CHUNKS) + "/([.0-9a-f-]+)", true); | 668 (context, std::string(URI_CHUNKS) + "/([.0-9a-f-]+)", true); |
676 | 669 |
677 OrthancPlugins::RegisterRestCallback<LookupInstances> | 670 OrthancPlugins::RegisterRestCallback<LookupInstances> |