Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
nodegraphhandler.cc
Go to the documentation of this file.
1 
18 #if !ION_PRODUCTION
19 
21 
22 
23 #include <algorithm>
24 #include <sstream>
25 
26 #include "ion/base/invalid.h"
27 #include "ion/base/serialize.h"
28 #include "ion/base/stringutils.h"
31 #include "ion/gfxutils/printer.h"
32 
33 ION_REGISTER_ASSETS(IonRemoteNodeGraphRoot);
34 
35 namespace ion {
36 namespace remote {
37 
39  : HttpServer::RequestHandler("/ion/nodegraph") {
40  IonRemoteNodeGraphRoot::RegisterAssetsOnce();
41 }
42 
44 
46  if (node.Get() && !IsNodeTracked(node))
47  nodes_.push_back(node);
48 }
49 
51  if (node.Get()) {
52  std::vector<gfx::NodePtr>::iterator it =
53  std::find(nodes_.begin(), nodes_.end(), node);
54  if (it != nodes_.end()) {
55  nodes_.erase(it);
56  return true;
57  }
58  }
59  return false;
60 }
61 
63  return std::find(nodes_.begin(), nodes_.end(), node) != nodes_.end();
64 }
65 
67  const std::string& path_in, const HttpServer::QueryMap& args,
68  std::string* content_type) {
69  const std::string path = path_in.empty() ? "index.html" : path_in;
70 
71  if (path == "update") {
72  gfxutils::Printer printer;
73  SetUpPrinter(args, &printer);
74  return GetPrintString(&printer);
75  } else {
76  const std::string& data =
77  base::ZipAssetManager::GetFileData("ion/nodegraph/" + path);
78  if (!base::IsInvalidReference(data)) {
80  if (base::EndsWith(path, "html"))
81  *content_type = "text/html";
82  return data;
83  }
84  }
85  return std::string();
86 }
87 
88 void NodeGraphHandler::SetUpPrinter(const HttpServer::QueryMap& args,
89  gfxutils::Printer* printer) {
91  printer->EnableAddressPrinting(false);
92 
93  HttpServer::QueryMap::const_iterator it = args.find("format");
94  if (it != args.end()) {
95  const std::string& format_string = it->second;
96  if (format_string == "HTML")
98  }
99 
100  it = args.find("enable_address_printing");
101  if (it != args.end())
102  printer->EnableAddressPrinting(it->second == "true");
103 
104  it = args.find("enable_full_shape_printing");
105  if (it != args.end())
106  printer->EnableFullShapePrinting(it->second == "true");
107 }
108 
109 const std::string NodeGraphHandler::GetPrintString(gfxutils::Printer* printer) {
110  std::ostringstream s;
111 
112  s << "<span class=\"nodes_header\">Tracked Nodes";
113  if (frame_.Get())
114  s << " at frame " << frame_->GetCounter();
115  s << "</span><br><br>\n";
116 
117  if (printer->GetFormat() == gfxutils::Printer::kText)
118  s << "<pre>\n";
119  else if (printer->GetFormat() == gfxutils::Printer::kHtml)
120  s << "<div class=\"tree\">\n";
121 
122  for (size_t i = 0; i < nodes_.size(); ++i)
123  printer->PrintScene(nodes_[i], s);
124 
125  if (printer->GetFormat() == gfxutils::Printer::kText)
126  s << "</pre>\n";
127  else if (printer->GetFormat() == gfxutils::Printer::kHtml)
128  s << "</div>\n";
129 
130  return s.str();
131 }
132 
133 } // namespace remote
134 } // namespace ion
135 
136 #endif
bool IsInvalidReference(const T &value)
IsInvalidReference() returns true if a passed const reference of type T has an address of InvalidRefe...
Definition: invalid.h:41
void EnableFullShapePrinting(bool enable)
Sets/returns a flag indicating whether shape contents should be written.
Definition: printer.h:48
bool RemoveNode(const gfx::NodePtr &node)
Removes a Node from being tracked.
static const std::string & GetFileData(const std::string &filename)
Returns the data of the passed filename if the manager contains it.
T * Get() const
Returns a raw pointer to the instance, which may be NULL.
Definition: sharedptr.h:89
void SetFormat(Format format)
Sets/returns the printed format. The default is kText.
Definition: printer.h:43
ION_REGISTER_ASSETS(IonRemoteNodeGraphRoot)
Copyright 2016 Google Inc.
bool IsNodeTracked(const gfx::NodePtr &node) const
Returns true if the given Node is being tracked.
const std::string HandleRequest(const std::string &path, const HttpServer::QueryMap &args, std::string *content_type) override
The HandleRequest() function is passed the path (relative to its base path) of the file or directory ...
void EnableAddressPrinting(bool enable)
Sets/returns a flag indicating whether the addresses of objects should be written.
Definition: printer.h:57
bool EndsWith(const std::string &target, const std::string &end)
Returns whether target ends with end.
Definition: stringutils.h:81
std::map< std::string, std::string > QueryMap
Definition: httpserver.h:35
void AddNode(const gfx::NodePtr &node)
Adds a Node to track if it is not NULL or already tracked.
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
Definition: sharedptr.h:60
The Printer class can be used for debugging.
Definition: printer.h:31