From d4feaf4ff76c78862a2bc54851f3ed1f7709bcdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Wed, 12 Apr 2006 14:21:34 +0000 Subject: applied patch [ 1446663 ] in order to use typed list-elements instead of reparsing the send-string (up till now the list to send was converted to a string and this string was then converted into an OSC-message; this prevented us from sending of a symbol "12" (instead it became a float 12) svn path=/trunk/externals/OSCx/; revision=4885 --- src/sendOSC.c | 676 ++++++++++++++++------------------------------------------ 1 file changed, 184 insertions(+), 492 deletions(-) (limited to 'src/sendOSC.c') diff --git a/src/sendOSC.c b/src/sendOSC.c index 701bfa0..4340f8a 100644 --- a/src/sendOSC.c +++ b/src/sendOSC.c @@ -43,6 +43,7 @@ The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl -- tweaks for Win32 www.zeggz.com/raf 13-April-2002 -- ost_at_test.at + i22_at_test.at, 2000-2002 modified to compile as pd externel + --20060308 MP clear out some unused code and improve conversion from pd types to OSC types */ #if HAVE_CONFIG_H @@ -59,15 +60,10 @@ The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl #include "htmsocket.h" #include -#include #include #ifdef WIN32 #include -#include -#include -#include -#include #else #include #include @@ -79,29 +75,18 @@ The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl /////////////////////// // from sendOSC -typedef struct { - //enum {INT, FLOAT, STRING} type; - enum {INT_osc, FLOAT_osc, STRING_osc} type; - union { +typedef struct +{ + enum {INT_osc, FLOAT_osc, STRING_osc, NOTYPE_osc} type; + union + { int i; float f; char *s; } datum; } typedArg; -void CommandLineMode(int argc, char *argv[], void *htmsocket); - -OSCTimeTag ParseTimeTag(char *s); -void ParseInteractiveLine(OSCbuf *buf, char *mesg); -typedArg ParseToken(char *token); -int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args); -void SendBuffer(void *htmsocket, OSCbuf *buf); -void SendData(void *htmsocket, int size, char *data); -/* defined in OSC-system-dependent.c now */ -/* void fatal_error(char *s); */ -void send_complain(char *s, ...); -//static void *htmsocket; static int exitStatus = 0; static int useTypeTags = 0; @@ -124,16 +109,31 @@ typedef struct _sendOSC t_outlet *x_bdpthout;// bundle-depth floatoutlet } t_sendOSC; +static void *sendOSC_new(t_floatarg udpflag); +void sendOSC_openbundle(t_sendOSC *x); +static void sendOSC_closebundle(t_sendOSC *x); +static void sendOSC_settypetags(t_sendOSC *x, t_float *f); +static void sendOSC_connect(t_sendOSC *x, t_symbol *hostname, t_floatarg fportno); +void sendOSC_disconnect(t_sendOSC *x); +static void sendOSC_sendtyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv); +void sendOSC_send(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv); +static void sendOSC_free(t_sendOSC *x); +void sendOSC_setup(void); +typedArg ParseAtom(t_atom *a); +int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args); +void SendBuffer(void *htmsocket, OSCbuf *buf); +void SendData(void *htmsocket, int size, char *data); + static void *sendOSC_new(t_floatarg udpflag) { t_sendOSC *x = (t_sendOSC *)pd_new(sendOSC_class); outlet_new(&x->x_obj, &s_float); x->x_htmsocket = 0; // {{raf}} // set udp - x->x_protocol = SOCK_STREAM; + x->x_protocol = SOCK_DGRAM; ////MP20060308// not SOCK_STREAM but we don't use it anyway... // set typetags to 1 by default x->x_typetags = 1; - // bunlde is closed + // bundle is closed x->x_bundle = 0; OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf); x->x_bdpthout = outlet_new(&x->x_obj, 0); // outlet_float(); @@ -147,7 +147,7 @@ void sendOSC_openbundle(t_sendOSC *x) if (x->x_oscbuf->bundleDepth + 1 >= MAX_BUNDLE_NESTING || OSC_openBundle(x->x_oscbuf, OSCTT_Immediately())) { - send_complain("Problem opening bundle: %s\n", OSC_errorMessage); + error("Problem opening bundle: %s\n", OSC_errorMessage); return; } x->x_bundle = 1; @@ -156,17 +156,22 @@ void sendOSC_openbundle(t_sendOSC *x) static void sendOSC_closebundle(t_sendOSC *x) { - if (OSC_closeBundle(x->x_oscbuf)) { - send_complain("Problem closing bundle: %s\n", OSC_errorMessage); + if (OSC_closeBundle(x->x_oscbuf)) + { + error("Problem closing bundle: %s\n", OSC_errorMessage); return; } outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth); // in bundle mode we send when bundle is closed? - if(!OSC_isBufferEmpty(x->x_oscbuf) > 0 && OSC_isBufferDone(x->x_oscbuf)) { + if(!OSC_isBufferEmpty(x->x_oscbuf) > 0 && OSC_isBufferDone(x->x_oscbuf)) + { // post("x_oscbuf: something inside me?"); - if (x->x_htmsocket) { + if (x->x_htmsocket) + { SendBuffer(x->x_htmsocket, x->x_oscbuf); - } else { + } + else + { post("sendOSC: not connected"); } OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf); @@ -182,72 +187,56 @@ static void sendOSC_settypetags(t_sendOSC *x, t_float *f) post("sendOSC.c: setting typetags %d",x->x_typetags); } - -static void sendOSC_connect(t_sendOSC *x, t_symbol *hostname, - t_floatarg fportno) +static void sendOSC_connect(t_sendOSC *x, t_symbol *hostname, t_floatarg fportno) { int portno = fportno; + char *protocolStr; /* create a socket */ // make sure handle is available - if(x->x_htmsocket == 0) { - // + if(x->x_htmsocket == 0) + { x->x_htmsocket = OpenHTMSocket(hostname->s_name, portno); if (!x->x_htmsocket) - post("Couldn't open socket: "); - else { - post("connected to port %s:%d (hSock=%d)", hostname->s_name, portno, x->x_htmsocket); + post("sendOSC: Couldn't open socket: "); + else + { + switch (x->x_protocol) + { + case SOCK_DGRAM: + protocolStr = "UDP"; + break; + case SOCK_STREAM: + protocolStr = "TCP"; + break; + default: + protocolStr = "unknown"; + break; + } + post("sendOSC: connected to port %s:%d (hSock=%d) protocol = %s", + hostname->s_name, portno, x->x_htmsocket, protocolStr); outlet_float(x->x_obj.ob_outlet, 1); } } else - perror("call to sendOSC_connect() against UNavailable socket handle"); + perror("call to sendOSC_connect() against unavailable socket handle"); } void sendOSC_disconnect(t_sendOSC *x) { if (x->x_htmsocket) { - post("disconnecting htmsock (hSock=%d)...", x->x_htmsocket); + post("sendOSC: disconnecting htmsock (hSock=%d)...", x->x_htmsocket); CloseHTMSocket(x->x_htmsocket); x->x_htmsocket = 0; // {{raf}} semi-quasi-semaphorize this outlet_float(x->x_obj.ob_outlet, 0); } - else { + else + { perror("call to sendOSC_disconnect() against unused socket handle"); } } -/*void sendOSC_senduntyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv) -{ - char* targv[MAXPDARG]; - char tmparg[MAXPDSTRING]; - char* tmp = tmparg; - //char testarg[MAXPDSTRING]; - int c; - - post("sendOSC: use typetags 0/1 message and plain send method so send untypetagged..."); - return; - - //atom_string(argv,testarg, MAXPDSTRING); - for (c=0;c= .. - if (x->x_htmsocket) - { - CommandLineMode(argc, targv, x->x_htmsocket); - // post("test %d", c); - } - else { - post("sendOSC: not connected"); - // exit(3); - } -}*/ ////////////////////////////////////////////////////////////////////// // this is the real and only sending routine now, for both typed and @@ -255,35 +244,17 @@ void sendOSC_disconnect(t_sendOSC *x) static void sendOSC_sendtyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv) { - char* targv[MAX_ARGS]; - char tmparg[MAXPDSTRING]; - char* tmp = tmparg; - int c; - - char *messageName; + char messageName[MAXPDSTRING]; char *token; typedArg args[MAX_ARGS]; - int i,j; - int numArgs = 0; + int i; - messageName = ""; + messageName[0] = '\0'; // empty if(argc>MAX_ARGS) - { post ("sendOSC: too many arguments! (max: %d)", MAX_ARGS); return; } - - for (c=0;c= .. @@ -293,46 +264,64 @@ static void sendOSC_sendtyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv) post ("sendOSC: type tags? %d", useTypeTags); #endif - messageName = strtok(targv[0], ","); - j = 1; - for (i = j; i < argc; i++) { - token = strtok(targv[i],","); - args[i-j] = ParseToken(token); + atom_string(&argv[0], messageName, MAXPDSTRING); +// messageName = strtok(targv[0], ","); + for (i = 0; i < argc-1; i++) + { +// token = strtok(targv[i],","); + + args[i] = ParseAtom(&argv[i+1]); #ifdef DEBUG - printf("cell-cont: %s\n", targv[i]); - printf(" type-id: %d\n", args[i-j]); + switch (args[i].type) + { + case INT_osc: + printf("cell-cont: %d\n", args[i].datum.i); + break; + case FLOAT_osc: + printf("cell-cont: %f\n", args[i].datum.f); + break; + case STRING_osc: + printf("cell-cont: %s\n", args[i].datum.s); + break; + case NOTYPE_osc: + printf("unknown type\n"); + break; + } + printf(" type-id: %d\n", args[i].type); #endif - numArgs = i; } - - if(WriteMessage(x->x_oscbuf, messageName, numArgs, args)) { + if(WriteMessage(x->x_oscbuf, messageName, i, args)) + { post("sendOSC: usage error, write-msg failed: %s", OSC_errorMessage); return; } - if(!x->x_bundle) { + if(!x->x_bundle) + { SendBuffer(x->x_htmsocket, x->x_oscbuf); OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf); } } - else { - post("sendOSC: not connected"); - } + else post("sendOSC: not connected"); } void sendOSC_send(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv) { - if(!argc) { + if(!argc) + { post("not sending empty message."); return; } - if(x->x_typetags) { + if(x->x_typetags) + { useTypeTags = 1; sendOSC_sendtyped(x,s,argc,argv); useTypeTags = 0; - } else { + } + else + { sendOSC_sendtyped(x,s,argc,argv); } } @@ -342,11 +331,8 @@ static void sendOSC_free(t_sendOSC *x) sendOSC_disconnect(x); } -#ifdef WIN32 - void sendOSC_setup(void) { -#else - void sendOSC_setup(void) { -#endif +void sendOSC_setup(void) +{ sendOSC_class = class_new(gensym("sendOSC"), (t_newmethod)sendOSC_new, (t_method)sendOSC_free, sizeof(t_sendOSC), 0, A_DEFFLOAT, 0); @@ -375,10 +361,6 @@ static void sendOSC_free(t_sendOSC *x) class_sethelpsymbol(sendOSC_class, gensym("sendOSC-help.pd")); } - - - - /* Exit status codes: 0: successful 2: Message(s) dropped because of buffer overflow @@ -387,310 +369,53 @@ static void sendOSC_free(t_sendOSC *x) 5: Internal error */ -void CommandLineMode(int argc, char *argv[], void *htmsocket) { - char *messageName; - char *token; - typedArg args[MAX_ARGS]; - int i,j, numArgs; - OSCbuf buf[1]; - - OSC_initBuffer(buf, SC_BUFFER_SIZE, bufferForOSCbuf); - - if (argc > 1) { - post("argc (%d) > 1", argc); -/* if (OSC_openBundle(buf, OSCTT_Immediately())) { */ -/* send_complain("Problem opening bundle: %s\n", OSC_errorMessage); */ -/* return; */ -/* } */ - } - // ParseInteractiveLine(buf, argv); - messageName = strtok(argv[0], ","); +typedArg ParseAtom(t_atom *a) +{ + typedArg returnVal; + t_float f; + t_int i; + t_symbol s; + char buf[MAXPDSTRING]; - j = 1; - for (i = j; i < argc; i++) { - token = strtok(argv[i],","); - args[i-j] = ParseToken(token); + atom_string(a, buf, MAXPDSTRING); #ifdef DEBUG - printf("cell-cont: %s\n", argv[i]); - printf(" type-id: %d\n", args[i-j]); -#endif - numArgs = i; - } - - if(WriteMessage(buf, messageName, numArgs, args)) { - post("sendOSC: usage error. write-msg failed: %s", OSC_errorMessage); - return; - } - -/* for (i = 0; i < argc; i++) { */ -/* messageName = strtok(argv[i], ","); */ -/* //send_complain ("commandlinemode: count: %d %s\n",i, messageName); */ -/* if (messageName == NULL) { */ -/* break; */ -/* } */ - -/* j = 0; */ -/* while ((token = strtok(NULL, ",")) != NULL) { */ -/* args[j] = ParseToken(token); */ -/* j++; */ -/* if (j >= MAX_ARGS) { */ -/* send_complain("Sorry; your message has more than MAX_ARGS (%d) arguments; ignoring the rest.\n", */ -/* MAX_ARGS); */ -/* break; */ -/* } */ -/* } */ -/* numArgs = j; */ - -/* WriteMessage(buf, messageName, numArgs, args); */ - -/* } */ - -/* if (argc > 1) { */ -/* if (OSC_closeBundle(buf)) { */ -/* send_complain("Problem closing bundle: %s\n", OSC_errorMessage); */ -/* return; */ -/* } */ -/* } */ - - SendBuffer(htmsocket, buf); -} - -#define MAXMESG 2048 - -void InteractiveMode(void *htmsocket) { - char mesg[MAXMESG]; - OSCbuf buf[1]; - int bundleDepth = 0; /* At first, we haven't seen "[". */ - - OSC_initBuffer(buf, SC_BUFFER_SIZE, bufferForOSCbuf); - - while (fgets(mesg, MAXMESG, stdin) != NULL) { - if (mesg[0] == '\n') { - if (bundleDepth > 0) { - /* Ignore blank lines inside a group. */ - } else { - /* blank line => repeat previous send */ - SendBuffer(htmsocket, buf); - } - continue; - } - - if (bundleDepth == 0) { - OSC_resetBuffer(buf); - } - - if (mesg[0] == '[') { - OSCTimeTag tt = ParseTimeTag(mesg+1); - if (OSC_openBundle(buf, tt)) { - send_complain("Problem opening bundle: %s\n", OSC_errorMessage); - OSC_resetBuffer(buf); - bundleDepth = 0; - continue; - } - bundleDepth++; - } else if (mesg[0] == ']' && mesg[1] == '\n' && mesg[2] == '\0') { - if (bundleDepth == 0) { - send_complain("Unexpected ']': not currently in a bundle.\n"); - } else { - if (OSC_closeBundle(buf)) { - send_complain("Problem closing bundle: %s\n", OSC_errorMessage); - OSC_resetBuffer(buf); - bundleDepth = 0; - continue; - } - - bundleDepth--; - if (bundleDepth == 0) { - SendBuffer(htmsocket, buf); - } - } - } else { - ParseInteractiveLine(buf, mesg); - if (bundleDepth != 0) { - /* Don't send anything until we close all bundles */ - } else { - SendBuffer(htmsocket, buf); - } - } - } -} - -OSCTimeTag ParseTimeTag(char *s) { - char *p, *newline; - typedArg arg; - - p = s; - while (isspace(*p)) p++; - if (*p == '\0') return OSCTT_Immediately(); - - if (*p == '+') { - /* Time tag is for some time in the future. It should be a - number of seconds as an int or float */ - - newline = strchr(s, '\n'); - if (newline != NULL) *newline = '\0'; - - p++; /* Skip '+' */ - while (isspace(*p)) p++; - - arg = ParseToken(p); - if (arg.type == STRING_osc) { - send_complain("warning: inscrutable time tag request: %s\n", s); - return OSCTT_Immediately(); - } else if (arg.type == INT_osc) { - return OSCTT_PlusSeconds(OSCTT_CurrentTime(), - (float) arg.datum.i); - } else if (arg.type == FLOAT_osc) { - return OSCTT_PlusSeconds(OSCTT_CurrentTime(), arg.datum.f); - } else { - fatal_error("This can't happen!"); - } - } - - if (isdigit(*p) || (*p >= 'a' && *p <='f') || (*p >= 'A' && *p <='F')) { - /* They specified the 8-byte tag in hex */ - OSCTimeTag tt; - if (sscanf(p, "%llx", &tt) != 1) { - send_complain("warning: couldn't parse time tag %s\n", s); - return OSCTT_Immediately(); - } -#ifndef HAS8BYTEINT - if (ntohl(1) != 1) { - /* tt is a struct of seconds and fractional part, - and this machine is little-endian, so sscanf - wrote each half of the time tag in the wrong half - of the struct. */ - uint4 temp; - temp = tt.seconds; - tt.seconds = tt.fraction ; - tt.fraction = temp; - } + post("sendOSC: atom type %d (%s)", a->a_type, buf); #endif - return tt; - } - - send_complain("warning: invalid time tag: %s\n", s); - return OSCTT_Immediately(); -} - - -void ParseInteractiveLine(OSCbuf *buf, char *mesg) { - char *messageName, *token, *p; - typedArg args[MAX_ARGS]; - int thisArg; - - p = mesg; - while (isspace(*p)) p++; - if (*p == '\0') return; - - messageName = p; - - if (strcmp(messageName, "play\n") == 0) { - /* Special kludge feature to save typing */ - typedArg arg; - - if (OSC_openBundle(buf, OSCTT_Immediately())) { - send_complain("Problem opening bundle: %s\n", OSC_errorMessage); - return; - } - - arg.type = INT_osc; - arg.datum.i = 0; - WriteMessage(buf, "/voices/0/tp/timbre_index", 1, &arg); - - arg.type = FLOAT_osc; - arg.datum.i = 0.0f; - WriteMessage(buf, "/voices/0/tm/goto", 1, &arg); - - if (OSC_closeBundle(buf)) { - send_complain("Problem closing bundle: %s\n", OSC_errorMessage); - } - - return; - } - - while (!isspace(*p) && *p != '\0') p++; - if (isspace(*p)) { - *p = '\0'; - p++; - } - - thisArg = 0; - while (*p != '\0') { - /* flush leading whitespace */ - while (isspace(*p)) p++; - if (*p == '\0') break; - - if (*p == '"') { - /* A string argument: scan for close quotes */ - p++; - args[thisArg].type = STRING_osc; - args[thisArg].datum.s = p; - - while (*p != '"') { - if (*p == '\0') { - send_complain("Unterminated quote mark: ignoring line\n"); - return; - } - p++; - } - *p = '\0'; - p++; - } else { - token = p; - while (!isspace(*p) && (*p != '\0')) p++; - if (isspace(*p)) { - *p = '\0'; - p++; - } - args[thisArg] = ParseToken(token); - } - thisArg++; - if (thisArg >= MAX_ARGS) { - send_complain("Sorry, your message has more than MAX_ARGS (%d) arguments; ignoring the rest.\n", - MAX_ARGS); - break; - } - } - - if (WriteMessage(buf, messageName, thisArg, args) != 0) { - send_complain("Problem sending message: %s\n", OSC_errorMessage); - } -} - -typedArg ParseToken(char *token) { - char *p = token; - typedArg returnVal; - /* It might be an int, a float, or a string */ - - if (*p == '-') p++; - - if (isdigit(*p) || *p == '.') { - while (isdigit(*p)) p++; - if (*p == '\0') { + switch (a->a_type) + { + + case A_FLOAT: + f = atom_getfloat(a); + i = atom_getint(a); + if (f == (t_float)i) + { // assume that if the int and float are the same, it's an int returnVal.type = INT_osc; - returnVal.datum.i = atoi(token); - return returnVal; + returnVal.datum.i = i; } - if (*p == '.') { - p++; - while (isdigit(*p)) p++; - if (*p == '\0') { + else + { returnVal.type = FLOAT_osc; - returnVal.datum.f = atof(token); - return returnVal; - } + returnVal.datum.f = f; } - } - + return returnVal; + case A_SYMBOL: + s = *atom_getsymbol(a); returnVal.type = STRING_osc; - returnVal.datum.s = token; + returnVal.datum.s = s.s_name; + return returnVal; + default: + atom_string(a, buf, MAXPDSTRING); + error("sendOSC: atom type %d not implemented (%s)", a->a_type, buf); + returnVal.type = NOTYPE_osc; + returnVal.datum.s = NULL; return returnVal; } +} -int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args) { +int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args) +{ int j, returnVal; const int wmERROR = -1; @@ -699,8 +424,10 @@ int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args) { #ifdef DEBUG printf("WriteMessage: %s ", messageName); - for (j = 0; j < numArgs; j++) { - switch (args[j].type) { + for (j = 0; j < numArgs; j++) + { + switch (args[j].type) + { case INT_osc: printf("%d ", args[j].datum.i); break; @@ -714,149 +441,114 @@ int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args) { break; default: - fatal_error("Unrecognized arg type, (not exiting)"); - return(wmERROR); - // exit(5); + error("Unrecognized arg type %d", args[j].type); + break; } } printf("\n"); #endif - if (!useTypeTags) { + if (!useTypeTags) + { returnVal = OSC_writeAddress(buf, messageName); - if (returnVal) { - send_complain("Problem writing address: %s\n", OSC_errorMessage); + if (returnVal) + { + error("Problem writing address: %s\n", OSC_errorMessage); + } } - } else { + else + { /* First figure out the type tags */ char typeTags[MAX_ARGS+2]; - int i; typeTags[0] = ','; - for (i = 0; i < numArgs; ++i) { - switch (args[i].type) { + for (j = 0; j < numArgs; ++j) + { + switch (args[j].type) + { case INT_osc: - typeTags[i+1] = 'i'; + typeTags[j+1] = 'i'; break; case FLOAT_osc: - typeTags[i+1] = 'f'; + typeTags[j+1] = 'f'; break; case STRING_osc: - typeTags[i+1] = 's'; + typeTags[j+1] = 's'; break; default: - fatal_error("Unrecognized arg type (not exiting)"); - return(wmERROR); - // exit(5); + error("sendOSC: arg %d type is unrecognized(%d)", j, args[j].type); + break; } } - typeTags[i+1] = '\0'; + typeTags[j+1] = '\0'; returnVal = OSC_writeAddressAndTypes(buf, messageName, typeTags); - if (returnVal) { - send_complain("Problem writing address: %s\n", OSC_errorMessage); + if (returnVal) + { + error("Problem writing address: %s\n", OSC_errorMessage); } } - for (j = 0; j < numArgs; j++) { - switch (args[j].type) { + for (j = 0; j < numArgs; j++) + { + switch (args[j].type) + { case INT_osc: - if ((returnVal = OSC_writeIntArg(buf, args[j].datum.i)) != 0) { + if ((returnVal = OSC_writeIntArg(buf, args[j].datum.i)) != 0) + { return returnVal; } break; case FLOAT_osc: - if ((returnVal = OSC_writeFloatArg(buf, args[j].datum.f)) != 0) { + if ((returnVal = OSC_writeFloatArg(buf, args[j].datum.f)) != 0) + { return returnVal; } break; case STRING_osc: - if ((returnVal = OSC_writeStringArg(buf, args[j].datum.s)) != 0) { + if ((returnVal = OSC_writeStringArg(buf, args[j].datum.s)) != 0) + { return returnVal; } break; default: - fatal_error("Unrecognized arg type (not exiting)"); - returnVal = wmERROR; - // exit(5); + break; // just skip bad types (which we won't get anyway unless this code is buggy) } } return returnVal; } -void SendBuffer(void *htmsocket, OSCbuf *buf) { +void SendBuffer(void *htmsocket, OSCbuf *buf) +{ #ifdef DEBUG printf("Sending buffer...\n"); #endif - if (OSC_isBufferEmpty(buf)) { + if (OSC_isBufferEmpty(buf)) + { post("SendBuffer() called but buffer empty"); return; } - if (!OSC_isBufferDone(buf)) { + if (!OSC_isBufferDone(buf)) + { fatal_error("SendBuffer() called but buffer not ready!, not exiting"); - // exit(5); return; //{{raf}} } SendData(htmsocket, OSC_packetSize(buf), OSC_getPacket(buf)); } -void SendData(void *htmsocket, int size, char *data) { - if (!SendHTMSocket(htmsocket, size, data)) { +void SendData(void *htmsocket, int size, char *data) +{ + if (!SendHTMSocket(htmsocket, size, data)) + { post("SendData::SendHTMSocket()failure -- not connected"); CloseHTMSocket(htmsocket); - // sendOSC_disconnect(); - //exit(3); - // return; - } } - -/* defined in OSC-system-dependent.c now */ -/* void fatal_error(char *s) { */ -/* fprintf(stderr, "FATAL ERROR: %s\n", s); */ -/* post("fatal error, not exiting ..."); */ -/* //exit(4); */ -/* } */ - -#include -void send_complain(char *s, ...) { - va_list ap; - va_start(ap, s); - vfprintf(stderr, s, ap); - va_end(ap); } - -#ifdef COMPUTE_MESSAGE_SIZE - /* Unused code to find the size of a message */ - - /* Compute size */ - size = SynthControl_effectiveStringLength(messageName); - - for (j = 0; j < numArgs; j++) { - switch (args[j].type) { - case INT_osc: case FLOAT_osc: - size += 4; - break; - - case STRING_osc: - size += SynthControl_effectiveStringLength(args[j].datum.s); - break; - - default: - fatal_error("Unrecognized token type ( not exiting)"); - // exit(4); - } - } - - if (!SynthControl_willMessageFit(buf, size)) { - send_complain("Message \"%s\" won't fit in buffer: dropping.", messageName); - return; - } -#endif -- cgit v1.2.1