diff options
Diffstat (limited to 'backends/ola.cpp')
-rw-r--r-- | backends/ola.cpp | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/backends/ola.cpp b/backends/ola.cpp index fd121a0..09d68c9 100644 --- a/backends/ola.cpp +++ b/backends/ola.cpp @@ -1,3 +1,5 @@ +#define BACKEND_NAME "ola" + #include "ola.h" #include <cstring> #include <ola/DmxBuffer.h> @@ -7,7 +9,6 @@ #include <ola/io/SelectServer.h> #include <ola/network/Socket.h> -#define BACKEND_NAME "ola" static ola::io::SelectServer* ola_select = NULL; static ola::OlaCallbackClient* ola_client = NULL; @@ -26,7 +27,7 @@ MM_PLUGIN_API int init(){ //register backend if(mm_backend_register(ola)){ - fprintf(stderr, "Failed to register OLA backend\n"); + LOG("Failed to register backend"); return 1; } @@ -35,7 +36,7 @@ MM_PLUGIN_API int init(){ } static int ola_configure(char* option, char* value){ - fprintf(stderr, "Unknown OLA backend option %s\n", option); + LOGPF("Unknown backend option %s", option); return 1; } @@ -48,7 +49,7 @@ static instance* ola_instance(){ data = (ola_instance_data*)calloc(1, sizeof(ola_instance_data)); if(!data){ - fprintf(stderr, "Failed to allocate memory\n"); + LOG("Failed to allocate memory"); return NULL; } @@ -64,7 +65,7 @@ static int ola_configure_instance(instance* inst, char* option, char* value){ return 0; } - fprintf(stderr, "Unknown OLA option %s for instance %s\n", option, inst->name); + LOGPF("Unknown instance configuration option %s for instance %s", option, inst->name); return 1; } @@ -76,7 +77,7 @@ static channel* ola_channel(instance* inst, char* spec, uint8_t flags){ //primary channel sanity check if(!chan_a || chan_a > 512){ - fprintf(stderr, "Invalid OLA channel specification %s\n", spec); + LOGPF("Invalid channel specification %s", spec); return NULL; } chan_a--; @@ -85,14 +86,14 @@ static channel* ola_channel(instance* inst, char* spec, uint8_t flags){ if(*spec_next == '+'){ chan_b = strtoul(spec_next + 1, NULL, 10); if(!chan_b || chan_b > 512){ - fprintf(stderr, "Invalid wide-channel spec %s\n", spec); + LOGPF("Invalid wide-channel spec %s", spec); return NULL; } chan_b--; //if mapped mode differs, bail if(IS_ACTIVE(data->data.map[chan_b]) && data->data.map[chan_b] != (MAP_FINE | chan_a)){ - fprintf(stderr, "Fine channel already mapped for OLA spec %s\n", spec); + LOGPF("Fine channel already mapped for spec %s", spec); return NULL; } @@ -103,7 +104,7 @@ static channel* ola_channel(instance* inst, char* spec, uint8_t flags){ if(IS_ACTIVE(data->data.map[chan_a])){ if((*spec_next == '+' && data->data.map[chan_a] != (MAP_COARSE | chan_b)) || (*spec_next != '+' && data->data.map[chan_a] != (MAP_SINGLE | chan_a))){ - fprintf(stderr, "Primary OLA channel already mapped at differing mode: %s\n", spec); + LOGPF("Primary channel already mapped at differing mode: %s", spec); return NULL; } } @@ -189,7 +190,7 @@ static void ola_data_receive(unsigned int universe, const ola::DmxBuffer& ola_dm } if(!chan){ - fprintf(stderr, "Active channel %zu on %s not known to core\n", p, inst->name); + LOGPF("Active channel %" PRIsize_t " on %s not known to core", p, inst->name); return; } @@ -207,7 +208,7 @@ static void ola_data_receive(unsigned int universe, const ola::DmxBuffer& ola_dm } if(mm_channel_event(chan, val)){ - fprintf(stderr, "Failed to push OLA channel event to core\n"); + LOG("Failed to push event to core"); return; } } @@ -216,7 +217,7 @@ static void ola_data_receive(unsigned int universe, const ola::DmxBuffer& ola_dm static void ola_register_callback(const std::string &error) { if(!error.empty()){ - fprintf(stderr, "OLA backend failed to register for universe: %s\n", error.c_str()); + LOGPF("Failed to register for universe: %s", error.c_str()); } } @@ -228,20 +229,20 @@ static int ola_start(size_t n, instance** inst){ ola::network::IPV4SocketAddress ola_server(ola::network::IPV4Address::Loopback(), ola::OLA_DEFAULT_PORT); ola::network::TCPSocket* ola_socket = ola::network::TCPSocket::Connect(ola_server); if(!ola_socket){ - fprintf(stderr, "Failed to connect to OLA server\n"); + LOG("Failed to connect to server"); return 1; } ola_client = new ola::OlaCallbackClient(ola_socket); if(!ola_client->Setup()){ - fprintf(stderr, "Failed to start OLA client\n"); + LOG("Failed to start client"); goto bail; } ola_select->AddReadDescriptor(ola_socket); - fprintf(stderr, "OLA backend registering connection descriptor to core\n"); + LOG("Registering connection descriptor to core"); if(mm_manage_fd(ola_socket->ReadDescriptor(), BACKEND_NAME, 1, NULL)){ goto bail; } @@ -255,7 +256,7 @@ static int ola_start(size_t n, instance** inst){ //check for duplicate instances (using the same universe) for(p = 0; p < u; p++){ if(inst[u]->ident == inst[p]->ident){ - fprintf(stderr, "OLA universe used in multiple instances, use one instance: %s - %s\n", inst[u]->name, inst[p]->name); + LOGPF("Universe used in multiple instances, use one instance: %s - %s", inst[u]->name, inst[p]->name); goto bail; } } @@ -292,6 +293,6 @@ static int ola_shutdown(size_t n, instance** inst){ ola_select = NULL; } - fprintf(stderr, "OLA backend shut down\n"); + LOG("Backend shut down"); return 0; } |