Commit dd4e7895 authored by Andreas Schmidt's avatar Andreas Schmidt

Add Python bindings for codingParameters.

parent dc696f1d
Pipeline #1649 passed with stages
in 1 minute and 39 seconds
......@@ -24,13 +24,18 @@ cdef extern from "proto/channelStateInformation.h":
ctypedef prrtChannelStateInformation PrrtChannelStateInformation
cdef extern from "proto/codingParams.h":
cdef struct prrtCodingParams:
uint8_t k;
uint8_t r;
uint8_t n;
uint8_t n_p;
ctypedef struct prrtCodingParams:
uint8_t k
uint8_t r
uint8_t n
uint8_t c
uint8_t *n_cycle
ctypedef prrtCodingParams PrrtCodingParams
PrrtCodingParams *PrrtCodingParams_create()
PrrtCodingParams *PrrtCodingParams_copy(PrrtCodingParams *cpar)
bint PrrtCodingParams_update(PrrtCodingParams *cpar, uint8_t k, uint8_t n)
bint PrrtCodingParams_destroy(PrrtCodingParams *cpar)
cdef extern from "util/list.h":
cdef struct list:
......@@ -121,6 +126,9 @@ cdef extern from "proto/socket.h":
int32_t PrrtSocket_timedrecv(PrrtSocket *sock_ptr, void *buf_ptr, const uint32_t wait_time) nogil
bint PrrtSocket_set_sock_opt(PrrtSocket *sock_ptr, const_char *name, const uint32_t value)
uint32_t PrrtSocket_get_sock_opt(PrrtSocket *sock_ptr, const_char *name)
bint PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n)
PrrtCodingParams *PrrtSocket_get_coding_parameters(PrrtSocket *s)
bint PrrtSocket_uses_thread_pinning(PrrtSocket *socket)
uint32_t PrrtSocket_get_rtt(PrrtSocket *socket)
bint PrrtSocket_uses_thread_pinning(PrrtSocket *socket)
......@@ -145,4 +153,4 @@ cdef extern from "util/bptree.h":
cdef extern from "util/pipe.h":
ctypedef struct Pipe:
pass
\ No newline at end of file
pass
#include <pthread.h>
#include "../util/common.h"
#include "../util/dbg.h"
#include "../defines.h"
......@@ -33,6 +34,28 @@ bool PrrtCodingParams_update(PrrtCodingParams *cpar, uint8_t k, uint8_t n) {
return true;
}
PrrtCodingParams* PrrtCodingParams_copy(PrrtCodingParams *cpar) {
PrrtCodingParams *result = PrrtCodingParams_create();
check(pthread_mutex_lock(&cpar->lock) == EXIT_SUCCESS, "Lock failed.");
result->k = cpar->k;
result->n = cpar->n;
result->r = cpar->r;
result->c = cpar->c;
result->n_cycle = (uint8_t*) realloc(result->n_cycle, result->c * sizeof(int8_t));
memcpy(result->n_cycle, cpar->n_cycle, result->c * sizeof(int8_t));
// PrrtCoder_get_coder(&result->coder, result->n, result->k); // TODO
check(pthread_mutex_unlock(&cpar->lock) == EXIT_SUCCESS, "Unlock failed");
return result;
error:
PERROR("Could not copy%s", "");
return NULL;
}
bool PrrtCodingParams_destroy(PrrtCodingParams * cpar) {
pthread_mutex_destroy(&cpar->lock);
......
......@@ -19,6 +19,7 @@ typedef struct prrtCodingParams {
} PrrtCodingParams;
PrrtCodingParams * PrrtCodingParams_create(void);
PrrtCodingParams * PrrtCodingParams_copy(PrrtCodingParams *cpar);
bool PrrtCodingParams_update(PrrtCodingParams * cpar, uint8_t k, uint8_t n);
bool PrrtCodingParams_destroy(PrrtCodingParams * cpar);
......
......@@ -478,6 +478,10 @@ bool PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n) {
return true;
}
PrrtCodingParams *PrrtSocket_get_coding_parameters(PrrtSocket *s) {
return PrrtCodingParams_copy(s->codingParameters);
}
bool PrrtSocket_cleanup(PrrtSocket *s) {
if (s->isSender) {
......
......@@ -93,6 +93,8 @@ uint32_t PrrtSocket_get_sock_opt(PrrtSocket *s, const char *name);
bool PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n);
PrrtCodingParams *PrrtSocket_get_coding_parameters(PrrtSocket *s);
int PrrtSocket_interrupt(PrrtSocket *s);
int PrrtSocket_close(PrrtSocket *s);
......
......@@ -75,6 +75,36 @@ cdef extern from "util/list.c":
cdef extern from "util/pipe.c":
pass
cdef class PrrtCodingConfiguration:
cdef cprrt.PrrtCodingParams* _c_config
def __cinit__(self):
self._c_config = cprrt.PrrtCodingParams_create()
def __dealloc__(self):
if self._c_config != NULL:
cprrt.PrrtCodingParams_destroy(self._c_config)
cdef copy(self, cprrt.PrrtCodingParams* other):
cprrt.PrrtCodingParams_destroy(self._c_config)
self._c_config = other
property k:
def __get__(self):
return int(self._c_config.k)
property n:
def __get__(self):
return int(self._c_config.n)
property r:
def __get__(self):
return int(self._c_config.r)
property c:
def __get__(self):
return int(self._c_config.c)
property n_cycle:
def __get__(self):
return list(<uint8_t[:self._c_config.c]> self._c_config.n_cycle)
cdef class PrrtSocket:
cdef cprrt.PrrtSocket* _c_socket
cdef bint isSender
......@@ -117,6 +147,16 @@ cdef class PrrtSocket:
raise Exception("Not a sender.")
return cprrt.PrrtSocket_get_rtt(self._c_socket) * 0.000001
property coding_configuration:
def __get__(self):
if not self.isSender:
raise Exception("Not a sender.")
res = PrrtCodingConfiguration()
cdef cprrt.PrrtCodingParams *params = cprrt.PrrtSocket_get_coding_parameters(self._c_socket)
res.copy(params)
return res
def recv(self):
cdef char buffer[65536]
cdef int32_t len
......
#!/usr/bin/env bash
rm prrt/prrt.c
# logging
echo "##############################################"
gcc-5 -v
python3 -c "import Cython; print(Cython.__name__, 'version', Cython.__version__)"
python3 -c "import setuptools; print(setuptools.__name__, 'version', setuptools.__version__)"
echo "##############################################"
python3 setup.py build_ext --inplace
cp prrt*.so ./build/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment