import logging
from threading import Thread

import zmq
from zmq import Context
from zmq.devices import ThreadDevice

logger = logging.getLogger("ZeroMqEventManager.ForwarderDevice")


class ForwarderDevice(object):
    def __init__(self, context, pub_address, sub_address):
        # type: (Context, str, str) -> None
        self.context = context
        self.sub_address = pub_address
        self.push_address = sub_address

        self.frontend = None
        self.backend = None

        self.running = False
        self.device = None

    def start(self):
        # Socket facing clients
        self.device = ThreadDevice(zmq.FORWARDER, zmq.SUB, zmq.PUB)
        self.device.daemon = True
        self.device.setsockopt_in(zmq.SUBSCRIBE, b"")
        self.device.bind_in(self.sub_address)
        self.device.bind_out(self.push_address)
        self.device.start()

    def stop(self):
        pass
