Operating-System-Simulator / Sim04 / simulator.h
simulator.h
Raw
#ifndef SIMULATOR_H
#define SIMULATOR_H

#include "datatypes.h"
#include "StringUtils.h"
#include "pthread.h"
#include "simtimer.h"

// function prototypes
bool accessMemory( MemoryNode *memNodePtr, int startIndex, int endIndex, int pid );
void allocateMemory( ConfigDataType *configPtr, fileWriteList **fileWriteListPtr, PCBLinkedList **pcbLLPtr,
                MemoryNode *memNodePtr, MemoryNode **headPtr, PCB *pcbPtr, int base, int offset );
void changeProcessState( ConfigDataType *configPtr, 
                            fileWriteList **fileWriteList, PCB *PCB, int state );
bool checkProgramEnd( PCBLinkedList **PCBLinkedListPtr );
PCB *chooseNextProcess( ConfigDataType *configPtr, fileWriteList **fileWriteList, 
                                               PCBLinkedList *PCBLinkedListPtr );
PCBLinkedList *clearPCBList( PCBLinkedList *pcbList );
MemoryNode *clearProcessMemory( MemoryNode *memNodePtr, MemoryNode **headPtr, int pid );
void createPCB( OpCodeType *startOpCode, PCBLinkedList **PCBLLIterPtr, int cycleTime );
int decrementCycles( ConfigDataType *configPtr, OpCodeType *opCodePtr, PCB *PCB );
void displayHandler( ConfigDataType *configPtr, fileWriteList **fileWriteListPtr, 
                                    char *toWrite, bool writeOnly, bool newLine );
MemoryNode *findOpenMemory( int logicalStartIndex, int logicalEndIndex, MemoryNode *memNodePtr );
PCB *FCFS_N_Choice( PCBLinkedList **PCBList, ConfigDataType *configPtr, fileWriteList **fileWriteListPtr );
PCB *SJF_N_Choice( PCBLinkedList **pcbList, ConfigDataType *configPtr, fileWriteList **fileWriteListPtr );
PCB *FCFS_P_Choice( PCBLinkedList **PCBList, ConfigDataType *configPtr, fileWriteList **fileWriteListPtr );
PCB *SRTF_P_Choice( PCBLinkedList **PCBList, ConfigDataType *configPtr, fileWriteList **fileWriteListPtr );
PCB *RR_P_Choice( PCBLinkedList **PCBList, ConfigDataType *configPtr, fileWriteList **fileWriteListPtr );
int getNextPID();
int getPCBListLength( PCBLinkedList **PCBList );
int getTimeFromOpCode( ConfigDataType *configPtr, OpCodeType *opCodePtr );
void initializeProcesses( ConfigDataType *configPtr, fileWriteList **fileWriteListPtr,
                          PCBLinkedList **PCBLinkedList );
void printPCBList( PCBLinkedList **pcbLLPtr );
void printMemoryList( MemoryNode *memNodePtr, ConfigDataType *configPtr, 
                      fileWriteList **fileWriteListPtr, int displayType );
void printWriteList( fileWriteList **fileWriteListPtr );
void scanForNewPCBs( OpCodeType **metaDataMstrPtr, PCBLinkedList **PCBLinkedListPtr, ConfigDataType *configPtr );
PCB *runProcess( ConfigDataType *configPtr, fileWriteList **fileWriteList, 
                 PCBLinkedList *PCBLinkedListPtr, PCB *PCB, MemoryNode *memNodePtr, MemoryNode **headPtr );
void runSim( ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr );
void runTimerFor( long milliseconds );
void runTimerForCycle( ConfigDataType *configPtr, OpCodeType *opCodePtr, PCB *PCB, PCBLinkedList **PCBLinkedListPtr, fileWriteList **writeList );
fileWriteList *writeToFile( ConfigDataType *configPtr, fileWriteList **printList );
void segfault( ConfigDataType *configPtr, fileWriteList **printList, PCBLinkedList **pcbLLPtr,
               MemoryNode *memNodePtr, MemoryNode **headPtr, PCB *pcbPtr );
void verifyLogicalAllocation( MemoryNode *memNodePtr, int startIndex, int endIndex, bool *collision );

enum PROCESS_STATES{NEW=0, READY, RUNNING, WAITING, EXIT};

enum MEMORY_USED{USED=6, OPEN};

enum MEMORY_PRINT{INIT=8, SUCCESS, CLEARONE, FAIL, CLEARALL, ACCESS_SUCCESS, ACCESS_FAIL};

// string end for fileWriteList 
#define END_OF_STRLIST "---end-of-list---"

#define STR_NEWLINE "--------------------------------------------------\n"

#define END_OF_MEM_LIST -1

#define END_OF_PCB_LIST -1

#endif // SIMULATOR_H