Exemplo n.º 1
0
class QueueElement(IElement):
    def __init__(self, id):
        super().__init__(id)
        self.init()

    def init(self):
        self.thread = None
        self.loop = False
        self.buffer = Buffer(self.id)

    def start(self):
        self.loop = True
        self.buffer.start()
        self.thread = Thread(target=self.run)
        self.thread.start()

    def stop(self):
        self.loop = False
        self.buffer.stop()
        self.thread.join()

    def run(self):
        while(self.loop):
            value = self.buffer.pop()
            if value is not None:
                if self.product is not None:
                    self.notify(self.product.process(value))
                else:
                    self.notify(value)

    def update(self, value):
        self.buffer.push(value)
Exemplo n.º 2
0
    def test_02(self):
        buf1 = Buffer("buf1")

        for i in range(1, 10):
            value = "TEST_{0}".format(i)
            buf1.push(value)
            self.assertEqual(i, buf1.size())
        
        buf1.clear()
        self.assertEqual(0, buf1.size())
Exemplo n.º 3
0
class VideoDisplaySubThread(IdentityObject):
    def __init__(self, id, logger, params):
        self.id = id
        self._loop = False
        self.buffer = Buffer(id)
        self.logger = logger
        self.params = params
        self.title = params["title"]
        self.left = params["left"]
        self.top = params["top"]

    def start(self):
        self.logger.info("VideoDisplaySubThread.start() IN")
        self._loop = True
        self.buffer.start()
        self._thread = threading.Thread(target=self.process)
        self._thread.start()
        self.logger.info("VideoDisplaySubThread.start() OUT")

    def stop(self):
        self.logger.info("VideoDisplaySubThread.stop() IN")
        self._loop = False
        self.buffer.stop()
        self._thread.join()
        self.logger.info("VideoDisplaySubThread.stop() OUT")

    def request(self, request):
        self.buffer.push(request)

    def process(self):
        self.logger.info("VideoDisplaySubThread.process() IN")
        while self._loop:
            request = self.buffer.pop()
            if request.Command == request.command_start:
                cv2.namedWindow(self.title,
                                cv2.WINDOW_AUTOSIZE | cv2.WINDOW_GUI_NORMAL)
                cv2.moveWindow(self.title, self.left, self.top)

            elif request.Command == request.command_stop:
                cv2.destroyWindow(self.title)

            elif request.Command == request.command_data:
                cv2.imshow(self.title, request.Body)
                cv2.waitKey(1)

            else:
                pass

        self.logger.info("VideoDisplaySubThread.process() OUT")
Exemplo n.º 4
0
    def test_01(self):
        buf1 = Buffer("buf1")
        buf2 = Buffer("buf2")
        buf3 = Buffer("buf3")

        buf1.start()
        buf2.start()
        buf3.start()

        expect = "test_test_test"

        buf1.push(expect)
        self.assertEqual(1, buf1.size())

        value2 = buf1.pop()
        self.assertEqual(0, buf1.size())
        self.assertEqual(expect, value2)

        buf2.push(value2)
        self.assertEqual(1, buf2.size())

        value3 = buf2.pop()
        self.assertEqual(0, buf2.size())
        self.assertEqual(expect, value3)

        buf3.push(value3)
        self.assertEqual(1, buf3.size())

        actual = buf3.pop()
        self.assertEqual(0, buf3.size())
        self.assertEqual(expect, actual)