From 405c805f249cacb07f8861d5550abda8f6694d0c Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Tue, 26 Mar 2013 22:17:19 +0100 Subject: Various smaller bug-fixes (see details) - Pass -DPHP_CONFIG=/usr/bin/zts-php-config for custom php-config - More php bug fixes - Fixed nasty "parse from string" bug - Reindented source code --- contrib/cmake/FindPHP5.cmake | 28 +++++++---- docs/CentOS.md | 54 ++++++++++++++++++++++ src/bindings/swig/php/CMakeLists.txt | 10 ++-- src/bindings/swig/php/test.php | 46 +++++++++++++----- src/bindings/swig/php/uscxml.i | 19 ++------ src/bindings/swig/php/uscxmlNativePHP.php | 4 ++ src/uscxml/Interpreter.cpp | 26 +++++++---- src/uscxml/Interpreter.h | 12 ++--- .../plugins/element/postpone/PostponeElement.cpp | 2 +- .../plugins/invoker/http/HTTPServletInvoker.h | 4 +- .../basichttp/libevent/EventIOProcessor.h | 4 +- src/uscxml/server/HTTPServer.cpp | 6 +-- src/uscxml/server/HTTPServer.h | 4 +- src/uscxml/server/InterpreterServlet.cpp | 12 ++--- src/uscxml/server/InterpreterServlet.h | 11 +++-- test/src/test-url.cpp | 22 +++++---- 16 files changed, 185 insertions(+), 79 deletions(-) create mode 100644 docs/CentOS.md diff --git a/contrib/cmake/FindPHP5.cmake b/contrib/cmake/FindPHP5.cmake index 620c1c7..6ad81a5 100644 --- a/contrib/cmake/FindPHP5.cmake +++ b/contrib/cmake/FindPHP5.cmake @@ -1,11 +1,13 @@ if (UNIX) - find_program(PHP_CONFIG - NAMES php-config - PATHS - /usr/bin - /usr/local/bin - /opt/local/bin - ) + if (NOT PHP_CONFIG) + find_program(PHP_CONFIG + NAMES php-config + PATHS + /usr/bin + /usr/local/bin + /opt/local/bin + ) + endif() if (PHP_CONFIG) execute_process(COMMAND ${PHP_CONFIG} --includes OUTPUT_VARIABLE PHP_INCLUDE_DIRS @@ -26,7 +28,15 @@ if (UNIX) OUTPUT_VARIABLE PHP_LDFLAGS ERROR_VARIABLE PHP_LDFLAGS_errors RESULT_VARIABLE PHP_LDFLAGS_result) - + + set(PHP_ZTS_ENABLED OFF) + execute_process(COMMAND ${PHP_CONFIG} --configure-options + OUTPUT_VARIABLE PHP_CONFIGURE_OPTIONS + ERROR_VARIABLE PHP_CONFIGURE_OPTIONS_errors + RESULT_VARIABLE PHP_CONFIGURE_OPTIONS_result) + if (PHP_CONFIGURE_OPTIONS MATCHES ".*enable-maintainer-zts.*") + set(PHP_ZTS_ENABLED ON) + endif() endif() else() message(STATUS "Finding PHP5 on Windows is not supported") @@ -34,4 +44,4 @@ endif() INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(PHP5 DEFAULT_MSG PHP_CONFIG PHP_INCLUDE_DIRS PHP_LIBRARIES PHP_LDFLAGS) -MARK_AS_ADVANCED(PHP_LIBRARIES PHP_INCLUDE_DIRS PHP_LDFLAGS) +MARK_AS_ADVANCED(PHP_LIBRARIES PHP_INCLUDE_DIRS PHP_LDFLAGS PHP_ZTS_ENABLED) diff --git a/docs/CentOS.md b/docs/CentOS.md new file mode 100644 index 0000000..e70f45f --- /dev/null +++ b/docs/CentOS.md @@ -0,0 +1,54 @@ +Install CentOS +Minimal Profile +sudo yum install wget +sudo yum groupinstall "Development tools" + + +$ wget http://sourceforge.net/projects/boost/files/latest/download +$ tar xvjf boost* +$ cd boost* +$ ./bootstrap.sh +$ ./b2 --layout=tagged install + +sudo yum install libtool-ltdl-devel +sudo yum install libxml2-devel +sudo yum install libpng-devel +sudo yum install libjpeg-devel +sudo yum install libtiff-devel +sudo yum install libcurl-devel +sudo yum install mesa-libGL-devel +sudo yum install pcre-devel +sudo yum remove swig + +$ wget http://sourceforge.net/projects/openvrml/files/latest/download +$ tar xvjf openvrml* +$ cd openvrml* +$ ./configure --disable-render-text-node --disable-script-node-javascript --disable-script-node-java --disable-gl-renderer --disable-xembed --disable-player --disable-examples +$ make install + +$ wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz +$ tar xvzf cmake-2.8.10.2.tar.gz +$ cd cmake-2.8.10 +$ ./configure +$ make install + +$ svn co http://www.openscenegraph.org/svn/osg/OpenSceneGraph/tags/OpenSceneGraph-3.1.5 OpenSceneGraph +$ cd OpenSceneGraph +$ mkdir build && cd build +$ cmake .. +$ make +$ make install + +$ wget http://sourceforge.net/projects/boost/files/latest/download +$ tar xvjf swig* +$ cd swig* +$ ./configure +$ make +$ make install + +$ git clone git://github.com/tklab-tud/uscxml.git +$ cd uscxml +$ mkdir build && cd build +$ cmake .. +$ make + diff --git a/src/bindings/swig/php/CMakeLists.txt b/src/bindings/swig/php/CMakeLists.txt index 2a63bb9..17c9465 100644 --- a/src/bindings/swig/php/CMakeLists.txt +++ b/src/bindings/swig/php/CMakeLists.txt @@ -64,14 +64,18 @@ SET_SOURCE_FILES_PROPERTIES(uscxml.i PROPERTIES CPLUSPLUS ON) SWIG_ADD_MODULE(uscxmlNativePHP php5 uscxml.i) foreach(PHP_LIBRARY ${PHP_LIBRARIES}) - SWIG_LINK_LIBRARIES(uscxmlNativePHP ${PHP_LIBRARY}) +# SWIG_LINK_LIBRARIES(uscxmlNativePHP ${PHP_LIBRARY}) endforeach() +SWIG_LINK_LIBRARIES(uscxmlNativePHP uscxml) if (APPLE) set_target_properties(uscxmlNativePHP PROPERTIES LINK_FLAGS ${PHP_MODULE_CXX_FLAGS}) endif() -#set_target_properties(uscxmlNativePHP PROPERTIES LINK_FLAGS ${PHP_LDFLAGS}) + +if (PHP_ZTS_ENABLED) + # we are only building php bindings for unices anyhow + set_target_properties(uscxmlNativePHP PROPERTIES COMPILE_FLAGS "-DZTS -DPTHREADS") +endif() set_target_properties(uscxmlNativePHP PROPERTIES FOLDER "Bindings") -SWIG_LINK_LIBRARIES(uscxmlNativePHP uscxml) diff --git a/src/bindings/swig/php/test.php b/src/bindings/swig/php/test.php index 992f962..3ac64eb 100644 --- a/src/bindings/swig/php/test.php +++ b/src/bindings/swig/php/test.php @@ -2,24 +2,42 @@ require_once('uscxmlNativePHP.php'); -$exts = get_loaded_extensions(); -foreach ($exts as $e) -{ - echo "Name: ".$e." --"; - print_r(get_extension_funcs($e)); -} +// $exts = get_loaded_extensions(); +// foreach ($exts as $e) +// { +// echo "Name: ".$e." --"; +// print_r(get_extension_funcs($e)); +// } class MyMonitor extends InterpreterMonitor { + function beforeExitingStates($interpreter,$statesToExit) { + print "MyMonitor.beforeExitingStates()\n"; + } + function afterExitingStates($interpreter) { + print "MyMonitor.afterExitingStates()\n"; + } + function beforeEnteringStates($interpreter,$statesToEnter) { + print "MyMonitor.beforeEnteringStates()\n"; + } + function afterEnteringStates($interpreter) { + print "MyMonitor.afterEnteringStates()\n"; + } function onStableConfiguration($interpreter) { - print "MyMonitor.onStableConfiguration()\n"; - } + print "MyMonitor.onStableConfiguration()\n"; + } function beforeCompletion($interpreter) { - print "MyMonitor.beforeCompletion()\n"; + print "MyMonitor.beforeCompletion()\n"; } function afterCompletion($interpreter) { - print "MyMonitor.afterCompletion()\n"; + print "MyMonitor.afterCompletion()\n"; + } + function beforeMicroStep($interpreter) { + print "MyMonitor.beforeMicroStep()\n"; + } + function beforeTakingTransitions($interpreter,$transitions) { + print "MyMonitor.beforeTakingTransitions()\n"; } -}; +} $monitor = new MyMonitor(); @@ -27,4 +45,10 @@ $interpreter = Interpreter::fromURI('https://raw.github.com/tklab-tud/uscxml/mas $interpreter->addMonitor($monitor); $interpreter->interpret(); +// $interpreter = Interpreter::fromURI('https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-invoked.scxml'); +// $parentQueue = +// $interpreter->setParentQueue($parentQueue); +// $interpreter->addMonitor($monitor); +// $interpreter->interpret(); + ?> \ No newline at end of file diff --git a/src/bindings/swig/php/uscxml.i b/src/bindings/swig/php/uscxml.i index 3aafb11..edf51e0 100644 --- a/src/bindings/swig/php/uscxml.i +++ b/src/bindings/swig/php/uscxml.i @@ -1,27 +1,19 @@ %module(directors="1", allprotected="1") uscxmlNativePHP // import swig typemaps -//%include -//%include -//%include %include +// macros from cmake +%import "uscxml/config.h" + // disable warning related to unknown base class #pragma SWIG nowarn=401 -//%ignore boost::enable_shared_from_this; - -//%javaconst(1); - -# %shared_ptr(uscxml::dom::Element); -# %shared_ptr(uscxml::dom::Executable); - //************************************************** // This ends up in the generated wrapper code //************************************************** %{ - #include "../../../uscxml/Message.h" #include "../../../uscxml/Interpreter.h" @@ -29,12 +21,12 @@ using namespace uscxml; %} +// Add this to the very top of the generated wrapper code + %insert("begin") %{ void*** tsrm_ls; %} -//%rename(toString) operator<<; - %feature("director") uscxml::InterpreterMonitor; //*********************************************** @@ -43,4 +35,3 @@ void*** tsrm_ls; %include "../../../uscxml/Message.h" %include "../../../uscxml/Interpreter.h" - diff --git a/src/bindings/swig/php/uscxmlNativePHP.php b/src/bindings/swig/php/uscxmlNativePHP.php index 3b34dc9..6bab7af 100644 --- a/src/bindings/swig/php/uscxmlNativePHP.php +++ b/src/bindings/swig/php/uscxmlNativePHP.php @@ -26,6 +26,10 @@ if (!extension_loaded('uscxmlNativePHP')) { +abstract class uscxmlNativePHP { + const ZTS = ZTS; +} + /* PHP Proxy Classes */ class Data { public $_cPtr=null; diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 0bc0f2e..ef30033 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -60,10 +60,12 @@ Interpreter* Interpreter::fromDOM(const Arabica::DOM::Node& node) { } Interpreter* Interpreter::fromXML(const std::string& xml) { - std::istringstream is(xml); - is.seekg(0); + std::stringstream* ss = new std::stringstream(); + (*ss) << xml; + // we need an auto_ptr for arabica to assume ownership + std::auto_ptr ssPtr(ss); Arabica::SAX::InputSource inputSource; - inputSource.setByteStream(is); + inputSource.setByteStream(ssPtr); return fromInputSource(inputSource); } @@ -75,25 +77,29 @@ Interpreter* Interpreter::fromURI(const std::string& uri) { return NULL; } } - Arabica::SAX::InputSource inputSource; + + Interpreter* interpreter = NULL; // this is required for windows filenames and does not harm on unices if (boost::iequals(absUrl.scheme(), "file")) { + Arabica::SAX::InputSource inputSource; inputSource.setSystemId(absUrl.path()); + interpreter = fromInputSource(inputSource); } else if (boost::iequals(absUrl.scheme(), "http")) { // handle http per arabica + Arabica::SAX::InputSource inputSource; inputSource.setSystemId(absUrl.asString()); + interpreter = fromInputSource(inputSource); } else { // use curl for everything else std::stringstream ss; ss << absUrl; if (absUrl.downloadFailed()) { + LOG(ERROR) << "Downloading SCXML document from " << absUrl << " failed"; return NULL; } - ss.seekg(0); - inputSource.setByteStream(ss); + interpreter = fromXML(ss.str()); } - Interpreter* interpreter = fromInputSource(inputSource); // try to establish URI root for relative src attributes in document if (interpreter) @@ -282,7 +288,7 @@ void Interpreter::interpret() { if (!_scxml) return; // dump(); - + _sessionId = getUUID(); std::string datamodelName; @@ -2547,7 +2553,7 @@ void Interpreter::setupIOProcessors() { ioProcIter++; continue; } - + _ioProcessors[ioProcIter->first] = Factory::createIOProcessor(ioProcIter->first, this); _ioProcessors[ioProcIter->first].setType(ioProcIter->first); _ioProcessors[ioProcIter->first].setInterpreter(this); @@ -2690,4 +2696,4 @@ void Interpreter::dump() { } -} \ No newline at end of file +} diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index 9929f70..d60a7e4 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -79,11 +79,11 @@ public: }; enum Capabilities { - CAN_NOTHING = 0, - CAN_BASIC_HTTP = 1, - CAN_GENERIC_HTTP = 2, + CAN_NOTHING = 0, + CAN_BASIC_HTTP = 1, + CAN_GENERIC_HTTP = 2, }; - + virtual ~Interpreter(); static Interpreter* fromDOM(const Arabica::DOM::Node& node); @@ -173,7 +173,7 @@ public: void setCapabilities(unsigned int capabilities) { _capabilities = capabilities; } - + void setName(const std::string& name); const std::string& getName() { return _name; @@ -320,7 +320,7 @@ protected: std::string _name; std::string _sessionId; unsigned int _capabilities; - + Data _cmdLineOptions; IOProcessor getIOProcessor(const std::string& type); diff --git a/src/uscxml/plugins/element/postpone/PostponeElement.cpp b/src/uscxml/plugins/element/postpone/PostponeElement.cpp index 53782e1..baa8e62 100644 --- a/src/uscxml/plugins/element/postpone/PostponeElement.cpp +++ b/src/uscxml/plugins/element/postpone/PostponeElement.cpp @@ -45,7 +45,7 @@ void PostponeElement::enterElement(const Arabica::DOM::Node& node) if (HAS_ATTR(node, "chaining")) { chained = boost::iequals(ATTR(node, "chaining"), "true"); } - + // when will we refire the event? std::string until; try { diff --git a/src/uscxml/plugins/invoker/http/HTTPServletInvoker.h b/src/uscxml/plugins/invoker/http/HTTPServletInvoker.h index ad89fee..229ead5 100644 --- a/src/uscxml/plugins/invoker/http/HTTPServletInvoker.h +++ b/src/uscxml/plugins/invoker/http/HTTPServletInvoker.h @@ -34,7 +34,9 @@ public: virtual void setURL(const std::string& url) { _url = url; } - bool canAdaptPath() { return false; } + bool canAdaptPath() { + return false; + } protected: tthread::recursive_mutex _mutex; diff --git a/src/uscxml/plugins/ioprocessor/basichttp/libevent/EventIOProcessor.h b/src/uscxml/plugins/ioprocessor/basichttp/libevent/EventIOProcessor.h index 9bb717b..5446624 100644 --- a/src/uscxml/plugins/ioprocessor/basichttp/libevent/EventIOProcessor.h +++ b/src/uscxml/plugins/ioprocessor/basichttp/libevent/EventIOProcessor.h @@ -43,7 +43,9 @@ public: _url = url; } - bool canAdaptPath() { return false; } + bool canAdaptPath() { + return false; + } // URLMonitor void downloadStarted(const URL& url); diff --git a/src/uscxml/server/HTTPServer.cpp b/src/uscxml/server/HTTPServer.cpp index dd06ab7..0d5feee 100644 --- a/src/uscxml/server/HTTPServer.cpp +++ b/src/uscxml/server/HTTPServer.cpp @@ -218,7 +218,7 @@ void HTTPServer::httpRecvReqCallback(struct evhttp_request *req, void *callbackD request.data.compound["content"] = Data::fromJSON(request.data.compound["content"].atom); } } - + if (callbackData == NULL) { HTTPServer::getInstance()->processByMatchingServlet(request); } else { @@ -237,7 +237,7 @@ void HTTPServer::processByMatchingServlet(const Request& request) { // is the servlet path a prefix of the actual path? std::string servletPath = "/" + servletIter->first; if (boost::iequals(actualPath.substr(0, servletPath.length()), servletPath) && // actual path is a prefix - boost::iequals(actualPath.substr(servletPath.length(), 1), "/")) { // and next character is a '/' + boost::iequals(actualPath.substr(servletPath.length(), 1), "/")) { // and next character is a '/' if (bestPath.length() < servletPath.length()) { // this servlet is a better match bestPath = servletPath; @@ -307,7 +307,7 @@ bool HTTPServer::registerServlet(const std::string& path, HTTPServlet* servlet) if (boost::starts_with(actualPath, "/")) actualPath = actualPath.substr(1); std::string suffixedPath = actualPath; - + // if this servlet allows to adapt the path, do so int i = 2; while(INSTANCE->_servlets.find(suffixedPath) != INSTANCE->_servlets.end()) { diff --git a/src/uscxml/server/HTTPServer.h b/src/uscxml/server/HTTPServer.h index 990d0a7..7356737 100644 --- a/src/uscxml/server/HTTPServer.h +++ b/src/uscxml/server/HTTPServer.h @@ -83,7 +83,9 @@ private: class HTTPServlet { public: virtual void httpRecvRequest(const HTTPServer::Request& request) = 0; - virtual bool canAdaptPath() { return true; } + virtual bool canAdaptPath() { + return true; + } virtual void setURL(const std::string& url) = 0; /// Called by the server with the actual URL }; diff --git a/src/uscxml/server/InterpreterServlet.cpp b/src/uscxml/server/InterpreterServlet.cpp index fb8a6ef..e537275 100644 --- a/src/uscxml/server/InterpreterServlet.cpp +++ b/src/uscxml/server/InterpreterServlet.cpp @@ -2,10 +2,10 @@ #include "uscxml/Interpreter.h" namespace uscxml { - + InterpreterServlet::InterpreterServlet(Interpreter* interpreter) { _interpreter = interpreter; - + std::stringstream path; path << _interpreter->getName(); int i = 2; @@ -19,13 +19,13 @@ InterpreterServlet::InterpreterServlet(Interpreter* interpreter) { void InterpreterServlet::httpRecvRequest(const HTTPServer::Request& req) { tthread::lock_guard lock(_mutex); - + // evhttp_request_own(req.curlReq); - + _requests[toStr((uintptr_t)req.curlReq)] = req; - + Event event = req; - + event.name = "http." + event.data.compound["type"].atom; event.origin = toStr((uintptr_t)req.curlReq); _interpreter->receive(event); diff --git a/src/uscxml/server/InterpreterServlet.h b/src/uscxml/server/InterpreterServlet.h index 7235466..72f2f67 100644 --- a/src/uscxml/server/InterpreterServlet.h +++ b/src/uscxml/server/InterpreterServlet.h @@ -6,10 +6,11 @@ namespace uscxml { class Interpreter; - + class InterpreterServlet : public HTTPServlet { public: InterpreterServlet(Interpreter* interpreter); + virtual ~InterpreterServlet() {} virtual void httpRecvRequest(const HTTPServer::Request& req); std::string getPath() { @@ -21,7 +22,9 @@ public: void setURL(const std::string& url) { _url = url; } - bool canAdaptPath() { return false; } + bool canAdaptPath() { + return false; + } std::map& getRequests() { return _requests; @@ -32,14 +35,14 @@ public: protected: Interpreter* _interpreter; - + tthread::recursive_mutex _mutex; std::map _requests; std::string _path; std::string _url; }; - + } diff --git a/test/src/test-url.cpp b/test/src/test-url.cpp index f2d0cb9..3165a20 100644 --- a/test/src/test-url.cpp +++ b/test/src/test-url.cpp @@ -13,10 +13,14 @@ using namespace boost; class TestServlet : public HTTPServlet { public: TestServlet(bool adaptPath) : _canAdaptPath(adaptPath) {} - + void httpRecvRequest(const HTTPServer::Request& request) {}; - bool canAdaptPath() { return _canAdaptPath; } - void setURL(const std::string& url) { _actualUrl = url; } + bool canAdaptPath() { + return _canAdaptPath; + } + void setURL(const std::string& url) { + _actualUrl = url; + } std::string _actualUrl; bool _canAdaptPath; @@ -34,13 +38,13 @@ int main(int argc, char** argv) { { TestServlet* testServlet1 = new TestServlet(false); TestServlet* testServlet2 = new TestServlet(false); - + assert(HTTPServer::registerServlet("/foo", testServlet1)); assert(!HTTPServer::registerServlet("/foo", testServlet2)); HTTPServer::unregisterServlet(testServlet1); assert(HTTPServer::registerServlet("/foo", testServlet2)); HTTPServer::unregisterServlet(testServlet1); - + assert(HTTPServer::registerServlet("/foo/bar/", testServlet1)); assert(!HTTPServer::registerServlet("/foo/bar/", testServlet2)); HTTPServer::unregisterServlet(testServlet1); @@ -51,7 +55,7 @@ int main(int argc, char** argv) { TestServlet* testServlet1 = new TestServlet(true); TestServlet* testServlet2 = new TestServlet(true); TestServlet* testServlet3 = new TestServlet(true); - + assert(HTTPServer::registerServlet("/foo", testServlet1)); assert(HTTPServer::registerServlet("/foo", testServlet2)); assert(HTTPServer::registerServlet("/foo", testServlet3)); @@ -63,7 +67,7 @@ int main(int argc, char** argv) { HTTPServer::unregisterServlet(testServlet2); HTTPServer::unregisterServlet(testServlet3); } - + { Data data = Data::fromJSON("asdf"); std::cout << data << std::endl; @@ -93,7 +97,7 @@ int main(int argc, char** argv) { std::stringstream content; content << url; } - + { URL url("https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-ecmascript.scxml"); std::cout << url.asString() << std::endl; @@ -102,7 +106,7 @@ int main(int argc, char** argv) { std::stringstream content; content << url; } - + { URL url("file:Document/Text.foo"); std::cout << url.asString() << std::endl; -- cgit v0.12