#ifndef METADATAOPS #define METADATAOPS #include "StandardConstants.h" #include "StringUtils.h" typedef enum {BAD_ARG_VAL = -1, NO_ACCESS_ERR, MD_FILE_ACCESS_ERR, MD_CORRUPT_DESCRIPTOR_ERR, OPCMD_ACCESS_ERR, CORRUPT_OPCMD_ERR, CORRUPT_OPCMD_ARG_ERR, UNBALANCED_START_END_ERR, COMPLETE_OPCMD_FOUND_MSG, LAST_OPCMD_FOUND_MSG } OpCodeMessages; typedef struct OpCodeTypeStruct { int pid; char command[MAX_STR_LEN]; char inOutArg[MAX_STR_LEN]; char strArg1[MAX_STR_LEN]; int intArg2; int intArg3; int opEndTime; struct OpCodeTypeStruct *nextNode; } OpCodeType; /* Name: addNode Process: adds metadata node to linked list recursively, handles empty list Function Input/Parameters: ptr to head or next linked node (OpCodeType *), ptr to new node (OpCodeType *) Function Output/Parameters: none Function Output/Returned: pointer to previous node, or head node (OpCodeType *) Device Input/Device: none Device Output/Device: none Dependencies: malloc, copyString */ OpCodeType *addNode(OpCodeType *localPtr, OpCodeType *newNode); /* Name: clearMetaDataList Process: recursively traverses list, frees dynamically allocated nodes Function Input/Parameters: node opcode (const OpCodeType *) Function Output/Parameters: none Function Output/Returned: NULL (OpCodeType *) Device Input/Device: none Device Output/Device: none Dependencies: ??? */ OpCodeType *clearMetaDataList(OpCodeType *localPtr); /* Name: displayMetaData Process: data dump/display of all opcode items Function Input/Parameters: pointer to head of opcode/metadata list (const OpCodeType *) Function Output/Parameters: none Function Output/Returned: calculated time (int) Device Input/Device: none Device Output/Device: none Dependencies: printf, compareString */ void displayMetaData(const OpCodeType *localPtr); /* Name: getCommand Process: parses thre letter command part of opcode str Function Input/Parameters: input opcode str (const char *), starting index (int) Function Output/Parameters: parsed command (char *) Function Output/Returned: updated starting index for use by calling fct (int) Device Input/Device: none Device Output/Device: none Dependencies: none */ int getCommand(char *cmd, const char *inputStr, int index); /* Name: getMetaData Process: main driver function to upload, parse, and store list of op code commands in a linked list Function Input/Parameters: file name (const char *) Function Output/Parameters: ptr to opcode linked list head ptr (OpCodeType **), result msg of fct state after completion (char *) Function Output/Returned: Boolean result of operation (bool) Device Input/File: op code list uploaded Device Output/Device: none Dependencies: copyString, fopen, getStringToDelimiter, compareString, fclose, malloc, getOpCommand, updateStartCount, updateEndCount, clearMetaDataList, free, addNode */ bool getMetaData(const char *fileName, OpCodeType **opCodeDataHead, char *endStateMsg); /* Name: getOpCommand Process: acquires one op command line from a previously opened file, parses it, and sets various struct members according to the three letter command Function Input/Parameters: ptr to open file handle (FILE *) Function Output/Parameters: ptr to one opcode struct (OpCodeType *) Function Output/Returned: coded result of operation (OpCodeMessages) Device Input/File: opcode line uploaded Device Output/Device: none Dependencies: getStringToDelimiter, getCommand, copyString, verifyValidCommand, compareString, getStringArg, verifyFirstStringArg, getNumberArg */ OpCodeMessages getOpCommand(FILE *filePtr, OpCodeType *inData); /* Name: getNumberArg Process: starts at given index, captures and assembles int arg, returns as parameter Function Input/Parameters: input str (const char *), starting index (int) Function Output/Parameters: pointer to captured integer value Function Output/Returned: updated index for next function start Device Input/Device: none Device Output/Device: none Dependencies: isDigit */ int getNumberArg(int *number, const char *inputStr, int index); /* Name: getStringArg Process: starts at given index, captures and assembles str arg, returns as parameter Function Input/Parameters: input str (const char *), starting index (int) Function Output/Parameters: ptr to captured string argument (char *) Function Output/Returned: updated index for next fct start Device Input/Device: none Device Output/Device: none Dependencies: none */ int getStringArg(char *strArg, const char *inputStr, int index); /* Name: isDigit Process: tests character parameter for digit, returns true if is digit, false otherwise Function Input/Parameters: test character (char) Function Output/Parameters: none Function Output/Returned: bool result of test (bool) Device Input/Device: none Device Output/Device: none Dependencies: none */ bool isDigit(char testChar); /* Name: updateEndCount Process: manages count of "end" arguments to be compared at end of process input Function Input/Parameters: initial count (int), test string for "end" (const char *) Function Output/Parameters: none Function Output/Returned: updated count, if "end" string found, otherwise no change Device Input/Device: none Device Output/Device: none Dependencies: compareString */ int updateEndCount(int count, const char *opString); /* Name: updateStartCount Process: manages count of "start" arguments to be compared at start of process input Function Input/Parameters: initial count (int), test string for "start" (const char *) Function Output/Parameters: none Function Output/Returned: updated count, if "start" string found, otherwise no change Device Input/Device: none Device Output/Device: none Dependencies: compareString */ int updateStartCount(int count, const char *opString); /* Name: verifyFirstStringArg Process: checks for all possibilities of first argument string of op command Function Input/Parameters: test string (const char *) Function Output/Parameters: none Function Output/Returned: bool result of test (bool) Device Input/Device: none Device Output/Device: none Dependencies: compareString */ bool verifyFirstStringArg(const char *strArg); /* Name: verifyValidCommand Process: checks for all possibilities of three-letter opcode command Function Input/Parameters: test string for command (const char *) Function Output/Parameters: none Function Output/Returned: bool result of test (bool) Device Input/Device: none Device Output/Device: none Dependencies: compareString */ bool verifyValidCommand(char *testCmd); #endif // METADATAOPS