Modestus Moon OS  R4
CS 450 project
R2

Files

file  pcb.h
 
file  linked_list.h
 

Functions

e_PROCESS_STATE_t getState (const char *name)
 getState gets the current state of the process More...
 
e_PCB_ERROR_CODE_t changeProcessState (const char *processName, e_PROCESS_STATE_t state)
 changeProcessState changes the state of the process being called More...
 
const char * errorToString (e_PCB_ERROR_CODE_t error)
 errorToString creates a string form of the error passed in More...
 
const char * classToString (e_PROCESS_CLASS_t processClass)
 classToString creates a string form of the class passed in More...
 
const char * stateToString (e_PROCESS_STATE_t state)
 stateToString creates a string form of the state passed in More...
 
e_PROCESS_CLASS_t stringToClass (const char *stringifiedClass)
 stringToClass returns the enum representation of a string More...
 
void printPCBFunc (void *pcb)
 printPCBFunc prints the status of a process More...
 
void setPrintFunction (linkedList_t *list, void(*newPrintFunc)(void *))
 sets the function whose job it is to print the list to the screen. More...
 

Detailed Description

This grouping provides a quick access to all development that occured during module R2. Each function or file that was added during this module can be found here.

Function Documentation

e_PCB_ERROR_CODE_t changeProcessState ( const char *  processName,
e_PROCESS_STATE_t  state 
)

changeProcessState changes the state of the process being called

Parameters
namethe name of the process to change the state of
statethe state to change the process to
Returns
e_PCB_ERROR_CODE_t value that describes the result

Definition at line 168 of file pcb.c.

References BLOCKED, ERROR_PCB_NOT_FOUND, ERROR_STATE_INVALID, findPCB(), INITIAL, insertPCB(), prevPCBError, READY, removePCB(), RUNNING, SUCCESS, and TERMINAL.

Referenced by blockPCB(), and unblockPCB().

169 {
171 
172  if (newState != INITIAL && newState != READY && newState != RUNNING &&
173  newState != BLOCKED && newState != TERMINAL)
174  {
176  return ERROR_STATE_INVALID;
177  }
178 
179  pcb_t* process = findPCB(processName);
180  if (!process) return ERROR_PCB_NOT_FOUND;
181 
182  process->processState = newState;
183 
184  removePCB(process);
185  insertPCB(process);
186 
187  return prevPCBError;
188 }
Definition: pcb.h:47
Definition: pcb.h:47
Definition: pcb.h:38
typedef for pcb_t struct
void insertPCB(pcb_t *pcbToInsert)
insertPCB insert the PCB into the queue represented by the process state, following each queue's rule...
Definition: pcb.c:132
Definition: pcb.h:47
Definition: pcb.h:47
pcb_t * findPCB(const char *processName)
findPCB will search all queues for the PCB with the input name
Definition: pcb.c:100
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
Definition: pcb.h:47
e_PCB_ERROR_CODE_t removePCB(pcb_t *pcbToRemove)
removePCB remove the input PCB from its associated queue
Definition: pcb.c:162
const char* classToString ( e_PROCESS_CLASS_t  processClass)

classToString creates a string form of the class passed in

Parameters
classthe class to parse to a string
Returns
the const char* of the class

Definition at line 289 of file pcb.c.

References CLASS_UNKNOWN, SYSTEM, and USER_APP.

Referenced by printPCBFunc().

290 {
291  switch(processClass)
292  {
293  case SYSTEM: return "System";
294  case USER_APP: return "User-App";
295  case CLASS_UNKNOWN: return "Class Unknown";
296  default: return "Error parsing class code";
297  }
298  return "Error parsing class code";
299 }
Definition: pcb.h:54
Definition: pcb.h:54
const char* errorToString ( e_PCB_ERROR_CODE_t  error)

errorToString creates a string form of the error passed in

Parameters
errorthe error to parse to a string
Returns
the const char* of the error

Definition at line 267 of file pcb.c.

References ERROR, ERROR_ALLOCATING_NODE, ERROR_CLASS_INVALID, ERROR_FREEING_NODE, ERROR_FREEING_PCB, ERROR_FREEING_STACK, ERROR_INSERTING_PCB, ERROR_NAME_COLLISION, ERROR_NAME_INVALID, ERROR_PCB_NOT_FOUND, ERROR_PRIORITY_INVALID, ERROR_REMOVING_PCB, ERROR_STATE_INVALID, and SUCCESS.

Referenced by blockPCB(), createPCB(), deletePCB(), resumePCB(), setPriority(), showPCB(), suspendPCB(), and unblockPCB().

268 {
269  switch(error)
270  {
271  case SUCCESS: return "Success";
272  case ERROR: return "Error";
273  case ERROR_PCB_NOT_FOUND: return "Error: PCB not found";
274  case ERROR_NAME_INVALID: return "Error: name invalid";
275  case ERROR_PRIORITY_INVALID: return "Error: priority invalid";
276  case ERROR_FREEING_NODE: return "Error freeing node";
277  case ERROR_FREEING_STACK: return "Error freeing stack";
278  case ERROR_FREEING_PCB: return "Error freeing PCB";
279  case ERROR_REMOVING_PCB: return "Error removing PCB";
280  case ERROR_STATE_INVALID: return "Error: State Invalid";
281  case ERROR_CLASS_INVALID: return "Error: Class Invalid";
282  case ERROR_ALLOCATING_NODE: return "Error Allocating Node";
283  case ERROR_NAME_COLLISION: return "Error: PCB Name Already in Use";
284  case ERROR_INSERTING_PCB: return "Error: PCB States have resulted in invalid transition";
285  default: return "Error parsing error code";
286  }
287 }
Definition: pcb.h:38
Definition: pcb.h:38
e_PROCESS_STATE_t getState ( const char *  name)

getState gets the current state of the process

Parameters
namethe name of the process
Returns
e_PROCESS_STATE_t the state of the process

Definition at line 210 of file pcb.c.

References findPCB(), prevPCBError, and SUCCESS.

211 {
213  pcb_t* process = findPCB(name);
214  return process->processState;
215 }
Definition: pcb.h:38
typedef for pcb_t struct
pcb_t * findPCB(const char *processName)
findPCB will search all queues for the PCB with the input name
Definition: pcb.c:100
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
void printPCBFunc ( void *  pcb)

printPCBFunc prints the status of a process

Parameters
pcbvoid pointer to a process

Definition at line 335 of file pcb.c.

References classToString(), printf, stateToString(), and suspensionToString().

Referenced by initPCBQueues(), setPriority(), and showPCB().

336 {
337  printf("PCB: %s | Priority: %d | Class: %s | State: %s | Suspension Status: %s\r\n",
338  ((pcb_t*)pcb)->name, ((pcb_t*)pcb)->priority, classToString(((pcb_t*)pcb)->processClass),
339  stateToString(((pcb_t*)pcb)->processState), suspensionToString(((pcb_t*)pcb)->processSuspensionState));
340 }
const char * classToString(e_PROCESS_CLASS_t processClass)
classToString creates a string form of the class passed in
Definition: pcb.c:289
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
typedef for pcb_t struct
const char * stateToString(e_PROCESS_STATE_t state)
stateToString creates a string form of the state passed in
Definition: pcb.c:301
const char * suspensionToString(e_PROCESS_SUSPENSION_STATE_t state)
Definition: pcb.c:317
void setPrintFunction ( linkedList_t list,
void(*)(void *)  newPrintFunc 
)

sets the function whose job it is to print the list to the screen.

Parameters
listto set the search funtion for
newPrintFuncpointer to function whose job is to print the data contained in the node. The argument of this function is the data conatined in the node. Traversal of the list starts one after the head and goes to the node before the tail.

Definition at line 207 of file linked_list.c.

Referenced by initHeap(), initPCBQueues(), and listTest().

208 {
209  list->printNodeFunc = newPrintFunc;
210 }
const char* stateToString ( e_PROCESS_STATE_t  state)

stateToString creates a string form of the state passed in

Parameters
statethe state to parse to a string
Returns
the const char* of the state

Definition at line 301 of file pcb.c.

References BLOCKED, INITIAL, READY, RUNNING, STATE_UNKNOWN, and TERMINAL.

Referenced by printPCBFunc().

302 {
303  switch(state)
304  {
305  case INITIAL: return "Initial";
306  case READY: return "Ready";
307  case RUNNING: return "Running";
308  case BLOCKED: return "Blocked";
309  //case SUSPENDED_READY: return "Suspended-ready";
310  //case SUSPENDED_BLOCKED: return "Suspened-blocked";
311  case TERMINAL: return "Terminal";
312  case STATE_UNKNOWN: return "State unknown";
313  default: return "Error parsing state code";
314  }
315 }
Definition: pcb.h:47
Definition: pcb.h:47
Definition: pcb.h:47
Definition: pcb.h:47
Definition: pcb.h:47
e_PROCESS_CLASS_t stringToClass ( const char *  stringifiedClass)

stringToClass returns the enum representation of a string

Parameters
stringifiedClassthe string that represents a process class enum
Returns
string represenation of the e_PROCESS_STATE_t enum, returns value CLASS_UNKNOWN if error in processing occurs;

Definition at line 328 of file pcb.c.

References CLASS_UNKNOWN, strcmp(), SYSTEM, and USER_APP.

Referenced by createPCB().

329 {
330  if(!strcmp("System", stringifiedClass)){ return SYSTEM; }
331  if(!strcmp("User-App", stringifiedClass)){ return USER_APP; }
332  return CLASS_UNKNOWN;
333 }
Definition: pcb.h:54
Definition: pcb.h:54
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77