예제 #1
0
    def unsubscribe_me(self):
        if self.args.keep_subscribed:
            return

        logger.info("unsubscribing from '%s:%d'" % self.chaosc_address[0], self.chaosc_address[1])
        msg = OSCMessage("/unsubscribe")
        msg.appendTypedArg(self.own_address[0], "s")
        msg.appendTypedArg(self.own_address[1], "i")
        msg.appendTypedArg(self.args.authenticate, "s")
        self.sendto(msg, self.chaosc_address)
예제 #2
0
    def run(self):

        while self.running:
            try:
                reads, writes, errs = select.select([self.osc_sock], [], [],
                                                    0.005)
            except Exception, e:
                logging.exception(e)
                pass
            else:
                if reads:
                    try:
                        osc_input, address = self.osc_sock.recvfrom(8192)
                        osc_address, typetags, messages = decode_osc(
                            osc_input, 0, len(osc_input))
                        queue.put_nowait((osc_address, messages))
                    except Exception, e:
                        logger.info(e)
예제 #3
0
    def __init__(self, args):
        """Instantiate an OSCServer.
        server_address ((host, port) tuple): the local host & UDP-port
        the server listens on
        """
        self.address_family = args.address_family

        self.args = args
        self.own_address = client_host, client_port = resolve_host(args.client_host, args.client_port, self.address_family, socket.AI_PASSIVE)
        self.chaosc_address = chaosc_host, chaosc_port = resolve_host(args.chaosc_host, args.chaosc_port, self.address_family)

        logger.info("binding to %s:%r", client_host, client_port)
        UDPServer.__init__(self, self.own_address, OSCRequestHandler)

        self.socket.setblocking(0)
        if hasattr(args, "subscribe") and args.subscribe:
            self.subscribe_me()

        self.callbacks = {}
예제 #4
0
    def subscribe_me(self):
        """Use this procedure for a quick'n dirty subscription to your chaosc instance.

        :param chaosc_address: (chaosc_host, chaosc_port)
        :type chaosc_address: tuple

        :param receiver_address: (host, port)
        :type receiver_address: tuple

        :param token: token to get authorized for subscription
        :type token: str
        """
        logger.info("subscribing to '%s:%d' with label %r" % self.chaosc_address[0], self.chaosc_address[1], self.args.subscriber_label)
        msg = OSCMessage("/subscribe")
        msg.appendTypedArg(self.own_address[0], "s")
        msg.appendTypedArg(self.own_address[1], "i")
        msg.appendTypedArg(self.args.authenticate, "s")
        if self.args.subscriber_label is not None:
            msg.appendTypedArg(self.args.subscriber_label, "s")
        self.sendto(msg, self.chaosc_address)
예제 #5
0
    def __init__(self, args):
        super(OSCThread, self).__init__()
        self.args = args
        self.running = True

        self.client_address = resolve_host(args.client_host, args.client_port,
                                           args.address_family)

        self.chaosc_address = chaosc_host, chaosc_port = resolve_host(
            args.chaosc_host, args.chaosc_port, args.address_family)

        self.osc_sock = socket.socket(args.address_family, 2, 17)
        self.osc_sock.bind(self.client_address)
        self.osc_sock.setblocking(0)

        logger.info("%s: starting up osc receiver on '%s:%d'",
                    datetime.now().strftime("%x %X"), self.client_address[0],
                    self.client_address[1])

        self.subscribe_me()
예제 #6
0
    def __init__(self, args):
        SimpleOSCServer.__init__(self, args)

        self.addMsgHandler("X", self.stats_handler)

        if "unsubscribe" == args.subparser_name:
            msg = OSCMessage("/unsubscribe")
            msg.appendTypedArg(args.host, "s")
            msg.appendTypedArg(args.port, "i")
            msg.appendTypedArg(args.authenticate, "s")
            self.sendto(msg, self.chaosc_address)
            logger.info("unsubscribe %r:%r from %r:%r",
                args.host, args.port, args.chaosc_host, args.chaosc_port)

        elif "subscribe" == args.subparser_name:
            msg = OSCMessage("/subscribe")
            msg.appendTypedArg(args.host, "s")
            msg.appendTypedArg(args.port, "i")
            msg.appendTypedArg(args.authenticate, "s")
            if args.subscriber_label:
                msg.appendTypedArg(args.subscriber_label, "s")
            self.sendto(msg, self.chaosc_address)
            logger.info("subscribe %r:%r to %r:%r",
                args.host, args.port, args.chaosc_host, args.chaosc_port)

        elif "list" == args.subparser_name:
            msg = OSCMessage("/list")
            msg.appendTypedArg(args.client_host, "s")
            msg.appendTypedArg(args.client_port, "i")
            self.sendto(msg, self.chaosc_address)
        elif "save" == args.subparser_name:
            msg = OSCMessage("/save")
            msg.appendTypedArg(args.authenticate, "s")
            self.sendto(msg, self.chaosc_address)
        elif "pause" == args.subparser_name:
            msg = OSCMessage("/pause")
            msg.appendTypedArg(args.pause_state, "i")
            self.sendto(msg, self.chaosc_address)
        else:
            raise Exception("unknown command")
            sys.exit(1)
예제 #7
0
def main():
    arg_parser = ArgParser("ekgplotter")
    arg_parser.add_global_group()
    arg_parser.add_chaosc_group()
    arg_parser.add_subscriber_group()
    client_group = arg_parser.add_client_group()
    arg_parser.add_argument(client_group, '-W', "--client_width", type=int, default=640,
                      help='my host, defaults to "::"')
    arg_parser.add_argument(client_group, '-B', "--client_height", type=int, default=480,
                      help='my port, defaults to 8000')
    args = arg_parser.finalize()

    args.chaosc_host, args.chaosc_port = resolve_host(args.chaosc_host, args.chaosc_port, args.address_family)

    window = EkgPlotWidget(args)
    window.setWindowFlags(QtCore.Qt.FramelessWindowHint)
    logger.info("foooooooo")
    window.setWindowTitle("EKGPlotterMain")
    window.show()
    # sys.excepthook = window.sigint_handler
    # signal.signal(signal.SIGTERM, window.sigterm_handler)
    qtapp.exec_()
예제 #8
0
    def stats_handler(self, name, desc, messages, packet, client_address):
        if name == "#bundle":
            logger.info("subscribed client count: %d", len(messages))
            for osc_address, typetags, args in messages:
                logger.info("    host=%r, port=%r, label=%r", args[0], args[1], args[2])
        else:
            logger.info("chaosc returned status %r with args %r", name, messages)

        sys.exit(0)
예제 #9
0
    def __init__(self, args, parent=None):
        self.args = args
        QtGui.QMainWindow.__init__(self, parent)

        self.osc_sock = QUdpSocket(self)
        logger.info("osc bind localhost %d", self.args.client_port)
        self.osc_sock.bind(QHostAddress(self.args.client_host),
                           self.args.client_port)
        self.osc_sock.readyRead.connect(self.got_message)
        self.osc_sock.error.connect(self.handle_osc_error)
        self.subscribe()

        self.graphics_view = QtGui.QGraphicsView(self)
        self.resize(640, 480)
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Monospace"))
        font.setPointSize(12)
        font.setItalic(True)
        self.setFont(font)
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Midlight, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Dark, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Mid, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Shadow, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.AlternateBase,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipBase,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Midlight,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Dark, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Mid, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Shadow, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipBase,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Midlight,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Dark, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Mid, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Shadow, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipBase,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipText,
                         brush)
        self.graphics_view.setPalette(palette)
        self.graphics_view.setAutoFillBackground(False)
        self.graphics_view.setObjectName(_fromUtf8("graphics_view"))
        self.setCentralWidget(self.graphics_view)
        self.graphics_view.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.graphics_view.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.graphics_view.setRenderHint(QtGui.QPainter.Antialiasing, True)
        self.graphics_view.setFrameStyle(QtGui.QFrame.NoFrame)
        self.graphics_scene = QtGui.QGraphicsScene(self)
        self.graphics_scene.setSceneRect(0, 0, 640, 480)
        self.graphics_view.setScene(self.graphics_scene)
        self.default_font = QtGui.QFont("Monospace", 12)
        self.default_font.setStyleHint(QtGui.QFont.Monospace)
        self.default_font.setBold(True)
        self.graphics_scene.setFont(self.default_font)
        self.font_metrics = QtGui.QFontMetrics(self.default_font)
        self.line_height = self.font_metrics.height()
        self.setWindowTitle(_translate("MainWindow", "DumpGrabberMain", None))
        columns = 3
        self.column_width = 640 / columns
        self.text_storage = ExclusiveTextStorage(columns, self.default_font,
                                                 self.column_width,
                                                 self.line_height,
                                                 self.graphics_scene)
        self.text_storage.init_columns()
        self.regex = re.compile("^/(uwe|merle|bjoern)/(.*?)$")
        self.osc_sock.readyRead.connect(self.got_message)
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.render_image)
        self.timer.start(100)
예제 #10
0
 def reconnect(self):
     logger.info("reconnect serial")
     self.close()
     self.connect()
예제 #11
0
 def close(self):
     if self.serial_sock is not None:
         logger.info("close serial")
         self.serial_sock.close()
예제 #12
0
 def sigterm_handler(self, *args):
     logger.info("sigterm_handler")
     self.unsubscribe()
     QtGui.QApplication.exit()
예제 #13
0
class MjpegStreamingServer(QTcpServer):
    """A simple async http class which provides a mjpeg stream and if found,
        an index.html file containing the mjpeg stream.

        Parent should implement the interface 'MjpegStreamingConsumerInterface'
    """
    def __init__(self, server_address, parent=None, fps=12.5):
        super(MjpegStreamingServer, self).__init__(parent)
        self.server_address = server_address
        self.newConnection.connect(self.new_connection)
        assert isinstance(parent, MjpegStreamingConsumerInterface)
        self.widget = parent

        self.sockets = list()
        self.img_data = None
        self.fps = fps
        self.timer_delta = 1000 / fps
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.send_image)
        self.timer.start(self.timer_delta)
        self.stream_clients = list()
        self.get_regex = re.compile("^GET /(\w+?)\.(\w+?) HTTP/(\d+\.\d+)$")
        self.host_regex = re.compile("^Host: (\w+?):(\d+)$")
        self.html_map = dict()

    def handle_request(self):
        sock = self.sender()
        sock_id = id(sock)
        logger.info("handle_request: sock_id=%r", sock_id)
        if sock.state() in (QTcpSocket.UnconnectedState,
                            QTcpSocket.ClosingState):
            logger.info("connection closed")
            self.sockets.remove(sock)
            sock.deleteLater()
            return

        client_data = str(sock.readAll())
        logger.info("request %r", client_data)
        line = client_data.split("\r\n")[0]
        logger.info("first line: %r", line)
        try:
            resource, ext, http_version = self.get_regex.match(line).groups()
            logger.info("resource=%r, ext=%r, http_version=%r", resource, ext,
                        http_version)
        except AttributeError:
            try:
                host, port = self.host_regex.match(line).groups()
                logger.info("found host header %r %r", host, port)
                #return
                #sock.write("HTTP/1.1 501 Not Implemented\r\n")
                return
            except AttributeError:
                logger.info("no matching request - sending 404 not found")
                sock.write("HTTP/1.1 404 Not Found\r\n")
                return
        else:
            if ext == "ico":
                directory = self.widget.pubdir()
                try:
                    data = open(os.path.join(directory, "favicon.ico"),
                                "rb").read()
                except IOError:
                    logger.error(
                        "request not found/handled - sending 404 not found")
                    sock.write("HTTP/1.1 404 Not Found\r\n")
                    return
                else:
                    sock.write(QByteArray('HTTP/1.1 200 Ok\r\nContent-Type:' \
                        'image/x-ico\r\n\r\n%s' % data))
            elif ext == "html":
                directory = self.widget.pubdir()
                try:
                    data = open(os.path.join(directory, "index.html"),
                                "rb").read() % sock_id
                    self.html_map[sock_id] = None
                except IOError:
                    logger.error(
                        "request not found/handled - sending 404 not found")
                    sock.write("HTTP/1.1 404 Not Found\r\n")
                    return
                else:
                    sock.write(
                        QByteArray('HTTP/1.1 200 Ok\r\nContent-Type:"\
                        "text/html;encoding: utf-8\r\n\r\n%s' % data))
            elif ext == "mjpeg":
                try:
                    _, html_sock_id = resource.split("_", 1)
                    html_sock_id = int(html_sock_id)
                except ValueError:
                    html_sock_id = None

                if sock not in self.stream_clients:
                    logger.info("starting streaming...")
                    if html_sock_id is not None:
                        self.html_map[html_sock_id] = sock
                    self.stream_clients.append(sock)
                    sock.write(
                        QByteArray('HTTP/1.1 200 Ok\r\n" \
                        "Content-Type: multipart/x-mixed-replace;" \
                        "boundary=--2342\r\n\r\n'))
            else:
                logger.error(
                    "request not found/handled - sending 404 not found")
                sock.write("HTTP/1.1 404 Not Found\r\n")

    def slot_remove_connection(self):
        try:
            sock = self.sender()
        except RuntimeError:
            return
        if sock.state() == QTcpSocket.UnconnectedState:
            self.__remove_connection(sock)

    def __remove_connection(self, sock):
        sock_id = id(sock)
        sock.disconnected.disconnect(self.slot_remove_connection)
        sock.close()
        sock.deleteLater()
        try:
            self.sockets.remove(sock)
            logger.info("connection %r removed", sock_id)
        except ValueError, msg:
            logger.info("connection %r was not stored?", sock_id)

        try:
            self.stream_clients.remove(sock)
        except ValueError:
            logger.info("connection %r was not streaming", sock_id)

        # cleaning up streaming connections if that sock is serving index.html
        try:
            stream_client = self.html_map.pop(sock_id)
        except KeyError:
            logger.info("connection %r has no child connections", sock_id)
        else:
            try:
                stream_client.close()
                stream_client.deleteLater()
            except AttributeError, msg:
                logger.info("no stream client")
            else:
예제 #14
0
        # cleaning up streaming connections if that sock is serving index.html
        try:
            stream_client = self.html_map.pop(sock_id)
        except KeyError:
            logger.info("connection %r has no child connections", sock_id)
        else:
            try:
                stream_client.close()
                stream_client.deleteLater()
            except AttributeError, msg:
                logger.info("no stream client")
            else:
                try:
                    self.stream_clients.remove(stream_client)
                    logger.info("child connection %r removed from streaming",
                                id(stream_client))
                except ValueError:
                    pass

                try:
                    self.sockets.remove(stream_client)
                    logger.info("child connection %r removed from storage",
                                id(stream_client))
                except ValueError:
                    pass

    def send_image(self):
        if not self.stream_clients:
            return

        img_data = self.widget.render_image()
예제 #15
0
 def handle_osc_error(self, error):
     logger.info("osc socket error %d", error)
예제 #16
0
 def closeEvent(self, event):
     logger.info("closeEvent", event)
     self.unsubscribe()
     event.accept()
예제 #17
0
            except Exception, e:
                logging.exception(e)
                pass
            else:
                if reads:
                    try:
                        osc_input, address = self.osc_sock.recvfrom(8192)
                        osc_address, typetags, messages = decode_osc(
                            osc_input, 0, len(osc_input))
                        queue.put_nowait((osc_address, messages))
                    except Exception, e:
                        logger.info(e)

        self.unsubscribe_me()
        self.osc_sock.close()
        logger.info("OSCThread is going down")


queue = Queue.Queue()


class Actor(object):
    def __init__(self, name, num_data, color, ix, max_actors, actor_height):
        self.name = name
        self.num_data = num_data
        self.color = color
        self.ix = ix
        self.max_actors = max_actors
        self.actor_height = actor_height
        self.updated = 0
예제 #18
0
    def handle_request(self):
        sock = self.sender()
        logger.info("handle_request: %s %d", sock.peerAddress(), sock.peerPort())
        sock_id = id(sock)
        if sock.state() in (QTcpSocket.UnconnectedState, QTcpSocket.ClosingState):
            logger.info("connection closed")
            self.sockets.remove(sock)
            sock.deleteLater()
            return

        client_data = str(sock.readAll())
        logger.info("request %r", client_data)
        line = client_data.split("\r\n")[0]
        logger.info("first line: %r", line)
        try:
            resource, ext, http_version = self.get_regex.match(line).groups()
            logger.info("resource=%r, ext=%r, http_version=%r", resource, ext, http_version)
        except AttributeError:
            try:
                host, port = self.host_regex.match(line).groups()
                print "found host header", host, port
                return
                #sock.write("HTTP/1.1 501 Not Implemented\r\n")
            except AttributeError:
                logger.info("no matching request - sending 404 not found")
                sock.write("HTTP/1.1 404 Not Found\r\n")
                return
        else:
            if ext == "ico":
                directory = os.path.dirname(os.path.abspath(__file__))
                data = open(os.path.join(directory, "favicon.ico"), "rb").read()
                sock.write(QByteArray('HTTP/1.1 200 Ok\r\nContent-Type: image/x-ico\r\n\r\n%s' % data))
            elif ext == "html":
                directory = os.path.dirname(os.path.abspath(__file__))
                data = open(os.path.join(directory, "index.html"), "rb").read() % sock_id
                self.html_map[sock_id] = None
                sock.write(QByteArray('HTTP/1.1 200 Ok\r\nContent-Type: text/html;encoding: utf-8\r\n\r\n%s' % data))
            elif ext == "mjpeg":
                try:
                    _, html_sock_id = resource.split("_", 1)
                    html_sock_id = int(html_sock_id)
                except ValueError:
                    html_sock_id = None

                if sock not in self.stream_clients:
                    logger.info("starting streaming...")
                    if html_sock_id is not None:
                        self.html_map[html_sock_id] = sock
                    self.stream_clients.append(sock)
                    sock.write(QByteArray('HTTP/1.1 200 Ok\r\nContent-Type: multipart/x-mixed-replace; boundary=--2342\r\n\r\n'))
            else:
                logger.error("request not found/handled - sending 404 not found")
                sock.write("HTTP/1.1 404 Not Found\r\n")
예제 #19
0
 def exit():
     logger.info("the command seems to get no response - I'm dying now gracefully")
     os._exit(-1)