annotate src/liblo-0.26/examples/example_server.c @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents e13257ea84a4
children
rev   line source
Chris@4 1 /*
Chris@4 2 * Copyright (C) 2004 Steve Harris, Uwe Koloska
Chris@4 3 *
Chris@4 4 * This program is free software; you can redistribute it and/or modify
Chris@4 5 * it under the terms of the GNU Lesser General Public License as
Chris@4 6 * published by the Free Software Foundation; either version 2.1 of the
Chris@4 7 * License, or (at your option) any later version.
Chris@4 8 *
Chris@4 9 * This program is distributed in the hope that it will be useful,
Chris@4 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@4 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@4 12 * GNU Lesser General Public License for more details.
Chris@4 13 *
Chris@4 14 * $Id$
Chris@4 15 */
Chris@4 16
Chris@4 17 #include <stdio.h>
Chris@4 18 #include <stdlib.h>
Chris@4 19 #include <unistd.h>
Chris@4 20
Chris@4 21 #include "lo/lo.h"
Chris@4 22
Chris@4 23 int done = 0;
Chris@4 24
Chris@4 25 void error(int num, const char *m, const char *path);
Chris@4 26
Chris@4 27 int generic_handler(const char *path, const char *types, lo_arg **argv,
Chris@4 28 int argc, void *data, void *user_data);
Chris@4 29
Chris@4 30 int foo_handler(const char *path, const char *types, lo_arg **argv, int argc,
Chris@4 31 void *data, void *user_data);
Chris@4 32
Chris@4 33 int quit_handler(const char *path, const char *types, lo_arg **argv, int argc,
Chris@4 34 void *data, void *user_data);
Chris@4 35
Chris@4 36 int main()
Chris@4 37 {
Chris@4 38 /* start a new server on port 7770 */
Chris@4 39 lo_server_thread st = lo_server_thread_new("7770", error);
Chris@4 40
Chris@4 41 /* add method that will match any path and args */
Chris@4 42 lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL);
Chris@4 43
Chris@4 44 /* add method that will match the path /foo/bar, with two numbers, coerced
Chris@4 45 * to float and int */
Chris@4 46 lo_server_thread_add_method(st, "/foo/bar", "fi", foo_handler, NULL);
Chris@4 47
Chris@4 48 /* add method that will match the path /quit with no args */
Chris@4 49 lo_server_thread_add_method(st, "/quit", "", quit_handler, NULL);
Chris@4 50
Chris@4 51 lo_server_thread_start(st);
Chris@4 52
Chris@4 53 while (!done) {
Chris@4 54 #ifdef WIN32
Chris@4 55 Sleep(1);
Chris@4 56 #else
Chris@4 57 usleep(1000);
Chris@4 58 #endif
Chris@4 59 }
Chris@4 60
Chris@4 61 lo_server_thread_free(st);
Chris@4 62
Chris@4 63 return 0;
Chris@4 64 }
Chris@4 65
Chris@4 66 void error(int num, const char *msg, const char *path)
Chris@4 67 {
Chris@4 68 printf("liblo server error %d in path %s: %s\n", num, path, msg);
Chris@4 69 fflush(stdout);
Chris@4 70 }
Chris@4 71
Chris@4 72 /* catch any incoming messages and display them. returning 1 means that the
Chris@4 73 * message has not been fully handled and the server should try other methods */
Chris@4 74 int generic_handler(const char *path, const char *types, lo_arg **argv,
Chris@4 75 int argc, void *data, void *user_data)
Chris@4 76 {
Chris@4 77 int i;
Chris@4 78
Chris@4 79 printf("path: <%s>\n", path);
Chris@4 80 for (i=0; i<argc; i++) {
Chris@4 81 printf("arg %d '%c' ", i, types[i]);
Chris@4 82 lo_arg_pp(types[i], argv[i]);
Chris@4 83 printf("\n");
Chris@4 84 }
Chris@4 85 printf("\n");
Chris@4 86 fflush(stdout);
Chris@4 87
Chris@4 88 return 1;
Chris@4 89 }
Chris@4 90
Chris@4 91 int foo_handler(const char *path, const char *types, lo_arg **argv, int argc,
Chris@4 92 void *data, void *user_data)
Chris@4 93 {
Chris@4 94 /* example showing pulling the argument values out of the argv array */
Chris@4 95 printf("%s <- f:%f, i:%d\n\n", path, argv[0]->f, argv[1]->i);
Chris@4 96 fflush(stdout);
Chris@4 97
Chris@4 98 return 0;
Chris@4 99 }
Chris@4 100
Chris@4 101 int quit_handler(const char *path, const char *types, lo_arg **argv, int argc,
Chris@4 102 void *data, void *user_data)
Chris@4 103 {
Chris@4 104 done = 1;
Chris@4 105 printf("quiting\n\n");
Chris@4 106 fflush(stdout);
Chris@4 107
Chris@4 108 return 0;
Chris@4 109 }
Chris@4 110
Chris@4 111 /* vi:set ts=8 sts=4 sw=4: */