Revision: 7381
http://playerstage.svn.sourceforge.net/playerstage/?rev=7381&view=rev
Author: gerkey
Date: 2009-03-08 03:27:54 +0000 (Sun, 08 Mar 2009)
Log Message:
-----------
First cut at webgazebo
Modified Paths:
--------------
code/branches/federation/gazebo/SConstruct
Added Paths:
-----------
code/branches/federation/gazebo/webgazebo/
code/branches/federation/gazebo/webgazebo/README
code/branches/federation/gazebo/webgazebo/SConscript
code/branches/federation/gazebo/webgazebo/WebGazebo.cc
code/branches/federation/gazebo/webgazebo/WebGazebo.hh
code/branches/federation/gazebo/webgazebo/main.cc
Modified: code/branches/federation/gazebo/SConstruct
===================================================================
--- code/branches/federation/gazebo/SConstruct 2009-03-08 02:57:32 UTC (rev
7380)
+++ code/branches/federation/gazebo/SConstruct 2009-03-08 03:27:54 UTC (rev
7381)
@@ -143,8 +143,10 @@
# DEFAULT list of subdirectories to build
#######
subdirs = ['libgazebo','server', 'player']
+# Disabled, pending test for <event.h>
+if False:
+ subdirs.append('webgazebo')
-
#######
# Generate help text
#######
Added: code/branches/federation/gazebo/webgazebo/README
===================================================================
--- code/branches/federation/gazebo/webgazebo/README
(rev 0)
+++ code/branches/federation/gazebo/webgazebo/README 2009-03-08 03:27:54 UTC
(rev 7381)
@@ -0,0 +1,3 @@
+webgazebo is an HTTP interface to Gazebo. It uses libgazebo to talk to
+a Gazebo simulation, and libevent to provide an HTTP socket to the outside
+world.
Added: code/branches/federation/gazebo/webgazebo/SConscript
===================================================================
--- code/branches/federation/gazebo/webgazebo/SConscript
(rev 0)
+++ code/branches/federation/gazebo/webgazebo/SConscript 2009-03-08
03:27:54 UTC (rev 7381)
@@ -0,0 +1,48 @@
+#Import variable
+Import('*')
+
+env.Append(CPPPATH = '#webgazebo')
+
+libEnv = Environment (
+ CC = 'g++',
+ CCFLAGS = Split ('-pipe -W -Wall -g'),
+
+ #CXXCOMSTR = 'Compiling $TARGET',
+ #CCCOMSTR = 'Compiling $TARGET',
+
+ #SHCXXCOMSTR = 'Compiling $TARGET',
+ #SHCCCOMSTR = 'Compiling $TARGET',
+
+ #SHLINKCOMSTR = 'Linking $TARGET',
+ #LINKCOMSTR = 'Linking $TARGET',
+
+ LIBS=Split('event'),
+)
+
+sources = Split('WebGazebo.cc')
+headers = Split('WebGazebo.hh')
+
+sharedLib = libEnv.SharedLibrary('webgazebo', sources)
+staticLib = libEnv.StaticLibrary('webgazebo', sources)
+
+import os
+
+exeEnv = Environment (
+ CC = 'g++',
+ CCFLAGS = Split ('-pipe -W -Wall -g'),
+
+ #CXXCOMSTR = 'Compiling $TARGET',
+ #CCCOMSTR = 'Compiling $TARGET',
+
+ #SHCXXCOMSTR = 'Compiling $TARGET',
+ #SHCCCOMSTR = 'Compiling $TARGET',
+
+ #SHLINKCOMSTR = 'Linking $TARGET',
+ #LINKCOMSTR = 'Linking $TARGET',
+
+ LIBS=Split('webgazebo event'),
+ LIBPATH=Split(os.getcwd()),
+ CPPPATH=Split('#.')
+)
+
+webgazebo = exeEnv.Program('webgazebo', 'main.cc')
Added: code/branches/federation/gazebo/webgazebo/WebGazebo.cc
===================================================================
--- code/branches/federation/gazebo/webgazebo/WebGazebo.cc
(rev 0)
+++ code/branches/federation/gazebo/webgazebo/WebGazebo.cc 2009-03-08
03:27:54 UTC (rev 7381)
@@ -0,0 +1,34 @@
+#include "WebGazebo.hh"
+
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+
+WebGazebo::WebGazebo(std::string _host, int _port) :
+ host(_host), port(_port)
+{
+ // Not sure whether it's safe to do this more that once in one process
+ event_init();
+
+ this->eh = evhttp_start(this->host.c_str(), this->port);
+ assert(eh);
+}
+
+WebGazebo::~WebGazebo()
+{
+ // No event_fini() to call...
+}
+
+void
+WebGazebo::GenericURICallback(evhttp_request* req, void* arg)
+{
+ WebGazebo* obj = (WebGazebo*)arg;
+
+ printf("in server cb for uri:%s:\n", req->uri);
+ struct evbuffer* eb = evbuffer_new();
+ assert(eb);
+ evbuffer_add_printf(eb, "response for:%s:\n", req->uri);
+ evhttp_send_reply(req, 200, "foo", eb);
+ evbuffer_free(eb);
+}
+
Added: code/branches/federation/gazebo/webgazebo/WebGazebo.hh
===================================================================
--- code/branches/federation/gazebo/webgazebo/WebGazebo.hh
(rev 0)
+++ code/branches/federation/gazebo/webgazebo/WebGazebo.hh 2009-03-08
03:27:54 UTC (rev 7381)
@@ -0,0 +1,26 @@
+#include <string>
+
+// 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>
+
+class WebGazebo
+{
+ public:
+ WebGazebo(std::string _host, int _port);
+ ~WebGazebo();
+
+ private:
+ std::string host;
+ int port;
+
+ struct evhttp* eh;
+
+ // Static, so that it can be passed as a callback to libevent
+ static void GenericURICallback(evhttp_request* req, void* arg);
+};
+
Added: code/branches/federation/gazebo/webgazebo/main.cc
===================================================================
--- code/branches/federation/gazebo/webgazebo/main.cc
(rev 0)
+++ code/branches/federation/gazebo/webgazebo/main.cc 2009-03-08 03:27:54 UTC
(rev 7381)
@@ -0,0 +1,62 @@
+#include "webgazebo/WebGazebo.hh"
+
+#include <stdlib.h>
+
+#define USAGE "USAGE: webgazebo [-h <host>] [-p <port>]"
+
+int g_port;
+std::string g_host;
+
+bool ParseArgs(int argc, char** argv);
+
+int
+main(int argc, char** argv)
+{
+ //evhttp_set_gencb(eh, cb, NULL);
+ //evhttp_set_cb(eh, "/foo", cb, NULL);
+
+ //event_dispatch();
+
+ if(!ParseArgs(argc, argv))
+ {
+ fputs(USAGE, stderr);
+ exit(1);
+ }
+
+ WebGazebo wg(g_host, g_port);
+
+ return 0;
+}
+
+bool
+ParseArgs(int argc, char** argv)
+{
+ char *flags = (char*)("p:h:");
+ int ch;
+
+ while ((ch = getopt(argc, argv, flags)) != -1)
+ {
+ switch(ch)
+ {
+ // port
+ case 'p':
+ if(!optarg)
+ return false;
+ g_port = atoi(optarg);
+ break;
+ // host
+ case 'h':
+ if(!optarg)
+ return false;
+ g_host = optarg;
+ break;
+ default:
+ return false;
+ }
+ }
+
+ if((g_host.size() == 0) || (g_port == 0))
+ return false;
+
+ return true;
+}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit