Skip to content
Snippets Groups Projects
Commit ced2cfcb authored by Sergey Linev's avatar Sergey Linev
Browse files

rbrowser: simplify data model, do not need extra description class

Correctly handle request to same directory - reuse already build list of
items
parent 0d5b59a3
No related merge requests found
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
#include <TSystem.h> #include <TSystem.h>
#include <vector> #include <vector>
#include <sstream>
#include <iostream>
namespace ROOT { namespace ROOT {
namespace Experimental { namespace Experimental {
...@@ -43,7 +41,7 @@ public: ...@@ -43,7 +41,7 @@ public:
long modtime{0}; ///<! modification time long modtime{0}; ///<! modification time
int64_t size{0}; ///<! file size int64_t size{0}; ///<! file size
// this is part for browser, visisble for I/O // this is part for browser, visible for I/O
std::string fsize; ///< file size std::string fsize; ///< file size
std::string mtime; ///< modification time std::string mtime; ///< modification time
std::string ftype; ///< file attributes std::string ftype; ///< file attributes
...@@ -58,32 +56,7 @@ public: ...@@ -58,32 +56,7 @@ public:
virtual ~RRootFileItem() = default; virtual ~RRootFileItem() = default;
}; };
/** Web-based ROOT file browser */
class RBrowserFSDescription {
std::vector<RRootFileItem> fDesc; ///< current description
int fTopNode{0}; ///<! selected top node
std::string fDrawJson; ///<! JSON with main nodes drawn by client
bool fPreferredOffline{false}; ///<! indicates that full description should be provided to client
void ResetRndrInfos();
public:
RBrowserFSDescription() = default;
void AddFolder(const char *name);
void AddFile(const char *name);
void Build(const std::string &path);
/** Number of unique nodes in the geometry */
int GetNumNodes() const { return fDesc.size(); }
bool IsBuild() const { return GetNumNodes() > 0; }
std::string ProcessBrowserRequest(const std::string &req = "");
};
class RBrowser { class RBrowser {
...@@ -92,10 +65,18 @@ protected: ...@@ -92,10 +65,18 @@ protected:
std::string fTitle; ///<! title std::string fTitle; ///<! title
unsigned fConnId{0}; ///<! connection id unsigned fConnId{0}; ///<! connection id
RBrowserFSDescription fDesc; ///<! file system decription std::string fDescPath; ///<! last scanned directory
std::vector<RRootFileItem> fDesc; ///<! current items list
std::shared_ptr<RWebWindow> fWebWindow; ///<! web window to show geometry std::shared_ptr<RWebWindow> fWebWindow; ///<! web window to show geometry
void AddFolder(const char *name);
void AddFile(const char *name);
void Build(const std::string &path);
std::string ProcessBrowserRequest(const std::string &msg);
bool IsBuild() const { return fDesc.size() > 0; }
void WebWindowCallback(unsigned connid, const std::string &arg); void WebWindowCallback(unsigned connid, const std::string &arg);
public: public:
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "TString.h" #include "TString.h"
#include "TROOT.h" #include "TROOT.h"
#include "TBufferJSON.h" #include "TBufferJSON.h"
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
...@@ -115,7 +116,7 @@ ROOT::Experimental::RRootFileItem::RRootFileItem(const std::string &_name, int _ ...@@ -115,7 +116,7 @@ ROOT::Experimental::RRootFileItem::RRootFileItem(const std::string &_name, int _
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
/// Add folder /// Add folder
void ROOT::Experimental::RBrowserFSDescription::AddFolder(const char *name) void ROOT::Experimental::RBrowser::AddFolder(const char *name)
{ {
FileStat_t sbuf; FileStat_t sbuf;
...@@ -136,7 +137,7 @@ void ROOT::Experimental::RBrowserFSDescription::AddFolder(const char *name) ...@@ -136,7 +137,7 @@ void ROOT::Experimental::RBrowserFSDescription::AddFolder(const char *name)
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
/// Add file /// Add file
void ROOT::Experimental::RBrowserFSDescription::AddFile(const char *name) void ROOT::Experimental::RBrowser::AddFile(const char *name)
{ {
FileStat_t sbuf; FileStat_t sbuf;
...@@ -156,8 +157,10 @@ void ROOT::Experimental::RBrowserFSDescription::AddFile(const char *name) ...@@ -156,8 +157,10 @@ void ROOT::Experimental::RBrowserFSDescription::AddFile(const char *name)
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
/// Collect information for provided directory /// Collect information for provided directory
void ROOT::Experimental::RBrowserFSDescription::Build(const std::string &path) void ROOT::Experimental::RBrowser::Build(const std::string &path)
{ {
fDescPath = path;
void *dirp; void *dirp;
const char *name; const char *name;
std::string spath = path; std::string spath = path;
...@@ -196,7 +199,7 @@ void ROOT::Experimental::RBrowserFSDescription::Build(const std::string &path) ...@@ -196,7 +199,7 @@ void ROOT::Experimental::RBrowserFSDescription::Build(const std::string &path)
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
/// constructor /// constructor
std::string ROOT::Experimental::RBrowserFSDescription::ProcessBrowserRequest(const std::string &msg) std::string ROOT::Experimental::RBrowser::ProcessBrowserRequest(const std::string &msg)
{ {
std::string res; std::string res;
...@@ -212,8 +215,9 @@ std::string ROOT::Experimental::RBrowserFSDescription::ProcessBrowserRequest(con ...@@ -212,8 +215,9 @@ std::string ROOT::Experimental::RBrowserFSDescription::ProcessBrowserRequest(con
if (!request) if (!request)
return res; return res;
// TODO: one could rebuild information only when other directory is requested // rebuild list only when selected directory changed
if (1) { //((request->path.compare("/") == 0) && (request->first == 0)) { if (!IsBuild() || (request->path != fDescPath)) {
fDescPath = request->path;
Build(request->path); Build(request->path);
} }
...@@ -222,11 +226,15 @@ std::string ROOT::Experimental::RBrowserFSDescription::ProcessBrowserRequest(con ...@@ -222,11 +226,15 @@ std::string ROOT::Experimental::RBrowserFSDescription::ProcessBrowserRequest(con
reply.first = request->first; reply.first = request->first;
reply.nchilds = fDesc.size(); reply.nchilds = fDesc.size();
// TODO: return only requested number of nodes, to be done later // return only requested number of nodes
// no items ownership, RRootBrowserReply must be always temporary object // no items ownership, RRootBrowserReply must be always temporary object
for (auto &node : fDesc) // TODO: implement sorting
reply.nodes.emplace_back(&node); int seq = 0;
for (auto &node : fDesc) {
if ((seq >= request->first) && ((seq < request->first + request->number) || (request->number == 0)))
reply.nodes.emplace_back(&node);
seq++;
}
res = "BREPL:"; res = "BREPL:";
res.append(TBufferJSON::ToJSON(&reply, 103).Data()); res.append(TBufferJSON::ToJSON(&reply, 103).Data());
...@@ -261,7 +269,6 @@ ROOT::Experimental::RBrowser::RBrowser() ...@@ -261,7 +269,6 @@ ROOT::Experimental::RBrowser::RBrowser()
ROOT::Experimental::RBrowser::~RBrowser() ROOT::Experimental::RBrowser::~RBrowser()
{ {
} }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
...@@ -301,19 +308,16 @@ void ROOT::Experimental::RBrowser::WebWindowCallback(unsigned connid, const std: ...@@ -301,19 +308,16 @@ void ROOT::Experimental::RBrowser::WebWindowCallback(unsigned connid, const std:
if (arg == "CONN_READY") { if (arg == "CONN_READY") {
} else if (arg == "GETDRAW") { fConnId = connid;
} else if (arg == "QUIT_ROOT") { } else if (arg == "QUIT_ROOT") {
RWebWindowsManager::Instance()->Terminate(); RWebWindowsManager::Instance()->Terminate();
} else if ((arg.compare(0, 7, "SETVI0:") == 0) || (arg.compare(0, 7, "SETVI1:") == 0)) {
// change visibility for specified nodeid
} else if (arg.compare(0,6, "BRREQ:") == 0) { } else if (arg.compare(0,6, "BRREQ:") == 0) {
// central place for processing browser requests // central place for processing browser requests
//if (!fDesc.IsBuild()) fDesc.Build(); //if (!fDesc.IsBuild()) fDesc.Build();
auto json = fDesc.ProcessBrowserRequest(arg.substr(6)); auto json = ProcessBrowserRequest(arg.substr(6));
if (json.length() > 0) fWebWindow->Send(connid, json); if (json.length() > 0) fWebWindow->Send(connid, json);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment