blob: e1e143f2176a7df4d3c70913ce5a2cb16b331c39 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#include <string.h>
#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;
}
|