corretti errori e debug

master
Emanuele Trabattoni 2020-03-20 11:58:16 +01:00
parent d57327cb4a
commit c168a8df07
3 changed files with 12 additions and 5 deletions

View File

@ -22,10 +22,12 @@ app = Flask(__name__)
@app.route('/tscprinter/printer/<ip>/<command>', 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/<command>', 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)
serve(app, listen=listen)

View File

@ -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

View File

@ -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']