Revision: 7425
http://playerstage.svn.sourceforge.net/playerstage/?rev=7425&view=rev
Author: gerkey
Date: 2009-03-10 05:38:39 +0000 (Tue, 10 Mar 2009)
Log Message:
-----------
updated to work with webgazebo
Modified Paths:
--------------
code/websim/include/websim/websim.h
code/websim/src/websim.cc
Modified: code/websim/include/websim/websim.h
===================================================================
--- code/websim/include/websim/websim.h 2009-03-10 03:19:57 UTC (rev 7424)
+++ code/websim/include/websim/websim.h 2009-03-10 05:38:39 UTC (rev 7425)
@@ -50,7 +50,7 @@
WebSim(const std::string& _fedfile,
const std::string& _host,
int _port);
- ~WebSim();
+ virtual ~WebSim();
void Update();
@@ -60,17 +60,22 @@
std::string& error) = 0;
virtual bool DeleteModel(const std::string& name,
std::string& error) = 0;
- virtual bool SetModelState(const std::string& name,
- const Pose& p,
- const Velocity& v,
- const Acceleration& a,
- std::string& error) = 0;
- virtual bool GetModelState(const std::string& name,
- Pose& p,
- Velocity& v,
- Acceleration& a,
- std::string& error) = 0;
+ virtual bool SetModelPVA(const std::string& name,
+ const Pose& p,
+ const Velocity& v,
+ const Acceleration& a,
+ std::string& error) = 0;
+ virtual bool GetModelPVA(const std::string& name,
+ Pose& p,
+ Velocity& v,
+ Acceleration& a,
+ std::string& error) = 0;
+ protected:
+ void StringSplit(const std::string &s,
+ std::vector<std::string> &t,
+ const std::string &d);
+
private:
std::string fedfile;
std::string host;
@@ -81,9 +86,6 @@
// Static, so that it can be passed as a callback to libevent
static void EventCallback(evhttp_request* req, void* arg);
- void StringSplit(const std::string &s,
- std::vector<std::string> &t,
- const std::string &d);
bool GetValue(std::string& value,
struct evkeyvalq* query_args,
const std::string& key);
Modified: code/websim/src/websim.cc
===================================================================
--- code/websim/src/websim.cc 2009-03-10 03:19:57 UTC (rev 7424)
+++ code/websim/src/websim.cc 2009-03-10 05:38:39 UTC (rev 7425)
@@ -190,7 +190,7 @@
Pose p;
Velocity v;
Acceleration a;
- if(GetModelState(model, p, v, a, response))
+ if(GetModelPVA(model, p, v, a, response))
{
char buf[1024];
snprintf(buf, sizeof(buf),
@@ -218,7 +218,7 @@
}
else if(action == "set")
{
- if(prop == "pose")
+ if(prop == "pva")
{
std::string sx, sy, sz, sroll, spitch, syaw;
@@ -226,24 +226,24 @@
Pose p;
Velocity v;
Acceleration a;
- if(!GetModelState(model, p, v, a, response))
+ if(!GetModelPVA(model, p, v, a, response))
{
response = "Failed to get pose before setting it";
return false;
}
try
{
- if(GetValue(sx, kv, "x"))
+ if(GetValue(sx, kv, "px"))
p.x = boost::lexical_cast<float>(sx);
- if(GetValue(sy, kv, "y"))
+ if(GetValue(sy, kv, "py"))
p.y = boost::lexical_cast<float>(sy);
- if(GetValue(sz, kv, "z"))
+ if(GetValue(sz, kv, "pz"))
p.z = boost::lexical_cast<float>(sz);
- if(GetValue(sroll, kv, "r"))
+ if(GetValue(sroll, kv, "pr"))
p.r = boost::lexical_cast<float>(sroll);
- if(GetValue(spitch, kv, "p"))
+ if(GetValue(spitch, kv, "pp"))
p.p = boost::lexical_cast<float>(spitch);
- if(GetValue(syaw, kv, "a"))
+ if(GetValue(syaw, kv, "pa"))
p.a = boost::lexical_cast<float>(syaw);
if(GetValue(sx, kv, "vx"))
@@ -279,7 +279,7 @@
return false;
}
- return(SetModelState(model, p, v, a, response));
+ return(SetModelPVA(model, p, v, a, response));
}
else
{
@@ -293,3 +293,74 @@
return false;
}
}
+
+void
+WebSim::EventCallback(evhttp_request* req, void* arg)
+{
+ WebSim* obj = (WebSim*)arg;
+
+ // Pull out query args
+ struct evkeyvalq query_args;
+ evhttp_parse_query(req->uri, &query_args);
+
+ struct evbuffer* eb = evbuffer_new();
+ assert(eb);
+
+ int response_code;
+ std::string response_string;
+ std::string model, prop, action, response;
+ if(!obj->ParseURI(model, prop, action, req->uri, response))
+ {
+ response_code = 400;
+ response_string = "Invalid request";
+ }
+ else if(!obj->HandleURI(model, prop, action, &query_args, response))
+ {
+ response_code = 400;
+ response_string = "Invalid request";
+ }
+ else
+ {
+ response_code = 200;
+ response_string = "OK";
+ }
+
+ evbuffer_add_printf(eb, "%s\n", response.c_str());
+ /*
+ printf("[webgazebo] Sending reply: %d %s\n",
+ response_code, response_string.c_str());
+ */
+ evhttp_send_reply(req, response_code, response_string.c_str(), eb);
+ evbuffer_free(eb);
+
+ obj->DeleteKeyVal(&query_args);
+}
+
+bool
+WebSim::ParseURI(std::string& model,
+ std::string& prop,
+ std::string& action,
+ std::string uri,
+ std::string& response)
+{
+ // Remove the query args
+ std::vector<std::string> uri_parts;
+ StringSplit(uri, uri_parts, "?");
+ assert(uri_parts.size() > 0);
+ std::string bare_uri = uri_parts[0];
+
+ // We require 3 path components: model/property/action
+ StringSplit(bare_uri, uri_parts, "/");
+ // There should be 4 parts, with the first one empty
+ if(uri_parts.size() != 4)
+ {
+ response = "Must be 3 slash-separated parts in the URI";
+ return false;
+ }
+
+ model = uri_parts[1];
+ prop = uri_parts[2];
+ action = uri_parts[3];
+
+ return true;
+}
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