changeset 4:1ed03945c057

showing unavailable peers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Sep 2018 14:42:57 +0200
parents 9bcd6eadcff5
children 5e6de82bb10f
files Framework/HttpQueries/DetectTransferPlugin.cpp Framework/HttpQueries/DetectTransferPlugin.h Framework/TransferToolbox.h Plugin/Plugin.cpp Resources/OrthancExplorer.js
diffstat 5 files changed, 77 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- 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<std::string>&  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<std::string>& 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)));
     }
 
     {
--- 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 <orthanc/OrthancCPlugin.h>
-#include <set>
+#include <map>
 
 
 namespace OrthancPlugins
 {
   class DetectTransferPlugin : public IHttpQuery
   {
+  public:
+    typedef std::map<std::string, PeerCapabilities>  Peers;
+    
   private:
-    std::set<std::string>&  target_;
-    std::string             peer_;
-    std::string             uri_;
+    Peers&       target_;
+    std::string  peer_;
+    std::string  uri_;
 
   public:
-    DetectTransferPlugin(std::set<std::string>&  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<std::string>& activePeers,
+    static void Apply(Peers& peers,
                       OrthancPluginContext* context,
                       size_t threadsCount,
                       unsigned int timeout);
--- 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);
--- 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<std::string> 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<std::string>::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();
--- 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('<li data-role="list-divider">Orthanc peers</li>');
-
   $.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 = $('<li>')
-          .html('<a href="#" rel="close">' + name + '</a>')
-          .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 = $('<li>')
+              .html('<a href="#" rel="close">' + name + '</a>')
+              .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);