from logging import Logger
from pymasep.communication import SocketHandler


class SocketHandlerQueue(SocketHandler):
    """
    Thread used to handle received messages from conn, addr

    :param conn: connected socket
    :param addr: remote address
    :param logger: logger used to log send and receive message
    :param queue: queue where the received messages are put
    """

    def __init__(self,
                 conn,
                 addr,
                 logger: Logger,
                 queue):
        super().__init__(conn=conn, addr=addr, logger=logger)
        self.receive_queue = queue

    def on_receive(self, frame):
        """
        Callback when a message is received (except for BYE frame). Put the frame message on the queue

        :param frame: frame received
        """
        self.receive_queue.put(frame.message)
