libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/net/osc_misc.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   PSYCHOSYNTH                                                           *
00004  *   ===========                                                           *
00005  *                                                                         *
00006  *   Copyright (C) 2007 Juan Pedro Bolivar Puente                          *
00007  *                                                                         *
00008  *   This program is free software: you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation, either version 3 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 #ifndef PSYNTH_OSCMISC_H
00024 #define PSYNTH_OSCMISC_H
00025 
00026 #include <cstdio>
00027 #include <lo/lo.h>
00028 
00029 namespace psynth
00030 {
00031 
00032 #define LO_HANDLER_ARGS const char* path, const char* types,\
00033         lo_arg** argv, int argc, lo_message msg
00034 
00035 #define LO_HANDLER(clax,name)                   \
00036 int _##name##_cb (LO_HANDLER_ARGS);\
00037 inline static int name##_cb(LO_HANDLER_ARGS, void* osc_listener)\
00038 { \
00039     return ((clax*)osc_listener)->_##name##_cb(path, types, argv, argc, msg);\
00040 }
00041 
00042 
00043 inline bool lo_address_equals(lo_address a, lo_address b)
00044 {
00045     return strcmp(lo_address_get_hostname(a), lo_address_get_hostname(b)) == 0
00046         && strcmp(lo_address_get_port(a), lo_address_get_port(b)) == 0;
00047     // FIXME: && lo_address_get_protocol(a) == lo_address_get_protocol(b);
00048 }
00049 
00050 inline int lo_address_cmp(lo_address a, lo_address b)
00051 {
00052     int res;
00053 
00054     res = strcmp(lo_address_get_hostname(a), lo_address_get_hostname(b));
00055     if (!res) {
00056         res = strcmp(lo_address_get_port(a), lo_address_get_port(b));
00057     }
00058 
00059     return res;
00060 }
00061 
00062 inline int lo_generic_handler(const char *path, const char *types, lo_arg **argv,
00063                               int argc, lo_message msg, void *user_data)
00064 {
00065     int i;
00066 
00067     printf("--- OSC Message ---\n");
00068     printf("from host: %s\n", lo_address_get_hostname(lo_message_get_source(msg)));
00069     printf("from port: %s\n", lo_address_get_port(lo_message_get_source(msg)));
00070     printf("path: <%s>\n", path);
00071 
00072     for (i=0; i<argc; i++) {
00073         printf("arg %d '%c' ", i, types[i]);
00074         lo_arg_pp((lo_type)types[i], argv[i]);
00075         printf("\n");
00076     }
00077     
00078     printf("\n");
00079     fflush(stdout);
00080 
00081     return 1;
00082 }
00083 
00084 } /* namespace psynth */
00085 
00086 #endif /* PSYNTH_OSCMISC_H */