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