Revision: 8259 http://playerstage.svn.sourceforge.net/playerstage/?rev=8259&view=rev Author: rtv Date: 2009-09-14 17:26:16 +0000 (Mon, 14 Sep 2009)
Log Message: ----------- new functionality Modified Paths: -------------- code/websim/CMakeLists.txt code/websim/src/req_sim.cc code/websim/src/websim.cc code/websim/src/websim.hh Added Paths: ----------- code/websim/COPYING.txt code/websim/README.txt code/websim/img/ code/websim/img/favicon.ico Modified: code/websim/CMakeLists.txt =================================================================== --- code/websim/CMakeLists.txt 2009-09-11 23:13:24 UTC (rev 8258) +++ code/websim/CMakeLists.txt 2009-09-14 17:26:16 UTC (rev 8259) @@ -149,19 +149,15 @@ -#INSTALL (FILES README.txt COPYING.txt DESTINATION .) -INSTALL (FILES DESTINATION .) +INSTALL (FILES DESTINATION .) SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "WebSim") -#SET(CPACK_PACKAGE_DESCRIPTION_FILE "/home/abbas/websim/README.txt") -#SET(CPACK_RESOURCE_FILE_LICENSE "/home/abbas/websim/COPYING.txt") -#SET(CPACK_RESOURCE_FILE_README "/home/abbas/websim/README.txt") -SET(CPACK_PACKAGE_VERSION_MAJOR "0") -SET(CPACK_PACKAGE_VERSION_MINOR "1") -SET(CPACK_PACKAGE_VERSION_PATCH "0") -SET(CPACK_PACKAGE_VERSION "0.1") -SET(CPACK_PACKAGE_VENDOR "Richard Vaughan") +SET(CPACK_PACKAGE_VENDOR "The Player Project") +# SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.txt") +SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.txt") +SET(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.txt") +SET(CPACK_PACKAGE_VERSION_MAJOR ${V_MAJOR}) +SET(CPACK_PACKAGE_VERSION_MINOR ${V_MINOR}) +SET(CPACK_PACKAGE_VERSION_PATCH ${V_BUGFIX}) SET(CPACK_NSIS_DISPLAY_NAME "WebSim 0.1") - - INCLUDE(CPack) Added: code/websim/COPYING.txt =================================================================== --- code/websim/COPYING.txt (rev 0) +++ code/websim/COPYING.txt 2009-09-14 17:26:16 UTC (rev 8259) @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. Property changes on: code/websim/COPYING.txt ___________________________________________________________________ Added: svn:eol-style + native Added: code/websim/README.txt =================================================================== --- code/websim/README.txt (rev 0) +++ code/websim/README.txt 2009-09-14 17:26:16 UTC (rev 8259) @@ -0,0 +1,16 @@ + +WebSim +====== + +A C++ library that implements an HTTP interface to robot simulators. + +Authors +------- ++ Richard Vaughan ++ Brian Gerkey ++ Nate Koenig ++ Abbas Sadat + +Thanks +------- +WebSim's development was supported by Greg Broten and Simon Monkton of Defense R&D Canada, Suffield. Property changes on: code/websim/README.txt ___________________________________________________________________ Added: svn:eol-style + native Added: code/websim/img/favicon.ico =================================================================== (Binary files differ) Property changes on: code/websim/img/favicon.ico ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: code/websim/src/req_sim.cc =================================================================== --- code/websim/src/req_sim.cc 2009-09-11 23:13:24 UTC (rev 8258) +++ code/websim/src/req_sim.cc 2009-09-14 17:26:16 UTC (rev 8259) @@ -2,12 +2,10 @@ #include <stdlib.h> using namespace websim; -const double TICK_INTERVAL = 1.0; +const uint32_t TICK_INTERVAL = 100; // 100 msec // todo: XML format for more sim requests - - bool WebSim::HandleSimRequest(const std::string& prop, const std::string& action, Format format, @@ -78,29 +76,23 @@ std::vector<std::string> links; GenerateSampleUrls(links); - //replacing 'HOST' by actual 'host:port' term - for(unsigned int j=0;j<links.size();j++){ - unsigned int i=0; - i = links[j].find("HOST"); - while(i!=std::string::npos){ + std::string clockuri = "http://" + hostportname + "/sim/clock/get"; - links[j].replace(i, 4, hostportname); - i = links[j].find("HOST"); - } - } - response = "<html><head><title>WebSim</title></head>" "<body>" "<h1>Welcome to " + IdentificationString() + "</h1>" "<p>" + package + "-" + version + " HTTP interface to " + IdentificationString() + "-" + VersionString() + "</h1>" - "<hr>"; + "<hr>" + "Example URIs available at this server:<br>" + "<ul>" + "<li><a href=" + clockuri + ">" + clockuri + "</a>"; for(unsigned int k=0;k<links.size();k++) - response += links[k]; + response += "<li>" + links[k] + "</li>"; - response +="<hr>" + response +="</ul><hr>" "<p><a href=\"http://playerstage.org/index.php?src=websim\">WebSim</a>" " is part of the <a href=\"http://playerstage.org\">Player Project</a>" "</body></html>"; @@ -279,52 +271,35 @@ return false; } -void WebSim::GenerateSampleUrls(std::vector<std::string> &list){ - +void WebSim::GenerateSampleUrls(std::vector<std::string> &list) +{ std::vector<std::string> sensors; std::vector<std::string> temp; - - + GetModelChildren("",temp); - while(temp.size()>0 && sensors.size() < 50){ - - std::string m = temp.at(0); - temp.erase(temp.begin()); - - unsigned int size = temp.size(); - GetModelChildren(m, temp); - if(temp.size()==size){ - - sensors.push_back(m); - - } - - - } - - bool laser=false,ranger=false,fiducial=false; - - - for(unsigned int i=0;i<sensors.size();i++){ - - if(sensors[i].find("laser")!=std::string::npos && !laser){ - list.push_back("<a href=http://HOST/"+sensors[i]+"/data/get > http://HOST/"+sensors[i]+"/data/get</a> <br>"); - laser = true; - } - - if(sensors[i].find("fiducial")!=std::string::npos && !fiducial){ - list.push_back("<a href=http://HOST/"+sensors[i]+"/data/get > http://HOST/"+sensors[i]+"/data/get</a> <br>"); - fiducial = true; - } - - if((sensors[i].find("ranger")!=std::string::npos || sensors[i].find("irarray")!=std::string::npos) && !ranger){ - list.push_back("<a href=http://HOST/"+sensors[i]+"/data/get > http://HOST/"+sensors[i]+"/data/get</a> <br>"); - ranger = true; - } + + while(temp.size()>0 && sensors.size() < 50) + { + std::string m = temp.at(0); + temp.erase(temp.begin()); - - } - + unsigned int size = temp.size(); + GetModelChildren(m, temp); + + if(temp.size()==size) + sensors.push_back(m); + } + + char* names[] = { "laser", "ranger", "fiducial" }; + unsigned int index = 0; + + for(unsigned int i=0;i<sensors.size();i++) + if(sensors[i].find( names[index] )!=std::string::npos ) + { + std::string uri = "http://" + hostportname + "/"+sensors[i]+"/data/get"; + list.push_back( "<a href=" + uri + ">" + uri + "</a> <br>"); + index++; + } } Modified: code/websim/src/websim.cc =================================================================== --- code/websim/src/websim.cc 2009-09-11 23:13:24 UTC (rev 8258) +++ code/websim/src/websim.cc 2009-09-14 17:26:16 UTC (rev 8259) @@ -32,6 +32,9 @@ #include <string.h> #include <libxml/encoding.h> +#include <iostream> +#include <fstream> + #include "websim.hh" using namespace websim; @@ -104,39 +107,24 @@ } } -void WebSim::Confederate::TickCb( const std::string& name, Confederate* conf, void* arg ) -{ - conf->Tick(); -} - void -WebSim::Go() +WebSim::Tick() { // tick all my confederates - //ForEachConfederate( Confederate::TickCb, NULL ); - - for( std::map<std::string,Confederate*>::iterator it = confederates.begin(); - it != confederates.end(); - it++ ) - it->second->Tick(); + std::map<std::string,Confederate*>::iterator it; + for( it = confederates.begin(); it != confederates.end(); it++ ) + it->second->Tick(); } void WebSim::Wait() { - 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 ); + 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 ); + } } void @@ -272,8 +260,8 @@ return out; } +static const char* FAVICONFILE = "favicon.ico"; - void WebSim::EventCallback(evhttp_request* req, void* arg) { @@ -290,6 +278,43 @@ std::string response_string; std::string model, prop, action, response; puts(req->uri); + + static char* favicon_data = NULL; + static int favicon_data_len = 0; + + // handle favicon requests + if( strcmp( req->uri, "/favicon.ico" ) == 0 ) + { + if( ! favicon_data ) + { + std::ifstream in; + in.open( FAVICONFILE, std::ios::binary ); + + if( in.fail() ) + { + evhttp_send_reply( req, 400, "File not found", eb ); + evbuffer_free(eb); + return; + } + else + { + puts( "loading favicon" ); + in.seekg( 0, std::ios::end ); + favicon_data_len = in.tellg(); + in.seekg( 0, std::ios::beg ); + + favicon_data = new char[favicon_data_len]; + in.read( favicon_data, favicon_data_len ); + } + } + + // we now have good favicon data + evbuffer_add( eb, favicon_data, favicon_data_len ); + evhttp_send_reply( req, 200, "OK", eb ); + evbuffer_free(eb); + return; + } + if(!obj->ParseURI(model, prop, action, req->uri, response)) { response_code = 400; Modified: code/websim/src/websim.hh =================================================================== --- code/websim/src/websim.hh 2009-09-11 23:13:24 UTC (rev 8258) +++ code/websim/src/websim.hh 2009-09-14 17:26:16 UTC (rev 8259) @@ -68,11 +68,11 @@ void LoadFederationFile( const std::string& filename ); /** Wait for go signals from all confederates */ - void Wait(); - - /** Send go signals to all confederates */ - void Go(); + virtual void Wait(); + /** Run one simulation step on all confederates */ + void Tick(); + // Interface to be implemented by simulators ========================================================== /** Return a string that usefully identifies the simulator for a @@ -101,9 +101,9 @@ whether or not the clock is currently paused. WebSim uses this to implement clock synchronization in simulator federation, but it can also be used by end-users. - @param seconds The amount of simulated time to run until pausing, in seconds. + @param msec The amount of simulated time to run until pausing, in milliseconds. */ - virtual bool ClockRunFor( double seconds )=0; + virtual bool ClockRunFor( uint32_t msec )=0; /** Create a model of the specified type */ virtual bool CreateModel(const std::string& name, @@ -116,7 +116,7 @@ /** Gets the type of the model from simulation. @param name The name of the model - @param tyep the type of the model + @param type the type of the model @returns TRUE if the method is successful. */ @@ -542,7 +542,6 @@ int Push( const std::string& name, Pose p, Velocity v, Acceleration a ); - 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 @@ -550,7 +549,6 @@ // list of pointers to Puppet objects that are hosted on this // connection - can iterate over these to update all puppets - //GList* puppet_list; std::list<Puppet*> puppet_list; // unique ID for this confederate in format "hostname:port", used as This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit