diff --git a/driver/main.py b/driver/main.py index 905d75f..94b2506 100644 --- a/driver/main.py +++ b/driver/main.py @@ -22,10 +22,12 @@ app = Flask(__name__) @app.route('/tscprinter/printer//', methods=['POST']) def printer_in(ip, command): parameters = request.get_json() + print(f"Comando Stampante: {ip} {command} {str(parameters)}") # questo prossimo mi sa che non funzia perché la funzione # inizia a esistere quando si esegue tsc_manager.main ma poi non # viene esportata nello scope del modulo tsc_manager queue_id = tsc_manager.get_queue_id(ip) + print(queue_id) if queue_id is not None and queue_id in queues_in: queues_in[queue_id].put({'name': command, 'parameters': parameters}) return "Comando Stampante Inviato", 200 @@ -35,6 +37,7 @@ def printer_in(ip, command): @app.route('/tscprinter/gest/', methods=['POST']) def gest_in(command): parameters = request.get_json() + print(f"Comando Gestore: {str(parameters)}") # istes di sopra queue_command = tsc_manager.get_queue_command() if queue_command is not None: @@ -80,4 +83,6 @@ if __name__ == '__main__': # dico (aspettando) a django che siamo pronti a ricevere gli indirizzi # delle stampanti notifier.send_hello(queue_out) - serve(app, listen=listen) \ No newline at end of file + serve(app, listen=listen) + + \ No newline at end of file diff --git a/driver/tsc_manager.py b/driver/tsc_manager.py index bbbd703..114a7d3 100644 --- a/driver/tsc_manager.py +++ b/driver/tsc_manager.py @@ -28,18 +28,20 @@ def get_queue_command(): #lancia i thread, uno per stampante def main(q_in :queue.Queue, q_out :queue.Queue, q_comm: queue.Queue, logger: logging.getLogger): global printer_map + logger.info("Acceso manager") + printer_map['queue_command'] = q_comm while True: try: - comando = q_comm.get(block=True, timeout=Q_TIMEOUT) + comando = q_comm.get(block=True) cmd = comando['name'] par = comando['parameters'] - + logger.info(f"Arrivato comando {cmd}") if cmd == "CONNETTI": + logger.info(f"Connetto a {par['ip']}:{par['port']}") printer_map[par['ip']] = {} # genera nuove code in ingresso per la nuova stampante q_in_prt = queue.Queue() q_cmd_prt = queue.Queue() - printer_map['queue_command'] = q_comm printer_map[par['ip']]['queue_id'] = q_in_prt # aggiungi la nuova coda al dict delle code printer_map[par['ip']]['port'] = par['port'] # lancia un thread stampante con la nuova coda ingresso diff --git a/driver/tsc_printer.py b/driver/tsc_printer.py index 3c33b7a..be20421 100644 --- a/driver/tsc_printer.py +++ b/driver/tsc_printer.py @@ -75,7 +75,7 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s while True: # connetti mantieni vivo il socket try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as prt: - prt.create_connection(address=(ip, port), timeout=SOCK_TIMEOUT) + prt.connect((ip, port)) while True: itm = q_in.get(block=True) cmd = itm['name']