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