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