diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-03-27 16:05:27 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-03-27 16:05:27 (GMT) |
commit | c0e29f9d4574be340d23c88605bf8868b166f718 (patch) | |
tree | 9118eb60caf48830ebbeef70e8b8cf1687735c32 /src/bindings/swig/php | |
parent | 83f0b4ecbd83e83b5404afd5cead7a08966495bf (diff) | |
download | uscxml-c0e29f9d4574be340d23c88605bf8868b166f718.zip uscxml-c0e29f9d4574be340d23c88605bf8868b166f718.tar.gz uscxml-c0e29f9d4574be340d23c88605bf8868b166f718.tar.bz2 |
Polished PHP interface somewhat
Diffstat (limited to 'src/bindings/swig/php')
-rw-r--r-- | src/bindings/swig/php/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/bindings/swig/php/test.php | 31 | ||||
-rw-r--r-- | src/bindings/swig/php/uscxml.i | 7 | ||||
-rw-r--r-- | src/bindings/swig/php/uscxmlNativePHP.php | 443 |
4 files changed, 471 insertions, 15 deletions
diff --git a/src/bindings/swig/php/CMakeLists.txt b/src/bindings/swig/php/CMakeLists.txt index 17c9465..91c6c36 100644 --- a/src/bindings/swig/php/CMakeLists.txt +++ b/src/bindings/swig/php/CMakeLists.txt @@ -45,6 +45,7 @@ if(APPLE) _zend_register_resource _zend_rsrc_list_get_rsrc_type _zend_wrong_param_count + _zend_throw_exception _zval_used_for_init ) set(PHP_MODULE_CXX_FLAGS @@ -74,7 +75,9 @@ endif() if (PHP_ZTS_ENABLED) # we are only building php bindings for unices anyhow - set_target_properties(uscxmlNativePHP PROPERTIES COMPILE_FLAGS "-DZTS -DPTHREADS") + set_target_properties(uscxmlNativePHP PROPERTIES COMPILE_FLAGS "-DZTS -DPTHREADS -DSWIG") +else() + set_target_properties(uscxmlNativePHP PROPERTIES COMPILE_FLAGS "-DSWIG") endif() set_target_properties(uscxmlNativePHP PROPERTIES FOLDER "Bindings") diff --git a/src/bindings/swig/php/test.php b/src/bindings/swig/php/test.php index 6a15429..6896ab0 100644 --- a/src/bindings/swig/php/test.php +++ b/src/bindings/swig/php/test.php @@ -41,20 +41,31 @@ class MyMonitor extends InterpreterMonitor { $monitor = new MyMonitor(); -$interpreter = Interpreter::fromURI('https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-ecmascript.scxml'); -$interpreter->addMonitor($monitor); -$interpreter->interpret(); +// $interpreter = Interpreter::fromURI('https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-ecmascript.scxml'); +// $interpreter->addMonitor($monitor); +// $interpreter->interpret(); -$interpreter = Interpreter::fromURI('https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-invoked.scxml'); +$interpreter = Interpreter::fromURI('/Users/sradomski/Documents/TK/Code/uscxml/test/samples/uscxml/test-invoked.scxml'); $parentQueue = new ParentQueue(); $interpreter->setParentQueue($parentQueue); -$interpreter->interpret(); //$interpreter->start(); - -#while($interpreter->isRunning()) { +$interpreter->interpret(); +exit(); +while($interpreter->isRunning()) { $event = $parentQueue->pop(); - print_r($event); - print(Event_name_get($event) . "\n"); -#} + print("Name: " . $event->getName() . "\n"); + print("Content: " . $event->getContent() . "\n"); + + print("Namelist: \n"); + $namelist = $event->getNameList(); + print("\tSize: ". $namelist->size() ."\n"); + + $keys = $event->getNameListKeys(); + + for ($i = 0; $i < $keys->size(); $i++) { + print("\t" . $namelist->get($keys->get($i)) . "\n"); + } + +} ?>
\ No newline at end of file diff --git a/src/bindings/swig/php/uscxml.i b/src/bindings/swig/php/uscxml.i index 54e9f27..6180d05 100644 --- a/src/bindings/swig/php/uscxml.i +++ b/src/bindings/swig/php/uscxml.i @@ -1,7 +1,7 @@ %module(directors="1", allprotected="1") uscxmlNativePHP // import swig typemaps -%include <std_string.i> +%include "stl.i" // macros from cmake %import "uscxml/config.h" @@ -40,4 +40,7 @@ void*** tsrm_ls; %include "../../../uscxml/Interpreter.h" %include "../../../uscxml/concurrency/BlockingQueue.h" -%template(ParentQueue) uscxml::concurrency::BlockingQueue<uscxml::Event>; +%template(ParentQueue) uscxml::concurrency::BlockingQueue<uscxml::SendRequest>; +%template(NameList) std::map<std::string, std::string>; +%template(ParamList) std::vector<std::string>; +%template(Params) std::map<std::string, std::vector<std::string> >; diff --git a/src/bindings/swig/php/uscxmlNativePHP.php b/src/bindings/swig/php/uscxmlNativePHP.php index 91f6b21..7a63a1a 100644 --- a/src/bindings/swig/php/uscxmlNativePHP.php +++ b/src/bindings/swig/php/uscxmlNativePHP.php @@ -94,6 +94,38 @@ class Data { function toXMLString() { return Data_toXMLString($this->_cPtr); } + + function getCompund() { + return Data_getCompund($this->_cPtr); + } + + function setCompound($compound) { + Data_setCompound($this->_cPtr,$compound); + } + + function getArray() { + return Data_getArray($this->_cPtr); + } + + function setArray($array) { + Data_setArray($this->_cPtr,$array); + } + + function getAtom() { + return Data_getAtom($this->_cPtr); + } + + function setAtom($atom) { + Data_setAtom($this->_cPtr,$atom); + } + + function getType() { + return Data_getType($this->_cPtr); + } + + function setType($type) { + Data_setType($this->_cPtr,$type); + } } class Event { @@ -138,6 +170,76 @@ class Event { } } + function getName() { + return Event_getName($this->_cPtr); + } + + function setName($name) { + Event_setName($this->_cPtr,$name); + } + + function getType() { + return Event_getType($this->_cPtr); + } + + function setType($type) { + Event_setType($this->_cPtr,$type); + } + + function getOrigin() { + return Event_getOrigin($this->_cPtr); + } + + function setOrigin($origin) { + Event_setOrigin($this->_cPtr,$origin); + } + + function getOriginType() { + return Event_getOriginType($this->_cPtr); + } + + function setOriginType($originType) { + Event_setOriginType($this->_cPtr,$originType); + } + + function getDOM() { + return Event_getDOM($this->_cPtr); + } + + function setDOM($dom) { + Event_setDOM($this->_cPtr,$dom); + } + + function getSendId() { + return Event_getSendId($this->_cPtr); + } + + function setSendId($sendId) { + Event_setSendId($this->_cPtr,$sendId); + } + + function getInvokeId() { + return Event_getInvokeId($this->_cPtr); + } + + function setInvokeId($invokeId) { + Event_setInvokeId($this->_cPtr,$invokeId); + } + + function getData() { + $r=Event_getData($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 setData($invokeId) { + Event_setData($this->_cPtr,$invokeId); + } + static function fromXML($xmlString) { $r=Event_fromXML($xmlString); if (is_resource($r)) { @@ -174,6 +276,7 @@ class InvokeRequest extends Event { } function __get($var) { + if ($var === 'namelist') return new NameList(InvokeRequest_namelist_get($this->_cPtr)); $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); @@ -191,6 +294,78 @@ class InvokeRequest extends Event { } } + function getType() { + return InvokeRequest_getType($this->_cPtr); + } + + function setType($type) { + InvokeRequest_setType($this->_cPtr,$type); + } + + function getSource() { + return InvokeRequest_getSource($this->_cPtr); + } + + function setSource($src) { + InvokeRequest_setSource($this->_cPtr,$src); + } + + function getContent() { + return InvokeRequest_getContent($this->_cPtr); + } + + function setContent($content) { + InvokeRequest_setContent($this->_cPtr,$content); + } + + function isAutoForwarded() { + return InvokeRequest_isAutoForwarded($this->_cPtr); + } + + function setAutoForwarded($autoForward) { + InvokeRequest_setAutoForwarded($this->_cPtr,$autoForward); + } + + function getNameList() { + $r=InvokeRequest_getNameList($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 NameList($r); + } + return $r; + } + + function getNameListKeys() { + $r=InvokeRequest_getNameListKeys($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 ParamList($r); + } + return $r; + } + + function getParams() { + $r=InvokeRequest_getParams($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 Params($r); + } + return $r; + } + + function getParamKeys() { + $r=InvokeRequest_getParamKeys($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 ParamList($r); + } + return $r; + } + static function fromXML($xmlString) { $r=InvokeRequest_fromXML($xmlString); if (is_resource($r)) { @@ -227,6 +402,7 @@ class SendRequest extends Event { } function __get($var) { + if ($var === 'namelist') return new NameList(SendRequest_namelist_get($this->_cPtr)); $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); @@ -244,6 +420,78 @@ class SendRequest extends Event { } } + function getTarget() { + return SendRequest_getTarget($this->_cPtr); + } + + function setTarget($target) { + SendRequest_setTarget($this->_cPtr,$target); + } + + function getType() { + return SendRequest_getType($this->_cPtr); + } + + function setType($type) { + SendRequest_setType($this->_cPtr,$type); + } + + function getDelayMs() { + return SendRequest_getDelayMs($this->_cPtr); + } + + function setDelayMs($delayMs) { + SendRequest_setDelayMs($this->_cPtr,$delayMs); + } + + function getContent() { + return SendRequest_getContent($this->_cPtr); + } + + function setContent($content) { + SendRequest_setContent($this->_cPtr,$content); + } + + function getNameList() { + $r=SendRequest_getNameList($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 NameList($r); + } + return $r; + } + + function getNameListKeys() { + $r=SendRequest_getNameListKeys($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 ParamList($r); + } + return $r; + } + + function getParams() { + $r=SendRequest_getParams($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 Params($r); + } + return $r; + } + + function getParamKeys() { + $r=SendRequest_getParamKeys($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 ParamList($r); + } + return $r; + } + static function fromXML($xmlString) { $r=SendRequest_fromXML($xmlString); if (is_resource($r)) { @@ -641,7 +889,7 @@ class ParentQueue { } function __construct($res=null) { - if (is_resource($res) && get_resource_type($res) === '_p_uscxml__concurrency__BlockingQueueT_uscxml__Event_t') { + if (is_resource($res) && get_resource_type($res) === '_p_uscxml__concurrency__BlockingQueueT_uscxml__SendRequest_t') { $this->_cPtr=$res; return; } @@ -661,7 +909,7 @@ class ParentQueue { 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 new SendRequest($r); } return $r; } @@ -671,5 +919,196 @@ class ParentQueue { } } +class NameList { + 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($arg1=null) { + if (is_resource($arg1) && get_resource_type($arg1) === '_p_std__mapT_std__string_std__string_t') { + $this->_cPtr=$arg1; + return; + } + switch (func_num_args()) { + case 0: $this->_cPtr=new_NameList(); break; + default: $this->_cPtr=new_NameList($arg1); + } + } + + function size() { + return NameList_size($this->_cPtr); + } + + function clear() { + NameList_clear($this->_cPtr); + } + + function get($key) { + return NameList_get($this->_cPtr,$key); + } + + function set($key,$x) { + NameList_set($this->_cPtr,$key,$x); + } + + function del($key) { + NameList_del($this->_cPtr,$key); + } + + function has_key($key) { + return NameList_has_key($this->_cPtr,$key); + } + + function is_empty() { + return NameList_is_empty($this->_cPtr); + } +} + +class ParamList { + 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($n=null) { + if (is_resource($n) && get_resource_type($n) === '_p_std__vectorT_std__string_t') { + $this->_cPtr=$n; + return; + } + switch (func_num_args()) { + case 0: $this->_cPtr=new_ParamList(); break; + default: $this->_cPtr=new_ParamList($n); + } + } + + function size() { + return ParamList_size($this->_cPtr); + } + + function capacity() { + return ParamList_capacity($this->_cPtr); + } + + function reserve($n) { + ParamList_reserve($this->_cPtr,$n); + } + + function clear() { + ParamList_clear($this->_cPtr); + } + + function push($x) { + ParamList_push($this->_cPtr,$x); + } + + function is_empty() { + return ParamList_is_empty($this->_cPtr); + } + + function pop() { + return ParamList_pop($this->_cPtr); + } + + function get($i) { + return ParamList_get($this->_cPtr,$i); + } + + function set($i,$val) { + ParamList_set($this->_cPtr,$i,$val); + } +} + +class Params { + 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($arg1=null) { + if (is_resource($arg1) && get_resource_type($arg1) === '_p_std__mapT_std__string_std__vectorT_std__string_t_t') { + $this->_cPtr=$arg1; + return; + } + switch (func_num_args()) { + case 0: $this->_cPtr=new_Params(); break; + default: $this->_cPtr=new_Params($arg1); + } + } + + function size() { + return Params_size($this->_cPtr); + } + + function clear() { + Params_clear($this->_cPtr); + } + + function get($key) { + $r=Params_get($this->_cPtr,$key); + 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 ParamList($r); + } + return $r; + } + + function set($key,$x) { + Params_set($this->_cPtr,$key,$x); + } + + function del($key) { + Params_del($this->_cPtr,$key); + } + + function has_key($key) { + return Params_has_key($this->_cPtr,$key); + } + + function is_empty() { + return Params_is_empty($this->_cPtr); + } +} + ?> |