def start(self): ModuleBase.start(self) for handler in self.__handlers: handler.start() RFModule.instance().register_device_handler(self.__radio_handler)
def stop(self): RFModule.instance().unregister_device_handler(self.__radio_handler) for handler in self.__handlers: handler.stop() ModuleBase.stop(self)
def load_and_configure_modules(cls, db): import_modules(['modules'], 'modules') for mod in ModuleBase.registered_modules(): if isinstance(mod, ModuleBase): mod.initialize() mod.configure(db)
def configure(self, database): ModuleBase.configure(self, database) # Checking database table try: database.select(Authentication.__exists_query) except: database.write(Authentication.__create_stmt) # Checking administrator user with database.writer(): admin_username = database.select(Authentication.__admin_exists_query).fetchone() if not admin_username: database.write( Authentication.__admin_insert_stmt, 'admin', hashlib.md5('admin').hexdigest()) print 'AUTH| Created default administrator user'
def configure(self, database): ModuleBase.configure(self, database) self.__radio_handler = RadioHandler() self.__handlers = [] # register communication handlers for idx in xrange(len(sysargs.communication.modes)): mode = sysargs.communication.modes[idx] port = sysargs.communication.ports[idx] host = sysargs.communication.hosts[idx] if mode.lower() == 'mcast': if port is None: port = ClientModule.DEFAULT_PORT if host is None: host = ClientModule.DEFAULT_MCAST_GROUP handler = UDPHandler(host, port, handler=self.handle_received_message, multicast=True) self.__handlers.append(handler) elif mode.lower() == 'bcast': if port is None: port = ClientModule.DEFAULT_PORT if host is None: host = ClientModule.DEFAULT_BCAST_ADDRESS handler = UDPHandler(host, port, handler=self.handle_received_message, broadcast=True) self.__handlers.append(handler) elif mode.lower() == 'udp': if port is None: port = ClientModule.DEFAULT_PORT if host is None: host = ClientModule.DEFAULT_BIND_ADDRESS handler = UDPHandler(host, port, handler=self.handle_received_message) self.__handlers.append(handler) elif mode.lower() == 'tcp': if port is None: port = ClientModule.DEFAULT_PORT if host is None: host = ClientModule.DEFAULT_BIND_ADDRESS handler = TCPHandler(host, port, handler=self.handle_received_message) self.__handlers.append(handler) else: print 'Unsupported communication mode:', mode
def initialize(self): ModuleBase.initialize(self) self.__sessions = { }
def stop_modules(cls): for mod in reversed( ModuleBase.registered_modules() ): if isinstance(mod, ModuleBase): mod.stop()
def start_modules(cls): for mod in ModuleBase.registered_modules(): if isinstance(mod, ModuleBase): mod.start()
def stop(self): try: self.__rf.stop() ModuleBase.stop(self) finally: self.__rf.cleanup()
def start(self): ModuleBase.start(self) self.__rf.start()
def configure(self, database): ModuleBase.configure(self, database) self.__rf.register_message_receiver(self)
def initialize(self): ModuleBase.initialize(self) self.__rf = NRF24L01P(payload_length=8, debug=False) self.__handlers = []