/// <summary> /// This function creates scheduler flags /// </summary> /// <param name="flags"> the OS flags to use to create the scheduler flags</param> /// <returns> the created scheduler flags or null if an error occurred</returns> private SchedulerFlags?CreateSchedulerFlags(OSFlags flags) { SchedulerFlags temp = new SchedulerFlags(); temp.schedulingPolicies = flags.schedulingPolicy; if (temp.schedulingPolicies == EnumSchedulingPolicies.ROUND_ROBIN) // if we are using round robin scheduling { temp.RR_Priority_Policy = flags.priorityPolicy; temp.RR_TimeSlice = flags.RR_Time_Slice; temp.RR_Type = flags.roundRobinType; temp.TimeSliceUnit = flags.RR_Time_Slice_Unit; } temp.allowCPUAffinity = flags.allowCPUAffinity; temp.defaultScheduler = flags.useDefaultScheduler; temp.runningWithNoProcesses = flags.runWithNoprocesses; temp.cpuClockSpeed = (int)sld_ClockSpeed.Value; temp.issuedLotteryTickets = new List <LotteryTicket>(); temp.drawnLotteryTickets = new List <LotteryTicket>(); return(temp); }
/// <summary> /// This function creates the flags for creating the OS core based on selected UI options /// </summary> /// <returns> the selected OS flags or null if an error occurred</returns> private OSFlags?CreateOsFlags() { OSFlags temp = new OSFlags(); if (rdb_Round_Robin.IsChecked != null && rdb_Round_Robin.IsChecked.Value) // if round robin is selected { temp.schedulingPolicy = EnumSchedulingPolicies.ROUND_ROBIN; if (rdb_RR_Seconds.IsChecked != null && rdb_RR_Seconds.IsChecked.Value) // if the seconds time unit is selected { temp.RR_Time_Slice_Unit = EnumTimeUnit.SECONDS; temp.RR_Time_Slice = Double.Parse(cmb_RRSeconds.SelectedValue.ToString()); } else if (rdb_RR_Ticks.IsChecked != null && rdb_RR_Ticks.IsChecked.Value) // if the ticks time unit is selected { temp.RR_Time_Slice_Unit = EnumTimeUnit.TICKS; temp.RR_Time_Slice = Double.Parse(cmb_RRTicks.SelectedValue.ToString()); } else { MessageBox.Show("Please Select a time unit"); // no time unit was selected return(null); } if (rdb_No_Priority.IsChecked != null && rdb_No_Priority.IsChecked.Value) // if the no priority option is selected { temp.priorityPolicy = EnumPriorityPolicy.NO_PRIORITY; } else if (rdb_Non_Preemptive.IsChecked != null && rdb_Non_Preemptive.IsChecked.Value) // if the non pre-emptive priority option is selected { temp.priorityPolicy = EnumPriorityPolicy.NON_PRE_EMPTIVE; } else if (rdb_Preemptive.IsChecked != null && rdb_Preemptive.IsChecked.Value) // if the pre-emptive priority option is selected { temp.priorityPolicy = EnumPriorityPolicy.PRE_EMPTIVE; } else { MessageBox.Show("Please Select a priority policy"); // if no priority option is selected return(null); } if (rdb_Static.IsChecked != null && rdb_Static.IsChecked.Value) // if the static option is selected { temp.roundRobinType = EnumRoundRobinType.STATIC; } else if (rdb_Dynamic.IsChecked != null && rdb_Dynamic.IsChecked.Value) // if the dynamic option is selected { temp.roundRobinType = EnumRoundRobinType.DYNAMIC; } else { MessageBox.Show("Please Select a Round Robin Type"); // if no option was selected return(null); } } else if (rdb_FirstCome_FirstServed.IsChecked != null && rdb_FirstCome_FirstServed.IsChecked.Value) // if first come first served is selected { temp.schedulingPolicy = EnumSchedulingPolicies.FIRST_COME_FIRST_SERVED; } else if (rdb_Shortest_Job_First.IsChecked != null && rdb_Shortest_Job_First.IsChecked.Value) // if shortest job first is selected { temp.schedulingPolicy = EnumSchedulingPolicies.SHORTEST_JOB_FIRST; } else if (rdb_Lottery.IsChecked != null && rdb_Lottery.IsChecked.Value) // if lottery is selected { temp.schedulingPolicy = EnumSchedulingPolicies.LOTTERY_SCHEDULING; } else if (rdb_FairShare.IsChecked != null && rdb_FairShare.IsChecked.Value) // if fair share is selected { temp.schedulingPolicy = EnumSchedulingPolicies.FAIR_SHARE_SCEDULING; } else { MessageBox.Show("Please select a scheduling policy"); // if no policy is selected return(null); } temp.CPUClockSpeed = (int)sld_ClockSpeed.Value; // clock speed if (chk_CPU_Affinity.IsChecked != null && chk_CPU_Affinity.IsChecked.Value) // is CPU affinity allowed? { temp.allowCPUAffinity = true; } else { temp.allowCPUAffinity = false; } temp.osState = EnumOSState.STOPPED; // the OS starts in the stopped state if (chk_No_Processes.IsChecked != null && chk_No_Processes.IsChecked.Value) // re we running with no processes? { temp.runWithNoprocesses = true; } else { temp.runWithNoprocesses = false; } if (chk_Suspend_On_Pre_emption.IsChecked != null && chk_Suspend_On_Pre_emption.IsChecked.Value) //Should processes suspend on pre-emption { temp.suspendOnPreEmption = true; } else { temp.suspendOnPreEmption = false; } if (chk_Suspend_On_State_Change_Running.IsChecked != null && chk_Suspend_On_State_Change_Running.IsChecked.Value) // should processes suspend when entering the running state { temp.suspendOnStateChange_Running = true; } else { temp.suspendOnStateChange_Running = false; } if (chk_Suspend_On_State_Change_Ready.IsChecked != null && chk_Suspend_On_State_Change_Ready.IsChecked.Value) // should processes suspend when entering the ready state { temp.suspendOnStateChange_Ready = true; } else { temp.suspendOnStateChange_Ready = false; } if (chk_Suspend_On_State_Change_Waiting.IsChecked != null && chk_Suspend_On_State_Change_Waiting.IsChecked.Value) // should processes suspend when entering the running state { temp.suspendOnStateChange_Waiting = true; } else { temp.suspendOnStateChange_Waiting = false; } if (chk_Use_Default_Scheduler.IsChecked != null && chk_Use_Default_Scheduler.IsChecked.Value) // are we using the default scheduler { temp.useDefaultScheduler = true; } else { temp.useDefaultScheduler = false; } if (chk_FaultKill.IsChecked != null && chk_FaultKill.IsChecked.Value) // should processes be killed upon having a page fault { temp.faultKill = true; } else { temp.faultKill = false; } if (chk_ForceKill.IsChecked != null && chk_ForceKill.IsChecked.Value) // should processes be force killed { temp.forceKill = true; } else { temp.forceKill = false; } SchedulerFlags?schedulerFlags = CreateSchedulerFlags(temp); if (schedulerFlags == null) { MessageBox.Show("An error occurred while creating the scheduler flags"); return(null); } temp.scheduler = new Scheduler(schedulerFlags.Value); // create a scheduler temp.interruptHandles = new InterruptHandles(); return(temp); // return the OS flags }