Revision: 7741
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7741&view=rev
Author:   asadat
Date:     2009-05-29 21:10:46 +0000 (Fri, 29 May 2009)

Log Message:
-----------
added 'format' as a parameter of http request to specify response format

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

Modified: code/websim/src/websim.cc
===================================================================
--- code/websim/src/websim.cc   2009-05-29 21:09:08 UTC (rev 7740)
+++ code/websim/src/websim.cc   2009-05-29 21:10:46 UTC (rev 7741)
@@ -186,21 +186,34 @@
                   struct evkeyvalq* kv,
                   std::string& response)
 {
+
+  bool xmlresponse = false;
+  std::string format;
+  // specify the format of the response: Text or Xml
+  if(GetValue(format,kv,"format")){
+
+       if(format == "xml")
+               xmlresponse = true;
+       else
+               xmlresponse = false;
+  }
+
   // The special simulation model
   if(model == "sim")
   {
-    return HandleSimRequest(prop, action, kv, response);
+    return HandleSimRequest(prop, action, xmlresponse, kv, response);
   }
   // Everything else must be an existing model
   else
   {
-    return HandleModelRequest(model, prop, action, kv, response);
+    return HandleModelRequest(model, prop, action, xmlresponse, kv, response);
   }
 }
 
 bool
 WebSim::HandleSimRequest(const std::string& prop,
                             const std::string& action,
+                           bool xmlresponse,   
                             struct evkeyvalq* kv,
                             std::string& response)
 {
@@ -258,8 +271,9 @@
   else if(prop == "extent")
         {
                double x,y,z;
-               GetModelExtent("sim", x, y, z, response);
-               GetXMLModelExtent("sim", x, y, z, response);
+               Pose center;
+               GetModelExtent("sim", x, y, z, center, response);
+               GetXMLModelExtent("sim", x, y, z, center, response);
                
         }
   else if(prop == "robots")
@@ -295,6 +309,7 @@
 WebSim::HandleModelRequest(const std::string& model,
                               const std::string& prop,
                               const std::string& action,
+                             bool xmlresponse,
                               struct evkeyvalq* kv,
                               std::string& response)
 {
@@ -308,7 +323,12 @@
                Time t;
       if(GetModelPVA(model, t, p, v, a, response))
       {
-        GetTextPVA(model, t, p, v, a, response);
+       
+       if(xmlresponse)
+               GetXMLPVA(model, t, p, v, a, response);
+       else
+               GetTextPVA(model, t, p, v, a, response);
+               
       
         return true;
       }
@@ -325,8 +345,12 @@
        std::vector<double> ranges;
        if(GetLaserData(model, t, res, fov, p,ranges, response))
        {
-                GetTextLaserData(model, t, res, fov, p, ranges, response);
-                        return true;
+               if(xmlresponse)
+                        GetXMLLaserData(model, t, res, fov, p, ranges, 
response);
+               else
+                        GetTextLaserData(model, t, res, fov, p, ranges, 
response);
+
+                       return true;
                                
        }       
         else
@@ -343,9 +367,13 @@
        
        if(GetRangerData(model, t, p, ranges, response))
        {
-               
-                GetXMLRangerData(model, t, p, ranges, response);
-                        return true;
+               if(xmlresponse)
+       
+                        GetXMLRangerData(model, t, p, ranges, response);
+               else
+                        GetTextRangerData(model, t, p, ranges, response);
+                       
+               return true;
                                
        }       
         else
@@ -354,23 +382,32 @@
           return false;
         }
 
-    }else if(prop == "extent")
-        {
-               double x,y,z;
-               GetModelExtent(model, x, y, z, response);
-               GetXMLModelExtent(model, x, y, z, response);
+    }else if(prop == "extent"){
+       double x,y,z;
+       Pose center;
+       if(GetModelExtent(model, x, y, z, center, response))    
+       {
+               if(xmlresponse)
+                       GetXMLModelExtent(model, x, y, z, center, response);
+               else
+                       GetTextModelExtent(model, x, y, z, center, response);
                
-        }
-    else
-    {
-      response = "ERROR: Unknown property " + prop + " for model " + model;
-      return false;
-    }
-  }
-  else if(action == "set")
+       }else{
+       
+               response = "ERROR: failed to get the extent of model " + model;
+               return false;
+       
+       }
+   }else{
+       response = "ERROR: Unknown property " + prop + " for model " + model;
+       return false;
+       }       
+    
+
+}else if(action == "set")
   {
     if(prop == "pva")
-    {
+    {  
       std::string sx, sy, sz, sroll, spitch, syaw;
 
       // Get pose first, fill in what the caller provided
@@ -625,7 +662,7 @@
                }
 
                
-               char buf[2048];
+               char buf[4096];
                snprintf(buf, sizeof(buf), 
                         "%s's state @%s: \n  laser: (%s)\n  resolution: (%d)\n 
 fov(%.2f)\n"
                         "  pose (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f)\n",
@@ -652,7 +689,7 @@
     xmlTextWriterPtr writer;
     xmlBufferPtr buf;
     xmlChar *tmp;    
-    char str[32];
+    char str[128];
 
     
     std::string res;
@@ -671,9 +708,8 @@
     
     xmlTextWriterStartElement(writer, BAD_CAST "Data");
    
-    sprintf(str,"%s",t.String().c_str());
-    tmp = ConvertInput(str,MY_ENCODING);
-    xmlTextWriterWriteAttribute(writer, BAD_CAST "Time", BAD_CAST tmp);    
+        
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "Time", BAD_CAST 
t.String().c_str());    
     xmlTextWriterWriteAttribute(writer, BAD_CAST "Type", BAD_CAST "laser");    
     
     tmp = ConvertInput(name.c_str(),MY_ENCODING);
@@ -689,7 +725,7 @@
     tmp = ConvertInput(str,MY_ENCODING);
     xmlTextWriterWriteAttribute(writer, BAD_CAST "FOV", BAD_CAST tmp);    
 
-    sprintf(str,"%.3f,%.3f,%.3f,%.3f,%.3f,%.3f",p.x, p.y, 0.f, 0.f, 0.f, p.a);
+    sprintf(str,"%.3f,%.3f,%.3f,%.3f,%.3f,%.3f",p.x, p.y, p.z, p.r, p.p, p.a);
     tmp = ConvertInput(str,MY_ENCODING);
     xmlTextWriterWriteAttribute(writer, BAD_CAST "Pose", BAD_CAST tmp);    
    
@@ -823,15 +859,16 @@
                   double& x,
                   double& y,
                   double& z,
+                  Pose& center,
                   std::string& response)
 {
        char buf[1024];
        if(name == "sim")
-               snprintf(buf, sizeof(buf),"World Extent: (%.3f,%.3f,%.3f)\n",
-                               x, y, z);
+               snprintf(buf, sizeof(buf),"World Extent: (%.3f,%.3f,%.3f)\n     
   Origin (%.3f,%.3f,%.3f,%.3f,%.3f,%.3f)",
+                               x, y, z, center.x, center.y, center.z, 
center.r, center.p, center.a);
        else
-               snprintf(buf, sizeof(buf),"%s's Extent: (%.3f,%.3f,%.3f)\n",
-                               name.c_str(), x, y, z);
+               snprintf(buf, sizeof(buf),"%s's Extent: (%.3f,%.3f,%.3f)\n      
  Origin (%.3f,%.3f,%.3f,%.3f,%.3f,%.3f)",
+                               name.c_str(), x, y, z, center.x, center.y, 
center.z, center.r, center.p, center.a);
 
        response = buf;
        
@@ -842,13 +879,14 @@
                   double& x,
                   double& y,
                   double& z,
+                  Pose& center,
                   std::string& response)
 {
        
     xmlTextWriterPtr writer;
     xmlBufferPtr buf;
     xmlChar *tmp;    
-    char str[32];
+    char str[1024];
 
     buf = xmlBufferCreate();
     writer = xmlNewTextWriterMemory(buf, 0);
@@ -876,6 +914,10 @@
     tmp = ConvertInput(str,MY_ENCODING);
     xmlTextWriterWriteAttribute(writer, BAD_CAST "Z", BAD_CAST tmp);    
    
+    
sprintf(str,"%.3f,%.3f,%.3f,%.3f,%.3f,%.3f",center.x,center.y,center.z,center.r,center.p,center.a);
+    tmp = ConvertInput(str,MY_ENCODING);
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "Origin", BAD_CAST tmp);    
+    
     xmlTextWriterEndElement(writer);
    
     xmlTextWriterEndElement(writer);

Modified: code/websim/src/websim.hh
===================================================================
--- code/websim/src/websim.hh   2009-05-29 21:09:08 UTC (rev 7740)
+++ code/websim/src/websim.hh   2009-05-29 21:10:46 UTC (rev 7741)
@@ -48,6 +48,7 @@
 class Velocity;
 class Acceleration;
 class Time;
+class Bounds;
 
 class WebSim
 {
@@ -83,19 +84,6 @@
                                                                        
Acceleration& a,
                                                                        
std::string& response) = 0;
 
-  void GetTextPVA(const std::string& name, 
-                                                                       Time& t,
-                                                                       const 
Pose& p,
-                                                                       const 
Velocity& v,
-                                                                       const 
Acceleration& a,
-                                                                       
std::string& response);
-  
-  void GetXMLPVA(const std::string& name, 
-                                                                       Time& t,
-                                                                       const 
Pose& p,
-                                                                       const 
Velocity& v,
-                                                                       const 
Acceleration& a,
-                                                                       
std::string& response);
   virtual bool GetLaserData(const std::string& name,
                                                                        Time& t,
                                                                        
uint32_t& resolution,
@@ -103,25 +91,7 @@
                                                                        Pose& p,
                                                                        
std::vector<double>& ranges,
                                                                        
std::string& response) = 0;
-                                                                       
-  void GetTextLaserData(const std::string& name,
-                                                                       Time& t,
-                                                                       
uint32_t& resolution,
-                                                                       double& 
fov,
-                                                                       Pose& p,
-                                                       
-                                                                       
std::vector<double>& ranges,
-                                                                       
std::string& response);
 
-                                                                       
-  void GetXMLLaserData(const std::string& name,
-                                                                       Time& t,
-                                                                       
uint32_t& resolution,
-                                                                       double& 
fov,
-                                                                       Pose& p,
-                                                                       
std::vector<double>& ranges,
-                                                                       
std::string& response);
-
         
   virtual bool GetRangerData(const std::string& name,
                                                                        Time& t,
@@ -130,36 +100,14 @@
                                                                        
std::string& response) = 0;
   
    
-   void GetTextRangerData(const std::string& name,
-                                                                       Time& t,
-                                                                       
std::vector<Pose>& p,
-                                                                       
std::vector<double>& ranges,
-                                                                       
std::string& response);
 
-   
-   void GetXMLRangerData(const std::string& name,
-                                                                       Time& t,
-                                                                       
std::vector<Pose>& p,
-                                                                       
std::vector<double>& ranges,
-                                                                       
std::string& response);
-
   
    virtual bool GetModelExtent(const std::string& name,
-                                                                       double& 
x,
-                                                                       double& 
y,
-                                                                       double& 
z,
+                                                                       double& 
bx,
+                                                                       double& 
by,
+                                                                       double& 
bz,
+                                                                       Pose& 
center,
                                                                        
std::string& response) = 0;
-   void GetTextModelExtent(const std::string& name,
-                                                                       double& 
x,
-                                                                       double& 
y,
-                                                                       double& 
z,
-                                                                       
std::string& response);
-
-   void GetXMLModelExtent(const std::string&,
-                                                                       double& 
x,
-                                                                       double& 
y,
-                                                                       double& 
z,
-                                                                       
std::string& response);
   virtual bool GetNumberOfRobots(unsigned int& n) = 0;
   
   virtual bool GetSayStrings(std::vector<std::string>& sayings) = 0;
@@ -202,11 +150,13 @@
                                          std::string& response);
   bool HandleSimRequest(const std::string& prop,
                                                                const 
std::string& action,
+                                                               bool 
xmlresponse,
                                                                struct 
evkeyvalq* kv,
                                                                std::string& 
response);
   bool HandleModelRequest(const std::string& model,
                                                                  const 
std::string& prop,
                                                                  const 
std::string& action,
+                                                                 bool 
xmlresponse,
                                                                  struct 
evkeyvalq* kv,
                                                                  std::string& 
response);
   bool ParseURI(std::string& model,
@@ -216,6 +166,62 @@
                                         std::string& response);
   void DeleteKeyVal(struct evkeyvalq* query_args);
   
+  void GetTextPVA(const std::string& name, 
+                                                                       Time& t,
+                                                                       const 
Pose& p,
+                                                                       const 
Velocity& v,
+                                                                       const 
Acceleration& a,
+                                                                       
std::string& response);
+  
+  void GetXMLPVA(const std::string& name, 
+                                                                       Time& t,
+                                                                       const 
Pose& p,
+                                                                       const 
Velocity& v,
+                                                                       const 
Acceleration& a,
+                                                                       
std::string& response);
+                                                                       
+  void GetTextLaserData(const std::string& name,
+                                                                       Time& t,
+                                                                       
uint32_t& resolution,
+                                                                       double& 
fov,
+                                                                       Pose& p,
+                                                       
+                                                                       
std::vector<double>& ranges,
+                                                                       
std::string& response);
+
+                                                                       
+  void GetXMLLaserData(const std::string& name,
+                                                                       Time& t,
+                                                                       
uint32_t& resolution,
+                                                                       double& 
fov,
+                                                                       Pose& p,
+                                                                       
std::vector<double>& ranges,
+                                                                       
std::string& response);
+   void GetTextRangerData(const std::string& name,
+                                                                       Time& t,
+                                                                       
std::vector<Pose>& p,
+                                                                       
std::vector<double>& ranges,
+                                                                       
std::string& response);
+
+   
+   void GetXMLRangerData(const std::string& name,
+                                                                       Time& t,
+                                                                       
std::vector<Pose>& p,
+                                                                       
std::vector<double>& ranges,
+                                                                       
std::string& response);
+   void GetTextModelExtent(const std::string& name,
+                                                                       double& 
x,
+                                                                       double& 
y,
+                                                                       double& 
z,
+                                                                       Pose& 
center,
+                                                                       
std::string& response);
+
+   void GetXMLModelExtent(const std::string&,
+                                                                       double& 
x,
+                                                                       double& 
y,
+                                                                       double& 
z,
+                                                                       Pose& 
center,
+                                                                       
std::string& response);
   // forward decare
   class Confederate;
   
@@ -383,6 +389,15 @@
   {}  
 };
 
+class Bounds
+{
+public:
+       /// largest value in range, initially zero
+       double max; 
+       /// smallest value in range, initially zero
+       double min;
+    
+       Bounds() : max(0), min(0) { /* empty*/  }
+};
 
-
 }


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

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to