summaryrefslogtreecommitdiff
path: root/src/py/cam/cam_null.py
blob: a6da9671ba4f72f061ae1d1c88aa0719cfda9fcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

import selectors
import sys


class NullRenderer:
    def __init__(self, state):
        self.state = state

        self.cm = state['cm']
        self.contexts = state['contexts']

        self.running = False

    def setup(self):
        pass

    def run(self):
        print('Capturing...')

        self.running = True

        sel = selectors.DefaultSelector()
        sel.register(self.cm.efd, selectors.EVENT_READ, self.readcam)
        sel.register(sys.stdin, selectors.EVENT_READ, self.readkey)

        print('Press enter to exit')

        while self.running:
            events = sel.select()
            for key, mask in events:
                callback = key.data
                callback(key.fileobj)

        print('Exiting...')

    def readcam(self, fd):
        self.running = self.state['event_handler'](self.state)

    def readkey(self, fileobj):
        sys.stdin.readline()
        self.running = False

    def request_handler(self, ctx, req):
        self.state['request_prcessed'](ctx, req)