Revision: 7434
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7434&view=rev
Author:   rtv
Date:     2009-03-10 07:00:05 +0000 (Tue, 10 Mar 2009)

Log Message:
-----------
added rtv federation client side stuff

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

Added Paths:
-----------
    code/websim/src/websim.hh

Removed Paths:
-------------
    code/websim/src/websim.h

Modified: code/websim/CMakeLists.txt
===================================================================
--- code/websim/CMakeLists.txt  2009-03-10 06:53:56 UTC (rev 7433)
+++ code/websim/CMakeLists.txt  2009-03-10 07:00:05 UTC (rev 7434)
@@ -2,17 +2,32 @@
 
 cmake_minimum_required( VERSION 2.4 FATAL_ERROR )
 
+include(FindPkgConfig)
+
+pkg_search_module( GLIB REQUIRED glib-2.0 )
+IF( GLIB_FOUND )
+  MESSAGE( STATUS ${INDENT} "Glib version ${GLIB_VERSION} detected at 
${GLIB_PREFIX}" )
+  MESSAGE( STATUS "    GLIB_CFLAGS = ${GLIB_CFLAGS}" )
+  MESSAGE( STATUS "    GLIB_LDFLAGS = ${GLIB_LDFLAGS}" )
+ELSE( GLIB_FOUND )
+  MESSAGE( ${INDENT} "Glib not detected" )
+ENDIF( GLIB_FOUND )
+
+include_directories( ${GLIB_INCLUDE_DIRS} )
+link_directories(${GLIB_LIBRARY_DIRS} )
+
 include_directories(include)
-add_library(websim SHARED src/websim.cc)
-add_library(websim-static STATIC src/websim.cc)
+add_library(websim SHARED src/websim.cc src/parser.cc src/confederate.cc )
+add_library(websim-static STATIC src/websim.cc src/parser.cc 
src/confederate.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
 set_target_properties(websim-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
 
-target_link_libraries(websim event)
+target_link_libraries(websim event ${GLIB_LIBRARIES} )
 
 install(TARGETS websim websim-static 
         LIBRARY DESTINATION lib
         ARCHIVE DESTINATION lib)
-install(FILES src/websim.h DESTINATION include/websim)
+install(FILES src/websim.hh DESTINATION include/websim)
+

Modified: code/websim/src/websim.cc
===================================================================
--- code/websim/src/websim.cc   2009-03-10 06:53:56 UTC (rev 7433)
+++ code/websim/src/websim.cc   2009-03-10 07:00:05 UTC (rev 7434)
@@ -25,7 +25,7 @@
  * SVN: $Id: gazebo.h 7398 2009-03-09 07:21:49Z natepak $
  */
 
-#include "websim.h"
+#include "websim.hh"
 
 #include <boost/lexical_cast.hpp>
 
@@ -34,15 +34,24 @@
 
 using namespace websim;
 
+const std::string WebSim::package = "WebSim";
+const std::string WebSim::version = "0.1";
+
 WebSim::WebSim(const std::string& _fedfile,
                const std::string& _host, 
-               int _port) :
+               unsigned short _port) :
         fedfile(_fedfile), host(_host), port(_port), tick_count_expected(0)
 {
   // Set up the HTTP server
   // Not sure whether it's safe to do this more that once in one process
   event_init();
 
+  printf( "%s %s\n", package.c_str(), version.c_str() );
+  
+  char buf[512];
+  snprintf( buf, 512, "%s:%u", host.c_str(), port );
+  hostportname = buf;
+
   printf("[websim] Starting HTTP server listening on %s:%d...",
          this->host.c_str(), this->port);
   fflush(stdout);
@@ -50,7 +59,12 @@
   assert(eh);
   evhttp_set_gencb(eh, &WebSim::EventCallback, (void*)this);
   puts("Done.");
-
+  
+  // if a federation file was specified, we parse it to populate the
+  // WebSim with confederates and puppets.
+  if( fedfile != "" )
+        Parser p( this, _fedfile.c_str() );  
+  
   puts("[websim] Ready");
 }
 

Deleted: code/websim/src/websim.h
===================================================================
--- code/websim/src/websim.h    2009-03-10 06:53:56 UTC (rev 7433)
+++ code/websim/src/websim.h    2009-03-10 07:00:05 UTC (rev 7434)
@@ -1,164 +0,0 @@
-/*
- *  WebSim - Library for web-enabling and federating simulators.
- *  Copyright (C) 2009
- *    Richard Vaughan, Brian Gerkey, and Nate Koenig
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */ 
-
-/* Desc: HTTP portal to libgazebo
- * Author: Brian Gerkey
- * Date: 9 March 2009
- * SVN: $Id: gazebo.h 7398 2009-03-09 07:21:49Z natepak $
- */
-
-#include <string>
-#include <vector>
-#include <map>
-
-// These headers must be included prior to the libevent headers
-#include <sys/types.h>
-#include <sys/queue.h>
-
-// libevent
-#include <event.h>
-#include <evhttp.h>
-
-namespace websim
-{
-
-class Pose;
-class Velocity;
-class Acceleration;
-
-class WebSim
-{
-  public:
-    WebSim(const std::string& _fedfile, 
-           const std::string& _host,
-           int _port);
-    virtual ~WebSim();
-
-    void Update();
-
-    // Interface to be implemented by simulators
-    virtual bool CreateModel(const std::string& name, 
-                             const std::string& type,
-                             std::string& response) = 0;
-    virtual bool DeleteModel(const std::string& name,
-                             std::string& response) = 0;
-    virtual bool SetModelPVA(const std::string& name, 
-                             const Pose& p,
-                             const Velocity& v,
-                             const Acceleration& a,
-                             std::string& response) = 0;
-    virtual bool GetModelPVA(const std::string& name, 
-                             Pose& p,
-                             Velocity& v,
-                             Acceleration& a,
-                             std::string& response) = 0;
-
-  protected:
-    void StringSplit(const std::string &s, 
-                     std::vector<std::string> &t, 
-                     const std::string &d);
-
-  private:
-    std::string fedfile;
-    std::string host;
-    int port;
-
-    // Number of ticks we require before exiting Update()
-    int tick_count_expected;
-    // Number of ticks we've received since the last Update()
-    int tick_count;
-
-    struct evhttp* eh;
-
-    // Static, so that it can be passed as a callback to libevent
-    static void EventCallback(evhttp_request* req, void* arg);
-
-    bool GetValue(std::string& value,
-                  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);
-    bool HandleSimRequest(const std::string& prop,
-                          const std::string& action,
-                          struct evkeyvalq* kv,
-                          std::string& response);
-    bool HandleModelRequest(const std::string& model,
-                            const std::string& prop,
-                            const std::string& action,
-                            struct evkeyvalq* kv,
-                            std::string& response);
-    bool ParseURI(std::string& model,
-                  std::string& prop,
-                  std::string& action,
-                  std::string uri,
-                  std::string& response);
-    void DeleteKeyVal(struct evkeyvalq* query_args);
-};
-
-class Pose
-{
-public:
-  double x,y,z,r,p,a;
-  
-  Pose() :
-        x(0), y(0), z(0), r(0), p(0), a(0)
-  {
-        // nothing to do
-  }
-  
-  Pose( double x, double y, double z,
-                 double r, double p, double a ) :
-        x(x), y(y), z(z), r(r), p(p), a(a)
-  {
-        // nothing to do
-  }
-  
-};
-
-class Velocity : public Pose
-{
-public:
-  Velocity() : Pose()
-  {}
-
-  Velocity( double x, double y, double z,
-                               double r, double p, double a ) :
-        Pose( x, y, z, r, p, a )
-  {}  
-};
-
-class Acceleration : public Pose
-{
-public:
-  Acceleration() : Pose()
-  {}
-        
-  Acceleration( double x, double y, double z,
-                                        double r, double p, double a ) :
-        Pose( x, y, z, r, p, a )
-  {}  
-};
-
-
-}

Added: code/websim/src/websim.hh
===================================================================
--- code/websim/src/websim.hh                           (rev 0)
+++ code/websim/src/websim.hh   2009-03-10 07:00:05 UTC (rev 7434)
@@ -0,0 +1,285 @@
+/*
+ *  WebSim - Library for web-enabling and federating simulators.
+ *  Copyright (C) 2009
+ *    Richard Vaughan, Brian Gerkey, and Nate Koenig
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */ 
+
+/* Desc: HTTP interface to simulators
+ * Author: Brian Gerkey, Richard Vaughan
+ * Date: 9 March 2009
+ * SVN: $Id: gazebo.h 7398 2009-03-09 07:21:49Z natepak $
+ */
+
+#include <string>
+#include <vector>
+#include <map>
+
+// These headers must be included prior to the libevent headers
+#include <sys/types.h>
+#include <sys/queue.h>
+
+// libevent
+#include <event.h>
+#include <evhttp.h>
+
+// GLib-2.0
+#include <glib.h>
+
+// YAML
+#include <yaml.h>
+
+namespace websim
+{
+
+class Pose;
+class Velocity;
+class Acceleration;
+
+class WebSim
+{
+  public:
+    WebSim(const std::string& _fedfile, 
+           const std::string& _host,
+           unsigned short _port);
+    virtual ~WebSim();
+
+    void Update();
+
+    // Interface to be implemented by simulators
+    virtual bool CreateModel(const std::string& name, 
+                             const std::string& type,
+                             std::string& response) = 0;
+    virtual bool DeleteModel(const std::string& name,
+                             std::string& response) = 0;
+    virtual bool SetModelPVA(const std::string& name, 
+                             const Pose& p,
+                             const Velocity& v,
+                             const Acceleration& a,
+                             std::string& response) = 0;
+    virtual bool GetModelPVA(const std::string& name, 
+                             Pose& p,
+                             Velocity& v,
+                             Acceleration& a,
+                             std::string& response) = 0;
+
+  protected:
+    void StringSplit(const std::string &s, 
+                     std::vector<std::string> &t, 
+                     const std::string &d);
+
+
+  // Number of ticks we require before exiting Update()
+  int tick_count_expected;
+  // Number of ticks we've received since the last Update()
+  int tick_count;
+  
+  private:
+    std::string fedfile;
+    std::string host;
+    std::string hostportname; // format "host:port" to uniquely identify this 
instance
+    unsigned short port;
+
+    struct evhttp* eh;
+
+    // Static, so that it can be passed as a callback to libevent
+    static void EventCallback(evhttp_request* req, void* arg);
+
+    bool GetValue(std::string& value,
+                  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);
+    bool HandleSimRequest(const std::string& prop,
+                          const std::string& action,
+                          struct evkeyvalq* kv,
+                          std::string& response);
+    bool HandleModelRequest(const std::string& model,
+                            const std::string& prop,
+                            const std::string& action,
+                            struct evkeyvalq* kv,
+                            std::string& response);
+    bool ParseURI(std::string& model,
+                  std::string& prop,
+                  std::string& action,
+                  std::string uri,
+                  std::string& response);
+    void DeleteKeyVal(struct evkeyvalq* query_args);
+
+
+          // forward decare
+  class Confederate;
+
+  // manage an object we control on some federated simulators
+  class Puppet
+  {
+  private:
+        WebSim* ws;
+
+  public:  
+        Puppet( WebSim* ws,  const char* name );
+        
+        // unique ID used as a system-widel handle for this puppet, used as
+        // hash table key
+        const char* name;
+        
+        bool created;
+        
+        // the remote servers that are hosting an instance of this puppet
+        GList* confederates;
+        
+        // sends the current physical state of the puppet to all
+        // confederates
+        void Push( Pose p, Velocity v, Acceleration a );
+        
+        // create an instance of the puppet on this confederate, using the
+        // named puppet prototype (defined locally at the conferderate)
+        void AddConfederate( Confederate* conf, 
+                                                                const char* 
prototype );
+  };
+  
+  // manage a federated simulator
+  class Confederate
+  {
+        typedef struct 
+        {
+               const char* name;
+               Confederate* conf;
+        } cb_chunk_t;
+        
+  private:
+        // connection to a remote http simulation server
+        struct evhttp_connection* http_con;  
+        struct evhttp_request* http_req;
+        
+        static void PuppetCreationCallback(  evhttp_request* req, void* arg );
+        static void PuppetPushCallback( evhttp_request* req, void* arg );
+
+        // counts the number of status messages sent and replies not yet 
received
+        unsigned int unacknowledged_pushes;
+
+        WebSim* ws;
+
+  public:
+        Confederate( WebSim* ws, const char* host, unsigned short port );  
+        ~Confederate();
+        
+        void AddPuppet( Puppet* puppet,
+                                                 const char* prototype );
+        
+        int Push( const char* name, Pose p, Velocity v, Acceleration a );
+
+        int RunStep();
+        
+        // list of pointers to Puppet objects that are hosted on this
+        // connection - can iterate over these to update all puppets
+        GList* puppet_list;
+                
+        // unique ID for this confederate in format "hostname:port", used as
+        // hash table key
+        const char* name;  
+  };
+  
+  class Parser
+  {
+  private:
+        yaml_event_t event;
+        yaml_parser_t parser;
+        WebSim* ws;
+        
+        void parse_failed( const char* message );
+        yaml_event_t next_event( const char* msg );
+        void expect( yaml_event_type_t event_type, const char* msg );
+        bool test( yaml_event_type_t event_type, const char* msg );
+        Confederate* GetConfederate( const char* host, unsigned short port );
+        Confederate* GetConfederate( const char* hostandport );
+        void parse_puppet_mapping( Puppet* pup );
+        void parse_puppet_mapping_sequence( Puppet* pup );
+        void parse_model_mapping( std::string host );
+        void parse_model_mapping_sequence( std::string host );
+        void parse_host_mapping();
+        void parse_document();
+        void parse_stream();
+        
+  public:
+        Parser( WebSim* ws, const char* filename );
+  };
+
+ private:
+  // static const unsigned short DEFAULT_PORT;
+  static const std::string package;
+  static const std::string version;
+    
+  GHashTable* puppets;
+  GHashTable* confederates;
+
+  /** Get a puppet by name */
+  Puppet* GetPuppet( const char* name );
+  
+  /** Get a confederate by name in format "host:port" */
+  Confederate* GetConfederate( const char* name );
+};
+
+class Pose
+{
+public:
+  double x,y,z,r,p,a;
+  
+  Pose() :
+        x(0), y(0), z(0), r(0), p(0), a(0)
+  {
+        // nothing to do
+  }
+  
+  Pose( double x, double y, double z,
+                 double r, double p, double a ) :
+        x(x), y(y), z(z), r(r), p(p), a(a)
+  {
+        // nothing to do
+  }
+  
+};
+
+class Velocity : public Pose
+{
+public:
+  Velocity() : Pose()
+  {}
+
+  Velocity( double x, double y, double z,
+                               double r, double p, double a ) :
+        Pose( x, y, z, r, p, a )
+  {}  
+};
+
+class Acceleration : public Pose
+{
+public:
+  Acceleration() : Pose()
+  {}
+        
+  Acceleration( double x, double y, double z,
+                                        double r, double p, double a ) :
+        Pose( x, y, z, r, p, a )
+  {}  
+};
+
+
+}


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