1 #include "ProcessWrapper.h"
\r
2 #include "dolSupport.h"
\r
7 ProcessWrapper::ProcessWrapper(char* name) {
\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
29 void ProcessWrapper::initialize() {
\r
30 _process.init(&_process);
\r
36 int ProcessWrapper::fire()
\r
38 return _process.fire(&_process);
\r
45 void ProcessWrapper::detach() {
\r
51 * Gets an index of a string, where the index must be separated by
\r
52 * a character specified in tokens.
\r
53 * Returns -1, when an error occurs.
\r
56 * getIndex("name_1_2", "_", 0) will return 1.
\r
57 * getIndex("name_1_2", "_", 1) will return 2.
\r
59 * @param string string to parse
\r
60 * @param tokens delimiter of indices
\r
61 * @param indexNumber position of index (starting at 0)
\r
63 int ProcessWrapper::getIndex(const char* string, char* tokens,
\r
64 int indexNumber) const {
\r
66 char* token_pointer;
\r
69 string_copy = (char*) malloc(sizeof(char) * (strlen(string) + 1));
\r
71 fprintf(stderr, "getIndex(): could not allocate memory.\n");
\r
75 strcpy(string_copy, string);
\r
77 token_pointer = strtok(string_copy, tokens);
\r
79 token_pointer = strtok(NULL, tokens);
\r
81 } while (index <= indexNumber && token_pointer != 0);
\r
83 if (token_pointer) {
\r
84 index = atoi(token_pointer);
\r
94 * Get the index of this process.
\r
95 * @param indexNumber position of index (starting at 0)
\r
97 int ProcessWrapper::getIndex(unsigned indexNumber) const {
\r
98 if (indexNumber < 4) {
\r
99 return _iteratorIndex[indexNumber];
\r
106 * Get the name of this process.
\r
108 char* ProcessWrapper::getName() const {
\r
116 #ifdef INCLUDE_PROFILER
\r
117 void ProcessWrapper::addToProfile(const char *event, void *port,
\r
119 if (profiler_output_file != NULL) {
\r
120 fprintf(profiler_output_file, "%u %s %s %p %d\n",
\r
121 profiler_event_counter++, _name, event, port,
\r
125 printf("profiler_output_file does not exist");
\r