1
0
mirror of https://github.com/linux-msm/qrtr.git synced 2024-11-01 10:18:06 +00:00
qrtr/qrtr.py
Dylan Van Assche ef44ad10f2
Some checks failed
CodeQL / Analyze (cpp) (push) Failing after 3m27s
Builds / Build (i386, gcc, debian:stable, i686-linux-gnu, x86, /usr/lib/i386-linux-gnu/pkgconfig, i386) (push) Failing after 13s
Builds / Build (armhf, arm-linux-gnueabihf-gcc, debian:testing, arm-linux-gnueabihf, arm, /usr/lib/arm-linux-gnueabihf/pkgconfig, cross-compile) (push) Failing after 16s
Builds / Build (i386, gcc, debian:bookworm, i686-linux-gnu, x86, /usr/lib/i386-linux-gnu/pkgconfig, i386) (push) Failing after 18s
Builds / Build (s390x, s390x-linux-gnu-gcc, debian:stable, s390x-linux-gnu, s390x, /usr/lib/s390x-linux-gnu/pkgconfig, cross-compile) (push) Failing after 3s
Builds / Build (x86-64, clang, debian:bookworm, , x86-64, , ) (push) Failing after 3s
Builds / Build (x86-64, clang, fedora:39, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, clang, debian:bullseye, , x86-64, , ) (push) Failing after 10s
Builds / Build (x86-64, clang, debian:testing, , x86-64, , ) (push) Failing after 5s
Builds / Build (x86-64, clang, archlinux:latest, , x86-64, , ) (push) Failing after 2s
Builds / Build (x86-64, clang, fedora:37, , x86-64, , ) (push) Failing after 5s
Builds / Build (x86-64, clang, fedora:38, , x86-64, , ) (push) Failing after 5s
Builds / Build (x86-64, clang, debian:stable, , x86-64, , ) (push) Failing after 6s
Builds / Build (x86-64, clang, fedora:latest, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, clang, ubuntu:focal, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, gcc, alpine:edge, x86-64, true) (push) Failing after 4s
Builds / Build (x86-64, gcc, archlinux:latest, , x86-64, , ) (push) Failing after 2s
Builds / Build (x86-64, gcc, alpine:latest, x86-64, true) (push) Failing after 6s
Builds / Build (x86-64, gcc, debian:bookworm, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, gcc, debian:bullseye, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, gcc, debian:stable, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, gcc, debian:testing, , x86-64, , ) (push) Failing after 4s
Builds / Build (arm64, aarch64-linux-gnu-gcc, debian:stable, aarch64-linux-gnu, aarch64, /usr/lib/aarch64-linux-gnu/pkgconfig, cross-compile) (push) Failing after 21s
Builds / Build (arm64, aarch64-linux-gnu-gcc, debian:testing, aarch64-linux-gnu, aarch64, /usr/lib/aarch64-linux-gnu/pkgconfig, cross-compile) (push) Failing after 20s
Builds / Build (i386, gcc, debian:testing, i686-linux-gnu, x86, /usr/lib/i386-linux-gnu/pkgconfig, i386) (push) Failing after 13s
Builds / Build (ppc64el, powerpc64le-linux-gnu-gcc, debian:stable, powerpc64le-linux-gnu, ppc64, /usr/lib/powerpc64le-linux-gnu/pkgconfig, cross-compile) (push) Failing after 12s
Builds / Build (armhf, arm-linux-gnueabihf-gcc, debian:stable, arm-linux-gnueabihf, arm, /usr/lib/arm-linux-gnueabihf/pkgconfig, cross-compile) (push) Failing after 18s
Builds / Build (ppc64el, powerpc64le-linux-gnu-gcc, debian:testing, powerpc64le-linux-gnu, ppc64, /usr/lib/powerpc64le-linux-gnu/pkgconfig, cross-compile) (push) Failing after 4s
Builds / Build (s390x, s390x-linux-gnu-gcc, debian:testing, s390x-linux-gnu, s390x, /usr/lib/s390x-linux-gnu/pkgconfig, cross-compile) (push) Failing after 4s
Builds / Build (x86-64, clang, ubuntu:jammy, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, clang, ubuntu:lunar, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, gcc, fedora:37, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, gcc, fedora:38, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, gcc, fedora:39, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, gcc, fedora:latest, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, gcc, ubuntu:focal, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, gcc, ubuntu:jammy, , x86-64, , ) (push) Failing after 4s
Builds / Build (x86-64, gcc, ubuntu:lunar, , x86-64, , ) (push) Failing after 4s
qrtr.py: adding missing buffer size arg to recvfrom
qrtr_recvfrom needs to know the size of the buffer, add this missing argument.
2024-08-21 17:51:52 +02:00

98 lines
3.3 KiB
Python
Executable File

#!/usr/bin/env python2.7
import ctypes
import collections
from ctypes import CDLL, CFUNCTYPE, POINTER, cast, py_object
from ctypes import c_char_p, c_void_p, c_int, pointer
_qrtr = CDLL("./libqrtr.so")
class qrtr:
Result = collections.namedtuple('Result', ['service', 'instance', 'addr'])
_cbtype = CFUNCTYPE(None, c_void_p, c_int, c_int, c_int, c_int)
def __init__(self, port=0):
self.sock = _qrtr.qrtr_open(port)
if self.sock < 0:
raise RuntimeError("unable to open qrtr socket")
self.service = None
self._qrtr = _qrtr
def __del__(self):
self._qrtr.qrtr_close(self.sock)
def _lookup_list_add(self, ptr, srv, instance, node, port):
res = qrtr.Result(srv, instance, (node, port))
cast(ptr, POINTER(py_object)).contents.value.append(res)
def lookup(self, srv, instance=0, ifilter=0):
results = []
err = _qrtr.qrtr_lookup(self.sock, srv, instance, ifilter,
qrtr._cbtype(self._lookup_list_add), cast(pointer(py_object(results)), c_void_p))
if err:
raise RuntimeError("query failed")
return results
def publish(self, service, version, instance):
err = _qrtr.qrtr_publish(self.sock, service, version, instance)
if err:
raise RuntimeError("publish failed")
self.service = (service, version, instance)
def new_server(self, service, version, instance):
err = _qrtr.qrtr_new_server(self.sock, service, version, instance)
if err:
raise RuntimeError("new_server failed")
self.service = (service, version, instance)
return self.service
def remove_server(self, service):
err = _qrtr.qrtr_remove_server(self.sock, *service)
if err:
raise RuntimeError("remove_server failed")
self.service = None
def new_lookup(self, service, version, instance):
err = _qrtr.qrtr_new_lookup(self.sock, service, version, instance)
if err:
raise RuntimeError("new_lookup failed")
return (service, version, instance)
def remove_lookup(self, lookup):
err = _qrtr.qrtr_remove_lookup(self.sock, *lookup)
if err:
raise RuntimeError("remove_lookup failed")
def send(self, addr, data):
node, port = addr
n = _qrtr.qrtr_sendto(self.sock, node, port, c_char_p(data), len(data))
if n:
raise RuntimeError("sendto failed")
def recv(self, sz=65536):
buf = ctypes.create_string_buffer(sz)
n = _qrtr.qrtr_recv(self.sock, c_char_p(ctypes.addressof(buf)), sz)
if n <= 0:
raise RuntimeError("recv failed")
return buf[0:n]
def recvfrom(self, sz=65536):
node = ctypes.c_int()
port = ctypes.c_int()
buf = ctypes.create_string_buffer(sz)
n = _qrtr.qrtr_recvfrom(self.sock, c_char_p(ctypes.addressof(buf)), sz,
ctypes.byref(node), ctypes.byref(port))
if n <= 0:
raise RuntimeError("recvfrom failed")
return (buf[0:n], (node.value, port.value))
def poll(self, tout=0):
return _qrtr.qrtr_poll(self.sock, tout)
if __name__ == "__main__":
svcs = qrtr().lookup(15) # 15 is the test service
print " service instance addr"
for svc in svcs:
print "% 8d % 8d %s" % (svc.service, svc.instance, svc.addr)