From 029c3144e04523cdcbc7d296e7bf22287754ed43 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 8 Oct 2015 07:51:20 +0200 Subject: added sample code for liblo --- app/dolmetschctl.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'app/dolmetschctl.c') diff --git a/app/dolmetschctl.c b/app/dolmetschctl.c index 3591628..1d695a5 100644 --- a/app/dolmetschctl.c +++ b/app/dolmetschctl.c @@ -20,9 +20,15 @@ * along with dolmetschctl. If not, see . */ +#include "config.h" + #include +#include +#include -#include "config.h" +#include "lo/lo.h" + +volatile int done = 0; void print_version() { @@ -36,9 +42,62 @@ void print_version() #endif } +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); +} + + +int generic_handler(const char *path, const char *types, lo_arg ** argv, + int argc, void *data, void *user_data) +{ + int i; + + printf("path: <%s>\n", path); + for(i = 0; i < argc; i++) { + printf("arg %d '%c' ", i, types[i]); + lo_arg_pp((lo_type)types[i], argv[i]); + printf("\n"); + } + printf("\n"); + fflush(stdout); + + return 1; +} + +int foo_handler(const char *path, const char *types, lo_arg ** argv, + int argc, void *data, void *user_data) +{ + printf("%s <- f:%f, i:%d\n", path, argv[0]->f, argv[1]->i); + fflush(stdout); + + return 0; +} + +int quit_handler(const char *path, const char *types, lo_arg ** argv, + int argc, void *data, void *user_data) +{ + done = 1; + printf("quiting\n"); + fflush(stdout); + + return 0; +} int main(int argc, char* argv[]) { - print_version(); + lo_server_thread st = lo_server_thread_new("7770", 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); + lo_server_thread_add_method(st, "/quit", "", quit_handler, NULL); + lo_server_thread_start(st); + + while (!done) { + usleep(1000); + } + + lo_server_thread_free(st); + return 0; } -- cgit v1.2.3