saj_returnCode saj_stringSequenceCopyIn( JNIEnv *env, jobjectArray stringArray, gapi_stringSeq *out) { jobject javaString; const gapi_char* vm_managed_c_string; jsize arrayLength; int i; saj_returnCode rc; assert(out != NULL); assert(stringArray != NULL); javaString = NULL; vm_managed_c_string = NULL; arrayLength = 0; i = 0; rc = SAJ_RETCODE_OK; arrayLength = (*env)->GetArrayLength(env, stringArray); saj_exceptionCheck(env); if (stringArray != NULL) { out->_maximum = arrayLength; out->_length = arrayLength; /* allocate a buffer of the right size */ out->_buffer = gapi_stringSeq_allocbuf(arrayLength); out->_release = FALSE; /* fill the string buffer with strings */ for (i = 0; i < arrayLength && rc == SAJ_RETCODE_OK; i++) { /* get the java String from the array */ javaString = (*env)->GetObjectArrayElement(env, stringArray, i); saj_exceptionCheck(env); /* translate the java string to a c string */ vm_managed_c_string = (*env)->GetStringUTFChars(env, javaString, 0); saj_exceptionCheck(env); if(vm_managed_c_string != NULL) { /* copy the c sting to the buffer */ out->_buffer[i] = gapi_string_dup(vm_managed_c_string); } else { rc = SAJ_RETCODE_ERROR; /* VM has thrown an OutOfMemoryError */ } /* release local references */ (*env)->ReleaseStringUTFChars(env, javaString, vm_managed_c_string); saj_exceptionCheck(env); } } return rc; }
gapi_boolean gapi_stringSeq_set_length ( gapi_stringSeq *seq, gapi_unsigned_long len) { gapi_boolean result = TRUE; gapi_string *buffer = NULL; if ( seq->_maximum > 0UL ) { assert(seq->_buffer); if ( len != seq->_maximum ) { buffer = gapi_stringSeq_allocbuf(len); if ( buffer ) { if ( seq->_release ) { gapi_free(seq->_buffer); } seq->_release = TRUE; seq->_maximum = len; } else { result = FALSE; } } else { buffer = seq->_buffer; } } else { buffer = gapi_stringSeq_allocbuf(len); if ( buffer ) { seq->_release = TRUE; seq->_maximum = len; } else { result = FALSE; } } if ( result ) { seq->_length = len; seq->_buffer = buffer; } return result; }
DDS_string * DDS_StringSeq_allocbuf ( DDS_unsigned_long len ) { return (DDS_string *) gapi_stringSeq_allocbuf ( (gapi_unsigned_long) len ); }
void DDS::ccpp_sequenceCopyIn( const DDS::StringSeq &from, gapi_stringSeq &to) { to._maximum = from.length(); to._length = from.length(); to._release = TRUE; if (to._maximum > 0){ to._buffer = gapi_stringSeq_allocbuf(to._length); for (CORBA::ULong i=0; i<to._length; i++) { const char *value = from[i]; to._buffer[i] = gapi_string_dup(value); } } else { to._buffer = NULL; }; }
static void builtinPartitionQosPolicyCopyout ( const struct v_builtinPartitionPolicy *src, gapi_partitionQosPolicy *dst) { unsigned long len = c_arraySize(src->name); if ( dst->name._maximum > 0 ) { if ( len != dst->name._maximum ) { if ( dst->name._release ) { gapi_free(dst->name._buffer); } dst->name._maximum = 0; dst->name._length = 0; dst->name._buffer = NULL; } } if ( len > 0 ) { if ( dst->name._length == 0 ) { if ( dst->name._maximum == 0 ) { dst->name._buffer = gapi_stringSeq_allocbuf(len) ; dst->name._maximum = len; dst->name._length = 0; dst->name._release = TRUE; } if ( dst->name._maximum >= len ) { unsigned long i; for ( i = 0; i < len; i++ ) { dst->name._buffer[i] = gapi_string_dup(src->name[i]); } } } } dst->name._length = len; }
void DDS::ccpp_AllocateGapiSeq(gapi_string* *buffer, gapi_unsigned_long len) { *buffer = gapi_stringSeq_allocbuf(len); }