예제 #1
0
 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"]
예제 #2
0
 def test_03(self):
     self.logger = Logger().getLogger()
     self.loop_work1 = True
     self.loop_work2 = True
     self.buffer = Buffer("TEST")
     self.buffer.start()
     self.logger.info("test_03 started")
     threading.Thread(target=self.work1).start()
     threading.Thread(target=self.work2).start()
     time.sleep(30)
     self.loop_work1 = False
     self.loop_work2 = False
     self.buffer.stop()
     self.logger.info("test_03 stoped")
예제 #3
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())
예제 #4
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)
예제 #5
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")
예제 #6
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)
예제 #7
0
class BufferTest(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass

    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)
    
    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())
    
    def work1(self):
        while(self.loop_work1):
            time.sleep(1)
            self.buffer.push("TEST {0}".format(time.time()))
            self.logger.info("work1 pushed")
    
    def work2(self):
        while(self.loop_work2):
            val = self.buffer.pop()
            self.logger.info("work2 poped({0})".format(val))

    def test_03(self):
        self.logger = Logger().getLogger()
        self.loop_work1 = True
        self.loop_work2 = True
        self.buffer = Buffer("TEST")
        self.buffer.start()
        self.logger.info("test_03 started")
        threading.Thread(target=self.work1).start()
        threading.Thread(target=self.work2).start()
        time.sleep(30)
        self.loop_work1 = False
        self.loop_work2 = False
        self.buffer.stop()
        self.logger.info("test_03 stoped")
예제 #8
0
 def init(self):
     self.thread = None
     self.loop = False
     self.buffer = Buffer(self.id)