summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-03-26 22:20:03 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-03-26 22:20:03 (GMT)
commit83f0b4ecbd83e83b5404afd5cead7a08966495bf (patch)
treeff887fca701fe27221a04bf2c304e3ecb4cbf7cc /src
parent405c805f249cacb07f8861d5550abda8f6694d0c (diff)
downloaduscxml-83f0b4ecbd83e83b5404afd5cead7a08966495bf.zip
uscxml-83f0b4ecbd83e83b5404afd5cead7a08966495bf.tar.gz
uscxml-83f0b4ecbd83e83b5404afd5cead7a08966495bf.tar.bz2
Implemented ParentQueues for PHP
Diffstat (limited to 'src')
-rw-r--r--src/bindings/swig/php/test.php16
-rw-r--r--src/bindings/swig/php/uscxml.i6
-rw-r--r--src/bindings/swig/php/uscxmlNativePHP.php91
-rw-r--r--src/uscxml/Interpreter.cpp3
-rw-r--r--src/uscxml/Interpreter.h5
-rw-r--r--src/uscxml/concurrency/BlockingQueue.h2
6 files changed, 79 insertions, 44 deletions
diff --git a/src/bindings/swig/php/test.php b/src/bindings/swig/php/test.php
index 3ac64eb..6a15429 100644
--- a/src/bindings/swig/php/test.php
+++ b/src/bindings/swig/php/test.php
@@ -45,10 +45,16 @@ $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();
+$interpreter = Interpreter::fromURI('https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-invoked.scxml');
+$parentQueue = new ParentQueue();
+$interpreter->setParentQueue($parentQueue);
+$interpreter->interpret();
+//$interpreter->start();
+
+#while($interpreter->isRunning()) {
+ $event = $parentQueue->pop();
+ print_r($event);
+ print(Event_name_get($event) . "\n");
+#}
?> \ No newline at end of file
diff --git a/src/bindings/swig/php/uscxml.i b/src/bindings/swig/php/uscxml.i
index edf51e0..54e9f27 100644
--- a/src/bindings/swig/php/uscxml.i
+++ b/src/bindings/swig/php/uscxml.i
@@ -16,6 +16,7 @@
%{
#include "../../../uscxml/Message.h"
#include "../../../uscxml/Interpreter.h"
+#include "../../../uscxml/concurrency/BlockingQueue.h"
using namespace uscxml;
@@ -29,9 +30,14 @@ void*** tsrm_ls;
%feature("director") uscxml::InterpreterMonitor;
+%ignore uscxml::NumAttr;
+
//***********************************************
// Parse the header file to generate wrappers
//***********************************************
%include "../../../uscxml/Message.h"
%include "../../../uscxml/Interpreter.h"
+%include "../../../uscxml/concurrency/BlockingQueue.h"
+
+%template(ParentQueue) uscxml::concurrency::BlockingQueue<uscxml::Event>;
diff --git a/src/bindings/swig/php/uscxmlNativePHP.php b/src/bindings/swig/php/uscxmlNativePHP.php
index 6bab7af..91f6b21 100644
--- a/src/bindings/swig/php/uscxmlNativePHP.php
+++ b/src/bindings/swig/php/uscxmlNativePHP.php
@@ -26,10 +26,6 @@ if (!extension_loaded('uscxmlNativePHP')) {
-abstract class uscxmlNativePHP {
- const ZTS = ZTS;
-}
-
/* PHP Proxy Classes */
class Data {
public $_cPtr=null;
@@ -336,39 +332,6 @@ class InterpreterMonitor {
}
}
-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();
@@ -457,6 +420,10 @@ class Interpreter {
Interpreter_join($this->_cPtr);
}
+ function isRunning() {
+ return Interpreter_isRunning($this->_cPtr);
+ }
+
function interpret() {
Interpreter_interpret($this->_cPtr);
}
@@ -654,5 +621,55 @@ class Interpreter {
}
}
+class ParentQueue {
+ 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($res=null) {
+ if (is_resource($res) && get_resource_type($res) === '_p_uscxml__concurrency__BlockingQueueT_uscxml__Event_t') {
+ $this->_cPtr=$res;
+ return;
+ }
+ $this->_cPtr=new_ParentQueue();
+ }
+
+ function push($elem) {
+ ParentQueue_push($this->_cPtr,$elem);
+ }
+
+ function push_front($elem) {
+ ParentQueue_push_front($this->_cPtr,$elem);
+ }
+
+ function pop() {
+ $r=ParentQueue_pop($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 isEmpty() {
+ return ParentQueue_isEmpty($this->_cPtr);
+ }
+}
+
?>
diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp
index ef30033..16b3209 100644
--- a/src/uscxml/Interpreter.cpp
+++ b/src/uscxml/Interpreter.cpp
@@ -38,7 +38,7 @@ Interpreter::Interpreter() : Arabica::SAX2DOM::Parser<std::string>() {
_sendQueue = NULL;
_parentQueue = NULL;
_running = false;
- _done = false;
+ _done = true;
_isInitialized = false;
_httpServlet = NULL;
_capabilities = CAN_BASIC_HTTP | CAN_GENERIC_HTTP;
@@ -884,6 +884,7 @@ void Interpreter::delayedSend(void* userdata, std::string eventName) {
if (boost::iequals(sendReq.target, "#_parent")) {
// send to parent scxml session
if (INSTANCE->_parentQueue != NULL) {
+// LOG(ERROR) << "Pushing into parent queue: " << INSTANCE->_parentQueue << std::endl;
INSTANCE->_parentQueue->push(sendReq);
} else {
LOG(ERROR) << "Can not send to parent, we were not invoked" << std::endl;
diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h
index d60a7e4..d75241e 100644
--- a/src/uscxml/Interpreter.h
+++ b/src/uscxml/Interpreter.h
@@ -98,6 +98,9 @@ public:
void join() {
if (_thread != NULL) _thread->join();
};
+ bool isRunning() {
+ return _running || !_done;
+ }
void interpret();
@@ -199,7 +202,7 @@ public:
static bool isParallel(const Arabica::DOM::Node<std::string>& state);
static bool isCompound(const Arabica::DOM::Node<std::string>& state);
static bool isDescendant(const Arabica::DOM::Node<std::string>& s1, const Arabica::DOM::Node<std::string>& s2);
-
+
bool isInitial(const Arabica::DOM::Node<std::string>& state);
Arabica::DOM::Node<std::string> getInitialState(Arabica::DOM::Node<std::string> state = Arabica::DOM::Node<std::string>());
static Arabica::XPath::NodeSet<std::string> getChildStates(const Arabica::DOM::Node<std::string>& state);
diff --git a/src/uscxml/concurrency/BlockingQueue.h b/src/uscxml/concurrency/BlockingQueue.h
index 0f4c965..0826590 100644
--- a/src/uscxml/concurrency/BlockingQueue.h
+++ b/src/uscxml/concurrency/BlockingQueue.h
@@ -28,6 +28,7 @@ public:
virtual T pop() {
tthread::lock_guard<tthread::mutex> lock(_mutex);
+// std::cout << "Popping from " << this << std::endl;
while (_queue.empty()) {
_cond.wait(_mutex);
}
@@ -41,6 +42,7 @@ public:
return _queue.empty();
}
+protected:
tthread::mutex _mutex;
tthread::condition_variable _cond;
std::list<T> _queue;