1 #include "ProcessWrapper.h"
\r
2 #include "dolSupport.h"
\r
7 ProcessWrapper::ProcessWrapper(
\r
8 sc_module_name name = sc_gen_unique_name("process"))
\r
11 _name = new char[strlen(name) + 1];
\r
12 strcpy(_name, name);
\r
14 _isDetached = false;
\r
15 for (int i = 0; i < 4; i++) {
\r
16 _iteratorIndex[i] = getIndex(_name, "_", i);
\r
23 ProcessWrapper::~ProcessWrapper() {
\r
32 void ProcessWrapper::initialize() {
\r
33 _process.init(&_process);
\r
39 int ProcessWrapper::fire()
\r
43 #ifdef INCLUDE_TRACE
\r
47 #ifdef INCLUDE_PERFORMANCE
\r
49 get_current_time(&start_time);
\r
52 returnValue = _process.fire(&_process);
\r
54 #ifdef INCLUDE_TRACE
\r
56 dol_functional_trace.create_computation_event(basename(),
\r
57 start_line, end_line);
\r
60 #ifdef INCLUDE_PERFORMANCE
\r
61 get_current_time(&end_time);
\r
63 performance_extraction.add_computation_performance(basename(),
\r
64 start_line, end_line, &start_time, &end_time);
\r
74 void ProcessWrapper::detach() {
\r
80 * Gets an index of a string, where the index must be separated by
\r
81 * a character specified in tokens.
\r
82 * Returns -1, when an error occurs.
\r
85 * getIndex("name_1_2", "_", 0) will return 1.
\r
86 * getIndex("name_1_2", "_", 1) will return 2.
\r
88 * @param string string to parse
\r
89 * @param tokens delimiter of indices
\r
90 * @param indexNumber position of index (starting at 0)
\r
92 int ProcessWrapper::getIndex(const char* string, char* tokens,
\r
93 int indexNumber) const {
\r
95 char* token_pointer;
\r
98 string_copy = (char*) malloc(sizeof(char) * (strlen(string) + 1));
\r
100 fprintf(stderr, "getIndex(): could not allocate memory.\n");
\r
104 strcpy(string_copy, string);
\r
106 token_pointer = strtok(string_copy, tokens);
\r
108 token_pointer = strtok(NULL, tokens);
\r
110 } while (index <= indexNumber && token_pointer != 0);
\r
112 if (token_pointer) {
\r
113 index = atoi(token_pointer);
\r
123 * Get the index of this process.
\r
124 * @param indexNumber position of index (starting at 0)
\r
126 int ProcessWrapper::getIndex(unsigned indexNumber) const {
\r
127 if (indexNumber < 4) {
\r
128 return _iteratorIndex[indexNumber];
\r
135 * Get the name of this process.
\r
137 char* ProcessWrapper::getName() const {
\r
145 #ifdef INCLUDE_PROFILER
\r
146 void ProcessWrapper::addToProfile(const char *event, void *port,
\r
148 if (profiler_output_file != NULL) {
\r
149 fprintf(profiler_output_file, "%u %s %s %p%s %d\n",
\r
150 profiler_event_counter++, _name, event, port, (event[0] == 'r') ? "I" : "O",
\r
154 printf("profiler_output_file does not exist");
\r