Revision: 7528
http://playerstage.svn.sourceforge.net/playerstage/?rev=7528&view=rev
Author: rtv
Date: 2009-03-18 02:58:32 +0000 (Wed, 18 Mar 2009)
Log Message:
-----------
global const-correctness and added basic sim time support
Modified Paths:
--------------
code/websim/src/confederate.cc
code/websim/src/parser.cc
code/websim/src/puppet.cc
code/websim/src/websim.cc
code/websim/src/websim.hh
Modified: code/websim/src/confederate.cc
===================================================================
--- code/websim/src/confederate.cc 2009-03-17 23:48:36 UTC (rev 7527)
+++ code/websim/src/confederate.cc 2009-03-18 02:58:32 UTC (rev 7528)
@@ -69,7 +69,7 @@
WebSim::Confederate::Confederate( WebSim* ws,
-
std::string uri ) :
+
const std::string& uri ) :
ws(ws),
puppet_list( NULL ),
name(uri)
@@ -165,7 +165,7 @@
}
void WebSim::Confederate::AddPuppet( Puppet* puppet,
-
std::string prototype )
+ const
std::string& prototype )
{
struct evhttp_request* er =
evhttp_request_new( PuppetCreationCallback, puppet );
@@ -219,7 +219,7 @@
}
}
-int WebSim::Confederate::Push( std::string name, Pose p, Velocity v,
Acceleration a )
+int WebSim::Confederate::Push( const std::string& name, Pose p, Velocity v,
Acceleration a )
{
//printf( "\tconfederate %s pushing state of \"%s\"\n",
// this->name.c_str(),
Modified: code/websim/src/parser.cc
===================================================================
--- code/websim/src/parser.cc 2009-03-17 23:48:36 UTC (rev 7527)
+++ code/websim/src/parser.cc 2009-03-18 02:58:32 UTC (rev 7528)
@@ -38,7 +38,7 @@
using namespace websim;
-void WebSim::LoadFederationFile( std::string filename )
+void WebSim::LoadFederationFile( const std::string& filename )
{
GError* err = NULL;
GKeyFile* keyfile = g_key_file_new();
@@ -89,8 +89,8 @@
}
}
- cout << "Looking up logical name for myself " << hostportname << endl;
-
+ // cout << "Looking up logical name for myself " << hostportname << endl;
+
// now we have made all the confederates.
// Let's look up the confederate for this instance
// read the array of entries for this host
@@ -99,7 +99,7 @@
hostportname.c_str(),
&err );
- cout << "my logical name is " << mylogicalname << endl;
+ // cout << "my logical name is " << mylogicalname << endl;
// now we look up all the models listed under my logical name
// get an array of confederate hosts
Modified: code/websim/src/puppet.cc
===================================================================
--- code/websim/src/puppet.cc 2009-03-17 23:48:36 UTC (rev 7527)
+++ code/websim/src/puppet.cc 2009-03-18 02:58:32 UTC (rev 7528)
@@ -32,7 +32,7 @@
using namespace websim;
-WebSim::Puppet::Puppet( WebSim* ws, std::string name ) :
+WebSim::Puppet::Puppet( WebSim* ws, const std::string& name ) :
ws( ws ),
name( name ),
created( false ),
@@ -54,7 +54,7 @@
}
void WebSim::Puppet::AddConfederate( Confederate* conf,
-
std::string prototype )
+
const std::string& prototype )
{
conf->AddPuppet( this, prototype );
confederates = g_list_append( confederates, conf );
Modified: code/websim/src/websim.cc
===================================================================
--- code/websim/src/websim.cc 2009-03-17 23:48:36 UTC (rev 7527)
+++ code/websim/src/websim.cc 2009-03-18 02:58:32 UTC (rev 7528)
@@ -37,6 +37,14 @@
const std::string WebSim::package = "WebSim";
const std::string WebSim::version = "0.1";
+
+std::string Time::String()
+{
+ std::string seconds = boost::lexical_cast<std::string>(sec);
+ std::string microseconds = boost::lexical_cast<std::string>(usec);
+ return( seconds + '.' + microseconds );
+}
+
WebSim::WebSim( const std::string& _host,
const unsigned short _port) :
tick_count_expected(0),
@@ -81,7 +89,7 @@
// No event_fini() to call...
}
-void WebSim::Confederate::TickCb( std::string name, Confederate* conf, void*
arg )
+void WebSim::Confederate::TickCb( const std::string& name, Confederate* conf,
void* arg )
{
conf->Tick();
}
@@ -141,7 +149,7 @@
}
bool
-WebSim::GetValue(std::string& value,
+WebSim::GetValue( std::string& value,
struct evkeyvalq* query_args,
const std::string& key)
{
@@ -176,18 +184,6 @@
}
}
-// 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();
-// }
-// }
-
bool
WebSim::HandleSimRequest(const std::string& prop,
const std::string& action,
@@ -234,6 +230,11 @@
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";
@@ -268,14 +269,16 @@
Pose p;
Velocity v;
Acceleration a;
- if(GetModelPVA(model, p, v, a, response))
+ Time t;
+ if(GetModelPVA(model, t, p, v, a, response))
{
char buf[1024];
snprintf(buf, sizeof(buf),
- "%s's state: \n pose: (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f)\n"
+ "%s's state @%s: \n pose: (%.3f,%.3f,%.3f)
(%.3f,%.3f,%.3f)\n"
" vel : (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f)\n"
" acc : (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f)\n",
model.c_str(),
+ t.String().c_str(),
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);
@@ -304,7 +307,8 @@
Pose p;
Velocity v;
Acceleration a;
- if(!GetModelPVA(model, p, v, a, response))
+ Time t;
+ if(!GetModelPVA(model, t, p, v, a, response))
{
response = "Failed to get pose before setting it";
return false;
@@ -411,10 +415,10 @@
}
bool
-WebSim::ParseURI(std::string& model,
- std::string& prop,
+WebSim::ParseURI( std::string& model,
+ std::string& prop,
std::string& action,
- std::string uri,
+ const std::string uri,
std::string& response)
{
// Remove the query args
@@ -441,16 +445,6 @@
return true;
}
-WebSim::Puppet* WebSim::GetPuppet( std::string name )
-{
- return( (Puppet*)g_hash_table_lookup( WebSim::puppets, name.c_str() ) );
-}
-
-WebSim::Confederate* WebSim::GetConfederate( std::string name )
-{
- return( (Confederate*)g_hash_table_lookup( WebSim::confederates,
name.c_str() ) );
-}
-
bool
WebSim::SetPuppetPVA( const std::string& name,
Pose& p,
@@ -470,16 +464,26 @@
return false;
}
- void WebSim::ForEachConfederate( void(*cb)(std::string,
WebSim::Confederate*, void*), void* arg )
+void WebSim::ForEachConfederate( void(*cb)(const std::string&,
WebSim::Confederate*, void*), void* arg )
{
g_hash_table_foreach( WebSim::confederates,
(GHFunc)cb,
arg );
}
-void WebSim::ForEachPuppet( void(*cb)(std::string, WebSim::Puppet*, void*),
void* arg )
+void WebSim::ForEachPuppet( void(*cb)(const std::string&, WebSim::Puppet*,
void*), void* arg )
{
g_hash_table_foreach( WebSim::puppets,
(GHFunc)cb,
arg );
}
+
+WebSim::Puppet* WebSim::GetPuppet( const std::string& name )
+{
+ return( (Puppet*)g_hash_table_lookup( WebSim::puppets, name.c_str() ) );
+}
+
+WebSim::Confederate* WebSim::GetConfederate( const std::string& name )
+{
+ return( (Confederate*)g_hash_table_lookup( WebSim::confederates,
name.c_str() ) );
+}
Modified: code/websim/src/websim.hh
===================================================================
--- code/websim/src/websim.hh 2009-03-17 23:48:36 UTC (rev 7527)
+++ code/websim/src/websim.hh 2009-03-18 02:58:32 UTC (rev 7528)
@@ -40,15 +40,13 @@
// GLib-2.0
#include <glib.h>
-// YAML
-// #include <yaml.h>
-
namespace websim
{
class Pose;
class Velocity;
class Acceleration;
+class Time;
class WebSim
{
@@ -58,7 +56,7 @@
virtual ~WebSim();
- void LoadFederationFile( std::string filename );
+ void LoadFederationFile( const std::string& filename );
/** Wait for go signals from all confederates */
void Wait();
@@ -78,11 +76,15 @@
const
Acceleration& a,
std::string& response) = 0;
virtual bool GetModelPVA(const std::string& name,
+ Time& t,
Pose& p,
Velocity& v,
Acceleration& a,
std::string& response) = 0;
-
+
+ /** Get the current simulation time */
+ virtual Time GetTime() = 0;
+
bool SetPuppetPVA( const std::string& name,
Pose& p,
Velocity& v,
@@ -93,12 +95,9 @@
std::vector<std::string> &t,
const std::string &d);
- //void EscapeLoopIfDone();
-
-
- // Number of ticks we require before exiting Update()
+ /**Number of ticks we require each step before exiting Wait() */
int tick_count_expected;
- // Number of ticks remaining before we can quit update
+ /** Number of ticks remaining in this step before we can quit Wait() */
int ticks_remaining;
protected:
@@ -111,7 +110,7 @@
// 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,
+ bool GetValue( std::string& value,
struct evkeyvalq* query_args,
const std::string& key);
bool HandleURI(const std::string& model,
@@ -135,7 +134,6 @@
std::string& response);
void DeleteKeyVal(struct evkeyvalq* query_args);
-
// forward decare
class Confederate;
@@ -146,7 +144,7 @@
WebSim* ws;
public:
- Puppet( WebSim* ws, std::string name );
+ Puppet( WebSim* ws, const std::string& name );
// unique ID used as a system-wide handle for this puppet, used as
// hash table key
@@ -164,18 +162,12 @@
// create an instance of the puppet on this confederate, using the
// named puppet prototype (defined locally at the conferderate)
void AddConfederate( Confederate* conf,
- std::string
prototype );
+ const
std::string& prototype );
};
// manage a federated simulator
class Confederate
{
-// typedef struct
-// {
-// std::string name;
-// Confederate* conf;
-// } cb_chunk_t;
-
private:
// connection to a remote http simulation server
struct evhttp_connection* http_con;
@@ -187,18 +179,17 @@
WebSim* ws;
public:
- Confederate( WebSim* ws, std::string uri );
+ Confederate( WebSim* ws, const std::string& uri );
~Confederate();
void AddPuppet( Puppet* puppet,
- std::string prototype );
+ const std::string& prototype
);
- int Push( std::string name, Pose p, Velocity v, Acceleration a );
+ int Push( const std::string& name, Pose p, Velocity v, Acceleration a
);
- static void TickCb( std::string name, Confederate* conf, void* arg );
+ static void TickCb( const std::string& name, Confederate* conf, void*
arg );
static void TickReplyCb( evhttp_request* req, void* arg );
-
// send a tick request to this host
int Tick();
@@ -230,18 +221,40 @@
public:
/** Get a puppet by name */
- Puppet* GetPuppet( std::string name );
+ Puppet* GetPuppet( const std::string& name );
/** Get a confederate by its logical name */
- Confederate* GetConfederate( std::string name );
+ Confederate* GetConfederate( const std::string& name );
/** For each confederate, call the callback function */
- void ForEachConfederate( void(*cb)(std::string, Confederate*, void*), void*
arg );
+ void ForEachConfederate( void(*cb)(const std::string&, Confederate*, void*),
void* arg );
/** For each puppet, call the callback function */
- void ForEachPuppet( void(*cb)(std::string, Puppet*, void*), void* arg );
+ void ForEachPuppet( void(*cb)(const std::string&, Puppet*, void*), void* arg
);
};
+class Time
+{
+public:
+ Time( unsigned long sec, unsigned long usec ) :
+ sec(sec), usec(usec)
+ { /* nothing to do except initialize */ }
+
+ Time() : sec(0), usec(0) {}
+
+ Time( uint64_t microseconds )
+ {
+ sec = microseconds / 1e6;
+ usec = microseconds - (sec * 1e6);
+ }
+
+ unsigned long sec; ///< seconds since the start of simulation time
+ unsigned long usec; ///< millions of a second since the last whole second
+
+ /** Returns the time in a human-readable string form "sec.usec" */
+ std::string String();
+};
+
class Pose
{
public:
@@ -287,4 +300,5 @@
};
+
}
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