aggiunte cose
parent
81185b11c6
commit
a0da94ea88
|
|
@ -8,30 +8,37 @@ Created on 19 mar 2020
|
|||
|
||||
from flask import Flask, escape, request
|
||||
import threading
|
||||
import multiprocessing
|
||||
import queue
|
||||
import sys
|
||||
import logging
|
||||
from waitress import serve
|
||||
import os
|
||||
from waitress import serve
|
||||
from driver import tsc_manager
|
||||
|
||||
#inizializza ascoltatore di Flask
|
||||
app = Flask(__name__)
|
||||
|
||||
#questo manda le rest di risposta a django
|
||||
@app.route('/markoprinter/<mac>/<command>', methods=['POST'])
|
||||
def hello(mac, command):
|
||||
@app.route('/tscprinter/printer/<ip>/<command>', methods=['POST'])
|
||||
def printer_in(ip, command):
|
||||
parameters = request.get_json()
|
||||
print(mac, command, parameters)
|
||||
queue_id = printer_manager.get_queue_id(mac)
|
||||
print(mac)
|
||||
print(printer_manager.mappa_mac)
|
||||
queue_id = tsc_manager.get_queue_id(ip)
|
||||
if queue_id is not None and queue_id in queues_in:
|
||||
print("trovata")
|
||||
queues_in[queue_id].put({'name': command, 'parameters': parameters})
|
||||
return "Inviato", 200
|
||||
return "Comando Stampante Inviato", 200
|
||||
else:
|
||||
print("non trovata")
|
||||
return "Stampante non trovata", 404
|
||||
|
||||
@app.route('/tscprinter/gest/<command>', methods=['POST'])
|
||||
def gest_in(command):
|
||||
parameters = request.get_json()
|
||||
queue_command = tsc_manager.get_queue_command()
|
||||
if queue_command is not None:
|
||||
queue_command.put({'name': command, 'parameters': parameters})
|
||||
return "Comando Gestore Inviato", 200
|
||||
else:
|
||||
return "Gestore non Disponibile", 404
|
||||
|
||||
|
||||
def build_logger():
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -51,11 +58,11 @@ def build_logger():
|
|||
logger.addHandler(cl)
|
||||
return logger
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = build_logger()
|
||||
queues_in = {}
|
||||
queue_out = multiprocessing.Queue()
|
||||
queue_command = queue.Queue()
|
||||
queue_out = queue.Queue()
|
||||
django_addr = ("http://{}:{}/"
|
||||
.format(os.getenv('DJANGO_HOST', '127.0.0.1'),
|
||||
os.getenv('DJANGO_PORT')))
|
||||
|
|
@ -63,8 +70,8 @@ if __name__ == '__main__':
|
|||
# args=[django_addr, queue_out, logger],
|
||||
# daemon=True)
|
||||
#t_notify_django.start()
|
||||
t_print = threading.Thread(target=printer_manager.main,
|
||||
args=[queues_in, queue_out, logger],
|
||||
t_print = threading.Thread(target=tsc_manager.main,
|
||||
args=[queues_in, queue_out, queue_command, logger],
|
||||
daemon=True)
|
||||
t_print.start()
|
||||
listen = "{}:{}".format(os.getenv("MARKOPRINTER_DRIVER_HOST"),
|
||||
|
|
|
|||
|
|
@ -6,20 +6,35 @@ Created on 19 mar 2020
|
|||
@contact: Scritto per Briq srl come collaboratore esterno, contiene dei frammenti di codice di proprieta' di Briq srl
|
||||
'''
|
||||
|
||||
import threading, socket, sys, queue
|
||||
import threading, socket, sys, queue, logging
|
||||
|
||||
Q_TIMEOUT = 2
|
||||
|
||||
def stampante(q_in, q_out, ip, ):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
#lancia i thread, uno per stampante
|
||||
def main(q_in :queue.Queue, q_out :queue.Queue, q_comm: queue.Queue, logger):
|
||||
def main(q_in :queue.Queue, q_out :queue.Queue, q_comm: queue.Queue, logger: logging.getLogger):
|
||||
queue_ip_map={}
|
||||
|
||||
def get_queue_id(ip):
|
||||
return True
|
||||
|
||||
def get_queue_command():
|
||||
return q_comm
|
||||
|
||||
while True:
|
||||
try:
|
||||
q_comm.get(block=True, timeout=Q_TIMEOUT)
|
||||
comando = q_comm.get(block=True, timeout=Q_TIMEOUT)
|
||||
if comando['name'] == "CONNETTI":
|
||||
elif comando['name'] == "DISCONNETTI":
|
||||
else:
|
||||
out
|
||||
logger.error("Comando non Trovato")
|
||||
except Empty:
|
||||
|
||||
|
||||
logger.error("Coda comandi vuota")
|
||||
pass
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue