From be3711cd809446c8ea3ab06a8f39e481bd429ca5 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 10 Oct 2015 06:32:51 +0200 Subject: improved error handling --- apps/dolmetschctl.c | 2 +- apps/osc.c | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'apps') diff --git a/apps/dolmetschctl.c b/apps/dolmetschctl.c index fb8f30d..cdf95bb 100644 --- a/apps/dolmetschctl.c +++ b/apps/dolmetschctl.c @@ -44,7 +44,7 @@ void print_version() int main(int argc, char* argv[]) { osc_t o; - if(osc_init(&o, "7770")) + if(osc_init(&o, "1200")) return -1; midi_t m; diff --git a/apps/osc.c b/apps/osc.c index 66b281a..7effa54 100644 --- a/apps/osc.c +++ b/apps/osc.c @@ -23,7 +23,7 @@ #include "config.h" #include -#include +#include #include #include "osc.h" @@ -31,7 +31,7 @@ static void print_error(int num, const char *msg, const char *path) { - fprintf(stderr, "liblo server error %d in path %s: %s\n", num, path, msg); + error(0, 0, "liblo server error %d in path %s: %s", num, path, msg); } static int generic_handler(const char *path, const char *types, lo_arg ** argv, @@ -54,9 +54,12 @@ int osc_init(osc_t* o, const char* port) { assert(o != NULL); - // TODO: what happends when this fails? o->st_ = lo_server_thread_new(port, print_error); - lo_server_thread_add_method(o->st_, NULL, NULL, generic_handler, NULL); + if(!o->st_) + return -1; + + if(!lo_server_thread_add_method(o->st_, NULL, NULL, generic_handler, NULL)) + return -1; return 0; } @@ -65,8 +68,9 @@ int osc_start(osc_t* o) { assert(o != NULL); - // TODO: what happends when this fails? - lo_server_thread_start(o->st_); + int ret = lo_server_thread_start(o->st_); + if(ret) + error(0, ret, "faild to create osc thread"); return 0; } @@ -75,7 +79,10 @@ int osc_stop(osc_t* o) { assert(o != NULL); - // TODO: what happends when this fails? + int ret = lo_server_thread_stop(o->st_); + if(ret) + error(0, ret, "faild to stop osc thread"); + lo_server_thread_free(o->st_); return 0; -- cgit v1.2.3