aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend.c
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2017-06-04 18:13:29 +0200
committercbdev <cb@cbcdn.com>2017-06-04 18:13:29 +0200
commit11e9dec049e64989c5f3656415d00c6c69851e8e (patch)
treef087aa41ead18a8b09657fd400bd8b20df80b13f /backend.c
parentbae15293ddc859a1ea426f15e7fa476f71ece020 (diff)
downloadmidimonster-11e9dec049e64989c5f3656415d00c6c69851e8e.tar.gz
midimonster-11e9dec049e64989c5f3656415d00c6c69851e8e.tar.bz2
midimonster-11e9dec049e64989c5f3656415d00c6c69851e8e.zip
Move instance allocator to backend object, introduce backend start function
Diffstat (limited to 'backend.c')
-rw-r--r--backend.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/backend.c b/backend.c
index 673fe9b..1d728d1 100644
--- a/backend.c
+++ b/backend.c
@@ -4,6 +4,66 @@
static size_t nbackends = 0;
static backend* backends = NULL;
+static size_t ninstances = 0;
+static instance** instances = NULL;
+
+instance* mm_instance(){
+ instance** new_inst = realloc(instances, (ninstances + 1) * sizeof(instance*));
+ if(!new_inst){
+ //TODO free
+ fprintf(stderr, "Failed to allocate memory\n");
+ ninstances = 0;
+ return NULL;
+ }
+ instances = new_inst;
+ instances[ninstances] = calloc(1, sizeof(instance));
+ if(!instances[ninstances]){
+ fprintf(stderr, "Failed to allocate memory\n");
+ return NULL;
+ }
+
+ return instances[ninstances++];
+}
+
+int mm_backend_instances(char* name, size_t* ninst, instance*** inst){
+ backend* b = backend_match(name);
+ size_t n = 0, u;
+ //count number of affected instances
+ for(u = 0; u < ninstances; u++){
+ if(instances[u]->backend == b){
+ n++;
+ }
+ }
+
+ *ninst = n;
+ *inst = calloc(n, sizeof(instance*));
+ if(!*inst){
+ fprintf(stderr, "Failed to allocate memory\n");
+ return 1;
+ }
+
+ n = 0;
+ for(u = 0; u < ninstances; u++){
+ if(instances[u]->backend == b){
+ (*inst)[n] = instances[u];
+ n++;
+ }
+ }
+ return 0;
+}
+
+void instances_free(){
+ size_t u;
+ for(u = 0; u < ninstances; u++){
+ free(instances[u]->name);
+ instances[u]->name = NULL;
+ instances[u]->backend = NULL;
+ free(instances[u]);
+ instances[u] = NULL;
+ }
+ free(instances);
+ ninstances = 0;
+}
backend* backend_match(char* name){
size_t u;
@@ -15,6 +75,16 @@ backend* backend_match(char* name){
return NULL;
}
+instance* instance_match(char* name){
+ size_t u;
+ for(u = 0; u < ninstances; u++){
+ if(!strcmp(instances[u]->name, name)){
+ return instances[u];
+ }
+ }
+ return NULL;
+}
+
int mm_backend_register(backend b){
if(!backend_match(b.name)){
backends = realloc(backends, (nbackends + 1) * sizeof(backend));
@@ -32,6 +102,15 @@ int mm_backend_register(backend b){
return 1;
}
+int backends_start(){
+ int rv = 0;
+ size_t u;
+ for(u = 0; u < nbackends; u++){
+ rv |= backends[u].start();
+ }
+ return rv;
+}
+
int backends_stop(){
size_t u;
for(u = 0; u < nbackends; u++){