aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--TODO1
-rw-r--r--backend.c20
-rw-r--r--backends/artnet.c18
-rw-r--r--backends/artnet.h2
-rw-r--r--backends/evdev.c18
-rw-r--r--backends/evdev.h2
-rw-r--r--backends/jack.c12
-rw-r--r--backends/jack.h2
-rw-r--r--backends/loopback.c2
-rw-r--r--backends/loopback.h2
-rw-r--r--backends/lua.c13
-rw-r--r--backends/lua.h2
-rw-r--r--backends/maweb.c16
-rw-r--r--backends/midi.c17
-rw-r--r--backends/midi.h2
-rw-r--r--backends/ola.cpp13
-rw-r--r--backends/ola.h2
-rw-r--r--backends/osc.c19
-rw-r--r--backends/osc.h2
-rw-r--r--backends/sacn.c17
-rw-r--r--backends/sacn.h2
-rw-r--r--backends/winmidi.c18
-rw-r--r--backends/winmidi.h2
-rw-r--r--midimonster.h2
24 files changed, 49 insertions, 157 deletions
diff --git a/TODO b/TODO
index f6fc728..1f1269d 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,4 @@
keepalive channels per backend?
-mm_backend_start might get some arguments so they don't have to fetch them all the time
Note source in channel value struct
Optimize core channel search (store backend offset)
diff --git a/backend.c b/backend.c
index 3a18f41..f5efca7 100644
--- a/backend.c
+++ b/backend.c
@@ -256,20 +256,34 @@ MM_API int mm_backend_register(backend b){
int backends_start(){
int rv = 0, current;
- size_t u, p;
+ size_t n, u, p;
+ instance** inst = NULL;
+
for(u = 0; u < nbackends; u++){
//only start backends that have instances
for(p = 0; p < ninstances && instances[p]->backend != backends + u; p++){
}
+
+ //backend has no instances, skip the start call
if(p == ninstances){
- fprintf(stderr, "Skipping start of backend %s\n", backends[u].name);
continue;
}
+
+ //fetch list of instances
+ if(mm_backend_instances(backends[u].name, &n, &inst)){
+ fprintf(stderr, "Failed to fetch instance list for initialization of backend %s\n", backends[u].name);
+ return 1;
+ }
- current = backends[u].start();
+ //start the backend
+ current = backends[u].start(n, inst);
if(current){
fprintf(stderr, "Failed to start backend %s\n", backends[u].name);
}
+
+ //clean up
+ free(inst);
+ inst = NULL;
rv |= current;
}
return rv;
diff --git a/backends/artnet.c b/backends/artnet.c
index e01f038..e4147ec 100644
--- a/backends/artnet.c
+++ b/backends/artnet.c
@@ -381,28 +381,15 @@ static int artnet_handle(size_t num, managed_fd* fds){
return 0;
}
-static int artnet_start(){
- size_t n, u, p;
+static int artnet_start(size_t n, instance** inst){
+ size_t u, p;
int rv = 1;
- instance** inst = NULL;
artnet_instance_data* data = NULL;
artnet_instance_id id = {
.label = 0
};
- //fetch all defined instances
- if(mm_backend_instances(BACKEND_NAME, &n, &inst)){
- fprintf(stderr, "Failed to fetch instance list\n");
- return 1;
- }
-
- if(!n){
- free(inst);
- return 0;
- }
-
if(!artnet_fds){
- free(inst);
fprintf(stderr, "Failed to start ArtNet backend: no descriptors bound\n");
return 1;
}
@@ -448,7 +435,6 @@ static int artnet_start(){
rv = 0;
bail:
- free(inst);
return rv;
}
diff --git a/backends/artnet.h b/backends/artnet.h
index f6a6709..738b55c 100644
--- a/backends/artnet.h
+++ b/backends/artnet.h
@@ -10,7 +10,7 @@ static instance* artnet_instance();
static channel* artnet_channel(instance* instance, char* spec, uint8_t flags);
static int artnet_set(instance* inst, size_t num, channel** c, channel_value* v);
static int artnet_handle(size_t num, managed_fd* fds);
-static int artnet_start();
+static int artnet_start(size_t n, instance** inst);
static int artnet_shutdown();
#define ARTNET_PORT "6454"
diff --git a/backends/evdev.c b/backends/evdev.c
index 0da5ae6..9998a03 100644
--- a/backends/evdev.c
+++ b/backends/evdev.c
@@ -393,21 +393,10 @@ static int evdev_handle(size_t num, managed_fd* fds){
return 0;
}
-static int evdev_start(){
- size_t n, u, fds = 0;
- instance** inst = NULL;
+static int evdev_start(size_t n, instance** inst){
+ size_t u, fds = 0;
evdev_instance_data* data = NULL;
- if(mm_backend_instances(BACKEND_NAME, &n, &inst)){
- fprintf(stderr, "Failed to fetch instance list\n");
- return 1;
- }
-
- if(!n){
- free(inst);
- return 0;
- }
-
for(u = 0; u < n; u++){
data = (evdev_instance_data*) inst[u]->impl;
@@ -415,7 +404,6 @@ static int evdev_start(){
if(data->output_enabled){
if(libevdev_uinput_create_from_device(data->output_proto, LIBEVDEV_UINPUT_OPEN_MANAGED, &data->output_ev)){
fprintf(stderr, "Failed to create evdev output device: %s\n", strerror(errno));
- free(inst);
return 1;
}
fprintf(stderr, "Created device node %s for instance %s\n", libevdev_uinput_get_devnode(data->output_ev), inst[u]->name);
@@ -426,7 +414,6 @@ static int evdev_start(){
if(data->input_fd >= 0){
if(mm_manage_fd(data->input_fd, BACKEND_NAME, 1, inst[u])){
fprintf(stderr, "Failed to register event input descriptor for instance %s\n", inst[u]->name);
- free(inst);
return 1;
}
fds++;
@@ -439,7 +426,6 @@ static int evdev_start(){
}
fprintf(stderr, "evdev backend registered %zu descriptors to core\n", fds);
- free(inst);
return 0;
}
diff --git a/backends/evdev.h b/backends/evdev.h
index 6504416..1f03941 100644
--- a/backends/evdev.h
+++ b/backends/evdev.h
@@ -15,7 +15,7 @@ static instance* evdev_instance();
static channel* evdev_channel(instance* instance, char* spec, uint8_t flags);
static int evdev_set(instance* inst, size_t num, channel** c, channel_value* v);
static int evdev_handle(size_t num, managed_fd* fds);
-static int evdev_start();
+static int evdev_start(size_t n, instance** inst);
static int evdev_shutdown();
#define INPUT_NODES "/dev/input"
diff --git a/backends/jack.c b/backends/jack.c
index e7bed04..047dce8 100644
--- a/backends/jack.c
+++ b/backends/jack.c
@@ -593,10 +593,9 @@ static int mmjack_handle(size_t num, managed_fd* fds){
return 0;
}
-static int mmjack_start(){
+static int mmjack_start(size_t n, instance** inst){
int rv = 1, feedback_fd[2];
- size_t n, u, p;
- instance** inst = NULL;
+ size_t u, p;
pthread_mutexattr_t mutex_attr;
mmjack_instance_data* data = NULL;
jack_status_t error;
@@ -618,12 +617,6 @@ static int mmjack_start(){
goto bail;
}
- //fetch all instances
- if(mm_backend_instances(BACKEND_NAME, &n, &inst)){
- fprintf(stderr, "Failed to fetch instance list\n");
- goto bail;
- }
-
for(u = 0; u < n; u++){
data = (mmjack_instance_data*) inst[u]->impl;
@@ -689,7 +682,6 @@ static int mmjack_start(){
rv = 0;
bail:
pthread_mutexattr_destroy(&mutex_attr);
- free(inst);
return rv;
}
diff --git a/backends/jack.h b/backends/jack.h
index a7f3e8b..c9f8c4c 100644
--- a/backends/jack.h
+++ b/backends/jack.h
@@ -9,7 +9,7 @@ static instance* mmjack_instance();
static channel* mmjack_channel(instance* inst, char* spec, uint8_t flags);
static int mmjack_set(instance* inst, size_t num, channel** c, channel_value* v);
static int mmjack_handle(size_t num, managed_fd* fds);
-static int mmjack_start();
+static int mmjack_start(size_t n, instance** inst);
static int mmjack_shutdown();
#define JACK_DEFAULT_CLIENT_NAME "MIDIMonster"
diff --git a/backends/loopback.c b/backends/loopback.c
index 41e6f85..616eccf 100644
--- a/backends/loopback.c
+++ b/backends/loopback.c
@@ -92,7 +92,7 @@ static int loopback_handle(size_t num, managed_fd* fds){
return 0;
}
-static int loopback_start(){
+static int loopback_start(size_t n, instance** inst){
return 0;
}
diff --git a/backends/loopback.h b/backends/loopback.h
index ee51c66..dee3e9d 100644
--- a/backends/loopback.h
+++ b/backends/loopback.h
@@ -7,7 +7,7 @@ static instance* loopback_instance();
static channel* loopback_channel(instance* inst, char* spec, uint8_t flags);
static int loopback_set(instance* inst, size_t num, channel** c, channel_value* v);
static int loopback_handle(size_t num, managed_fd* fds);
-static int loopback_start();
+static int loopback_start(size_t n, instance** inst);
static int loopback_shutdown();
typedef struct /*_loopback_instance_data*/ {
diff --git a/backends/lua.c b/backends/lua.c
index 40e6613..b165dd8 100644
--- a/backends/lua.c
+++ b/backends/lua.c
@@ -428,17 +428,10 @@ static int lua_handle(size_t num, managed_fd* fds){
return 0;
}
-static int lua_start(){
- size_t n, u, p;
- instance** inst = NULL;
+static int lua_start(size_t n, instance** inst){
+ size_t u, p;
lua_instance_data* data = NULL;
- //fetch all defined instances
- if(mm_backend_instances(BACKEND_NAME, &n, &inst)){
- fprintf(stderr, "Failed to fetch instance list\n");
- return 1;
- }
-
//resolve channels to their handler functions
for(u = 0; u < n; u++){
data = (lua_instance_data*) inst[u]->impl;
@@ -457,8 +450,6 @@ static int lua_start(){
}
}
- free(inst);
-
#ifdef MMBACKEND_LUA_TIMERFD
//register the timer with the core
fprintf(stderr, "Lua backend registering 1 descriptor to core\n");
diff --git a/backends/lua.h b/backends/lua.h
index 4ea5b0a..9e19506 100644
--- a/backends/lua.h
+++ b/backends/lua.h
@@ -16,7 +16,7 @@ static instance* lua_instance();
static channel* lua_channel(instance* inst, char* spec, uint8_t flags);
static int lua_set(instance* inst, size_t num, channel** c, channel_value* v);
static int lua_handle(size_t num, managed_fd* fds);
-static int lua_start();
+static int lua_start(size_t n, instance** inst);
static int lua_shutdown();
#ifndef MMBACKEND_LUA_TIMERFD
static uint32_t lua_interval();
diff --git a/backends/maweb.c b/backends/maweb.c
index d008cc0..28cad0c 100644
--- a/backends/maweb.c
+++ b/backends/maweb.c
@@ -989,17 +989,10 @@ static int maweb_handle(size_t num, managed_fd* fds){
return rv;
}
-static int maweb_start(){
- size_t n, u, p;
- instance** inst = NULL;
+static int maweb_start(size_t n, instance** inst){
+ size_t u, p;
maweb_instance_data* data = NULL;
- //fetch all defined instances
- if(mm_backend_instances(BACKEND_NAME, &n, &inst)){
- fprintf(stderr, "Failed to fetch instance list\n");
- return 1;
- }
-
for(u = 0; u < n; u++){
//sort channels
data = (maweb_instance_data*) inst[u]->impl;
@@ -1017,11 +1010,6 @@ static int maweb_start(){
}
}
- free(inst);
- if(!n){
- return 0;
- }
-
fprintf(stderr, "maweb backend registering %" PRIsize_t " descriptors to core\n", n);
//initialize timeouts
diff --git a/backends/midi.c b/backends/midi.c
index 92776ca..a7945ec 100644
--- a/backends/midi.c
+++ b/backends/midi.c
@@ -338,25 +338,13 @@ static int midi_handle(size_t num, managed_fd* fds){
return 0;
}
-static int midi_start(){
- size_t n = 0, p;
+static int midi_start(size_t n, instance** inst){
+ size_t p;
int nfds, rv = 1;
struct pollfd* pfds = NULL;
- instance** inst = NULL;
midi_instance_data* data = NULL;
snd_seq_addr_t addr;
- if(mm_backend_instances(BACKEND_NAME, &n, &inst)){
- fprintf(stderr, "Failed to fetch instance list\n");
- return 1;
- }
-
- //if there are no ports, do nothing
- if(!n){
- free(inst);
- return 0;
- }
-
//connect to the sequencer
if(snd_seq_open(&sequencer, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0){
fprintf(stderr, "Failed to open ALSA sequencer\n");
@@ -424,7 +412,6 @@ static int midi_start(){
bail:
free(pfds);
- free(inst);
return rv;
}
diff --git a/backends/midi.h b/backends/midi.h
index 4e16f90..579c9cb 100644
--- a/backends/midi.h
+++ b/backends/midi.h
@@ -7,7 +7,7 @@ static instance* midi_instance();
static channel* midi_channel(instance* instance, char* spec, uint8_t flags);
static int midi_set(instance* inst, size_t num, channel** c, channel_value* v);
static int midi_handle(size_t num, managed_fd* fds);
-static int midi_start();
+static int midi_start(size_t n, instance** inst);
static int midi_shutdown();
typedef struct /*_midi_instance_data*/ {
diff --git a/backends/ola.cpp b/backends/ola.cpp
index c13e8f9..088c20c 100644
--- a/backends/ola.cpp
+++ b/backends/ola.cpp
@@ -220,9 +220,8 @@ static void ola_register_callback(const std::string &error) {
}
}
-static int ola_start(){
- size_t n, u, p;
- instance** inst = NULL;
+static int ola_start(size_t n, instance** inst){
+ size_t u, p;
ola_instance_data* data = NULL;
ola_select = new ola::io::SelectServer();
@@ -255,12 +254,6 @@ static int ola_start(){
goto bail;
}
- //this should not happen anymore (backends without instances are not started anymore)
- if(!n){
- free(inst);
- return 0;
- }
-
for(u = 0; u < n; u++){
data = (ola_instance_data*) inst[u]->impl;
inst[u]->ident = data->universe_id;
@@ -277,10 +270,8 @@ static int ola_start(){
//run the ola select implementation to run all commands
ola_select->RunOnce();
- free(inst);
return 0;
bail:
- free(inst);
delete ola_client;
ola_client = NULL;
delete ola_select;
diff --git a/backends/ola.h b/backends/ola.h
index 0c42bac..2a55b77 100644
--- a/backends/ola.h
+++ b/backends/ola.h
@@ -11,7 +11,7 @@ extern "C" {
static channel* ola_channel(instance* instance, char* spec, uint8_t flags);
static int ola_set(instance* inst, size_t num, channel** c, channel_value* v);
static int ola_handle(size_t num, managed_fd* fds);
- static int ola_start();
+ static int ola_start(size_t n, instance** inst);
static int ola_shutdown();
}
diff --git a/backends/osc.c b/backends/osc.c
index b12ae40..61ae872 100644
--- a/backends/osc.c
+++ b/backends/osc.c
@@ -892,22 +892,10 @@ static int osc_handle(size_t num, managed_fd* fds){
return 0;
}
-static int osc_start(){
- size_t n, u, fds = 0;
- instance** inst = NULL;
+static int osc_start(size_t n, instance** inst){
+ size_t u, fds = 0;
osc_instance_data* data = NULL;
- //fetch all instances
- if(mm_backend_instances(BACKEND_NAME, &n, &inst)){
- fprintf(stderr, "Failed to fetch instance list\n");
- return 1;
- }
-
- if(!n){
- free(inst);
- return 0;
- }
-
//update instance identifiers
for(u = 0; u < n; u++){
data = (osc_instance_data*) inst[u]->impl;
@@ -916,7 +904,6 @@ static int osc_start(){
inst[u]->ident = data->fd;
if(mm_manage_fd(data->fd, BACKEND_NAME, 1, inst[u])){
fprintf(stderr, "Failed to register OSC descriptor for instance %s\n", inst[u]->name);
- free(inst);
return 1;
}
fds++;
@@ -927,8 +914,6 @@ static int osc_start(){
}
fprintf(stderr, "OSC backend registered %" PRIsize_t " descriptors to core\n", fds);
-
- free(inst);
return 0;
}
diff --git a/backends/osc.h b/backends/osc.h
index 6f3b923..24cc7e5 100644
--- a/backends/osc.h
+++ b/backends/osc.h
@@ -14,7 +14,7 @@ static instance* osc_instance();
static channel* osc_map_channel(instance* inst, char* spec, uint8_t flags);
static int osc_set(instance* inst, size_t num, channel** c, channel_value* v);
static int osc_handle(size_t num, managed_fd* fds);
-static int osc_start();
+static int osc_start(size_t n, instance** inst);
static int osc_shutdown();
typedef enum {
diff --git a/backends/sacn.c b/backends/sacn.c
index 75c327e..877cbb0 100644
--- a/backends/sacn.c
+++ b/backends/sacn.c
@@ -531,10 +531,9 @@ static int sacn_handle(size_t num, managed_fd* fds){
return 0;
}
-static int sacn_start(){
- size_t n, u, p;
+static int sacn_start(size_t n, instance** inst){
+ size_t u, p;
int rv = 1;
- instance** inst = NULL;
sacn_instance_data* data = NULL;
sacn_instance_id id = {
.label = 0
@@ -544,17 +543,6 @@ static int sacn_start(){
};
struct sockaddr_in* dest_v4 = NULL;
- //fetch all instances
- if(mm_backend_instances(BACKEND_NAME, &n, &inst)){
- fprintf(stderr, "Failed to fetch instance list\n");
- return 1;
- }
-
- if(!n){
- free(inst);
- return 0;
- }
-
if(!global_cfg.fds){
fprintf(stderr, "Failed to start sACN backend: no descriptors bound\n");
free(inst);
@@ -625,7 +613,6 @@ static int sacn_start(){
rv = 0;
bail:
- free(inst);
return rv;
}
diff --git a/backends/sacn.h b/backends/sacn.h
index 1d3268c..0d234d4 100644
--- a/backends/sacn.h
+++ b/backends/sacn.h
@@ -7,7 +7,7 @@ static instance* sacn_instance();
static channel* sacn_channel(instance* instance, char* spec, uint8_t flags);
static int sacn_set(instance* inst, size_t num, channel** c, channel_value* v);
static int sacn_handle(size_t num, managed_fd* fds);
-static int sacn_start();
+static int sacn_start(size_t n, instance** inst);
static int sacn_shutdown();
#define SACN_PORT "5568"
diff --git a/backends/winmidi.c b/backends/winmidi.c
index 790257b..0fc1aca 100644
--- a/backends/winmidi.c
+++ b/backends/winmidi.c
@@ -440,10 +440,9 @@ static int winmidi_match_output(char* prefix){
return -1;
}
-static int winmidi_start(){
- size_t n = 0, p;
+static int winmidi_start(size_t n, instance** inst){
+ size_t p;
int device, rv = -1;
- instance** inst = NULL;
winmidi_instance_data* data = NULL;
struct sockaddr_storage sockadd = {
0
@@ -453,18 +452,6 @@ static int winmidi_start(){
char* error = NULL;
DBGPF("winmidi main thread ID is %ld\n", GetCurrentThreadId());
- //fetch all instances
- if(mm_backend_instances(BACKEND_NAME, &n, &inst)){
- fprintf(stderr, "Failed to fetch instance list\n");
- return 1;
- }
-
- //no instances, we're done
- if(!n){
- free(inst);
- return 0;
- }
-
//output device list if requested
if(backend_config.list_devices){
winmidi_match_input(NULL);
@@ -552,7 +539,6 @@ static int winmidi_start(){
rv = 0;
bail:
- free(inst);
return rv;
}
diff --git a/backends/winmidi.h b/backends/winmidi.h
index 985c46a..7907a42 100644
--- a/backends/winmidi.h
+++ b/backends/winmidi.h
@@ -7,7 +7,7 @@ static instance* winmidi_instance();
static channel* winmidi_channel(instance* inst, char* spec, uint8_t flags);
static int winmidi_set(instance* inst, size_t num, channel** c, channel_value* v);
static int winmidi_handle(size_t num, managed_fd* fds);
-static int winmidi_start();
+static int winmidi_start(size_t n, instance** inst);
static int winmidi_shutdown();
typedef struct /*_winmidi_instance_data*/ {
diff --git a/midimonster.h b/midimonster.h
index 677eeee..bf30e8c 100644
--- a/midimonster.h
+++ b/midimonster.h
@@ -134,7 +134,7 @@ typedef void (*mmbackend_free_channel)(struct _backend_channel* c);
typedef int (*mmbackend_configure)(char* option, char* value);
typedef int (*mmbackend_configure_instance)(struct _backend_instance* instance, char* option, char* value);
typedef int (*mmbackend_process_fd)(size_t nfds, struct _managed_fd* fds);
-typedef int (*mmbackend_start)();
+typedef int (*mmbackend_start)(size_t ninstances, struct _backend_instance** inst);
typedef uint32_t (*mmbackend_interval)();
typedef int (*mmbackend_shutdown)();