From 42791afe69fc2f06a8c606008b933323c55b1039 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 10 Oct 2015 05:59:43 +0200 Subject: osc know has an own stuct too --- apps/osc.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'apps/osc.c') diff --git a/apps/osc.c b/apps/osc.c index 4cba491..701481f 100644 --- a/apps/osc.c +++ b/apps/osc.c @@ -30,8 +30,7 @@ static void print_error(int num, const char *msg, const char *path) { - printf("liblo server error %d in path %s: %s\n", num, path, msg); - fflush(stdout); + fprintf(stderr, "liblo server error %d in path %s: %s\n", num, path, msg); } static int generic_handler(const char *path, const char *types, lo_arg ** argv, @@ -39,43 +38,40 @@ static int generic_handler(const char *path, const char *types, lo_arg ** argv, { int i; - printf("path: <%s>\n", path); + printf("OSC(%s):%s", path, argc ? " ": " \n"); for(i = 0; i < argc; i++) { - printf("arg %d '%c' ", i, types[i]); + printf("arg %d '%c'", i, types[i]); lo_arg_pp((lo_type)types[i], argv[i]); - printf("\n"); + printf("%s", i >= (argc-1) ? "\n" : ", "); } - printf("\n"); - fflush(stdout); return 1; } -static int foo_handler(const char *path, const char *types, lo_arg ** argv, - int argc, void *data, void *user_data) + +int osc_init(osc_t* o, const char* port) { - printf("%s <- f:%f, i:%d\n", path, argv[0]->f, argv[1]->i); - fflush(stdout); + if(!o) + return -1; + + o->st_ = lo_server_thread_new(port, print_error); // TODO: what happends when this fails? + lo_server_thread_add_method(o->st_, NULL, NULL, generic_handler, NULL); return 0; } - -lo_server_thread osc_init(const char* port) +void osc_start(osc_t* o) { - lo_server_thread st = lo_server_thread_new(port, print_error); - lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL); - lo_server_thread_add_method(st, "/foo/bar", "fi", foo_handler, NULL); + if(!o) + return; - return st; + lo_server_thread_start(o->st_); } -void osc_start(lo_server_thread st) +void osc_stop(osc_t* o) { - lo_server_thread_start(st); -} + if(!o) + return; -void osc_stop(lo_server_thread st) -{ - lo_server_thread_free(st); + lo_server_thread_free(o->st_); } -- cgit v1.2.3