Revision: 7894
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7894&view=rev
Author:   rtv
Date:     2009-06-24 23:55:46 +0000 (Wed, 24 Jun 2009)

Log Message:
-----------
broke HandleSimRequests into manageable chunks and cleaned up a bit

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

Added Paths:
-----------
    code/websim/src/req_sim.cc

Modified: code/websim/CMakeLists.txt
===================================================================
--- code/websim/CMakeLists.txt  2009-06-24 22:54:43 UTC (rev 7893)
+++ code/websim/CMakeLists.txt  2009-06-24 23:55:46 UTC (rev 7894)
@@ -57,8 +57,8 @@
 
 
 include_directories(src)
-add_library(websim SHARED src/websim.cc src/parser.cc src/confederate.cc 
src/puppet.cc )
-add_library(websim-static STATIC src/websim.cc src/parser.cc 
src/confederate.cc src/puppet.cc )
+add_library(websim SHARED src/websim.cc src/parser.cc src/confederate.cc 
src/puppet.cc src/req_sim.cc )
+add_library(websim-static STATIC src/websim.cc src/parser.cc 
src/confederate.cc src/puppet.cc src/req_sim.cc )
 # Set output name to be the same as shared lib (may not work on Windows)
 set_target_properties(websim-static PROPERTIES OUTPUT_NAME websim)
 # Prevent deletion of existing lib of same name

Added: code/websim/src/req_sim.cc
===================================================================
--- code/websim/src/req_sim.cc                          (rev 0)
+++ code/websim/src/req_sim.cc  2009-06-24 23:55:46 UTC (rev 7894)
@@ -0,0 +1,194 @@
+#include "websim.hh"
+using namespace websim;
+
+// todo: XML format for sim requests
+
+bool WebSim::HandleSimRequest(const std::string& prop,
+                        const std::string& action,
+                        Format format, 
+                        struct evkeyvalq* kv,
+                        std::string& response)
+{
+  printf( "[%s] sim %s %s\n", 
+         IdentificationString().c_str(), prop.c_str(), action.c_str() );
+  
+  if(prop == "factory")
+    return HandleSimFactoryRequest( action, format, kv, response );
+  
+  if(prop == "clock")
+    return HandleSimClockRequest( action, format, kv, response );
+  
+  if(prop == "geometry")
+    return HandleSimGeometryRequest( action, format, kv, response );
+  
+  if(prop == "children")
+    return HandleSimChildrenRequest( action, format, kv, response );
+  
+  if(prop == "tree")
+    return HandleSimTreeRequest( action, format, kv, response );
+  
+  if(prop == "greet") 
+    return HandleSimGreetRequest( action, format, kv, response );
+  
+  response = "ERROR: Unknown property " + prop + " for sim. Candidates are: 
children clock factory greet tree.";
+  return false;
+}
+
+bool WebSim::HandleSimGeometryRequest( std::string action,
+                              Format format,
+                              struct evkeyvalq* kv,
+                              std::string& response)  
+{
+  /*
+    double x,y,z;
+    Pose center;
+    GetModelExtent("sim", x, y, z, center, response);
+    GetXMLModelExtent("sim", x, y, z, center, response);
+  */
+
+  response = "Warning: geometry not yet implemented";
+  return true; 
+}
+
+bool WebSim::HandleSimChildrenRequest( std::string action,
+                              Format format,
+                              struct evkeyvalq* kv,
+                              std::string& response)  
+{
+  if( action == "" ) 
+    action = "get"; // default action
+  
+  if( action == "get" )
+    {
+      std::vector<std::string> children;
+      GetModelChildren("",children);
+      
+      for(unsigned int i=0;i<children.size();i++)
+       response += "-" + children[i];
+      
+      return true;
+    }      
+
+  response = "ERROR: Unknown action " + action + " for sim/children. 
Candidates are: get (default).";        
+  return false;
+}
+
+bool WebSim::HandleSimTreeRequest( std::string action,
+                          Format format,
+                          struct evkeyvalq* kv,
+                          std::string& response)  
+{
+  if( action == "" ) 
+    action = "get"; // default action
+  
+  if( action == "get" )
+    {
+      GetModelTree("", format, response, false);
+      return true;
+    }
+  
+  response = "ERROR: Unknown action " + action + " for sim/tree. Candidates 
are: get (default).";                      
+  return false;
+}
+
+bool WebSim::HandleSimGreetRequest( std::string action,
+                           Format format,
+                           struct evkeyvalq* kv,
+                           std::string& response)  
+{
+  if( action == "" ) 
+    action = "get"; // default action
+  
+  if( action == "get" )
+    {
+      // TODO - check to see if this server was anticipated
+      response = "Greetings " + action;
+      printf( "[websim] WebSim peer %s connected\n", action.c_str() );
+      return true;
+    }
+
+  response = "ERROR: Unknown action " + action + " for sim/greet. Candidates 
are: get (default).";                           
+  return false;
+}
+
+bool WebSim::HandleSimFactoryRequest( std::string action,
+                             Format format,
+                             struct evkeyvalq* kv,
+                             std::string& response)  
+{
+  if(action == "create")
+    {
+      std::string name, type;
+      if(!GetValue(name, kv, "name"))
+       {
+         response = "ERROR: Missing name argument for sim/factory/create";
+         return false;
+       }
+      
+      if( !GetValue(type, kv, "type"))
+       {
+         response = "ERROR: Missing name type argument for sim/factory/create";
+         return false;
+       }
+      
+      return(CreateModel(name, type, response));
+    }
+  
+  if(action == "destroy")
+    {
+      std::string name, type;
+      if(!GetValue(name, kv, "name"))
+       {
+         response = "ERROR: Missing name argument for sim/factory/destroy";
+         return false;
+       }
+      
+      return(DeleteModel(name, response));
+    }
+
+  response = "ERROR: Unknown action " + action + " for sim/factory. Candidates 
are: create destroy";
+  return false;
+}
+
+bool WebSim::HandleSimClockRequest( std::string action,
+                              Format format,   
+                              struct evkeyvalq* kv,
+                              std::string& response)
+{
+  if( action == "" ) // DEFAULT ACTION
+    action = "get"; 
+  
+  if( action == "get" )
+    {
+      response = "Current time: " + GetTime().String() + " seconds.";
+      return true;
+    }
+  
+  if(action == "tick")
+    {
+      ticks_remaining--;
+      response = "Ticked the clock";
+      return true;
+    }
+  
+  if(action == "start")
+    {
+      if( ClockStart() )
+       response = "Started the clock";
+      else
+       response = "Failed to start the clock";     
+      return true;
+    }
+  
+  if(action == "stop")
+    {
+      if( ClockStop() )
+       response = "Stopped the clock";
+      else
+       response = "Failed to stop the clock";      
+      return true;
+    }
+  
+  response = "ERROR: Unknown action " + action + " for sim/clock. Candidates 
are: get (default) start stop.";  
+  return false;  
+}

Modified: code/websim/src/websim.cc
===================================================================
--- code/websim/src/websim.cc   2009-06-24 22:54:43 UTC (rev 7893)
+++ code/websim/src/websim.cc   2009-06-24 23:55:46 UTC (rev 7894)
@@ -19,8 +19,8 @@
  *
  */ 
 
-/* Desc: WebSim http server for robot interactiony
- * Author: Brian Gerkey, Richard Vaughan, Abbas 
+/* Desc: HTTP interface to simulators 
+ * Author: Brian Gerkey, Richard Vaughan, Abbas Sadat
  * Date: 9 March 2009
  * SVN: $Id: gazebo.h 7398 2009-03-09 07:21:49Z natepak $
  */
@@ -276,111 +276,10 @@
     }
 }
 
-bool
-WebSim::HandleSimRequest(const std::string& prop,
-                        const std::string& action,
-                        Format format, 
-                        struct evkeyvalq* kv,
-                        std::string& response)
-{
-  printf( "[%s] sim request %s %s\n", 
-         IdentificationString().c_str(), prop.c_str(), action.c_str() );
 
-  // The special factory property
-  if(prop == "factory")
-    {
-      if(action == "create")
-       {
-         std::string name, type;
-         if(!GetValue(name, kv, "name"))
-           {
-             response = "ERROR: Missing name argument for sim/factory/create";
-             return false;
-           }
-         
-         if( !GetValue(type, kv, "type"))
-           {
-             response = "ERROR: Missing name type argument for 
sim/factory/create";
-             return false;
-           }
-         
-         return(CreateModel(name, type, response));
-       }
-      else if(action == "destroy")
-       {
-         std::string name, type;
-         if(!GetValue(name, kv, "name"))
-           {
-             response = "ERROR: Missing name argument for sim/factory/destroy";
-             return false;
-           }
-         
-         return(DeleteModel(name, response));
-       }
-      else
-       {
-         response = "ERROR: Unknown action " + action + " for sim/factory";
-         return false;
-       }
-    }
-  else if(prop == "clock")
-    {
-      if(action == "tick")
-       {
-         ticks_remaining--;
-         response = "Ticked the clock";
-         return true;
-       }
-      else if(action == "get")
-       {
-         response = "Current time: " + GetTime().String();
-         return true;
-       }
-      else
-       {
-         response = "ERROR: Unknown action " + action + " for sim/clock";
-         return false;
-       }
-    }
-  else if(prop == "extent")
-    {/*
-       double x,y,z;
-       Pose center;
-       GetModelExtent("sim", x, y, z, center, response);
-       GetXMLModelExtent("sim", x, y, z, center, response);
-     */
-      return true;     
-    }
-  else if(prop == "children")
-    {
-      std::vector<std::string> children;
-      GetModelChildren("",children);
-       
-      for(unsigned int i=0;i<children.size();i++)
-       response += "-" + children[i];
-    }
-  else if(prop == "tree")
-    {
-      GetModelTree("", format, response, false);
-      return true;
-               
-    }
-  else if(prop == "greet") // action is the name of the greeting server
-    {    
-      // TODO - check to see if this server was anticipated
-      response = "Greetings " + action;
-      printf( "[websim] WebSim peer %s connected\n", action.c_str() );
-      return true;
-    }
-  else
-    {
-      response = "ERROR: Unknown property " + prop + " for sim";
-      return false;
-    }
-       
-  return false;
-}
 
+  
+
 bool
 WebSim::HandleModelRequest(const std::string& model,
                           const std::string& prop,

Modified: code/websim/src/websim.hh
===================================================================
--- code/websim/src/websim.hh   2009-06-24 22:54:43 UTC (rev 7893)
+++ code/websim/src/websim.hh   2009-06-24 23:55:46 UTC (rev 7894)
@@ -20,7 +20,7 @@
  */ 
 
 /* Desc: HTTP interface to simulators
- * Author: Brian Gerkey, Richard Vaughan
+ * Author: Brian Gerkey, Richard Vaughan, Abbas Sadat
  * Date: 9 March 2009
  * SVN: $Id: gazebo.h 7398 2009-03-09 07:21:49Z natepak $
  */
@@ -85,6 +85,20 @@
       for a human reader, e.g. "1.3.1" */
   virtual std::string VersionString() = 0;
 
+  /** Start the virtual clock running, unpausing the simulation. If
+      the clock is already running, this does nothing.
+      
+      @return true on succes, false on failure.
+  */
+  virtual bool ClockStart()=0;
+
+  /** Stop the virtual clock running, pausing the simulation. If the
+      clock is already stopped, this does nothing.
+
+      @return true on succes, false on failure.
+  */
+  virtual bool ClockStop()=0;
+
   virtual bool CreateModel(const std::string& name, 
                                                                        const 
std::string& type,
                                                                        
std::string& response) = 0;
@@ -230,29 +244,63 @@
       @returns TRUE if a parameter with the given key exists.
   */
   bool GetValue( std::string& value,
-                                        struct evkeyvalq* query_args, 
-                                        const std::string& key);
+                struct evkeyvalq* query_args, 
+                const std::string& key);
+
   bool HandleURI(const std::string& model,
-                                         const std::string& prop,
-                                         const std::string& action,
-                                         struct evkeyvalq* kv,
-                                         std::string& response);
+                const std::string& prop,
+                const std::string& action,
+                struct evkeyvalq* kv,
+                std::string& response);
+
   bool HandleSimRequest(const std::string& prop,
-                                                               const 
std::string& action,
-                                                               Format format,
-                                                               struct 
evkeyvalq* kv,
-                                                               std::string& 
response);
+                       const std::string& action,
+                       Format format,
+                       struct evkeyvalq* kv,
+                       std::string& response);
+
+  bool HandleSimClockRequest( std::string action,
+                             Format format,
+                             struct evkeyvalq* kv,
+                             std::string& response);  
+
+  bool HandleSimFactoryRequest( std::string action,
+                               Format format,
+                               struct evkeyvalq* kv,
+                               std::string& response);  
+  
+  bool HandleSimChildrenRequest( std::string action,
+                                Format format,
+                                struct evkeyvalq* kv,
+                                std::string& response);  
+
+  bool HandleSimTreeRequest( std::string action,
+                                Format format,
+                                struct evkeyvalq* kv,
+                                std::string& response);  
+
+  bool HandleSimGeometryRequest( std::string action,
+                                Format format,
+                                struct evkeyvalq* kv,
+                                std::string& response);  
+
+  bool HandleSimGreetRequest( 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);
+                         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,
-                                        std::string uri,
-                                        std::string& response);
+               std::string& prop,
+               std::string& action,
+               std::string uri,
+               std::string& response);
   void DeleteKeyVal(struct evkeyvalq* query_args);
   
   


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