From a1dd0a039f6579793bf5272898609b29f19a49c2 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Fri, 22 Mar 2013 18:31:52 +0100 Subject: Added php directors and fixed Interpreter::fromString --- src/bindings/swig/php/test.php | 22 +- src/bindings/swig/php/uscxmlNativePHP.php | 654 ++++++++++++++++++++++++++++++ src/uscxml/Interpreter.cpp | 9 +- test/src/test-url.cpp | 9 +- 4 files changed, 690 insertions(+), 4 deletions(-) create mode 100644 src/bindings/swig/php/uscxmlNativePHP.php diff --git a/src/bindings/swig/php/test.php b/src/bindings/swig/php/test.php index 598c559..992f962 100644 --- a/src/bindings/swig/php/test.php +++ b/src/bindings/swig/php/test.php @@ -1,4 +1,7 @@ addMonitor($monitor); +$interpreter->interpret(); ?> \ No newline at end of file diff --git a/src/bindings/swig/php/uscxmlNativePHP.php b/src/bindings/swig/php/uscxmlNativePHP.php new file mode 100644 index 0000000..3b34dc9 --- /dev/null +++ b/src/bindings/swig/php/uscxmlNativePHP.php @@ -0,0 +1,654 @@ +_cPtr,$value); + if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); + $this->_pData[$var] = $value; + } + + function __isset($var) { + if (function_exists('Data_'.$var.'_set')) return true; + if ($var === 'thisown') return true; + return array_key_exists($var, $this->_pData); + } + + function __get($var) { + $func = 'Data_'.$var.'_get'; + if (function_exists($func)) return call_user_func($func,$this->_cPtr); + if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); + return $this->_pData[$var]; + } + + const VERBATIM = 0; + + const INTERPRETED = Data_INTERPRETED; + + function __construct($atom__or_dom=null,$type_=null) { + if (is_resource($atom__or_dom) && get_resource_type($atom__or_dom) === '_p_uscxml__Data') { + $this->_cPtr=$atom__or_dom; + return; + } + switch (func_num_args()) { + case 0: $this->_cPtr=new_Data(); break; + case 1: $this->_cPtr=new_Data($atom__or_dom); break; + default: $this->_cPtr=new_Data($atom__or_dom,$type_); + } + } + + static function fromJSON($jsonString) { + $r=Data_fromJSON($jsonString); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new Data($r); + } + return $r; + } + + static function fromXML($xmlString) { + $r=Data_fromXML($xmlString); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new Data($r); + } + return $r; + } + + function toDocument() { + return Data_toDocument($this->_cPtr); + } + + function toXMLString() { + return Data_toXMLString($this->_cPtr); + } +} + +class Event { + public $_cPtr=null; + protected $_pData=array(); + + function __set($var,$value) { + $func = 'Event_'.$var.'_set'; + if (function_exists($func)) return call_user_func($func,$this->_cPtr,$value); + if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); + $this->_pData[$var] = $value; + } + + function __isset($var) { + if (function_exists('Event_'.$var.'_set')) return true; + if ($var === 'thisown') return true; + return array_key_exists($var, $this->_pData); + } + + function __get($var) { + if ($var === 'data') return new Data(Event_data_get($this->_cPtr)); + $func = 'Event_'.$var.'_get'; + if (function_exists($func)) return call_user_func($func,$this->_cPtr); + if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); + return $this->_pData[$var]; + } + + const INTERNAL = 1; + + const EXTERNAL = 2; + + const PLATFORM = 3; + + function __construct($xmlString=null) { + if (is_resource($xmlString) && get_resource_type($xmlString) === '_p_uscxml__Event') { + $this->_cPtr=$xmlString; + return; + } + switch (func_num_args()) { + case 0: $this->_cPtr=new_Event(); break; + default: $this->_cPtr=new_Event($xmlString); + } + } + + static function fromXML($xmlString) { + $r=Event_fromXML($xmlString); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new Event($r); + } + return $r; + } + + function toDocument() { + return Event_toDocument($this->_cPtr); + } + + function toXMLString() { + return Event_toXMLString($this->_cPtr); + } +} + +class InvokeRequest extends Event { + public $_cPtr=null; + + function __set($var,$value) { + $func = 'InvokeRequest_'.$var.'_set'; + if (function_exists($func)) return call_user_func($func,$this->_cPtr,$value); + if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); + Event::__set($var,$value); + } + + function __isset($var) { + if (function_exists('InvokeRequest_'.$var.'_set')) return true; + if ($var === 'thisown') return true; + return Event::__isset($var); + } + + function __get($var) { + $func = 'InvokeRequest_'.$var.'_get'; + if (function_exists($func)) return call_user_func($func,$this->_cPtr); + if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); + return Event::__get($var); + } + + function __construct($event=null) { + if (is_resource($event) && get_resource_type($event) === '_p_uscxml__InvokeRequest') { + $this->_cPtr=$event; + return; + } + switch (func_num_args()) { + case 0: $this->_cPtr=new_InvokeRequest(); break; + default: $this->_cPtr=new_InvokeRequest($event); + } + } + + static function fromXML($xmlString) { + $r=InvokeRequest_fromXML($xmlString); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new InvokeRequest($r); + } + return $r; + } + + function toDocument() { + return InvokeRequest_toDocument($this->_cPtr); + } + + function toXMLString() { + return InvokeRequest_toXMLString($this->_cPtr); + } +} + +class SendRequest extends Event { + public $_cPtr=null; + + function __set($var,$value) { + $func = 'SendRequest_'.$var.'_set'; + if (function_exists($func)) return call_user_func($func,$this->_cPtr,$value); + if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); + Event::__set($var,$value); + } + + function __isset($var) { + if (function_exists('SendRequest_'.$var.'_set')) return true; + if ($var === 'thisown') return true; + return Event::__isset($var); + } + + function __get($var) { + $func = 'SendRequest_'.$var.'_get'; + if (function_exists($func)) return call_user_func($func,$this->_cPtr); + if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); + return Event::__get($var); + } + + function __construct($event=null) { + if (is_resource($event) && get_resource_type($event) === '_p_uscxml__SendRequest') { + $this->_cPtr=$event; + return; + } + switch (func_num_args()) { + case 0: $this->_cPtr=new_SendRequest(); break; + default: $this->_cPtr=new_SendRequest($event); + } + } + + static function fromXML($xmlString) { + $r=SendRequest_fromXML($xmlString); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new SendRequest($r); + } + return $r; + } + + function toDocument() { + return SendRequest_toDocument($this->_cPtr); + } + + function toXMLString() { + return SendRequest_toXMLString($this->_cPtr); + } +} + +class InterpreterMonitor { + public $_cPtr=null; + protected $_pData=array(); + + function __set($var,$value) { + if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); + $this->_pData[$var] = $value; + } + + function __isset($var) { + if ($var === 'thisown') return true; + return array_key_exists($var, $this->_pData); + } + + function __get($var) { + if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); + return $this->_pData[$var]; + } + + function onStableConfiguration($interpreter) { + InterpreterMonitor_onStableConfiguration($this->_cPtr,$interpreter); + } + + function beforeCompletion($interpreter) { + InterpreterMonitor_beforeCompletion($this->_cPtr,$interpreter); + } + + function afterCompletion($interpreter) { + InterpreterMonitor_afterCompletion($this->_cPtr,$interpreter); + } + + function beforeMicroStep($interpreter) { + InterpreterMonitor_beforeMicroStep($this->_cPtr,$interpreter); + } + + function beforeTakingTransitions($interpreter,$transitions) { + InterpreterMonitor_beforeTakingTransitions($this->_cPtr,$interpreter,$transitions); + } + + function beforeEnteringStates($interpreter,$statesToEnter) { + InterpreterMonitor_beforeEnteringStates($this->_cPtr,$interpreter,$statesToEnter); + } + + function afterEnteringStates($interpreter) { + InterpreterMonitor_afterEnteringStates($this->_cPtr,$interpreter); + } + + function beforeExitingStates($interpreter,$statesToExit) { + InterpreterMonitor_beforeExitingStates($this->_cPtr,$interpreter,$statesToExit); + } + + function afterExitingStates($interpreter) { + InterpreterMonitor_afterExitingStates($this->_cPtr,$interpreter); + } + + function __construct($res=null) { + if (is_resource($res) && get_resource_type($res) === '_p_uscxml__InterpreterMonitor') { + $this->_cPtr=$res; + return; + } + if (get_class($this) === 'InterpreterMonitor') { + $_this = null; + } else { + $_this = $this; + } + $this->_cPtr=new_InterpreterMonitor($_this); + } +} + +class NumAttr { + public $_cPtr=null; + protected $_pData=array(); + + function __set($var,$value) { + if ($var === 'value') return NumAttr_value_set($this->_cPtr,$value); + if ($var === 'unit') return NumAttr_unit_set($this->_cPtr,$value); + if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); + $this->_pData[$var] = $value; + } + + function __isset($var) { + if (function_exists('NumAttr_'.$var.'_set')) return true; + if ($var === 'thisown') return true; + return array_key_exists($var, $this->_pData); + } + + function __get($var) { + if ($var === 'value') return NumAttr_value_get($this->_cPtr); + if ($var === 'unit') return NumAttr_unit_get($this->_cPtr); + if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); + return $this->_pData[$var]; + } + + function __construct($str) { + if (is_resource($str) && get_resource_type($str) === '_p_uscxml__NumAttr') { + $this->_cPtr=$str; + return; + } + $this->_cPtr=new_NumAttr($str); + } +} + +class Interpreter { + public $_cPtr=null; + protected $_pData=array(); + + function __set($var,$value) { + if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); + $this->_pData[$var] = $value; + } + + function __isset($var) { + if ($var === 'thisown') return true; + return array_key_exists($var, $this->_pData); + } + + function __get($var) { + if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); + return $this->_pData[$var]; + } + function __construct($h) { + $this->_cPtr=$h; + } + + const EARLY = 0; + + const LATE = 1; + + const CAN_NOTHING = 0; + + const CAN_BASIC_HTTP = 1; + + const CAN_GENERIC_HTTP = 2; + + static function fromDOM($node) { + $r=Interpreter_fromDOM($node); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new Interpreter($r); + } + return $r; + } + + static function fromXML($xml) { + $r=Interpreter_fromXML($xml); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new Interpreter($r); + } + return $r; + } + + static function fromURI($uri) { + $r=Interpreter_fromURI($uri); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new Interpreter($r); + } + return $r; + } + + static function fromInputSource($source) { + $r=Interpreter_fromInputSource($source); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new Interpreter($r); + } + return $r; + } + + function startPrefixMapping($arg1,$arg2) { + Interpreter_startPrefixMapping($this->_cPtr,$arg1,$arg2); + } + + function start() { + Interpreter_start($this->_cPtr); + } + + static function run($arg1) { + Interpreter_run($arg1); + } + + function join() { + Interpreter_join($this->_cPtr); + } + + function interpret() { + Interpreter_interpret($this->_cPtr); + } + + function addMonitor($monitor) { + Interpreter_addMonitor($this->_cPtr,$monitor); + } + + function removeMonitor($monitor) { + Interpreter_removeMonitor($this->_cPtr,$monitor); + } + + function setBaseURI($baseURI) { + Interpreter_setBaseURI($this->_cPtr,$baseURI); + } + + function getBaseURI() { + return Interpreter_getBaseURI($this->_cPtr); + } + + function toAbsoluteURI($uri) { + return Interpreter_toAbsoluteURI($this->_cPtr,$uri); + } + + function setCmdLineOptions($argc,$argv) { + Interpreter_setCmdLineOptions($this->_cPtr,$argc,$argv); + } + + function getCmdLineOptions() { + $r=Interpreter_getCmdLineOptions($this->_cPtr); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new Data($r); + } + return $r; + } + + function getHTTPServlet() { + return Interpreter_getHTTPServlet($this->_cPtr); + } + + function getDataModel() { + return Interpreter_getDataModel($this->_cPtr); + } + + function setParentQueue($parentQueue) { + Interpreter_setParentQueue($this->_cPtr,$parentQueue); + } + + function getXPathPrefix() { + return Interpreter_getXPathPrefix($this->_cPtr); + } + + function getXMLPrefix() { + return Interpreter_getXMLPrefix($this->_cPtr); + } + + function getNSContext() { + return Interpreter_getNSContext($this->_cPtr); + } + + function getXMLPrefixForNS($ns) { + return Interpreter_getXMLPrefixForNS($this->_cPtr,$ns); + } + + function receive($event,$toFront=false) { + Interpreter_receive($this->_cPtr,$event,$toFront); + } + + function receiveInternal($event) { + Interpreter_receiveInternal($this->_cPtr,$event); + } + + function getCurrentEvent() { + $r=Interpreter_getCurrentEvent($this->_cPtr); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new Event($r); + } + return $r; + } + + function getConfiguration() { + return Interpreter_getConfiguration($this->_cPtr); + } + + function getState($stateId) { + return Interpreter_getState($this->_cPtr,$stateId); + } + + function getDocument() { + return Interpreter_getDocument($this->_cPtr); + } + + function setCapabilities($capabilities) { + Interpreter_setCapabilities($this->_cPtr,$capabilities); + } + + function setName($name) { + Interpreter_setName($this->_cPtr,$name); + } + + function getName() { + return Interpreter_getName($this->_cPtr); + } + + function getSessionId() { + return Interpreter_getSessionId($this->_cPtr); + } + + function runOnMainThread($fps,$blocking=true) { + return Interpreter_runOnMainThread($this->_cPtr,$fps,$blocking); + } + + static function isMember($node,$set) { + return Interpreter_isMember($node,$set); + } + + function dump() { + Interpreter_dump($this->_cPtr); + } + + function hasLegalConfiguration() { + return Interpreter_hasLegalConfiguration($this->_cPtr); + } + + static function isState($state) { + return Interpreter_isState($state); + } + + static function isPseudoState($state) { + return Interpreter_isPseudoState($state); + } + + static function isTransitionTarget($elem) { + return Interpreter_isTransitionTarget($elem); + } + + static function isTargetless($transition) { + return Interpreter_isTargetless($transition); + } + + static function isAtomic($state) { + return Interpreter_isAtomic($state); + } + + static function isFinal($state) { + return Interpreter_isFinal($state); + } + + static function isHistory($state) { + return Interpreter_isHistory($state); + } + + static function isParallel($state) { + return Interpreter_isParallel($state); + } + + static function isCompound($state) { + return Interpreter_isCompound($state); + } + + static function isDescendant($s1,$s2) { + return Interpreter_isDescendant($s1,$s2); + } + + function isInitial($state) { + return Interpreter_isInitial($this->_cPtr,$state); + } + + function getInitialState($state=null) { + switch (func_num_args()) { + case 0: $r=Interpreter_getInitialState($this->_cPtr); break; + default: $r=Interpreter_getInitialState($this->_cPtr,$state); + } + return $r; + } + + static function getChildStates($state) { + return Interpreter_getChildStates($state); + } + + function getTargetStates($transition) { + return Interpreter_getTargetStates($this->_cPtr,$transition); + } + + static function filterChildElements($tagname_or_tagName,$node_or_nodeSet) { + return Interpreter_filterChildElements($tagname_or_tagName,$node_or_nodeSet); + } + + static function getUUID() { + return Interpreter_getUUID(); + } +} + + +?> diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 4ae4689..93d152e 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -78,8 +78,15 @@ Interpreter* Interpreter::fromURI(const std::string& uri) { // this is required for windows filenames and does not harm on unices if (boost::iequals(absUrl.scheme(), "file")) { inputSource.setSystemId(absUrl.path()); - } else { + } else if (boost::iequals(absUrl.scheme(), "http")) { + // handle http per arabica inputSource.setSystemId(absUrl.asString()); + } else { + // use curl for everything else + std::stringstream ss; + ss << absUrl; + ss.seekg(0); + inputSource.setByteStream(ss); } Interpreter* interpreter = fromInputSource(inputSource); diff --git a/test/src/test-url.cpp b/test/src/test-url.cpp index bbe4dbc..7b72250 100644 --- a/test/src/test-url.cpp +++ b/test/src/test-url.cpp @@ -1,5 +1,6 @@ #include "uscxml/URL.h" #include "uscxml/Message.h" +#include "uscxml/Interpreter.h" #include "uscxml/server/HTTPServer.h" #include @@ -24,6 +25,12 @@ public: int main(int argc, char** argv) { { + Interpreter* interpreter = Interpreter::fromURI("https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-execution.scxml"); + interpreter->interpret(); + delete interpreter; + } + + { TestServlet* testServlet1 = new TestServlet(false); TestServlet* testServlet2 = new TestServlet(false); @@ -94,7 +101,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