Skip to content

Commit dfa4f91

Browse files
committed
Route all core messages properly
1 parent 3b134cc commit dfa4f91

File tree

6 files changed

+80
-74
lines changed

6 files changed

+80
-74
lines changed

README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,16 @@ for detailed information).
300300

301301
## Development
302302

303-
The architecture is split into the `midimonster` core, handling mapping
304-
and resource management, and the backends, which are shared objects loaded
305-
at start time, which provide a protocol mapping to instances / channels.
303+
The architecture is split into the `core`, handling mapping and resource management,
304+
the `frontends` which handle how the core is invoked and presented (ie. command line or graphical interface),
305+
and the `backends`, which are shared objects loaded at start time providing a protocol mapping to instances / channels.
306306

307-
The API and structures are more-or-less documented in [midimonster.h](midimonster.h),
308-
more detailed documentation may follow.
307+
There is a general [developer information document](DEVELOPMENT.md) that outlines basic guidelines for
308+
contribution. The [MIDIMonster knowledge base](https://kb.midimonster.net/) has a section on development,
309+
containing additional helpful information and tutorials.
310+
311+
The backend API, lifecycle and structures are documented in [midimonster.h](midimonster.h), the
312+
frontend API and lifecycle in [core/core.h](core/core.h).
309313

310314
To build with `clang` sanitizers and even more warnings enabled, run `make sanitize`.
311315
This is useful to check for common errors and oversights.

core/backend.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int backends_handle(size_t nfds, managed_fd* fds){
5555
DBGPF("Notifying backend %s of %" PRIsize_t " waiting FDs", registry.backends[u].name, n);
5656
rv |= registry.backends[u].process(n, fds);
5757
if(rv){
58-
fprintf(stderr, "Backend %s failed to handle input\n", registry.backends[u].name);
58+
LOGPF("Backend %s failed to handle input", registry.backends[u].name);
5959
}
6060
}
6161
}
@@ -100,7 +100,7 @@ MM_API channel* mm_channel(instance* inst, uint64_t ident, uint8_t create){
100100
DBGPF("\tBucket %" PRIsize_t " entry %" PRIsize_t " inst %" PRIu64 " ident %" PRIu64, bucket, u, (uint64_t) channels.entry[bucket][u]->instance, channels.entry[bucket][u]->ident);
101101
if(channels.entry[bucket][u]->instance == inst
102102
&& channels.entry[bucket][u]->ident == ident){
103-
DBGPF("Requested channel %" PRIu64 " on instance %s already exists, reusing (bucket %" PRIsize_t ", %" PRIsize_t " search steps)\n", ident, inst->name, bucket, u);
103+
DBGPF("Requested channel %" PRIu64 " on instance %s already exists, reusing (bucket %" PRIsize_t ", %" PRIsize_t " search steps)", ident, inst->name, bucket, u);
104104
return channels.entry[bucket][u];
105105
}
106106
}
@@ -113,14 +113,14 @@ MM_API channel* mm_channel(instance* inst, uint64_t ident, uint8_t create){
113113
DBGPF("Creating previously unknown channel %" PRIu64 " on instance %s, bucket %" PRIsize_t, ident, inst->name, bucket);
114114
channels.entry[bucket] = realloc(channels.entry[bucket], (channels.n[bucket] + 1) * sizeof(channel*));
115115
if(!channels.entry[bucket]){
116-
fprintf(stderr, "Failed to allocate memory\n");
116+
LOG("Failed to allocate memory");
117117
channels.n[bucket] = 0;
118118
return NULL;
119119
}
120120

121121
channels.entry[bucket][channels.n[bucket]] = calloc(1, sizeof(channel));
122122
if(!channels.entry[bucket][channels.n[bucket]]){
123-
fprintf(stderr, "Failed to allocate memory\n");
123+
LOG("Failed to allocate memory");
124124
return NULL;
125125
}
126126

@@ -161,7 +161,7 @@ MM_API void mm_channel_update(channel* chan, uint64_t ident){
161161
//add to new bucket
162162
channels.entry[new_bucket] = realloc(channels.entry[new_bucket], (channels.n[new_bucket] + 1) * sizeof(channel*));
163163
if(!channels.entry[new_bucket]){
164-
fprintf(stderr, "Failed to allocate memory\n");
164+
LOG("Failed to allocate memory");
165165
channels.n[new_bucket] = 0;
166166
return;
167167
}
@@ -184,14 +184,14 @@ instance* mm_instance(backend* b){
184184
//extend
185185
registry.instances[u] = realloc(registry.instances[u], (n + 2) * sizeof(instance*));
186186
if(!registry.instances[u]){
187-
fprintf(stderr, "Failed to allocate memory\n");
187+
LOG("Failed to allocate memory");
188188
return NULL;
189189
}
190190
//sentinel
191191
registry.instances[u][n + 1] = NULL;
192192
registry.instances[u][n] = calloc(1, sizeof(instance));
193193
if(!registry.instances[u][n]){
194-
fprintf(stderr, "Failed to allocate memory\n");
194+
LOG("Failed to allocate memory");
195195
}
196196
registry.instances[u][n]->backend = b;
197197
return registry.instances[u][n];
@@ -238,7 +238,7 @@ MM_API int mm_backend_instances(char* name, size_t* ninst, instance*** inst){
238238

239239
*inst = calloc(i, sizeof(instance*));
240240
if(!*inst){
241-
fprintf(stderr, "Failed to allocate memory\n");
241+
LOG("Failed to allocate memory");
242242
return 1;
243243
}
244244

@@ -304,15 +304,15 @@ MM_API int mm_backend_register(backend b){
304304
registry.backends = realloc(registry.backends, (registry.n + 1) * sizeof(backend));
305305
registry.instances = realloc(registry.instances, (registry.n + 1) * sizeof(instance**));
306306
if(!registry.backends || !registry.instances){
307-
fprintf(stderr, "Failed to allocate memory\n");
307+
LOG("Failed to allocate memory");
308308
registry.n = 0;
309309
return 1;
310310
}
311311
registry.backends[registry.n] = b;
312312
registry.instances[registry.n] = NULL;
313313
registry.n++;
314314

315-
fprintf(stderr, "Registered backend %s\n", b.name);
315+
LOGPF("Registered backend %s", b.name);
316316
return 0;
317317
}
318318
return 1;
@@ -331,14 +331,14 @@ int backends_start(){
331331

332332
//fetch list of instances
333333
if(mm_backend_instances(registry.backends[u].name, &n, &inst)){
334-
fprintf(stderr, "Failed to fetch instance list for initialization of backend %s\n", registry.backends[u].name);
334+
LOGPF("Failed to fetch instance list for initialization of backend %s", registry.backends[u].name);
335335
return 1;
336336
}
337337

338338
//start the backend
339339
current = registry.backends[u].start(n, inst);
340340
if(current){
341-
fprintf(stderr, "Failed to start backend %s\n", registry.backends[u].name);
341+
LOGPF("Failed to start backend %s", registry.backends[u].name);
342342
}
343343

344344
//clean up
@@ -378,7 +378,7 @@ int backends_stop(){
378378
for(u = 0; u < registry.n; u++){
379379
//fetch list of instances
380380
if(mm_backend_instances(registry.backends[u].name, &n, &inst)){
381-
fprintf(stderr, "Failed to fetch instance list for shutdown of backend %s\n", registry.backends[u].name);
381+
LOGPF("Failed to fetch instance list for shutdown of backend %s", registry.backends[u].name);
382382
inst = NULL;
383383
n = 0;
384384
}

0 commit comments

Comments
 (0)