cannam@89: /* cannam@89: * Copyright (C) 2004 Steve Harris, Uwe Koloska cannam@89: * cannam@89: * This program is free software; you can redistribute it and/or modify cannam@89: * it under the terms of the GNU Lesser General Public License as cannam@89: * published by the Free Software Foundation; either version 2.1 of the cannam@89: * License, or (at your option) any later version. cannam@89: * cannam@89: * This program is distributed in the hope that it will be useful, cannam@89: * but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@89: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@89: * GNU Lesser General Public License for more details. cannam@89: * cannam@89: * $Id$ cannam@89: */ cannam@89: cannam@89: #include cannam@89: #include cannam@89: #include cannam@89: cannam@89: #include "lo/lo.h" cannam@89: cannam@89: int done = 0; cannam@89: cannam@89: void error(int num, const char *m, const char *path); cannam@89: cannam@89: int generic_handler(const char *path, const char *types, lo_arg **argv, cannam@89: int argc, void *data, void *user_data); cannam@89: cannam@89: int foo_handler(const char *path, const char *types, lo_arg **argv, int argc, cannam@89: void *data, void *user_data); cannam@89: cannam@89: int quit_handler(const char *path, const char *types, lo_arg **argv, int argc, cannam@89: void *data, void *user_data); cannam@89: cannam@89: int main() cannam@89: { cannam@89: /* start a new server on port 7770 */ cannam@89: lo_server_thread st = lo_server_thread_new("7770", error); cannam@89: cannam@89: /* add method that will match any path and args */ cannam@89: lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL); cannam@89: cannam@89: /* add method that will match the path /foo/bar, with two numbers, coerced cannam@89: * to float and int */ cannam@89: lo_server_thread_add_method(st, "/foo/bar", "fi", foo_handler, NULL); cannam@89: cannam@89: /* add method that will match the path /quit with no args */ cannam@89: lo_server_thread_add_method(st, "/quit", "", quit_handler, NULL); cannam@89: cannam@89: lo_server_thread_start(st); cannam@89: cannam@89: while (!done) { cannam@89: #ifdef WIN32 cannam@89: Sleep(1); cannam@89: #else cannam@89: usleep(1000); cannam@89: #endif cannam@89: } cannam@89: cannam@89: lo_server_thread_free(st); cannam@89: cannam@89: return 0; cannam@89: } cannam@89: cannam@89: void error(int num, const char *msg, const char *path) cannam@89: { cannam@89: printf("liblo server error %d in path %s: %s\n", num, path, msg); cannam@89: fflush(stdout); cannam@89: } cannam@89: cannam@89: /* catch any incoming messages and display them. returning 1 means that the cannam@89: * message has not been fully handled and the server should try other methods */ cannam@89: int generic_handler(const char *path, const char *types, lo_arg **argv, cannam@89: int argc, void *data, void *user_data) cannam@89: { cannam@89: int i; cannam@89: cannam@89: printf("path: <%s>\n", path); cannam@89: for (i=0; if, argv[1]->i); cannam@89: fflush(stdout); cannam@89: cannam@89: return 0; cannam@89: } cannam@89: cannam@89: int quit_handler(const char *path, const char *types, lo_arg **argv, int argc, cannam@89: void *data, void *user_data) cannam@89: { cannam@89: done = 1; cannam@89: printf("quiting\n\n"); cannam@89: fflush(stdout); cannam@89: cannam@89: return 0; cannam@89: } cannam@89: cannam@89: /* vi:set ts=8 sts=4 sw=4: */