コード例 #1
0
ファイル: FileManager.py プロジェクト: ngarbezza/tpi-so1-tp
 def store_in_memory(self, the_file):
     '''Puts a file into the memory. Search for an address available.'''
     for a in range(self.get_limit_address()):
         if Memory.get_instance().get_value_at(a) is None:
             Memory.get_instance().store_at(a, the_file)
             break
     return a
コード例 #2
0
 def readall(self, *args):
     '''
     Store in memory all the data of a file opened first
     in memory, in an address specified.
     '''
     curr_path = self.get_file_manager().get_current_path()
     file_path = curr_path + '/' + args[1].get_value()
     file_data = args[0].get_file_at(file_path).get_data()
     Memory.get_instance().store_at_relative(args[0], args[2].get_value(),
                                             file_data)
コード例 #3
0
ファイル: OS.py プロジェクト: ngarbezza/tpi-so1-tp
 def shutdown(self):
     self.set_inactive()
     self.get_cpu().shutdown()
     self.get_lt_scheduler().set_inactive()
     self.get_scheduler().set_inactive()
     for d in self.get_io_devices():
         self.get_io_devices()[d].shutdown()
     Memory.get_instance().clear_all()
     Logger.get_instance().close_log_file()
     self.reset()
コード例 #4
0
ファイル: FileManager.py プロジェクト: ngarbezza/tpi-so1-tp
 def close(self, file_name):
     '''
     Decrement the ref_count of the file. 
     If ref_count reaches 0, removes the file from memory.
     '''
     complete_name = self.get_current_path() + '/' + file_name
     for a in range(self.get_limit_address()):
         the_file = Memory.get_instance().get_value_at(a)
         if the_file is not None and the_file.get_name() == complete_name:
             the_file.dec_ref_count()
             if the_file.get_ref_count() <= 0:
                 Memory.get_instance().remove(a)
             break
     Logger.get_instance().log_closefile(file_name)
コード例 #5
0
ファイル: FileManager.py プロジェクト: ngarbezza/tpi-so1-tp
 def is_opened(self, file_name):
     '''Verify that a file is loaded in the memory.'''
     for a in range(self.get_limit_address()):
         value = Memory.get_instance().get_value_at(a)
         if value is not None and value.get_name() == file_name:
             return True
     return False
コード例 #6
0
ファイル: FileManager.py プロジェクト: ngarbezza/tpi-so1-tp
 def search_file_in_memory(self, name):
     '''Search for a file in memory by receiving a file name.'''
     for a in range(self.get_limit_address()):
         the_file = Memory.get_instance().get_value_at(a)
         if the_file is not None and the_file.get_name() == name:
             return the_file
     return None
コード例 #7
0
 def sub(self, *args):
     '''
     Instruction for data substract. Not implemented in Strings.
     
     @param args: tuple with PCB and the instruction arguments.
     '''
     mem = Memory.get_instance()
     args[1].do_sub(args[0], args[2], self.get_cpu().get_registers(), mem)
コード例 #8
0
 def add(self, *args):
     '''
     Instruction for data adding. Concatenation in Strings.
     
     @param args: tuple with PCB and the instruction arguments.
     '''
     mem = Memory.get_instance()
     args[1].do_add(args[0], args[2], self.get_cpu().get_registers(), mem)
コード例 #9
0
 def mov(self, *args):
     '''
     Instruction for data moving.
     
     @param args: tuple with PCB, destination and source of the mov.
     '''
     mem = Memory.get_instance()
     args[1].do_mov(args[0], args[2], self.get_cpu().get_registers(), mem)
コード例 #10
0
ファイル: OS.py プロジェクト: ngarbezza/tpi-so1-tp
 def load(self, file_name):
     '''
     Executes a file storaged in the file system, in the folder "programs". 
     First load the loader :-) , to leave in memory the program to run.
     '''
     if self.__loader_is_running():
         raise OSException('Error: The loader is running.')
     loader = self.__make_loader(file_name)
     self.__set_time_parameters(loader)
     banker = self.get_cpu().get_banker()
     banker.loader_come(banker.calculate_new_max(loader.get_pcb()))
     self.get_process_store().put_in_all_process(loader)
     self.get_process_store().put_in_ready_queue(loader.get_pcb())
     while Memory.get_instance().get_value_at(1) is None:
         time.sleep(1)
     self.__load_program(Memory.get_instance().get_value_at(1))
     Memory.get_instance().remove(1)
コード例 #11
0
ファイル: FileManager.py プロジェクト: ngarbezza/tpi-so1-tp
 def __init__(self, is_console):
     '''
     Constructor of FileManager. This class can be instantiated by the
     operating system, or by the console.
     '''
     if is_console:
         Memory()
         Logger()
         Logger.get_instance().open_log_file()
     self._limit_address = MAX_OPENED_FILES
     self._current_dir = ('/', 0)  #the root directory
     self._low_level_fm = LowerLevelFM()
コード例 #12
0
ファイル: OS.py プロジェクト: ngarbezza/tpi-so1-tp
 def __init__(self):
     ''' Constructor of OS.'''
     Memory()  #create the singleton memory
     Logger()  #initialize the logger
     self._parser = OSParser()
     self._file_manager = FileManager(False)
     self._proc_store = ProcessStore()
     self._io_devices = self.create_io_devices()
     banker = BankersAlgorithm(self.get_total_resources())
     ProcessKiller(banker, self._proc_store)
     self._cpu = CPU(banker, self._io_devices, self._proc_store)
     self._scheduler = self.create_scheduler(self._cpu, self._proc_store)
     self._lt_scheduler = LTScheduler(self._proc_store)
     self._active = False
コード例 #13
0
 def intinput(self, *args):
     '''Open a screen and request a integer.'''
     args[2].do_input(args[0], args[1], Memory.get_instance(), True)
コード例 #14
0
 def input(self, *args):
     '''Open a screen and request a string.'''
     args[2].do_input(args[0], args[1], Memory.get_instance(), False)
コード例 #15
0
 def show(self, *args):
     '''Print in screen instruction.'''
     pcb = args[0]
     for arg in args:
         if not arg == pcb: 
             arg.do_show(pcb, Memory.get_instance())
コード例 #16
0
ファイル: MemoryCell.py プロジェクト: ngarbezza/tpi-so1-tp
 def get_write_data(self, pcb):
     '''Get the data for a write operation (as a string).'''
     mem = Memory.get_instance()
     return str(mem.get_value_at_relative(pcb, self.get_value()))
     
コード例 #17
0
 def get_file_at(self, path):
     '''Search for a opened file.'''
     return Memory.get_instance().get_value_at(
         self.get_files_opened()[path])
コード例 #18
0
ファイル: FileManager.py プロジェクト: ngarbezza/tpi-so1-tp
 def check_available_space(self):
     '''Look for a memory address empty, if found it, returns it.'''
     for i in range(0, self._limit_address):
         if Memory.get_instance().get_value_at(i) is None:
             return True
     return False