dol: initial dol commit
[jump.git] / dol / src / dol / visitor / protothread / lib / ProcessWrapper.cpp
1 #include "ProcessWrapper.h"
2
3 /**
4  *
5  */
6 ProcessWrapper::ProcessWrapper(char* name, int iteratorIndex[4]) {
7     //copy name, deliberately avoid using strlen and strcpy for code size
8     //minimization
9     int nameLength = 0;
10     while (name[nameLength] != 0) {
11         nameLength++;
12     }
13     _name = new char[nameLength + 1];
14     for (int i = 0; i < nameLength; i++) {
15         _name[i] = name[i];
16     }
17
18     /*
19     _name = new char[strlen(name) + 1];
20     strcpy(_name, name);
21     */
22
23     _isDetached = false;
24     for (int i = 0; i < 4; i++) {
25         _iteratorIndex[i] = iteratorIndex[i];
26     }
27 }
28
29 /**
30  *
31  */
32 ProcessWrapper::~ProcessWrapper() {
33     if (_name) {
34         delete _name;
35     }
36 }
37
38 /**
39  *
40  */
41 void ProcessWrapper::init() {
42     _process.init(&_process);
43 }
44
45 /**
46  *
47  */
48 int ProcessWrapper::fire() {
49     return _process.fire(&_process);
50 }
51
52 /**
53  *
54  */
55 void ProcessWrapper::detach() {
56     _isDetached = true;
57 }
58
59 /**
60  * Get the index of this process.
61  * @param indexNumber position of index (starting at 0)
62  */
63 int ProcessWrapper::getIndex(unsigned indexNumber) const {
64   if (indexNumber < 4) {
65       return _iteratorIndex[indexNumber];
66   }
67   return -1;
68 }