/** * Helper function to initialize fields from Strings. * @param str string to store * @param object into which it should be stored * @param fieldid of field to store the jstring * @return false if the String could not allocate */ static jboolean storeField(const pcsl_string* str, jobject invocObj, jfieldID fid, jobject tmpobj) { if (str == NULL || pcsl_string_is_null(str)) { KNI_ReleaseHandle(tmpobj); } else { if (PCSL_STRING_OK != midp_jstring_from_pcsl_string(str, tmpobj)) { return KNI_FALSE; } } KNI_SetObjectField(invocObj, fid, tmpobj); return KNI_TRUE; }
/* JAVADOC COMMENT ELIDED */ KNIEXPORT KNI_RETURNTYPE_OBJECT Java_com_sun_j2me_location_PlatformLocationProvider_getListOfLocationProviders() { pcsl_string listOfProviders = PCSL_STRING_NULL; KNI_StartHandles(1); KNI_DeclareHandle(tempHandle); if (jsr179_property_get(JSR179_PROVIDER_LIST, &listOfProviders) == JSR179_STATUSCODE_OK) { midp_jstring_from_pcsl_string(&listOfProviders, tempHandle); } pcsl_string_free(&listOfProviders); KNI_EndHandlesAndReturnObject(tempHandle); }
/** * Get the class path for the specified dynamic component. * * @param componentId unique ID of the component * * @return class path or null if the component does not exist */ KNIEXPORT KNI_RETURNTYPE_OBJECT KNIDECL(com_sun_midp_midletsuite_DynamicComponentStorage_getComponentJarPath) { ComponentIdType componentId; MIDPError status; pcsl_string classPath = PCSL_STRING_NULL; KNI_StartHandles(1); KNI_DeclareHandle(resultHandle); componentId = KNI_GetParameterAsInt(1); status = get_jar_path(COMPONENT_DYNAMIC, (jint)componentId, &classPath); if (status != ALL_OK) { KNI_ThrowNew(midpRuntimeException, NULL); KNI_ReleaseHandle(resultHandle); } else { midp_jstring_from_pcsl_string(KNIPASSARGS &classPath, resultHandle); pcsl_string_free(&classPath); } KNI_EndHandlesAndReturnObject(resultHandle); }
/** * Copy a native Invocation to the supplied Invocation instance. * @param invoc the native InvocStore * @param mode the mode of copyout * @param invocObj the Invocation object to copy to * @param argsObj an object to use to refer to the arguments array * @param obj a temporary object handle * @return 0 if there were problems allocating Java Strings; * 1 if all the copies succeeded; * -1 if the Java Arrays allocated for args or data were insufficient */ static int copyOut(StoredInvoc *invoc, int mode, jobject invocObj, jobject argsObj, jobject obj) { int datalen = 0; int arraylen = 0; /* Set the required lengths for args and data arrays. */ KNI_SetIntField(invocObj, argsLenFid, invoc->argsLen); KNI_SetIntField(invocObj, dataLenFid, invoc->dataLen); /* Check if size of argument array and data array are correct. */ KNI_GetObjectField(invocObj, dataFid, obj); datalen = KNI_GetArrayLength(obj); if (datalen != invoc->dataLen) { /* Data array allocated by Java is not correct size. */ return -1; } KNI_GetObjectField(invocObj, argumentsFid, obj); arraylen = KNI_GetArrayLength(obj); if (arraylen != invoc->argsLen) { /* Args array allocated by Java is not correct size. */ return -1; } /* Copy out all the string fields. */ if (!(storeField(&invoc->url, invocObj, urlFid, obj) && storeField(&invoc->type, invocObj, typeFid, obj) && storeField(&invoc->action, invocObj, actionFid, obj) && storeField(&invoc->ID, invocObj, IDFid, obj) && storeField(&invoc->invokingClassname, invocObj, invokingClassnameFid, obj) && storeField(&invoc->invokingAuthority, invocObj, invokingAuthorityFid, obj) && storeField(&invoc->invokingAppName, invocObj, invokingAppNameFid, obj) && storeField(&invoc->invokingID, invocObj, invokingIDFid, obj) && storeField(&invoc->username, invocObj, usernameFid, obj) && storeField(&invoc->password, invocObj, passwordFid, obj))) { /* Some String allocation failed. */ return 0; } KNI_SetIntField(invocObj, invokingSuiteIdFid, invoc->invokingSuiteId); /* See if the suite and classname are needed. */ if (mode == MODE_TID || mode == MODE_TID_PREV || mode == MODE_TID_NEXT) { if (!storeField(&invoc->classname, invocObj, classnameFid, obj)) { /* A string allocation failed. */ return 0; } KNI_SetIntField(invocObj, suiteIdFid, invoc->suiteId); } /* Return the arguments if any; array length already checked. */ if (invoc->argsLen > 0) { int ndx; pcsl_string* args; /* For each stored arg create a string and store in the array. * No stored arg is null. If a string cannot be created * it is due to insufficient heap memory. */ KNI_GetObjectField(invocObj, argumentsFid, argsObj); args = invoc->args; for (ndx = 0; ndx < invoc->argsLen; ndx++, args++) { if (!pcsl_string_is_null(args)) { if (PCSL_STRING_OK != midp_jstring_from_pcsl_string(args, obj)) { /* String create failed; exit now. */ return 0; } } else { KNI_ReleaseHandle(obj); } KNI_SetObjectArrayElement(argsObj, ndx, obj); } } /* Return the data array if any; array length was already checked. */ if (invoc->dataLen > 0) { KNI_GetObjectField(invocObj, dataFid, obj); KNI_SetRawArrayRegion(obj, 0, invoc->dataLen, invoc->data); } KNI_SetBooleanField(invocObj, responseRequiredFid, invoc->responseRequired); KNI_SetIntField(invocObj, statusFid, invoc->status); KNI_SetIntField(invocObj, tidFid, invoc->tid); KNI_SetIntField(invocObj, previousTidFid, invoc->previousTid); /* Successful copy out. */ return 1; }
static jboolean getLocation(jobject locationInfo, jobject string_obj, ProviderInfo *pInfo) { jint i; jfieldID fid; jboolean ret = KNI_FALSE; if(pInfo != NULL) { if (pInfo->lastLocationTimestamp != 0) { /* Get location parameters */ KNI_SetBooleanField(locationInfo, locationInfoFieldID.isValid, pInfo->lastLocation.isValidCoordinate); KNI_SetDoubleField(locationInfo, locationInfoFieldID.latitude, pInfo->lastLocation.latitude); KNI_SetDoubleField(locationInfo, locationInfoFieldID.longitude, pInfo->lastLocation.longitude); KNI_SetFloatField(locationInfo, locationInfoFieldID.altitude, pInfo->lastLocation.altitude); KNI_SetFloatField(locationInfo, locationInfoFieldID.horizontalAccuracy, pInfo->lastLocation.horizontalAccuracy); KNI_SetFloatField(locationInfo, locationInfoFieldID.verticalAccuracy, pInfo->lastLocation.verticalAccuracy); KNI_SetFloatField(locationInfo, locationInfoFieldID.speed, pInfo->lastLocation.speed); KNI_SetFloatField(locationInfo, locationInfoFieldID.course, pInfo->lastLocation.course); KNI_SetIntField(locationInfo, locationInfoFieldID.method, pInfo->lastLocation.method); KNI_SetLongField(locationInfo, locationInfoFieldID.timestamp, pInfo->lastLocationTimestamp); if (pInfo->lastLocation.addressInfoFieldNumber == 0) { KNI_SetBooleanField(locationInfo, locationInfoFieldID.isAddressInfo, KNI_FALSE); } else { KNI_SetBooleanField(locationInfo, locationInfoFieldID.isAddressInfo, KNI_TRUE); for(i=0; i<pInfo->lastLocation.addressInfoFieldNumber; i++) { midp_jstring_from_pcsl_string(&pInfo->lastAddressInfo[i].data, string_obj); switch(pInfo->lastAddressInfo[i].fieldId) { case JSR179_ADDRESSINFO_EXTENSION: fid = locationInfoFieldID. AddressInfo_EXTENSION; break; case JSR179_ADDRESSINFO_STREET: fid = locationInfoFieldID. AddressInfo_STREET; break; case JSR179_ADDRESSINFO_POSTAL_CODE: fid = locationInfoFieldID. AddressInfo_POSTAL_CODE; break; case JSR179_ADDRESSINFO_CITY: fid = locationInfoFieldID. AddressInfo_CITY; break; case JSR179_ADDRESSINFO_COUNTY: fid = locationInfoFieldID. AddressInfo_COUNTY; break; case JSR179_ADDRESSINFO_STATE: fid = locationInfoFieldID. AddressInfo_STATE; break; case JSR179_ADDRESSINFO_COUNTRY: fid = locationInfoFieldID. AddressInfo_COUNTRY; break; case JSR179_ADDRESSINFO_COUNTRY_CODE: fid = locationInfoFieldID. AddressInfo_COUNTRY_CODE; break; case JSR179_ADDRESSINFO_DISTRICT: fid = locationInfoFieldID. AddressInfo_DISTRICT; break; case JSR179_ADDRESSINFO_BUILDING_NAME: fid = locationInfoFieldID. AddressInfo_BUILDING_NAME; break; case JSR179_ADDRESSINFO_BUILDING_FLOOR: fid = locationInfoFieldID. AddressInfo_BUILDING_FLOOR; break; case JSR179_ADDRESSINFO_BUILDING_ROOM: fid = locationInfoFieldID. AddressInfo_BUILDING_ROOM; break; case JSR179_ADDRESSINFO_BUILDING_ZONE: fid = locationInfoFieldID. AddressInfo_BUILDING_ZONE; break; case JSR179_ADDRESSINFO_CROSSING1: fid = locationInfoFieldID. AddressInfo_CROSSING1; break; case JSR179_ADDRESSINFO_CROSSING2: fid = locationInfoFieldID. AddressInfo_CROSSING2; break; case JSR179_ADDRESSINFO_URL: fid = locationInfoFieldID. AddressInfo_URL; break; case JSR179_ADDRESSINFO_PHONE_NUMBER: fid = locationInfoFieldID. AddressInfo_PHONE_NUMBER; break; default: fid = 0; break; } if(fid != 0) { KNI_SetObjectField(locationInfo, fid, string_obj); } } } if (pInfo->lastLocation.extraInfoSize > 0) { midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[0], string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoNMEA, string_obj); midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[1], string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoLIF, string_obj); midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[2], string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoPlain, string_obj); midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[3], string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoOther, string_obj); midp_jstring_from_pcsl_string(&pInfo->otherExtraInfoMimeType, string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoOtherMIMEType, string_obj); } ret = KNI_TRUE; } } return ret; }