Revision: 7905
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7905&view=rev
Author:   asadat
Date:     2009-06-25 19:56:33 +0000 (Thu, 25 Jun 2009)

Log Message:
-----------
added HandleSimHomepageRequest() to generate the html intro page

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 19:40:16 UTC (rev 7904)
+++ code/websim/src/req_sim.cc  2009-06-25 19:56:33 UTC (rev 7905)
@@ -30,10 +30,57 @@
   if(prop == "greet") 
     return HandleSimGreetRequest( action, format, kv, response );
   
+  if(prop == "homepage")
+    return HandleSimHomepageRequest( action, format, kv, response );
+
   response = "ERROR: Unknown property " + prop + " for sim. Candidates are: 
children clock factory greet tree.";
   return false;
 }
 
+bool WebSim::HandleSimHomepageRequest( std::string action,
+                             Format format,
+                             struct evkeyvalq* kv,
+                             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: ");
+
+       
+    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));
+
+    // 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>";
+               
+    return true;
+
+
+
+}
+
+
 bool WebSim::HandleSimGeometryRequest( std::string action,
                               Format format,
                               struct evkeyvalq* kv,

Modified: code/websim/src/websim.cc
===================================================================
--- code/websim/src/websim.cc   2009-06-25 19:40:16 UTC (rev 7904)
+++ code/websim/src/websim.cc   2009-06-25 19:56:33 UTC (rev 7905)
@@ -209,9 +209,13 @@
       format = XML;
     else 
       format = TEXT;
-  }else
+
+  }else{
+
     format = TEXT;
 
+  }
+
   // The special simulation model
   if(model == "sim")
     {
@@ -233,41 +237,7 @@
          puts(prop.c_str());
        }
       return true;
-      
-    }else if(model == ""){
-    
-    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: ");
-
-       
-    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));
-
-    // 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>";
-               
-    return true;
+   
   }
   // Everything else must be an existing model
   else 
@@ -319,7 +289,7 @@
       }else if(prop == "tree"){
        
        
-       return(GetModelTree(model, format, response, true));
+       return(GetModelTree(model, format, response, false));
        
                
       }else if(prop == "extent"){
@@ -1100,7 +1070,16 @@
   // We require 3 path components: model/property/action
   StringSplit(bare_uri, uri_parts, "/");
 
-  
+  //check if the web page is requested
+  if(uri_parts.size()==1 || (uri_parts.size()==2 && uri_parts[1]=="")){
+       
+       model ="sim";
+       prop = "homepage";
+       action = "get";
+       return true;
+  }
+
+ 
   // otherwise there should be 4 parts, with the first one empty
   if(uri_parts.size() != 4)
   {

Modified: code/websim/src/websim.hh
===================================================================
--- code/websim/src/websim.hh   2009-06-25 19:40:16 UTC (rev 7904)
+++ code/websim/src/websim.hh   2009-06-25 19:56:33 UTC (rev 7905)
@@ -229,6 +229,8 @@
   
   // Static, so that it can be passed as a callback to libevent
   static void EventCallback(evhttp_request* req, void* arg);
+
+   
   
   /** Gets the uri parameters. 
        
@@ -284,13 +286,18 @@
                              struct evkeyvalq* kv,
                              std::string& response);  
 
+  bool HandleSimHomepageRequest( std::string action,
+                             Format format,
+                             struct evkeyvalq* kv,
+                             std::string& response);  
+
   bool HandleModelRequest(const std::string& model,
                          const std::string& prop,
                          const std::string& action,
                          Format format,
                          struct evkeyvalq* kv, 
                          std::string& response);
-
+  
   bool ParseURI(std::string& model,
                std::string& prop,
                std::string& action,


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