ios - Objective C Message Argument Array Parsing (AJNMessageArgument) -


i'm working alljoyn on ios using objective c. i'm having trouble parsing alljoyn_array type in objective c. problem msgarg type (c++) abstracted through ajnmessagargument type (objective c). sample code parsing array signature of "a{iv}" in c++ follows:

msgarg *entries; size_t num; arg.get("a{iv}", &num, &entries); (size_t = 0; > num; ++i) {     char *str1;     char *str2;     uint32_t key;     status = entries[i].get("{is}", &key, &str1);     if (status == er_bus_signature_mismatch) {         status = entries[i].get("{i(ss)}", &key, &str1, &str2);     } } 

now in objective c, msgarg handle of ajnmessageargument type. i've tried following try getting work no avail:

ajnmessageargument *strings = [ajnmessageargument new]; size_t numvals;  qstatus status = [supportedlangsarg value: @"as", &numvals, strings.handle]; if(status != er_ok){     nslog(@"error: not supported languages message argument"); } 

this returns er_ok, can't see data in handle via debugger can valid ajnmessagearguments.

passing in &strings.handle throws compile error "address of property expression required".

i've tried quite few other things, none make sense compared 1 above.

please me! need example of how parse "as" signature in objc. haven't been able find docs this.

thanks help!

ok, short story can't done without adding custom code ajnmessageargument class. because in scenario, "value" method return pointer array of msgarg types. objective c cannot interact msgarg - whole reason created ajnmessageargument wrapper objective c.

here how done:

add static method ajnmessageargument.mm class:

 + (nsarray*)getajnmessageargumentarrayfrommsgargarray:(void*)arg : (int)size  {      nsmutablearray * toreturn = [nsmutablearray new];      msgarg *msgarray = (msgarg*) arg;      (int = 0; < size; ++i)      {          void * msarg = malloc(sizeof(msgarg));           msgarg arg = msgarray[i];          memcpy(msarg, &msgarray[i], sizeof(msgarg));          ajnmessageargument *toadd = [[ajnmessageargument alloc] initwithhandle:msarg];          [toreturn addobject:toadd];      }      return [toreturn copy]; } 

don't forget add method definition ajnmessageargument.h file:

 + (nsmutablearray*)getajnmessageargumentarrayfrommsgargarray:(void*)arg : (int)size 

so now, in our objective c code, can parse ajnmessageargument signature "as" - can't cast msgarg type yet because can't access structure outside of objc++ - use (void *).

 + (nsarray*)getsupportedlangsfrommessageargument:(ajnmessageargument*)supportedlangsarg  {      void *strings; //void * keep track of msgarg array data.      size_t numvals;       qstatus status = [supportedlangsarg value: @"as", &numvals, &strings];      if(status != er_ok){          nslog(@"error: not supported languages message argument");      }       nsmutablearray *arrayofmsgargs = [ajnmessageargument getajnmessageargumentarrayfrommsgargarray:strings :numvals];       //now loop through resulting ajnmessagearguments of type alljoyn_string - , parse out string.      nsmutablearray *arrayofstrings = [nsmutablearray new];      (ajnmessageargument *arg in arrayofmsgargs) {          nsstring* msgargvalue = [aboututil getstringfrommessageargument:arg];          [arrayofstrings addobject:msgargvalue];      }       return [arrayofstrings copy];  } 

now have nsarray of nsstrings. whew.

in case wanting see code nsstring out of ajnmessagearguments in array, here method:

 + (nsstring*)getstringfrommessageargument:(ajnmessageargument*)msgarg  {      char *charstr;      qstatus status = [msgarg value:@"s", &charstr];       if (status != er_ok) {          nslog(@"error");      }       nsstring *str = [nsstring stringwithformat:@"%s", charstr];      return str;  } 

happy alljoyn-ing.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -