1 #include "ProcessWrapper.h"
\r
2 #include "dolSupport.h"
\r
7 ProcessWrapper::ProcessWrapper(const char* name, const Id& n) : Process(n) {
\r
8 _name = new char[strlen(name) + 1];
\r
11 _isDetached = false;
\r
12 for (int i = 0; i < 4; i++) {
\r
13 _iteratorIndex[i] = getIndex(_name, "_", i);
\r
20 ProcessWrapper::~ProcessWrapper() {
\r
26 void ProcessWrapper::initialize() {
\r
27 _process.init(&_process);
\r
33 int ProcessWrapper::fire()
\r
35 return _process.fire(&_process);
\r
42 void ProcessWrapper::detach() {
\r
48 * Gets an index of a string, where the index must be separated by
\r
49 * a character specified in tokens.
\r
50 * Returns -1, when an error occurs.
\r
53 * getIndex("name_1_2", "_", 0) will return 1.
\r
54 * getIndex("name_1_2", "_", 1) will return 2.
\r
56 * @param string string to parse
\r
57 * @param tokens delimiter of indices
\r
58 * @param indexNumber position of index (starting at 0)
\r
60 int ProcessWrapper::getIndex(const char* string, char* tokens,
\r
61 int indexNumber) const {
\r
63 char* token_pointer;
\r
66 string_copy = (char*) malloc(sizeof(char) * (strlen(string) + 1));
\r
68 fprintf(stderr, "getIndex(): could not allocate memory.\n");
\r
72 strcpy(string_copy, string);
\r
74 token_pointer = strtok(string_copy, tokens);
\r
76 token_pointer = strtok(NULL, tokens);
\r
78 } while (index <= indexNumber && token_pointer != 0);
\r
80 if (token_pointer) {
\r
81 index = atoi(token_pointer);
\r
91 * Get the name of this process.
\r
93 char* ProcessWrapper::getName() const {
\r
99 * Get the index of this process.
\r
100 * @param indexNumber position of index (starting at 0)
\r
102 int ProcessWrapper::getIndex(unsigned indexNumber) const {
\r
103 if (indexNumber < 4) {
\r
104 return _iteratorIndex[indexNumber];
\r