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

Log Message:
-----------
functional client

Modified Paths:
--------------
    code/branches/federation/stage/examples/gzfed/confederate.cc
    code/branches/federation/stage/examples/gzfed/main.cc
    code/branches/federation/stage/examples/gzfed/websim.hh

Modified: code/branches/federation/stage/examples/gzfed/confederate.cc
===================================================================
--- code/branches/federation/stage/examples/gzfed/confederate.cc        
2009-03-10 05:48:01 UTC (rev 7427)
+++ code/branches/federation/stage/examples/gzfed/confederate.cc        
2009-03-10 05:52:20 UTC (rev 7428)
@@ -4,7 +4,8 @@
 #include "websim.hh"
 
 WebSim::Confederate::Confederate( WebSim* ws, const char* host, unsigned short 
port ) :
-  puppet_list( NULL )
+  puppet_list( NULL ),
+  unacknowledged_pushes( 0 )
 {
   if(! (http_con = evhttp_connection_new( host, port )) )
         printf( "Error: Confederate object failed to connect to server at 
%s:%d\n",
@@ -40,7 +41,7 @@
         pup->created = true;
   else
         {
-               printf( "bad response regarding puppet \"%s\"\n", pup->name );
+               printf( "bad response regarding puppet creation \"%s\"\n", 
pup->name );
                printf( "code: %d\n", req->response_code );             
                printf( "response: %s\n", req->input_buffer->buffer );
         }
@@ -81,11 +82,62 @@
         g_list_append( puppet_list, puppet );                                  
                                                 
 }
 
+void WebSim::Confederate::PuppetPushCallback( evhttp_request* req, void* arg )
+{
+  cb_chunk_t* ch = (cb_chunk_t*)arg;
+  
+  if( req->response_code == 200 )
+        {              
+               --ch->conf->unacknowledged_pushes;
+               printf( "puppet push for \"%s\" acked OK. Outstanding pushes 
%u\n",
+                                 ch->name, ch->conf->unacknowledged_pushes );
+        }
+  else
+        {
+               printf( "bad response regarding puppet push \"%s\"\n", ch->name 
);
+               printf( "code: %d\n", req->response_code );             
+               printf( "response: %s\n", req->input_buffer->buffer );
+        }
+}
+
 int WebSim::Confederate::Push( const char* name, Pose p, Velocity v, 
Acceleration a )
 {
   printf( "\tconfederate %s pushing state of \"%s\"\n",
                         this->name,
                         name );
+  
+  // compose a struct to send into the callback
+  cb_chunk_t ch;
+  ch.name = name;                                                              
                  
+  ch.conf = this;
+
+  struct evhttp_request* er = 
+        evhttp_request_new( PuppetPushCallback, &ch );
+  assert(er);
+  
+  char buf[512];
+  snprintf( buf, 512, "/%s/pva/set?"
+                               
"px=%.6f&py=%.6f&pz=%.6f&pr=%.6f&pp=%.6f&pa=%.6f&"
+                               
"vx=%.6f&vy=%.6f&vz=%.6f&vr=%.6f&vp=%.6f&va=%.6f&"
+                               
"ax=%.6f&ay=%.6f&az=%.6f&ar=%.6f&ap=%.6f&aa=%.6f",
+                               name,
+                               p.x, p.y, p.z, p.r, p.p, p.a,
+                               v.x, v.y, v.z, v.r, v.p, v.a,
+                               a.x, a.y, a.z, a.r, a.p, a.a );
+  
+  printf( "Emitting: http://%s%s\n";, this->name, buf );
+  
+  ++unacknowledged_pushes; // decremented when reply is received
+
+  int ret = evhttp_make_request( http_con, er, EVHTTP_REQ_GET, buf );
+  if( ret != 0 )
+        {
+               printf( "make request returned error %d\n", ret );
+               exit(0);
+        } 
+  
+  while( unacknowledged_pushes )
+        event_loop( EVLOOP_NONBLOCK ); // loops until the request has completed
 }
 
 int WebSim::Confederate::RunStep()

Modified: code/branches/federation/stage/examples/gzfed/main.cc
===================================================================
--- code/branches/federation/stage/examples/gzfed/main.cc       2009-03-10 
05:48:01 UTC (rev 7427)
+++ code/branches/federation/stage/examples/gzfed/main.cc       2009-03-10 
05:52:20 UTC (rev 7428)
@@ -8,6 +8,10 @@
 {
   WebSim ws( argv[1] );//, createcallback, stateupdatecallback );
   
+  WebSim::Pose p( 0,0,0,0,0,0 );
+  WebSim::Velocity v( 0,0,0,0,0,0 );
+  WebSim::Acceleration a( 0,0,0,0,0,0 );
+
   while( 1 )
         {
                        
@@ -20,9 +24,11 @@
                //}
 
                //for each model                
-               //  ws.Push( "monkey", x,y,z )            
-                                                 
-               //ws.Update();
+               
+               sleep( 1 );
+               
+               ws.Push( "monkey", p, v, a );                                   
          
+               ws.Update();
         }
 
   return 0;

Modified: code/branches/federation/stage/examples/gzfed/websim.hh
===================================================================
--- code/branches/federation/stage/examples/gzfed/websim.hh     2009-03-10 
05:48:01 UTC (rev 7427)
+++ code/branches/federation/stage/examples/gzfed/websim.hh     2009-03-10 
05:52:20 UTC (rev 7428)
@@ -90,13 +90,23 @@
   // 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:


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