Revision: 7484
http://playerstage.svn.sourceforge.net/playerstage/?rev=7484&view=rev
Author: rtv
Date: 2009-03-14 20:19:06 +0000 (Sat, 14 Mar 2009)
Log Message:
-----------
working webstage demo. tweaks needed to webgazebo for WS API changes
Modified Paths:
--------------
code/websim/src/confederate.cc
code/websim/src/websim.cc
code/websim/src/websim.hh
Modified: code/websim/src/confederate.cc
===================================================================
--- code/websim/src/confederate.cc 2009-03-14 01:13:25 UTC (rev 7483)
+++ code/websim/src/confederate.cc 2009-03-14 20:19:06 UTC (rev 7484)
@@ -52,6 +52,8 @@
break;
case 200: // OK
(*created) = true;
+ printf( "[websim] server responds OK to greeting with %s\n",
+ req->input_buffer->buffer );
break;
case 400:
printf( "[websim] server responds to greeting with error (400):
%s.\n",
@@ -149,7 +151,11 @@
{
Puppet* pup = (Puppet*)arg;
if( req->response_code == 200 )
- pup->created = true;
+ {
+ pup->created = true;
+ //printf( "Puppet %s creation ACK.\n",
+ // pup->name.c_str() );
+ }
else
{
printf( "bad response regarding puppet creation \"%s\"\n",
pup->name.c_str() );
@@ -170,7 +176,7 @@
puppet->name.c_str(),
prototype.c_str() );
- printf( "Emitting: http://%s%s\n", name.c_str(), buf );
+ //printf( "Emitting: http://%s%s\n", name.c_str(), buf );
int ret = evhttp_make_request( http_con, er, EVHTTP_REQ_GET, buf );
if( ret != 0 )
@@ -195,25 +201,22 @@
return;
}
- cb_chunk_t* ch = (cb_chunk_t*)arg;
- assert(ch);
+ Confederate* conf = (Confederate*)arg;
+ assert(conf);
if( req->response_code == 200 )
{
- ch->conf->ws->unacknowledged_pushes--;
- ch->conf->ws->EscapeLoopIfDone();
-
- //printf( "puppet push for \"%s\" acked OK. Outstanding pushes
%u\n",
- // ch->name.c_str(), ch->conf->ws->unacknowledged_pushes
);
+ conf->ws->unacknowledged_pushes--;
+
+ //printf( "conf %s puppet push ACK. Outstanding pushes %u\n",
+ // conf->name.c_str(), conf->ws->unacknowledged_pushes );
}
else
{
- printf( "bad response regarding puppet push \"%s\"\n",
ch->name.c_str() );
+ printf( "bad response regarding puppet push \"%s\"\n",
conf->name.c_str() );
printf( "code: %d\n", req->response_code );
printf( "response: %s\n", req->input_buffer->buffer );
}
-
- delete ch;
}
int WebSim::Confederate::Push( std::string name, Pose p, Velocity v,
Acceleration a )
@@ -221,14 +224,9 @@
//printf( "\tconfederate %s pushing state of \"%s\"\n",
// this->name.c_str(),
// name.c_str() );
-
- // compose a struct to send into the callback
- cb_chunk_t* ch = new cb_chunk_t();
- ch->name = name;
- ch->conf = this;
struct evhttp_request* er =
- evhttp_request_new( PuppetPushCallback, ch );
+ evhttp_request_new( PuppetPushCallback, this );
assert(er);
char buf[512];
@@ -264,15 +262,16 @@
return;
}
- WebSim* ws = (WebSim*)arg;
+ Confederate* conf = (Confederate*)arg;
+ assert(conf);
if( req->response_code == 200 )
{
- --ws->unacknowledged_ticks;
- ws->EscapeLoopIfDone();
-
- printf( "tick ACK. Outstanding ticks %u\n",
- ws->unacknowledged_ticks );
+ conf->ws->unacknowledged_ticks--;
+
+ //printf( "tick ACK from %s. Outstanding ticks %u\n",
+ // conf->name.c_str(),
+ // conf->ws->unacknowledged_ticks );
}
else
{
@@ -290,10 +289,10 @@
// name.c_str() );
struct evhttp_request* er =
- evhttp_request_new( TickReplyCb, ws );
+ evhttp_request_new( TickReplyCb, (void*)this );
assert(er);
- ++ws->unacknowledged_ticks; // decremented when reply is received
+ ws->unacknowledged_ticks++; // decremented when reply is received
int ret = evhttp_make_request( http_con, er, EVHTTP_REQ_GET,
"/sim/clock/tick" );
if( ret != 0 )
Modified: code/websim/src/websim.cc
===================================================================
--- code/websim/src/websim.cc 2009-03-14 01:13:25 UTC (rev 7483)
+++ code/websim/src/websim.cc 2009-03-14 20:19:06 UTC (rev 7484)
@@ -90,19 +90,25 @@
WebSim::Go()
{
// tick all my confederates
- ForEachConfederate( Confederate::TickCb, NULL );
+ ForEachConfederate( Confederate::TickCb, NULL );
}
void
WebSim::Wait()
{
- ticks_remaining = tick_count_expected;
-
- // a callback will jump out of this loop when we've heard Ticks from
- // all confederates
- event_dispatch();
-
- //printf( "STEP %lu\n", total_ticks++ );
+ if( tick_count_expected ) // if we're federated with anyone
+ {
+ ticks_remaining = tick_count_expected;
+
+ while( unacknowledged_ticks || unacknowledged_pushes ||
ticks_remaining )
+ {
+ //printf( "event loop in wait (%d %d %d)\n",
+ // unacknowledged_ticks,
unacknowledged_pushes, ticks_remaining );
+ event_loop( EVLOOP_ONCE );
+ }
+ }
+ else // not federated - just an isolated server
+ event_loop( EVLOOP_NONBLOCK );
}
void
@@ -170,17 +176,17 @@
}
}
-void WebSim::EscapeLoopIfDone()
-{
- // if we're done waiting for things we can bail out of the event loop
+// void WebSim::EscapeLoopIfDone()
+// {
+// // if we're done waiting for things we can bail out of the event loop
- printf( "testing %d %d %d\n", ticks_remaining, unacknowledged_pushes,
unacknowledged_ticks );
- if( ! (ticks_remaining || unacknowledged_pushes || unacknowledged_ticks) )
- {
- puts( "OUTTA HERE" );
- event_loopbreak();
- }
-}
+// printf( "testing %d %d %d\n", ticks_remaining, unacknowledged_pushes,
unacknowledged_ticks );
+// if( ! (ticks_remaining || unacknowledged_pushes || unacknowledged_ticks) )
+// {
+// puts( "OUTTA HERE" );
+// event_loopbreak();
+// }
+// }
bool
WebSim::HandleSimRequest(const std::string& prop,
@@ -226,8 +232,6 @@
{
ticks_remaining--;
response = "Ticked the clock";
-
- EscapeLoopIfDone();
return true;
}
else
Modified: code/websim/src/websim.hh
===================================================================
--- code/websim/src/websim.hh 2009-03-14 01:13:25 UTC (rev 7483)
+++ code/websim/src/websim.hh 2009-03-14 20:19:06 UTC (rev 7484)
@@ -93,7 +93,7 @@
std::vector<std::string> &t,
const std::string &d);
- void EscapeLoopIfDone();
+ //void EscapeLoopIfDone();
// Number of ticks we require before exiting Update()
@@ -170,11 +170,11 @@
// manage a federated simulator
class Confederate
{
- typedef struct
- {
- std::string name;
- Confederate* conf;
- } cb_chunk_t;
+// typedef struct
+// {
+// std::string name;
+// Confederate* conf;
+// } cb_chunk_t;
private:
// connection to a remote http simulation server
@@ -221,10 +221,10 @@
GHashTable* logical_hosts;
// counts the number of status messages sent and replies not yet received
- unsigned int unacknowledged_pushes;
+ int unacknowledged_pushes;
// counts the number of clock ticks sent and replies not yet received
- unsigned int unacknowledged_ticks;
+ int unacknowledged_ticks;
unsigned long total_ticks;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit