aboutsummaryrefslogtreecommitdiffhomepage
path: root/backends
diff options
context:
space:
mode:
Diffstat (limited to 'backends')
-rw-r--r--backends/Makefile26
-rw-r--r--backends/artnet.c16
-rw-r--r--backends/artnet.h2
-rw-r--r--backends/libmmbackend.c12
-rw-r--r--backends/libmmbackend.h6
-rw-r--r--backends/lua.c4
-rw-r--r--backends/osc.c18
-rw-r--r--backends/osc.h2
-rw-r--r--backends/sacn.c28
-rw-r--r--backends/sacn.h1
10 files changed, 82 insertions, 33 deletions
diff --git a/backends/Makefile b/backends/Makefile
index 22cb95b..2374df0 100644
--- a/backends/Makefile
+++ b/backends/Makefile
@@ -1,12 +1,13 @@
.PHONY: all clean full
OPTIONAL_BACKENDS = ola.so
+WINDOWS_BACKENDS = loopback.dll artnet.dll osc.dll sacn.dll
LINUX_BACKENDS = midi.so evdev.so
BACKENDS = artnet.so osc.so loopback.so sacn.so lua.so
BACKEND_LIB = libmmbackend.o
SYSTEM := $(shell uname -s)
-CFLAGS += -g -fPIC -I../
+CFLAGS += -g -fPIC -I../ -Wall -Wpedantic
CPPFLAGS += -g -fPIC -I../
LDFLAGS += -shared
@@ -20,8 +21,17 @@ LDFLAGS += -undefined dynamic_lookup
endif
artnet.so: ADDITIONAL_OBJS += $(BACKEND_LIB)
+artnet.dll: ADDITIONAL_OBJS += $(BACKEND_LIB)
+artnet.dll: LDLIBS += -lws2_32
+
osc.so: ADDITIONAL_OBJS += $(BACKEND_LIB)
+osc.dll: ADDITIONAL_OBJS += $(BACKEND_LIB)
+osc.dll: LDLIBS += -lws2_32
+
sacn.so: ADDITIONAL_OBJS += $(BACKEND_LIB)
+sacn.dll: ADDITIONAL_OBJS += $(BACKEND_LIB)
+sacn.dll: LDLIBS += -lws2_32
+
midi.so: LDLIBS = -lasound
evdev.so: CFLAGS += $(shell pkg-config --cflags libevdev)
evdev.so: LDLIBS = $(shell pkg-config --libs libevdev)
@@ -33,12 +43,24 @@ lua.so: LDLIBS += $(shell pkg-config --libs lua5.3)
%.so :: %.c %.h $(BACKEND_LIB)
$(CC) $(CFLAGS) $(LDLIBS) $< $(ADDITIONAL_OBJS) -o $@ $(LDFLAGS)
+%.dll :: %.c %.h $(BACKEND_LIB)
+ $(CC) $(CFLAGS) $< $(ADDITIONAL_OBJS) -o $@ $(LDFLAGS) $(LDLIBS)
+
%.so :: %.cpp %.h
$(CXX) $(CPPFLAGS) $(LDLIBS) $< $(ADDITIONAL_OBJS) -o $@ $(LDFLAGS)
all: $(BACKEND_LIB) $(BACKENDS)
+../libmmapi.a:
+ $(MAKE) -C ../ midimonster.exe
+
+windows: export CC = x86_64-w64-mingw32-gcc
+windows: LDLIBS += -lmmapi
+windows: LDFLAGS += -L../
+windows: CFLAGS += -Wno-format -Wno-pointer-sign
+windows: ../libmmapi.a $(BACKEND_LIB) $(WINDOWS_BACKENDS)
+
full: $(BACKEND_LIB) $(BACKENDS) $(OPTIONAL_BACKENDS)
clean:
- $(RM) $(BACKEND_LIB) $(BACKENDS) $(OPTIONAL_BACKENDS)
+ $(RM) $(BACKEND_LIB) $(BACKENDS) $(OPTIONAL_BACKENDS) $(WINDOWS_BACKENDS)
diff --git a/backends/artnet.c b/backends/artnet.c
index 8b404a6..a6df4ab 100644
--- a/backends/artnet.c
+++ b/backends/artnet.c
@@ -3,8 +3,8 @@
#include <errno.h>
#include "libmmbackend.h"
-
#include "artnet.h"
+
#define MAX_FDS 255
#define BACKEND_NAME "artnet"
@@ -32,7 +32,7 @@ static int artnet_listener(char* host, char* port){
return -1;
}
- fprintf(stderr, "ArtNet backend interface %zu bound to %s port %s\n", artnet_fds, host, port);
+ fprintf(stderr, "ArtNet backend interface %lu bound to %s port %s\n", artnet_fds, host, port);
artnet_fd[artnet_fds].fd = fd;
artnet_fd[artnet_fds].output_instances = 0;
artnet_fd[artnet_fds].output_instance = NULL;
@@ -212,7 +212,7 @@ static int artnet_transmit(instance* inst){
};
memcpy(frame.data, data->data.out, 512);
- if(sendto(artnet_fd[data->fd_index].fd, &frame, sizeof(frame), 0, (struct sockaddr*) &data->dest_addr, data->dest_len) < 0){
+ if(sendto(artnet_fd[data->fd_index].fd, (uint8_t*) &frame, sizeof(frame), 0, (struct sockaddr*) &data->dest_addr, data->dest_len) < 0){
fprintf(stderr, "Failed to output ArtNet frame for instance %s: %s\n", inst->name, strerror(errno));
}
@@ -230,7 +230,7 @@ static int artnet_set(instance* inst, size_t num, channel** c, channel_value* v)
artnet_instance_data* data = (artnet_instance_data*) inst->impl;
if(!data->dest_len){
- fprintf(stderr, "ArtNet instance %s not enabled for output (%zu channel events)\n", inst->name, num);
+ fprintf(stderr, "ArtNet instance %s not enabled for output (%lu channel events)\n", inst->name, num);
return 0;
}
@@ -295,7 +295,7 @@ static inline int artnet_process_frame(instance* inst, artnet_pkt* frame){
}
if(!chan){
- fprintf(stderr, "Active channel %zu on %s not known to core\n", p, inst->name);
+ fprintf(stderr, "Active channel %lu on %s not known to core\n", p, inst->name);
return 1;
}
@@ -367,7 +367,11 @@ static int artnet_handle(size_t num, managed_fd* fds){
}
} while(bytes_read > 0);
+ #ifdef _WIN32
+ if(bytes_read < 0 && WSAGetLastError() != WSAEWOULDBLOCK){
+ #else
if(bytes_read < 0 && errno != EAGAIN){
+ #endif
fprintf(stderr, "ArtNet failed to receive data: %s\n", strerror(errno));
}
@@ -438,7 +442,7 @@ static int artnet_start(){
}
}
- fprintf(stderr, "ArtNet backend registering %zu descriptors to core\n", artnet_fds);
+ fprintf(stderr, "ArtNet backend registering %lu descriptors to core\n", artnet_fds);
for(u = 0; u < artnet_fds; u++){
if(mm_manage_fd(artnet_fd[u].fd, BACKEND_NAME, 1, (void*) u)){
goto bail;
diff --git a/backends/artnet.h b/backends/artnet.h
index 90aedd5..f5aa745 100644
--- a/backends/artnet.h
+++ b/backends/artnet.h
@@ -1,4 +1,6 @@
+#ifndef _WIN32
#include <sys/socket.h>
+#endif
#include "midimonster.h"
int init();
diff --git a/backends/libmmbackend.c b/backends/libmmbackend.c
index 6320611..b27ebc5 100644
--- a/backends/libmmbackend.c
+++ b/backends/libmmbackend.c
@@ -53,7 +53,7 @@ int mmbackend_parse_sockaddr(char* host, char* port, struct sockaddr_storage* ad
}
int mmbackend_socket(char* host, char* port, int socktype, uint8_t listener){
- int fd = -1, status, yes = 1, flags;
+ int fd = -1, status, yes = 1;
struct addrinfo hints = {
.ai_family = AF_UNSPEC,
.ai_socktype = socktype,
@@ -106,12 +106,20 @@ int mmbackend_socket(char* host, char* port, int socktype, uint8_t listener){
}
//set nonblocking
- flags = fcntl(fd, F_GETFL, 0);
+ #ifdef _WIN32
+ u_long mode = 1;
+ if(ioctlsocket(fd, FIONBIO, &mode) != NO_ERROR){
+ closesocket(fd);
+ return 1;
+ }
+ #else
+ int flags = fcntl(fd, F_GETFL, 0);
if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0){
fprintf(stderr, "Failed to set socket nonblocking\n");
close(fd);
return -1;
}
+ #endif
return fd;
}
diff --git a/backends/libmmbackend.h b/backends/libmmbackend.h
index 38bfca0..77cad6a 100644
--- a/backends/libmmbackend.h
+++ b/backends/libmmbackend.h
@@ -1,14 +1,20 @@
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
+#ifdef _WIN32
+#include <ws2tcpip.h>
+//#define close closesocket
+#else
#include <sys/socket.h>
#include <netdb.h>
+#endif
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
+#include "../portability.h"
/* Parse spec as host specification in the form
* host port
diff --git a/backends/lua.c b/backends/lua.c
index 4a910a2..ec02575 100644
--- a/backends/lua.c
+++ b/backends/lua.c
@@ -161,8 +161,6 @@ static int lua_callback_output(lua_State* interpreter){
static int lua_callback_interval(lua_State* interpreter){
size_t n = 0;
- instance* inst = NULL;
- lua_instance_data* data = NULL;
uint64_t interval = 0;
int reference = LUA_NOREF;
@@ -174,8 +172,6 @@ static int lua_callback_interval(lua_State* interpreter){
//get instance pointer from registry
lua_pushstring(interpreter, LUA_REGISTRY_KEY);
lua_gettable(interpreter, LUA_REGISTRYINDEX);
- inst = (instance*) lua_touserdata(interpreter, -1);
- data = (lua_instance_data*) inst->impl;
//fetch and round the interval
interval = luaL_checkinteger(interpreter, 2);
diff --git a/backends/osc.c b/backends/osc.c
index 18c8bad..03e431f 100644
--- a/backends/osc.c
+++ b/backends/osc.c
@@ -1,8 +1,8 @@
#include <string.h>
#include <ctype.h>
#include <errno.h>
-#include "libmmbackend.h"
+#include "libmmbackend.h"
#include "osc.h"
/*
@@ -480,14 +480,14 @@ static int osc_register_pattern(osc_instance_data* data, char* pattern_path, cha
//parse min/max values
token = strtok(NULL, " ");
if(!token){
- fprintf(stderr, "Missing minimum specification for parameter %zu of OSC pattern %s\n", u, pattern_path);
+ fprintf(stderr, "Missing minimum specification for parameter %lu of OSC pattern %s\n", u, pattern_path);
return 1;
}
data->pattern[pattern].min[u] = osc_parse_value_spec(format[u], token);
token = strtok(NULL, " ");
if(!token){
- fprintf(stderr, "Missing maximum specification for parameter %zu of OSC pattern %s\n", u, pattern_path);
+ fprintf(stderr, "Missing maximum specification for parameter %lu of OSC pattern %s\n", u, pattern_path);
return 1;
}
data->pattern[pattern].max[u] = osc_parse_value_spec(format[u], token);
@@ -689,7 +689,7 @@ static int osc_output_channel(instance* inst, size_t channel){
//write data
if(offset + osc_data_length(data->channel[channel].type[p]) >= sizeof(xmit_buf)){
- fprintf(stderr, "Insufficient buffer size for OSC transmitting channel %s.%s at parameter %zu\n", inst->name, data->channel[channel].path, p);
+ fprintf(stderr, "Insufficient buffer size for OSC transmitting channel %s.%s at parameter %lu\n", inst->name, data->channel[channel].path, p);
return 1;
}
@@ -720,7 +720,7 @@ static int osc_set(instance* inst, size_t num, channel** c, channel_value* v){
osc_instance_data* data = (osc_instance_data*) inst->impl;
if(!data->dest_len){
- fprintf(stderr, "OSC instance %s does not have a destination, output is disabled (%zu channels)\n", inst->name, num);
+ fprintf(stderr, "OSC instance %s does not have a destination, output is disabled (%lu channels)\n", inst->name, num);
return 0;
}
@@ -778,7 +778,7 @@ static int osc_process_packet(instance* inst, char* local_path, char* format, ui
channel* chan = NULL;
if(payload_len % 4){
- fprintf(stderr, "Invalid OSC packet, data length %zu\n", payload_len);
+ fprintf(stderr, "Invalid OSC packet, data length %lu\n", payload_len);
return 0;
}
@@ -877,7 +877,11 @@ static int osc_handle(size_t num, managed_fd* fds){
}
} while(bytes_read > 0);
+ #ifdef _WIN32
+ if(bytes_read < 0 && WSAGetLastError() != WSAEWOULDBLOCK){
+ #else
if(bytes_read < 0 && errno != EAGAIN){
+ #endif
fprintf(stderr, "OSC failed to receive data for instance %s: %s\n", inst->name, strerror(errno));
}
@@ -924,7 +928,7 @@ static int osc_start(){
}
}
- fprintf(stderr, "OSC backend registered %zu descriptors to core\n", fds);
+ fprintf(stderr, "OSC backend registered %lu descriptors to core\n", fds);
free(inst);
return 0;
diff --git a/backends/osc.h b/backends/osc.h
index 4e9dec5..b2aaea7 100644
--- a/backends/osc.h
+++ b/backends/osc.h
@@ -1,6 +1,8 @@
#include "midimonster.h"
#include <sys/types.h>
+#ifndef _WIN32
#include <sys/socket.h>
+#endif
#define OSC_RECV_BUF 8192
#define OSC_XMIT_BUF 8192
diff --git a/backends/sacn.c b/backends/sacn.c
index 75bb76f..6f7d1a5 100644
--- a/backends/sacn.c
+++ b/backends/sacn.c
@@ -1,16 +1,18 @@
#include <string.h>
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
+#ifndef _WIN32
+#include <netdb.h>
#include <netinet/in.h>
+#include <sys/socket.h>
+#endif
#include "libmmbackend.h"
-
#include "sacn.h"
+
//upper limit imposed by using the fd index as 16-bit part of the instance id
#define MAX_FDS 4096
#define BACKEND_NAME "sacn"
@@ -71,7 +73,7 @@ static int sacn_listener(char* host, char* port, uint8_t fd_flags){
return -1;
}
- fprintf(stderr, "sACN backend interface %zu bound to %s port %s\n", global_cfg.fds, host, port);
+ fprintf(stderr, "sACN backend interface %lu bound to %s port %s\n", global_cfg.fds, host, port);
global_cfg.fd[global_cfg.fds].fd = fd;
global_cfg.fd[global_cfg.fds].flags = fd_flags;
global_cfg.fd[global_cfg.fds].universes = 0;
@@ -271,7 +273,7 @@ static int sacn_transmit(instance* inst){
memcpy(pdu.data.source_name, global_cfg.source_name, sizeof(pdu.data.source_name));
memcpy((((uint8_t*)pdu.data.data) + 1), data->data.out, 512);
- if(sendto(global_cfg.fd[data->fd_index].fd, &pdu, sizeof(pdu), 0, (struct sockaddr*) &data->dest_addr, data->dest_len) < 0){
+ if(sendto(global_cfg.fd[data->fd_index].fd, (uint8_t*) &pdu, sizeof(pdu), 0, (struct sockaddr*) &data->dest_addr, data->dest_len) < 0){
fprintf(stderr, "Failed to output sACN frame for instance %s: %s\n", inst->name, strerror(errno));
}
@@ -293,7 +295,7 @@ static int sacn_set(instance* inst, size_t num, channel** c, channel_value* v){
}
if(!data->xmit_prio){
- fprintf(stderr, "sACN instance %s not enabled for output (%zu channel events)\n", inst->name, num);
+ fprintf(stderr, "sACN instance %s not enabled for output (%lu channel events)\n", inst->name, num);
return 0;
}
@@ -378,7 +380,7 @@ static int sacn_process_frame(instance* inst, sacn_frame_root* frame, sacn_frame
}
if(!chan){
- fprintf(stderr, "Active channel %zu on %s not known to core", u, inst->name);
+ fprintf(stderr, "Active channel %lu on %s not known to core", u, inst->name);
return 1;
}
@@ -445,8 +447,8 @@ static void sacn_discovery(size_t fd){
pdu.data.page = page;
memcpy(pdu.data.data, global_cfg.fd[fd].universe + page * 512, universes * sizeof(uint16_t));
- if(sendto(global_cfg.fd[fd].fd, &pdu, sizeof(pdu) - (512 - universes) * sizeof(uint16_t), 0, (struct sockaddr*) &discovery_dest, sizeof(discovery_dest)) < 0){
- fprintf(stderr, "Failed to output sACN universe discovery frame for interface %zu: %s\n", fd, strerror(errno));
+ if(sendto(global_cfg.fd[fd].fd, (uint8_t*) &pdu, sizeof(pdu) - (512 - universes) * sizeof(uint16_t), 0, (struct sockaddr*) &discovery_dest, sizeof(discovery_dest)) < 0){
+ fprintf(stderr, "Failed to output sACN universe discovery frame for interface %lu: %s\n", fd, strerror(errno));
}
}
}
@@ -512,7 +514,11 @@ static int sacn_handle(size_t num, managed_fd* fds){
}
} while(bytes_read > 0);
+ #ifdef _WIN32
+ if(bytes_read < 0 && WSAGetLastError() != WSAEWOULDBLOCK){
+ #else
if(bytes_read < 0 && errno != EAGAIN){
+ #endif
fprintf(stderr, "sACN failed to receive data: %s\n", strerror(errno));
}
@@ -577,7 +583,7 @@ static int sacn_start(){
if(!data->unicast_input){
mcast_req.imr_multiaddr.s_addr = htobe32(((uint32_t) 0xefff0000) | ((uint32_t) data->uni));
- if(setsockopt(global_cfg.fd[data->fd_index].fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mcast_req, sizeof(mcast_req))){
+ if(setsockopt(global_cfg.fd[data->fd_index].fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (uint8_t*) &mcast_req, sizeof(mcast_req))){
fprintf(stderr, "Failed to join Multicast group for sACN universe %u on instance %s: %s\n", data->uni, inst[u]->name, strerror(errno));
}
}
@@ -604,7 +610,7 @@ static int sacn_start(){
}
}
- fprintf(stderr, "sACN backend registering %zu descriptors to core\n", global_cfg.fds);
+ fprintf(stderr, "sACN backend registering %lu descriptors to core\n", global_cfg.fds);
for(u = 0; u < global_cfg.fds; u++){
//allocate memory for storing last frame transmission timestamp
global_cfg.fd[u].last_frame = calloc(global_cfg.fd[u].universes, sizeof(uint64_t));
diff --git a/backends/sacn.h b/backends/sacn.h
index e7106f7..7af2a36 100644
--- a/backends/sacn.h
+++ b/backends/sacn.h
@@ -1,4 +1,3 @@
-#include <sys/socket.h>
#include "midimonster.h"
int init();