diff options
| author | Jaromil <[email protected]> | 2011-03-29 10:19:22 (GMT) |
|---|---|---|
| committer | Jaromil <[email protected]> | 2011-03-29 10:19:22 (GMT) |
| commit | 0ed004b617112b910d2adc6dd9381040f78b2759 (patch) | |
| tree | 1822bfc8a03ce2702901e65f2d52f5c46dfc8b9c | |
| parent | dadb21768fb7e6c76625c211cfdbd9c0723b5ac1 (diff) | |
rewrite of hdsync in C using OSC messagingosc
| -rw-r--r-- | src/hdosync.c | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/src/hdosync.c b/src/hdosync.c index ca3c373..28795a7 100644 --- a/src/hdosync.c +++ b/src/hdosync.c @@ -30,8 +30,52 @@ #include <arpa/inet.h> #include <netdb.h> +#include <getopt.h> + #include <lo/lo.h> +char iface[256]; +int chan = 0; + + +char *help = + "Usage: hdosync -c N -i IP\n"; + +const struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'v'}, + {"interface", required_argument, NULL, 'i'}, + {"channel", required_argument, NULL, 'c'}, + {0, 0, 0, 0} +}; +char *short_options = "hvi:c:"; + +void config_init (int argc, char *argv[]) { + int res; + do { + res = getopt_long (argc, argv, short_options, long_options, NULL); + switch(res) { + case 'h': + fprintf (stderr, "%s", help); + exit(0); + case 'v': + exit(0); + case 'i': + snprintf(iface,255,"%s",optarg); + break; + case 'c': + chan = atoi(optarg); + break; + } + } while (res > 0); + + if(!chan) { + fprintf(stderr,"error: channel not specified, use -c 1 and subsequent numbers\n"); + exit(1); + } +} + + void loErrorHandler(int num, const char *msg, const char *where) { fprintf(stderr,"liblo server error %d in path %s: %s\n", num, where, msg); } @@ -102,17 +146,34 @@ int udp_broadcast(char *hostname, char *port, char *message) { return(1); } +int offer_sync() { + return(0); +} +int listen_sync() { + return(0); +} + int main(int argc, char **argv) { lo_server server; + + config_init(argc, argv); + + if(chan==1) + offer_sync(); + else + listen_sync(); + char *port = "6666"; + fprintf(stderr,"creating new osc server\n"); + server = lo_server_new(port, loErrorHandler); if(server == NULL) { - fprintf("could not start an hdosync server with port %s\n", port); + fprintf(stderr,"could not start an hdosync server with port %s\n", port); exit(1); } - fprintf("starting hdosync server on port %s\n", port); + fprintf(stderr,"starting hdosync server on port %s\n", port); lo_server_add_method(server, NULL, NULL, loMessageHandler, NULL); |

