Revision: 7907
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7907&view=rev
Author:   asadat
Date:     2009-06-25 22:47:23 +0000 (Thu, 25 Jun 2009)

Log Message:
-----------
added webpage string for html code in the websim class

Modified Paths:
--------------
    code/websim/src/req_sim.cc
    code/websim/src/websim.cc
    code/websim/src/websim.hh

Modified: code/websim/src/req_sim.cc
===================================================================
--- code/websim/src/req_sim.cc  2009-06-25 20:34:46 UTC (rev 7906)
+++ code/websim/src/req_sim.cc  2009-06-25 22:47:23 UTC (rev 7907)
@@ -43,41 +43,17 @@
                              std::string& response)
 {
 
-    std::vector<std::string> links;
-    char tmp[2048];
-    sprintf(tmp,"%s %s", WebSim::package.c_str(), WebSim::version.c_str());
-    response = "<html><head ><title>WebSim</title></head><body><h3>";
-    response.append(tmp);
-       
-    response.append( "</h3><p>Welcome to WebSim, an HTTP interface to robot 
simulation. Through this program, you can get the state of the robots and their 
sensors using URIs. Here are some examples: ");
+    response = WebSim::webpage;                
 
-       
-    sprintf(tmp,"</p><p><a 
href=\"http://%s/sim/tree/get\";>http://%s/sim/tree/get</a></p>",hostportname.c_str(),
 hostportname.c_str());
-    links.push_back(std::string(tmp));
+    // replacing 'HOST' by actual 'host:port' term 
+    unsigned int i=0;
+    i = response.find("HOST");
+    while(i!=std::string::npos){
 
-    // todo - these should be automatically generated working links
-               
-    sprintf(tmp,"<p><a 
href=\"http://%s/position:1/pva/get\";>http://%s/position:1/pva/get</a></p>", 
hostportname.c_str(), hostportname.c_str());
-    links.push_back(std::string(tmp));
-
-       
-    sprintf(tmp, "<p><a 
href=\"http://%s/position:1/laser:0/data/get\";>http://%s/position:1/laser:0/data/get</a></p>",
 hostportname.c_str(), hostportname.c_str());
-    links.push_back(std::string(tmp));
-
-       
-    sprintf(tmp,"<p><a 
href=\"http://%s/position:1/ranger:0/data/get\";>http://%s/position:1/ranger:0:/data/get</a></p>",
 hostportname.c_str(), hostportname.c_str());
-    links.push_back(std::string(tmp));
-       
-       
-    sprintf(tmp,"<p><a 
href=\"http://%s/position:1/model:0/fiducial:0/data/get\";>http://%s/position:1/model:0/fiducial:0/data/get</a></p>",hostportname.c_str(),
 hostportname.c_str());
-    links.push_back(std::string(tmp));
-       
-    response += links[0]+links[1]+links[2]+ links[3]+links[4]+ 
"</body></html>";
-               
+       response.replace(i, 4, hostportname);
+       i = response.find("HOST");
+    }
     return true;
-
-
-
 }
 
 

Modified: code/websim/src/websim.cc
===================================================================
--- code/websim/src/websim.cc   2009-06-25 20:34:46 UTC (rev 7906)
+++ code/websim/src/websim.cc   2009-06-25 22:47:23 UTC (rev 7907)
@@ -43,6 +43,19 @@
 const std::string WebSim::package = "WebSim";
 const std::string WebSim::version = "0.1";
 
+std::string WebSim::webpage =
+ "<html><head ><title>WebSim</title></head><body><h3>" + WebSim::package + " " 
+ WebSim::version +
+ "</h3><p>Welcome to WebSim, an Http-based interface to robot simulations."
+ " Through this interface, you can get the state of the robots as well as 
sensors' data using URIs. Here are some examples:" 
+ "</p><p><a href=\"http://HOST/sim/tree/get\";> http://HOST/sim/tree/get 
</a></p>"
+ "<p><a href=\"http://HOST/position:1/pva/get\";> 
http://HOST/position:1/pva/get </a></p>"
+ "<p><a href=\"http://HOST/position:1/laser:0/data/get\";> 
http://HOST/position:1.laser:0/data/get </a></p>"
+ "<p><a href=\"http://HOST/position:1/ranger:0/data/get\";> 
http://HOST/position:1/ranger:0:/data/get </a></p>"
+ "<p><a href=\"http://HOST/position:1/model:0/fiducial:0/data/get\";> 
http://HOST/position:1/model:0/fiducial:0/data/get </a></p>"
+ "</body></html>";
+
+
+
 xmlChar *
 ConvertInput(const char *in, const char *encoding);
   
@@ -1071,7 +1084,7 @@
   StringSplit(bare_uri, uri_parts, "/");
 
   //check if the web page is requested
-  if(uri_parts.size()==1 || (uri_parts.size()==2 && uri_parts[1]=="")){
+  if(uri_parts.size()==2){
        
        model ="sim";
        prop = "homepage";

Modified: code/websim/src/websim.hh
===================================================================
--- code/websim/src/websim.hh   2009-06-25 20:34:46 UTC (rev 7906)
+++ code/websim/src/websim.hh   2009-06-25 22:47:23 UTC (rev 7907)
@@ -50,6 +50,9 @@
 class Bounds;
 class Fiducial;
 
+
+
+
 class WebSim
 {
 public:
@@ -226,6 +229,9 @@
   unsigned short port;
   
   struct evhttp* eh;
+
+  // the string which contains the html code of the home page
+  static std::string webpage;
   
   // Static, so that it can be passed as a callback to libevent
   static void EventCallback(evhttp_request* req, void* arg);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to