dol: initial dol commit
[jump.git] / dol / src / dol / visitor / protothread / lib / ProcessWrapper.cpp
diff --git a/dol/src/dol/visitor/protothread/lib/ProcessWrapper.cpp b/dol/src/dol/visitor/protothread/lib/ProcessWrapper.cpp
new file mode 100644 (file)
index 0000000..261f65c
--- /dev/null
@@ -0,0 +1,68 @@
+#include "ProcessWrapper.h"
+
+/**
+ *
+ */
+ProcessWrapper::ProcessWrapper(char* name, int iteratorIndex[4]) {
+    //copy name, deliberately avoid using strlen and strcpy for code size
+    //minimization
+    int nameLength = 0;
+    while (name[nameLength] != 0) {
+        nameLength++;
+    }
+    _name = new char[nameLength + 1];
+    for (int i = 0; i < nameLength; i++) {
+        _name[i] = name[i];
+    }
+
+    /*
+    _name = new char[strlen(name) + 1];
+    strcpy(_name, name);
+    */
+
+    _isDetached = false;
+    for (int i = 0; i < 4; i++) {
+        _iteratorIndex[i] = iteratorIndex[i];
+    }
+}
+
+/**
+ *
+ */
+ProcessWrapper::~ProcessWrapper() {
+    if (_name) {
+        delete _name;
+    }
+}
+
+/**
+ *
+ */
+void ProcessWrapper::init() {
+    _process.init(&_process);
+}
+
+/**
+ *
+ */
+int ProcessWrapper::fire() {
+    return _process.fire(&_process);
+}
+
+/**
+ *
+ */
+void ProcessWrapper::detach() {
+    _isDetached = true;
+}
+
+/**
+ * Get the index of this process.
+ * @param indexNumber position of index (starting at 0)
+ */
+int ProcessWrapper::getIndex(unsigned indexNumber) const {
+  if (indexNumber < 4) {
+      return _iteratorIndex[indexNumber];
+  }
+  return -1;
+}