device.java

来自「一个简单的操作系统模拟程序 java+swing 可进行一般的文件操作 进」· Java 代码 · 共 112 行

JAVA
112
字号
/*
 * Device.java ver 0.1.0
 *
 * Created on 2006年12月12日, 下午3:12
 *
 *To simulate a device to the system
 *
 *History   2006年12月12日 ver 0.1.0   class create
 *                                     first release
 *
 */

package ossimulation;

/**
 *
 * @author Decell.Zhou
 */
public class Device {
    
    /** Creates a new instance of Device */
    public Device(char argName) {
        name = argName;
        currentTime = 0;
        interruptRequestBit = 0;
        state = 0;//0 indicate that the device is idle
    }
    
    /**get the DRCB*/
    public DRCB getDRCB(){
        return currentRequest;
    }
    
    /**get the current device  tiem for the current request process time*/
    public int getCurrentTime(){
        return currentTime;
    }
    
    /**return the device's state*/
    public int getState(){
        return state;
    }
    
    /**get the interrupt bit,0 indicate that there is no interrupt*/
    public int getInterruptRequestBit(){
        return interruptRequestBit;
    }
    
    /**clear the interrupt request bit*/
    public void clearInterrupt(){
        interruptRequestBit = 0;
    }
    
    /**run method,simulate the behavior of device */
    public void run(){
        if(currentTime != 0){
            currentTime--;
            if(currentTime == 0){
                interruptRequestBit = 1;
                state = 0;// set the device to idle
            }
        }
    }
    
    /** load method, load a job into the device*/
    public void load(DRCB request){
        currentRequest = request;
        currentTime = currentRequest.getRequestTime();
        interruptRequestBit = 0;
        state = 1;//set the device to busy
    }
    
    /**main method, for the class debuging*/
    public static void main(String[] args){
        Device testDevice = new Device('A');
        PCB testPCB = new PCB(1);
        DRCB testDRCB = new DRCB(10,testPCB);
        testDevice.load(testDRCB);
        testDevice.run();
        
        System.out.println(testDevice.getInterruptRequestBit());
        System.out.println(testDevice.getDRCB().getRequestTime());
        System.out.println(testDevice.getCurrentTime());
        System.out.println(testDevice.getDRCB().getRequestProcess().getID());
        System.out.println("------------------------------");
        testDevice.run();
        testDevice.run();
        testDevice.run();
        System.out.println(testDevice.getCurrentTime());
        System.out.println(testDevice.getInterruptRequestBit());
        System.out.println("------------------------------");
        testDevice.run();
        testDevice.run();
        testDevice.run();
        testDevice.run();
        testDevice.run();
        System.out.println(testDevice.getCurrentTime());
        System.out.println(testDevice.getInterruptRequestBit());        
        System.out.println("------------------------------");
        testDevice.run();
        System.out.println(testDevice.getCurrentTime());
        System.out.println(testDevice.getInterruptRequestBit());
        
    }
    
    private char name;//the name of the device
    private DRCB currentRequest;//the process which requesting the device
    private int currentTime;//the current running time of the device
    private int interruptRequestBit;//the interrupt of the device
    private int state;//the busy or idle state of the device
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?