class Domotica: MAIN_CONFIG_FILE = 'conf/domotica.conf' logger_instance = logging.getLogger('domotica') save_data = [] def __init__(self): self.initialized = False self.RTCore = RealTimeCore.get_instance() self.rt_core = self.RTCore self.save_data.append(self.rt_core) self.conf = DomoticaConfigurator(self.MAIN_CONFIG_FILE) self.control = ControlCore.get_instance() self.save_data.append(self.control) self.network = NetworkCore.get_instance() def initialize(self): signal.signal(signal.SIGUSR1,self.signal_handler) self.logger_instance.info('Domotica, inicializa RealTimeCore') self.rt_core.initialize(self) self.logger_instance.info('Domotica, inicializa Configurator') self.conf.initialize(self) self.logger_instance.info('Domotica, inicializa ControlCore') self.control.initialize(self) self.logger_instance.info('Domotica, inicializa NetworkCore') self.network.initialize(self) self.initialized = True def start(self): if not self.initialized: raise DomoticaException("""No se inicializaron los cores. Llamar al metodo initialize() """) try : self.conf.load_configuration() except ConfiguratorException, e: self.logger_instance.info('Domotica, inicia sin cargar configuracion') self.logger_instance.debug("Error al cargar la configuracion %s" % repr(e)) self.rt_core.start() try : self.network.start() except KeyboardInterrupt: self.shutdown()
class ClientCore(SingletonCore,QObject): instance = None STATUS_TIMEOUT = 20 MAIN_CONFIG_FILE = 'ui/conf/domotica.conf' def __init__(self): QObject.__init__(self) self.net_core = ClientNetworkCore.get_instance() self.start_timer() self.clock_id = None self.in_ports = {} self.out_ports = {} self.channels = {} self.last_error = '' self.ports_loaded = False self.configurator = DomoticaConfigurator(self.MAIN_CONFIG_FILE) self.conf = {} self.load_configuration() # Context manager def __enter__(self): self.stop_timer() self.emit(QtCore.SIGNAL('requestWaiting()')) return self def __exit__(self, e_type, e_value, e_tb): self.start_timer() self.emit(QtCore.SIGNAL('requestArrived()')) # print "__exit__ client_Core" if e_type : if e_type == NetworkException : # print "uno" self.last_error = str(e_value) self.reset_status() self.emit(QtCore.SIGNAL('connectionClosed()')) return False if e_type == ClientCoreException: # print "dos" self.last_error = str(e_value) return False else: # print "tres" self.last_error = 'Se produjo un error inesperado' e = ClientCoreException(str(e_value),e_tb) self.last_error = str(e_value) self.emit(QtCore.SIGNAL('connectionClosed()')) raise e # Fin context manager def connect(self): with self as manager : self.net_core.connect() self.start_timer() self.emit(QtCore.SIGNAL('connected()')) # configuration def load_configuration(self): try : self.conf = self.configurator.load_configuration() except ConfiguratorException, e: print e else: