@@ -34,17 +34,11 @@ int validateArgs(int argc, char *argv[]) {
34
34
if (monitorTime < 0 ) {
35
35
printf (" monitorTime invalid\n " );
36
36
return EINVAL;
37
- } else if (monitorTime > 100000 ) {
38
- printf (" monitorTime invalid\n " );
39
- return EOVERFLOW;
40
37
}
41
38
42
39
if (iterations < 0 ) {
43
40
printf (" NITER invalid\n " );
44
41
return EINVAL;
45
- } else if (iterations > 100000 ) {
46
- printf (" NITER invalid\n " );
47
- return EOVERFLOW;
48
42
}
49
43
50
44
return 0 ;
@@ -64,6 +58,10 @@ CLI_ARGS parseArgs(int argc, char *argv[]) {
64
58
return args;
65
59
}
66
60
61
+ /* *
62
+ * Makes the termination output for resources
63
+ * @return
64
+ */
67
65
std::string getFormattedSystemResourceInfo () {
68
66
std::map<string, int >::iterator itr;
69
67
std::string systemResources;
@@ -80,36 +78,53 @@ std::string getFormattedSystemResourceInfo() {
80
78
return systemResources;
81
79
}
82
80
81
+ void convertStatus (STATUS tStatus, char *status) {
82
+ if (tStatus == IDLE) {
83
+ strcpy (status, IDLE_FLAG);
84
+ } else if (tStatus == WAIT) {
85
+ strcpy (status, WAIT_FLAG);
86
+ } else {
87
+ strcpy (status, RUN_FLAG);
88
+ }
89
+ }
90
+
91
+ void getFormattedSystemTaskResourceInfo (std::string reqResource, char * buffer) {
92
+ char *saveptr;
93
+ char *resourceName;
94
+ int resourcesNeeded;
95
+ char resourceString[RESOURCE_MAX_LEN];
96
+ strcpy (resourceString, reqResource.c_str ());
97
+ resourceName = strtok_r (resourceString, " :" , &saveptr);
98
+ resourcesNeeded = atoi (strtok_r (nullptr , " :" , &saveptr));
99
+
100
+ sprintf (buffer, " \t %s: (needed=\t %d, held= 0)\n " , resourceName, resourcesNeeded);
101
+ }
102
+
103
+ /* *
104
+ * Makes the termination output for tasks
105
+ * @return
106
+ */
83
107
std::string getFormattedSystemTaskInfo () { // TODO: refactor to be clearer
84
108
std::string systemTasks;
85
109
for (unsigned int i = 0 ; i < taskList.size (); i++) {
86
110
char buffer[1024 ];
87
- char status[20 ];
88
- if (taskList.at (i).status == IDLE) {
89
- strcpy (status, IDLE_FLAG);
90
- } else if (taskList.at (i).status == WAIT) {
91
- strcpy (status, WAIT_FLAG);
92
- } else {
93
- strcpy (status, RUN_FLAG);
94
- }
111
+ char status[RESOURCE_MAX_LEN];
112
+ convertStatus (taskList.at (i).status , status);
113
+
95
114
sprintf (buffer, " [%d] %s (%s, runTime= %i msec, idleTime= %i msec):\n " , i,
96
115
taskList.at (i).name , status,
97
116
taskList.at (i).busyTime , taskList.at (i).idleTime );
98
117
systemTasks.append (buffer);
118
+
99
119
sprintf (buffer, " \t (tid= %lu)\n " , threads[i]);
100
120
systemTasks.append (buffer);
121
+
101
122
for (auto &reqResource : taskList.at (i).reqResources ) {
102
- char *saveptr;
103
- char *resourceName;
104
- int resourcesNeeded;
105
- char resourceString[50 ];
106
- strcpy (resourceString, reqResource.c_str ());
107
- resourceName = strtok_r (resourceString, " :" , &saveptr);
108
- resourcesNeeded = atoi (strtok_r (nullptr , " :" , &saveptr));
109
-
110
- sprintf (buffer, " \t %s: (needed=\t %d, held= 0)\n " , resourceName, resourcesNeeded);
111
- systemTasks.append (buffer);
123
+ char resBuffer[1024 ];
124
+ getFormattedSystemTaskResourceInfo (reqResource, resBuffer);
125
+ systemTasks.append (resBuffer);
112
126
}
127
+
113
128
sprintf (buffer, " \t (RUN: %d times, WAIT: %lu msec)\n\n " , taskList.at (i).timesExecuted ,
114
129
taskList.at (i).totalWaitTime );
115
130
systemTasks.append (buffer);
@@ -160,7 +175,7 @@ void parseResourcesLine(const string &line) {
160
175
}
161
176
162
177
/* *
163
- * converts a task line to an item on the task list
178
+ * converts a task file line to an item on the task list
164
179
* @param line
165
180
*/
166
181
void parseTaskLine (const string &line) {
@@ -196,6 +211,11 @@ void parseTaskLine(const string &line) {
196
211
taskList.push_back (newTask);
197
212
}
198
213
214
+ /* *
215
+ * Returns Input File Line Type
216
+ * @param line
217
+ * @return
218
+ */
199
219
LINE_TYPES getInputFileLineType (const string &line) {
200
220
const char *flag;
201
221
if (!line.length () || line[0 ] == ' #' || line[0 ] == ' \r ' || line[0 ] == ' \n ' ) {
@@ -216,6 +236,10 @@ LINE_TYPES getInputFileLineType(const string &line) {
216
236
return INVALID_LINE;
217
237
}
218
238
239
+ /* *
240
+ * Converts a input line into a system resource, if a correct type
241
+ * @param line
242
+ */
219
243
void parseInputFileLine (const string &line) {
220
244
switch (getInputFileLineType (line)) {
221
245
case TASK_LINE:
@@ -236,6 +260,10 @@ void parseInputFileLine(const string &line) {
236
260
}
237
261
}
238
262
263
+ /* *
264
+ * Converts a input file into a system resource, if formatted correctly
265
+ * @param inputFile
266
+ */
239
267
void readInputFile (const string &inputFile) {
240
268
string line; // line read from file
241
269
0 commit comments