CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WebInterface.cc
Go to the documentation of this file.
7 
8 
9 WebInterface::WebInterface(std::string _exeURL, std::string _appURL)
10 {
11  exeURL = _exeURL;
12  appURL = _appURL;
13 
14  std::cout << "created a WebInterface for the DQMClient, the url = " << appURL << std::endl;
15  std::cout << "within context = " << exeURL << std::endl;
16 
18 }
19 
20 
21 std::string WebInterface::get_from_multimap(std::multimap<std::string, std::string> &mymap, std::string key)
22 {
23  std::multimap<std::string, std::string>::iterator it;
24  it = mymap.find(key);
25  if (it != mymap.end())
26  {
27  return (it->second);
28  }
29  return "";
30 }
31 
33 {
34  handleStandardRequest(in, out);
35  handleCustomRequest(in, out);
36 
37  // dispatch any messages:
38  if (msg_dispatcher.hasAnyMessages()) msg_dispatcher.dispatchMessages(out);
39 }
40 
42 {
43  CgiWriter writer(out, getContextURL());
44  writer.output_preamble();
45  writer.output_head();
46  page_p->printHTML(out);
47  writer.output_finish();
48 }
49 
50 void WebInterface::add(std::string name, WebElement * element_p)
51 {
52  page_p->add(name, element_p);
53 }
54 
56 {
57  std::multimap<std::string, std::string> request_multimap;
59  reader.read_form(request_multimap);
60 
61  // get the string that identifies the request:
62  std::string requestID = get_from_multimap(request_multimap, "RequestID");
63 
64  if (requestID == "Configure") Configure(in, out);
65  if (requestID == "Open") Open(in, out);
66 // if (requestID == "Subscribe") Subscribe(in, out);
67 // if (requestID == "Unsubscribe") Unsubscribe(in, out);
68  if (requestID == "ContentsOpen") ContentsOpen(in, out);
69  if (requestID == "Draw") DrawGif(in, out);
70 }
71 
73 {
75  reader.read_form(conf_map);
76 
77  std::string host = get_from_multimap(conf_map, "Hostname");
78  std::string port = get_from_multimap(conf_map, "Port");
79  std::string clientname = get_from_multimap(conf_map, "Clientname");
80 
81 }
82 
84 {
85  std::multimap<std::string, std::string> nav_map;
86 
88  reader.read_form(nav_map);
89 
90  std::string to_open = get_from_multimap(nav_map, "Open");
91  std::string current = get_from_multimap(nav_map, "Current");
92 
93  // if the user does not want to go to the top directory...
94  if (to_open != "top")
95  {
96  // ...and if the current directory is not the top...
97  if (current != "top")
98  {
99  // ...and if we don't want to go one directory up...
100  if (to_open != "..")
101  {
102  // ...then we need to add the current directory at the beginning of the to_open string
103  to_open = current + "/" + to_open;
104  }
105  }
106  }
107 
108 
109  std::cout << "will try to open " << to_open << std::endl;
110  if (dqmStore_)
111  {
112  if (to_open == "top")
113  {
114  dqmStore_->setCurrentFolder("/");
115  }
116  else if (to_open == "..")
117  {
118  dqmStore_->goUp();
119  }
120  else
121  {
122  dqmStore_->setCurrentFolder(to_open);
123  }
124  printNavigatorXML(dqmStore_->pwd(), out);
125  }
126  else
127  {
128  std::cout << "no DQMStore object, subscription to " << to_open << " failed!" << std::endl;
129  }
130 
131 }
132 
134 {
135  if (!dqmStore_)
136  {
137  std::cout << "NO GUI!!!" << std::endl;
138  return;
139  }
140 
141  out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
142 
143  *out << "<?xml version=\"1.0\" ?>" << std::endl;
144 
145  *out << "<navigator>" << std::endl;
146 
147  *out << "<current>" << current << "</current>" << std::endl;
148 
150 
151  std::list<std::string>::iterator it;
152 
153  std::list<std::string> open_l;
154  reader.give_subdirs(current, open_l, "SuperUser");
155  for (it = open_l.begin(); it != open_l.end(); it++)
156  *out << "<open>" << *it << "</open>" << std::endl;
157 
158  std::list<std::string> subscribe_l;
159  reader.give_files(current, subscribe_l, false);
160  for (it = subscribe_l.begin(); it != subscribe_l.end(); it++)
161  *out << "<subscribe>" << *it << "</subscribe>" << std::endl;
162 
163  std::list<std::string> unsubscribe_l;
164  reader.give_files(current, unsubscribe_l, true);
165  for (it = unsubscribe_l.begin(); it != unsubscribe_l.end(); it++)
166  *out << "<unsubscribe>" << *it << "</unsubscribe>" << std::endl;
167 
168  *out << "</navigator>" << std::endl;
169 
170 
171  std::cout << "<?xml version=\"1.0\" ?>" << std::endl;
172 
173  std::cout << "<navigator>" << std::endl;
174 
175  std::cout << "<current>" << current << "</current>" << std::endl;
176 
177  for (it = open_l.begin(); it != open_l.end(); it++)
178  std::cout << "<open>" << *it << "</open>" << std::endl;
179 
180  for (it = subscribe_l.begin(); it != subscribe_l.end(); it++)
181  std::cout << "<subscribe>" << *it << "</subscribe>" << std::endl;
182 
183  for (it = unsubscribe_l.begin(); it != unsubscribe_l.end(); it++)
184  std::cout << "<unsubscribe>" << *it << "</unsubscribe>" << std::endl;
185 
186  std::cout << "</navigator>" << std::endl;
187 
188 }
189 
191 {
192  std::multimap<std::string, std::string> nav_map;
193 
195  reader.read_form(nav_map);
196 
197  std::string to_open = get_from_multimap(nav_map, "Open");
198  std::string current = get_from_multimap(nav_map, "Current");
199 
200  // if the user does not want to go to the top directory...
201  if (to_open != "top")
202  {
203  // ...and if the current directory is not the top...
204  if (current != "top")
205  {
206  // ...and if we don't want to go one directory up...
207  if (to_open != "..")
208  {
209  // ...then we need to add the current directory at the beginning of the to_open string
210  to_open = current + "/" + to_open;
211  }
212  }
213  }
214 
215 
216  std::cout << "will try to open " << to_open << std::endl;
217  if (dqmStore_)
218  {
219  if (to_open == "top")
220  {
221  dqmStore_->cd();
222  }
223  else if (to_open == "..")
224  {
225  dqmStore_->goUp();
226  }
227  else
228  {
229  dqmStore_->setCurrentFolder(to_open);
230  }
231  printContentViewerXML(dqmStore_->pwd(), out);
232  }
233  else
234  {
235  std::cout << "no DQMStore object, subscription to " << to_open << " failed!" << std::endl;
236  }
237 }
238 
240 {
241  if (!(dqmStore_))
242  {
243  std::cout << "NO GUI!!!" << std::endl;
244  return;
245  }
246 
247  out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
248 
249  *out << "<?xml version=\"1.0\" ?>" << std::endl;
250 
251  *out << "<contentViewer>" << std::endl;
252 
253  *out << "<current>" << current << "</current>" << std::endl;
254 
256 
257  std::list<std::string>::iterator it;
258 
259  std::list<std::string> open_l;
260  reader.give_subdirs(current, open_l, "SuperUser");
261  for (it = open_l.begin(); it != open_l.end(); it++)
262  *out << "<open>" << *it << "</open>" << std::endl;
263 
264  std::list<std::string> view_l;
265  reader.give_files(current, view_l, true);
266  for (it = view_l.begin(); it != view_l.end(); it++)
267  *out << "<view>" << *it << "</view>" << std::endl;
268 
269  *out << "</contentViewer>" << std::endl;
270 }
271 
272 
274 {
275  std::multimap<std::string, std::string> view_multimap;
276  ME_MAP view_map;
277 
278  CgiReader cgi_reader(in);
279  cgi_reader.read_form(view_multimap);
280 
281  std::string current = get_from_multimap(view_multimap, "Current");
282 
283 
284  if (dqmStore_)
285  {
286  std::cout << "The DQMStore pointer is empty!" << std::endl;
287  return;
288  }
289 
290  ContentReader con_reader(dqmStore_);
291  std::multimap<std::string,std::string>::iterator lower = view_multimap.lower_bound("View");
292  std::multimap<std::string,std::string>::iterator upper = view_multimap.upper_bound("View");
293  std::multimap<std::string,std::string>::iterator it;
294  for (it = lower; it != upper; it++)
295  {
296  std::string name = it->second;
297  MonitorElement *pointer = con_reader.give_ME(name);
298  if (pointer != 0)
299  {
300  view_map.add(name, pointer);
301  std::cout << "ADDING " << name << " TO view_map!!!" << std::endl;
302  }
303  }
304 
305  // Print the ME_map into a file
306  std::string id = get_from_multimap(view_multimap, "DisplayFrameName");
307  std::cout << "will try to print " << id << std::endl;
308 
309  // And return the URL of the file:
310  out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
311  *out << "<?xml version=\"1.0\" ?>" << std::endl;
312  *out << "<fileURL>" << std::endl;
313  *out << getContextURL() + "/temporary/" + id + ".gif" << std::endl;
314  *out << "</fileURL>" << std::endl;
315 
316 }
317 
318 void WebInterface::printMap(ME_MAP view_map, std::string id)
319 {
320  view_map.print(id);
321 }
322 
323 void WebInterface::sendMessage(std::string title, std::string text, MessageType type)
324 {
325  Message * msg = new Message(title, text, type);
326  msg_dispatcher.add(msg);
327 }
MessageType
type
Definition: HCALResponse.h:22
void printContentViewerXML(std::string current, xgi::Output *out)
std::string get_from_multimap(std::multimap< string, string > &mymap, std::string key)
Definition: generic.h:7
#define Input(cl)
Definition: vmac.h:189
void give_files(std::string dir, std::list< std::string > &files, bool only_contents)
void print(std::string name)
print the map into a gif named &quot;name&quot;
Definition: ME_MAP.cc:23
virtual void Default(xgi::Input *in, xgi::Output *out)
Answers requests by sending the webpage of the application.
Definition: WebInterface.cc:41
void add(std::string name, MonitorElement *me_p)
add the ME named &quot;name&quot; to the map
Definition: ME_MAP.cc:9
void Open(xgi::Input *in, xgi::Output *out)
Answer navigator requests.
Definition: WebInterface.cc:83
void output_head()
Definition: CgiWriter.cc:17
void add(std::string, WebElement *)
Definition: WebPage.cc:8
void sendMessage(std::string the_title, std::string the_text, MessageType the_type)
Adds messages to the message dispatcher.
void output_finish()
Definition: CgiWriter.cc:33
void DrawGif(xgi::Input *in, xgi::Output *out)
Answers viewer requests.
WebPage * page_p
Definition: WebInterface.h:35
int port
Definition: query.py:115
void read_form(std::multimap< std::string, std::string > &form_info)
Definition: CgiReader.cc:6
MonitorElement * give_ME(std::string filename)
tuple text
Definition: runonSM.py:42
void add(Message *new_message)
WebInterface(std::string _exeURL, std::string _appURL)
Definition: WebInterface.cc:9
tuple out
Definition: dbtoconf.py:99
string host
Definition: query.py:114
std::string appURL
Definition: WebInterface.h:27
void printMap(ME_MAP view_map, std::string id)
Definition: ME_MAP.h:11
DQMStore * dqmStore_
Definition: WebInterface.h:34
void output_preamble()
Definition: CgiWriter.cc:3
void give_subdirs(std::string dir, std::list< std::string > &subdirs, std::string mode)
Definition: ContentReader.cc:5
std::string get_from_multimap(std::multimap< std::string, std::string > &mymap, std::string key)
Definition: WebInterface.cc:21
void handleStandardRequest(xgi::Input *in, xgi::Output *out)
Definition: WebInterface.cc:55
list key
Definition: combine.py:13
#define Output(cl)
Definition: vmac.h:193
void Configure(xgi::Input *in, xgi::Output *out)
Answers connection configuration requests.
Definition: WebInterface.cc:72
tuple cout
Definition: gather_cfg.py:121
std::string exeURL
Definition: WebInterface.h:26
void add(std::string, WebElement *)
Adds widgets to the page.
Definition: WebInterface.cc:50
void printNavigatorXML(std::string directory, xgi::Output *out)
Outputs the subdirectories and files of &quot;directory&quot;. Called by any of the above three.
void handleRequest(xgi::Input *in, xgi::Output *out)
Definition: WebInterface.cc:32
void ContentsOpen(xgi::Input *in, xgi::Output *out)
Answers ContentViewer requests.
MessageDispatcher msg_dispatcher
Definition: WebInterface.h:30