aggiungendo la logica..
parent
c29081e4c1
commit
ee4fecc893
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"ip1": {
|
||||
"queue_id": "queueObject",
|
||||
"thr": "threadObject",
|
||||
"port": "int"
|
||||
},
|
||||
"ip2": {
|
||||
"queue_id": "queueObject",
|
||||
"thr": "threadObject",
|
||||
"port": "int"
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
'''
|
||||
Created on 19 mar 2020
|
||||
|
||||
@author: Emanuele Trabattoni
|
||||
'''
|
||||
|
|
@ -6,22 +6,22 @@ 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, logging
|
||||
import threading, sys, queue, logging
|
||||
from driver.tsc_printer import tsc_printer
|
||||
|
||||
Q_TIMEOUT = 2
|
||||
URL_ERR = 'tscprinter/errore/'
|
||||
URL_EVENT = 'tscprinter/evento/'
|
||||
|
||||
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: logging.getLogger):
|
||||
queue_ip_map={}
|
||||
printer_map={}
|
||||
|
||||
def get_queue_id(ip):
|
||||
return True
|
||||
if ip in printer_map.keys():
|
||||
return printer_map[str(ip)]['queue_id']
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_queue_command():
|
||||
return q_comm
|
||||
|
|
@ -29,16 +29,34 @@ def main(q_in :queue.Queue, q_out :queue.Queue, q_comm: queue.Queue, logger: log
|
|||
while True:
|
||||
try:
|
||||
comando = q_comm.get(block=True, timeout=Q_TIMEOUT)
|
||||
if comando['name'] == "CONNETTI":
|
||||
cmd = comando['name']
|
||||
par = comando['parameters']
|
||||
|
||||
if cmd == "CONNETTI":
|
||||
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[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
|
||||
t_prt = threading.Thread(name = f"Stampante {par['ip']}:{par['port']}",
|
||||
target = tsc_printer,
|
||||
args = [q_in_prt, q_out, q_cmd_prt, par['ip'], par['port'], logger],
|
||||
daemon = True)
|
||||
printer_map[par['ip']]['thr'] = t_prt # aggiungi il nuovo thread al dict dei thread
|
||||
t_prt.start()
|
||||
pass
|
||||
|
||||
elif comando['name'] == "DISCONNETTI":
|
||||
pass
|
||||
|
||||
else:
|
||||
q_out.put({'url':URL_ERR,
|
||||
'msg':{'error':'comando inesistente'}
|
||||
})
|
||||
logger.error("Comando non Trovato")
|
||||
except queue.Empty:
|
||||
logger.error("Coda comandi vuota")
|
||||
except (InterruptedError, KeyboardInterrupt):
|
||||
logger.critical("sto quittando")
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
'''
|
||||
Created on 19 mar 2020
|
||||
|
||||
@author: Emanuele Trabattoni
|
||||
'''
|
||||
|
||||
import queue, sys, time, socket, logging
|
||||
|
||||
SOCK_TIMEOUT = 2
|
||||
|
||||
def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: str, port: int, logger: logging.getLogger):
|
||||
|
||||
def riconnetti_socket():
|
||||
pass
|
||||
|
||||
def invia_file():
|
||||
pass
|
||||
|
||||
def elimina_file():
|
||||
pass
|
||||
|
||||
def muovi_file():
|
||||
pass
|
||||
|
||||
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)
|
||||
while True:
|
||||
itm = q_in.get(block=True)
|
||||
cmd = itm['name']
|
||||
par = itm['parameters']
|
||||
if cmd == 'DOWNLOAD':
|
||||
pass
|
||||
elif cmd == 'REMOVE':
|
||||
pass
|
||||
elif cmd == 'MOVE':
|
||||
pass
|
||||
elif cmd == 'LIST':
|
||||
pass
|
||||
elif cmd == 'RUN':
|
||||
pass
|
||||
else:
|
||||
logger.error("Comando stampante non riconosciuto")
|
||||
except socket.timeout as st:
|
||||
logger.error(f"Stampante {__name__} irraggiungibile:{st}")
|
||||
prt.close()
|
||||
del prt
|
||||
except Exception as e:
|
||||
logger.error("Errore generale inizializzando la stampante: {}".format(e))
|
||||
|
||||
pass
|
||||
Loading…
Reference in New Issue