# HG changeset patch # User Sebastien Jodogne # Date 1537188177 -7200 # Node ID 1ed03945c057901e0fbcccb724afbba8f0b607f9 # Parent 9bcd6eadcff5976f2c0096c7db623ab3b372c45d showing unavailable peers diff -r 9bcd6eadcff5 -r 1ed03945c057 Framework/HttpQueries/DetectTransferPlugin.cpp --- a/Framework/HttpQueries/DetectTransferPlugin.cpp Mon Sep 17 12:14:20 2018 +0200 +++ b/Framework/HttpQueries/DetectTransferPlugin.cpp Mon Sep 17 14:42:57 2018 +0200 @@ -29,12 +29,13 @@ namespace OrthancPlugins { - DetectTransferPlugin::DetectTransferPlugin(std::set& target, + DetectTransferPlugin::DetectTransferPlugin(Peers& target, const std::string& peer) : target_(target), peer_(peer), uri_(URI_PLUGINS) { + target_[peer_] = PeerCapabilities_Disabled; } @@ -59,14 +60,16 @@ if (value[i].type() == Json::stringValue && value[i].asString() == PLUGIN_NAME) { - target_.insert(peer_); + // The "Bidirectional" status is set in "Plugin.cpp", given + // the configuration file + target_[peer_] = PeerCapabilities_Installed; } } } } - void DetectTransferPlugin::Apply(std::set& activePeers, + void DetectTransferPlugin::Apply(Peers& peers, OrthancPluginContext* context, size_t threadsCount, unsigned int timeout) @@ -79,7 +82,7 @@ for (size_t i = 0; i < queue.GetOrthancPeers().GetPeersCount(); i++) { queue.Enqueue(new OrthancPlugins::DetectTransferPlugin - (activePeers, queue.GetOrthancPeers().GetPeerName(i))); + (peers, queue.GetOrthancPeers().GetPeerName(i))); } { diff -r 9bcd6eadcff5 -r 1ed03945c057 Framework/HttpQueries/DetectTransferPlugin.h --- a/Framework/HttpQueries/DetectTransferPlugin.h Mon Sep 17 12:14:20 2018 +0200 +++ b/Framework/HttpQueries/DetectTransferPlugin.h Mon Sep 17 14:42:57 2018 +0200 @@ -20,22 +20,26 @@ #pragma once #include "IHttpQuery.h" +#include "../TransferToolbox.h" #include -#include +#include namespace OrthancPlugins { class DetectTransferPlugin : public IHttpQuery { + public: + typedef std::map Peers; + private: - std::set& target_; - std::string peer_; - std::string uri_; + Peers& target_; + std::string peer_; + std::string uri_; public: - DetectTransferPlugin(std::set& target, + DetectTransferPlugin(Peers& target, const std::string& peer); virtual Orthanc::HttpMethod GetMethod() const @@ -58,7 +62,7 @@ virtual void HandleAnswer(const void* answer, size_t size); - static void Apply(std::set& activePeers, + static void Apply(Peers& peers, OrthancPluginContext* context, size_t threadsCount, unsigned int timeout); diff -r 9bcd6eadcff5 -r 1ed03945c057 Framework/TransferToolbox.h --- a/Framework/TransferToolbox.h Mon Sep 17 12:14:20 2018 +0200 +++ b/Framework/TransferToolbox.h Mon Sep 17 14:42:57 2018 +0200 @@ -65,6 +65,13 @@ BucketCompression_Gzip }; + enum PeerCapabilities + { + PeerCapabilities_Disabled, + PeerCapabilities_Installed, + PeerCapabilities_Bidirectional + }; + unsigned int ConvertToMegabytes(uint64_t value); unsigned int ConvertToKilobytes(uint64_t value); diff -r 9bcd6eadcff5 -r 1ed03945c057 Plugin/Plugin.cpp --- a/Plugin/Plugin.cpp Mon Sep 17 12:14:20 2018 +0200 +++ b/Plugin/Plugin.cpp Mon Sep 17 14:42:57 2018 +0200 @@ -579,16 +579,39 @@ return; } - std::set activePeers; + OrthancPlugins::DetectTransferPlugin::Peers peers; OrthancPlugins::DetectTransferPlugin::Apply - (activePeers, context.GetOrthanc(), context.GetThreadsCount(), 2 /* timeout */); + (peers, context.GetOrthanc(), context.GetThreadsCount(), 2 /* timeout */); + + Json::Value result = Json::objectValue; + + for (OrthancPlugins::DetectTransferPlugin::Peers::const_iterator + it = peers.begin(); it != peers.end(); ++it) + { + switch (it->second) + { + case OrthancPlugins::PeerCapabilities_Disabled: + result[it->first] = "disabled"; + break; - Json::Value result = Json::arrayValue; + case OrthancPlugins::PeerCapabilities_Installed: + { + std::string remoteSelf; - for (std::set::const_iterator - it = activePeers.begin(); it != activePeers.end(); ++it) - { - result.append(*it); + if (context.LookupBidirectionalPeer(remoteSelf, it->first)) + { + result[it->first] = "installed"; + } + else + { + result[it->first] = "bidirectional"; + } + break; + } + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } } std::string s = result.toStyledString(); diff -r 9bcd6eadcff5 -r 1ed03945c057 Resources/OrthancExplorer.js --- a/Resources/OrthancExplorer.js Mon Sep 17 12:14:20 2018 +0200 +++ b/Resources/OrthancExplorer.js Mon Sep 17 14:42:57 2018 +0200 @@ -4,8 +4,6 @@ .attr('data-divider-theme', 'd') .attr('data-role', 'listview'); - items.append('
  • Orthanc peers
  • '); - $.ajax({ url: '../transfers/peers', type: 'GET', @@ -13,22 +11,32 @@ async: false, cache: false, success: function(peers) { - for (var i = 0; i < peers.length; i++) { - var name = peers[i]; - var item = $('
  • ') - .html('' + name + '') - .attr('name', name) - .click(function() { - clickedPeer = $(this).attr('name'); - }); - items.append(item); + console.log(peers); + var clickedPeer = null; + + for (var name in peers) { + if (peers.hasOwnProperty(name)) { + var item = $('
  • ') + .html('' + name + '') + .attr('name', name) + .click(function() { + clickedPeer = $(this).attr('name'); + }); + + if (peers[name] != 'installed' && + peers[name] != 'bidirectional') { + item.addClass('ui-disabled'); + } + + items.append(item); + } } // Launch the dialog $('#dialog').simpledialog2({ mode: 'blank', animate: false, - headerText: 'Choose target', + headerText: 'Choose Orthanc peer', headerClose: true, forceInput: false, width: '100%', @@ -38,7 +46,9 @@ function WaitForDialogToClose() { if (!$('#dialog').is(':visible')) { clearInterval(timer); - callback(clickedPeer); + if (clickedPeer !== null) { + callback(clickedPeer); + } } } timer = setInterval(WaitForDialogToClose, 100);