#
#   logactio  -  simple framework for doing configured action on certain
#                log file events
#
# SPDX-FileCopyrightText: Copyright 2012-  David Sommerseth <dazo@eurephia.org>
# SPDX-License-Identifier: GPL-2.0-only
#

import queue
import threading
import LogActio.Message as Message


class ReporterQueue:
    def __init__(self, qname, descr, processor):
        self.__thread = None
        self.__qname = qname
        self.__description = descr
        self.__queue = queue.Queue()

        self.__thread = threading.Thread(target=processor)


    def GetName(self):
        return self.__description


    def _Start(self):
        if not self.__thread.is_alive():
            self.__thread.start()


    def _Shutdown(self):
        self.__queue.put(Message.Message(Message.MSG_SHUTDOWN, 0, None))
        self.__queue.task_done()


    def _QueueMsg(self, prio, msg):
        self.__queue.put(Message.Message(Message.MSG_SEND, 0, msg))


    def _QueueGet(self):
        return self.__queue.get()
