Commit dd4e7895 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Add Python bindings for codingParameters.

parent dc696f1d
Loading
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -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)
+23 −0
Original line number Diff line number Diff line
#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);

+1 −0
Original line number Diff line number Diff line
@@ -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);

+4 −0
Original line number Diff line number Diff line
@@ -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) {
+2 −0
Original line number Diff line number Diff line
@@ -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);
Loading