aboutsummaryrefslogtreecommitdiffhomepage
path: root/artnet.c
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2017-06-05 18:53:41 +0200
committercbdev <cb@cbcdn.com>2017-06-05 18:53:41 +0200
commit40e123db7713b188162cd94d935f7a395405567a (patch)
treef745b15d41af6a38b675bdbe2de6473657c7e212 /artnet.c
parented55916e772264dc8278fc8c96d4139aec31e89e (diff)
downloadmidimonster-40e123db7713b188162cd94d935f7a395405567a.tar.gz
midimonster-40e123db7713b188162cd94d935f7a395405567a.tar.bz2
midimonster-40e123db7713b188162cd94d935f7a395405567a.zip
Core select loop
Diffstat (limited to 'artnet.c')
-rw-r--r--artnet.c49
1 files changed, 44 insertions, 5 deletions
diff --git a/artnet.c b/artnet.c
index 2684d46..6eef2fe 100644
--- a/artnet.c
+++ b/artnet.c
@@ -3,6 +3,13 @@
#define BACKEND_NAME "artnet"
static uint8_t default_net = 0;
+static struct {
+ char* host;
+ char* port;
+} bind = {
+ .host = NULL,
+ .port = NULL
+};
int artnet_init(){
backend artnet = {
@@ -26,8 +33,20 @@ int artnet_init(){
}
static int artnet_configure(char* option, char* value){
+ char* separator = value;
if(!strcmp(option, "bind")){
- //TODO create socket, hand over to be managed (unregister previous socket?)
+ for(; *separator && *separator != ' '; separator++){
+ }
+
+ if(*separator){
+ *separator = 0;
+ separator++;
+ free(bind.port);
+ bind.port = strdup(separator);
+ }
+
+ free(bind.host);
+ bind.host = strdup(value);
return 0;
}
else if(!strcmp(option, "net")){
@@ -67,10 +86,10 @@ static int artnet_configure_instance(instance* instance, char* option, char* val
}
else if(!strcmp(option, "output")){
if(!strcmp(value, "true")){
- data->mode |= MODE_OUTPUT;
+ data->mode |= output;
}
else{
- data->mode &= ~MODE_OUTPUT;
+ data->mode &= ~output;
}
return 0;
}
@@ -99,8 +118,25 @@ static int artnet_handle(size_t num, int* fd, void** data){
}
static int artnet_start(){
- //TODO
- return 1;
+ if(!bind.host){
+ bind.host = strdup("127.0.0.1");
+ }
+
+ if(!bind.port){
+ bind.port = strdup("6454");
+ }
+
+ if(!bind.host || !bind.port){
+ fprintf(stderr, "Failed to allocate memory\n");
+ return 1;
+ }
+
+ //TODO allocate all active universes
+ //TODO open socket
+ fprintf(stderr, "Listening for ArtNet data on %s port %s\n", bind.host, bind.port);
+ //TODO parse all universe destinations
+
+ return 0;
}
static int artnet_shutdown(){
@@ -115,6 +151,9 @@ static int artnet_shutdown(){
free(inst[p]->impl);
}
free(inst);
+
+ free(bind.host);
+ free(bind.port);
fprintf(stderr, "ArtNet backend shut down\n");
return 0;
}