void CreateFromFile(MGraph &G, char *filename, int IncInfo) { int i, j, k; VRType w = 0; VertexType v1, v2; FILE *f; f = fopen(filename, "r"); fscanf(f, "%d", &G.kind); if (G.kind % 2) w = INFINITY; fscanf(f, "%d", &G.vexnum); for (i = 0; i < G.vexnum; ++i) InputFromFile(f, G.vexs[i]); fscanf(f, "%d", &G.arcnum); for (i = 0; i < G.vexnum; ++i) for (j = 0; j < G.vexnum; ++j) { G.arcs[i][j].adj = w; G.arcs[i][j].info = NULL; } if (!(G.kind % 2)) w = 1; for (k = 0; k < G.arcnum; ++k) { fscanf(f, "%s%s", v1.name, v2.name); if (G.kind % 2) fscanf(f, "%d", &w); i = LocateVex(G, v1); j = LocateVex(G, v2); G.arcs[i][j].adj = w; if (IncInfo) InputArcFromFile(f, G.arcs[i][j].info); if (G.kind > 1) G.arcs[j][i] = G.arcs[i][j]; } fclose(f); }
int main(int argc, char *argv[]) { //set the variables int Select = 0; bool INTERACTIVE = false; bool test = false; SIMULATION* SIMINFO; FILE *DATA; if(argc !=5) { printf("+===================================+\n"); printf("| ProcSim |\n"); printf("|===================================|\n"); printf("| What type of simulation? |\n"); printf("|----+------------------------------|\n"); printf("| 1 | First Come First Server |\n"); printf("| 2 | Shortest Job First |\n"); printf("| 3 | Shortest Job Remaining |\n"); printf("| 4 | Round-Robin |\n"); printf("| 5 | Priority |\n"); printf("|----|--Multi-level Feedback Queue |\n"); printf("+----+------------------------------+\n\n\n\n"); printf("ProcSim <Input File> <Num of Processes> <Snapshot Time Interval> <Select>\n"); return -1; } if ((DATA=fopen(argv[1],"rt")) == NULL) { printf("Sorry Could not find the File\nIt might have ran away from you!\nmake sure it is in the same directory as me(Program)\n"); printf("I am going to skip the inputing from a file"); exit(0); } Select = atoi(argv[4]); //setup the Data SIMINFO= (SIMULATION*) malloc (sizeof (SIMULATION)); SIMINFO->IOProc = 0; SIMINFO->RQProc = 0; SIMINFO->Time = 0; SIMINFO->CPU_Idle = 0; SIMINFO->IOJFinished = -1;//indicate no jobs finished SIMINFO->TotalProc = atoi(argv[2]); SIMINFO->TimeInterval = atoi(argv[3]); SIMINFO->PCheck = false; sprintf(SIMINFO->SeqOfProc, ":"); PROCESS Proc[SIMINFO->TotalProc]; SIMINFO->RQProc = InputFromFile(Proc,DATA); SIMINFO->IOProc = 0; //ListProcess(Proc,SIMINFO); //just uncomment what function you need if(Select == 1) { FCFS(Proc, SIMINFO); } if(Select == 2) { SJF(Proc, SIMINFO); } if(Select == 3) { SJR(Proc, SIMINFO); } if(Select == 4) { RR(Proc, SIMINFO); } if(Select == 5) { PS(Proc,SIMINFO); } if(Select == 6) { //Not Implemented } if(test == true) { //Array_test(DATA,total); } //Interactive Mode if(INTERACTIVE == true) { //main menu for the ProSim functions printf("+===================================+\n"); printf("| ProcSim |\n"); printf("|===================================|\n"); printf("| What type of simulation? |\n"); printf("|----+------------------------------|\n"); printf("| 1 | First Come First Server |\n"); printf("| 2 | Shortest Job First |\n"); printf("| 3 | Shortest Job Remaining |\n"); printf("| 4 | Round-Robin |\n"); printf("| 5 | Priority |\n"); printf("| 6 | Multi-level Feedback Queue |\n"); printf("| x | Exit the program |\n"); printf("+----+------------------------------+\n"); } return 0; }
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rc; HBRUSH hBrush, hBrushOld; HPEN hPen, hPenOld; LOGBRUSH lgBrush; int index; static BioAPI_UUID_PTR uuid; BioAPI_RETURN bioReturn; TCHAR szUserName[100]; BioAPI_VERSION Version; BioAPI_BIR_HANDLE EnrolledTemplate, CapturedTemplate, ProcessedBir; BioAPI_INPUT_BIR birEnroll, birCapture, InputBirProcessed; BioAPI_BIR_HEADER birHeader; BioAPI_FAR MaxFAR, AchievedFAR; BioAPI_BOOL bResponse; BioAPI_BOOL bPrecedence = BioAPI_TRUE; static BioAPI_BSP_SCHEMA * CurrSchema; switch (iMsg) { case WM_PAINT : hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rc); lgBrush.lbStyle = BS_SOLID; lgBrush.lbColor = GetSysColor(COLOR_3DFACE); hBrush = CreateBrushIndirect(&lgBrush); hPen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DFACE)); hPenOld = SelectObject(hdc, hPen); hBrushOld = SelectObject(hdc, hBrush); Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom); SelectObject(hdc, hBrushOld); SelectObject(hdc, hPenOld); DeleteObject(hBrush); DeleteObject(hPen); EndPaint(hwnd, &ps); return 0; case WM_COMMAND : switch (HIWORD (wParam)) { case CBN_SELCHANGE : ReleaseBSP(&uuid); // Retrieve the index of the item selected index = SendMessage(hEnumTech, CB_GETCURSEL, 0, 0); // Retrieve a pointer to the uuid for the module CurrSchema = (BioAPI_BSP_SCHEMA *)SendMessage(hEnumTech, CB_GETITEMDATA, index, 0); uuid = (BioAPI_UUID *)malloc(sizeof(BioAPI_UUID)); if(uuid == NULL) { MessageBox(hwnd, TEXT("Unable to allocate memory to load the module identifier"), TEXT("BioAPI Sample"), MB_OK); return 0; } BioAPI_CopyUuid(uuid, CurrSchema->ModuleId); bioReturn = BioAPI_ModuleLoad(uuid, 0, NULL/*(BioAPI_ModuleEventHandler)BiometricEventHandler*/, 0); if(BioAPI_OK != bioReturn) { PrintErrorCode(bioReturn); free(uuid); uuid = NULL; return 0; } // wsprintf(szCurrHandle, TEXT("Current Handle: 0x%X"), hBtCurrent); // SetWindowText(hCurrHbt, szCurrHandle); Version.Major = BioAPI_MAJOR; Version.Minor = BioAPI_MINOR; bioReturn = BioAPI_ModuleAttach(uuid, &Version, &BioAPIWinMemoryFuncs, 0, 0,0,0, NULL, 0, NULL, &gModuleHandle); if(BioAPI_OK != bioReturn) { PrintErrorCode(bioReturn); BioAPI_ModuleUnload (uuid, NULL, 0); free(uuid); uuid = NULL; return 0; } break; case BN_CLICKED: switch (LOWORD (wParam)) { case IDOK : ReleaseBSP(&uuid); EndDialog(hwnd, 0); PostQuitMessage(0); break; case IDC_ENROLL : if(GetWindowText(hUserId, szUserName, 100)==0) MessageBox(hwnd, TEXT("Please specify a user id"), TEXT("Bad User Id"), MB_OK); else { bioReturn = BioAPI_Enroll(gModuleHandle, BioAPI_PURPOSE_ENROLL_FOR_VERIFICATION_ONLY, NULL, &EnrolledTemplate, NULL, -1, NULL); if(bioReturn != BioAPI_OK) { PrintErrorCode(bioReturn); return 0; } OutputToFile(szUserName, EnrolledTemplate); } break; case IDC_VERIFY : if(GetWindowText(hUserId, szUserName, 100)==0) MessageBox(hwnd, TEXT("Please specify a user id"), TEXT("Bad User Id"), MB_OK); else { if(InputFromFile(szUserName, &birEnroll) != BioAPI_OK) { MessageBox(hwnd, TEXT("User not enrolled"), TEXT("Bad User Id"), MB_OK); return 0; } // See if the BSP supports BioAPI_VerifyMatch by checking // the operations mask if(CurrSchema->Operations & BioAPI_VERIFYMATCH) { if((bioReturn = BioAPI_Capture(gModuleHandle, BioAPI_PURPOSE_VERIFY, &CapturedTemplate, -1, NULL)) != BioAPI_OK) { PrintErrorCode(bioReturn); GlobalFree(birEnroll.InputBIR.BIR); return 0; } if((bioReturn = BioAPI_GetHeaderFromHandle(gModuleHandle, CapturedTemplate, &birHeader)) != BioAPI_OK) { PrintErrorCode(bioReturn); GlobalFree(birEnroll.InputBIR.BIR); return 0; } if(birHeader.Type == BioAPI_BIR_DATA_TYPE_INTERMEDIATE) { birCapture.Form = BioAPI_BIR_HANDLE_INPUT; birCapture.InputBIR.BIRinBSP = &CapturedTemplate; if((bioReturn = BioAPI_Process(gModuleHandle, &birCapture, &ProcessedBir)) != BioAPI_OK) { PrintErrorCode(bioReturn); GlobalFree(birEnroll.InputBIR.BIR); return 0; } MaxFAR = 1; InputBirProcessed.Form = BioAPI_BIR_HANDLE_INPUT; InputBirProcessed.InputBIR.BIRinBSP = &ProcessedBir; } else { MaxFAR = 1; InputBirProcessed.Form = BioAPI_BIR_HANDLE_INPUT; InputBirProcessed.InputBIR.BIRinBSP = &CapturedTemplate; } bioReturn = BioAPI_VerifyMatch(gModuleHandle, &MaxFAR, NULL, &bPrecedence, &InputBirProcessed, &birEnroll, NULL, &bResponse, &AchievedFAR, NULL, NULL); } else // We simply call BioAPI_Verify { MaxFAR = 1; bioReturn = BioAPI_Verify(gModuleHandle, &MaxFAR, NULL, &bPrecedence, &birEnroll, NULL, &bResponse, &AchievedFAR, NULL, NULL, -1, NULL); } GlobalFree(birEnroll.InputBIR.BIR); if(bioReturn != BioAPI_OK) { PrintErrorCode(bioReturn); return 0; } if(bResponse == TRUE) MessageBox(hwnd, TEXT("Match"), TEXT("BioAPI"), MB_OK); else MessageBox(hwnd, TEXT("No Match"), TEXT("BioAPI"), MB_OK); } break; } break; } return 0 ; case WM_CLOSE : ReleaseBSP(&uuid); EndDialog(hwnd, 0); PostQuitMessage(0); return 0; case WM_DESTROY : ReleaseBSP(&uuid); EndDialog(hwnd, 0); PostQuitMessage(0); return 0 ; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; }