Esempio n. 1
0
 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
Esempio n. 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)
Esempio n. 3
0
 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()
Esempio n. 4
0
 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)
Esempio n. 5
0
 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
Esempio n. 6
0
 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
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 10
0
 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)
Esempio n. 11
0
 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()
Esempio n. 12
0
 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
Esempio n. 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)
Esempio n. 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)
Esempio n. 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())
Esempio n. 16
0
 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()))
     
Esempio n. 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])
Esempio n. 18
0
 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