From b7e009a98698c4ed81b16cbc274a3b47793c1bab Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 3 Jun 2017 23:02:46 +0200 Subject: Config parser --- backend.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 backend.c (limited to 'backend.c') diff --git a/backend.c b/backend.c new file mode 100644 index 0000000..e1e143f --- /dev/null +++ b/backend.c @@ -0,0 +1,43 @@ +#include +#include "midimonster.h" +#include "backend.h" + +static size_t nbackends = 0; +static backend* backends = NULL; + +backend* backend_match(char* name){ + size_t u; + for(u = 0; u < nbackends; u++){ + if(!strcmp(backends[u].name, name)){ + return backends + u; + } + } + return NULL; +} + +backend* mm_backend_register(backend b){ + if(!backend_match(b.name)){ + backends = realloc(backends, (nbackends + 1) * sizeof(backend)); + if(!backends){ + fprintf(stderr, "Failed to allocate memory\n"); + nbackends = 0; + return NULL; + } + backends[nbackends] = b; + nbackends++; + + fprintf(stderr, "Registered backend %s\n", b.name); + return backends + (nbackends - 1); + } + return NULL; +} + +int backends_stop(){ + size_t u; + for(u = 0; u < nbackends; u++){ + backends[u].shutdown(); + } + free(backends); + nbackends = 0; + return 0; +} -- cgit v1.2.3