From: Fernando C. <fca...@gm...> - 2021-03-01 11:32:32
|
Hello Mark, thanks for replying. So I can simply access the fields of the "argv" union, based upon the value of "type". Excellent. I looked at lo_osc_types.h as a reference. It seems to me, that some types may have more than one corresponding field. How to choose? Example 1: I have type = LO_STRING, which is 's' Should I read &argv[n]->S or &argv[n]->s ? Example 2: I have type = LO_INT32, which is 'i' Should I read argv[n]->i or argv[n]->i32 ? Same goes for 'f' (read from ->f or ->f32 ?) Thanks for the clarification Fernando Il giorno dom 28 feb 2021 alle ore 23:34 Mark Hotchkiss <Ma...@re...> ha scritto: > > Hi Fernando, > > I assume that you are talking about fetching the passed values out from a received message in the message handler. The values are each passed in a union. > > Here is one of my message handlers (sorry if it doesn't format well in an email): > > > // Callback handler for "/request/write <id> <node> <location> <parameter size> <parameter ID> <parameter format> <value>" > > // or <id> <node> <location> <parameter name> <parameter format> <value>" > > int handler_reqwrite(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data) > > { > if ( *(types+3) == 'i') // if the forth parameter is a size and not a name . . . > > if ( argv[2]->i == -1 ) // and if the location is ram and not a flash page . . . > > requestWrite( (void*)argv[0]->i, argv[1]->i, argv[3]->i, argv[4]->i, argv[5]->i, argv[6]); > else > requestWriteFlash( (void*)argv[0]->i, argv[1]->i, argv[3]->i, argv[4]->i, argv[5]->i, argv[6]); > else // if the forth parameter is a name and not a size . . . > > if ( argv[2]->i == -1 ) // and if the location is ram and not a flash page . . . > > requestWriteByName( (void*)argv[0]->i, argv[1]->i, &argv[3]->s, argv[4]->i, argv[5]); > else > requestWriteFlashByName( (void*)argv[0]->i, argv[1]->i, &argv[3]->s, argv[4]->i, argv[5]); > return 0; > } > > > Each 'lo_arg' type is a union of all of the OSC types and each 'argv' is a pointer to a union. As an example, if the second value passed was an 'int', then I would access it as: > > int size = argv[1]->i ; > > and if it was a string (which is actually a character-pointer, so we have a pointer to a pointer): > > char* name = &argv[1]->s ; > > Of course, the 'types' parameter would tell you the true type of the parameter so that you can access it correctly, and I have caused segmentation faults when I made the wrong assumption of the type. > > Is that what you needed? Let me know if you would like anything else. I have a ton of code now. > > Mark > > > > -----Original Message----- > From: Fernando Carello [mailto:fca...@gm...] > Sent: Sunday, February 28, 2021 9:00 AM > To: liblo development list > Subject: Re: [liblo] how to connect to a liblo TCP OSC server? > > > Hello, > I've successfully tested liblo in C, writing both client and server > implementations. > > Now I'm faced with a maybe silly problem... > > I can compose an OSC message from native C types using > lo_message_new() and appropriate > lo_message_add_* methods. > > But, how may I convert OSC arguments from lo_arg to native C types? > > Thanks! > Fernando > > > _______________________________________________ > liblo-devel mailing list > lib...@li... > https://lists.sourceforge.net/lists/listinfo/liblo-devel > > _______________________________________________ > liblo-devel mailing list > lib...@li... > https://lists.sourceforge.net/lists/listinfo/liblo-devel |