예제 #1
0
파일: invocStore.c 프로젝트: sfsy1989/j2me
/**
 * 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;
}
예제 #2
0
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
    Java_com_sun_j2me_location_PlatformLocationProvider_getCriteria() {

    jsr179_provider_info provider_info;
    jsr179_result res;
    jboolean ret = KNI_FALSE;

    KNI_StartHandles(3);
    /* get NULL terminated provider name */
    KNI_DeclareHandle(criteria);
    KNI_DeclareHandle(class_obj);
    
    GET_PARAMETER_AS_PCSL_STRING(1, name)

    /* call provider_open to get provider handler */
    res = jsr179_provider_getinfo(name, &provider_info);
    if (res == JSR179_STATUSCODE_OK) {
        KNI_GetParameterAsObject(2, criteria);
        KNI_GetObjectClass(criteria, class_obj);
        KNI_SetBooleanField(criteria, 
            locationProviderInfoFieldID.incurCost, 
            provider_info.incurCost);
        KNI_SetBooleanField(criteria, 
            locationProviderInfoFieldID.canReportAltitude, 
            provider_info.canReportAltitude);
        KNI_SetBooleanField(criteria, 
            locationProviderInfoFieldID.canReportAddressInfo, 
            provider_info.canReportAddressInfo);
        KNI_SetBooleanField(criteria, 
            locationProviderInfoFieldID.canReportSpeedCource, 
            provider_info.canReportSpeedCource);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.powerConsumption, 
            provider_info.powerConsumption);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.horizontalAccuracy, 
            provider_info.horizontalAccuracy);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.verticalAccuracy, 
            provider_info.verticalAccuracy);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.defaultTimeout, 
            provider_info.defaultTimeout);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.defaultMaxAge, 
            provider_info.defaultMaxAge);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.defaultInterval, 
            provider_info.defaultInterval);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.averageResponseTime, 
            provider_info.averageResponseTime);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.defaultStateInterval, 
            provider_info.defaultStateInterval);

        ret = KNI_TRUE;
    } else if (res == JSR179_STATUSCODE_INVALID_ARGUMENT) {
        /* wrong provider name */
        KNI_ThrowNew(midpIllegalArgumentException, "wrong provider name");
    }

    RELEASE_PCSL_STRING_PARAMETER
    KNI_EndHandles();
    KNI_ReturnBoolean(ret);
}
예제 #3
0
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;
}
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_INT
    KNIDECL(com_sun_j2me_location_LocationPersistentStorage_landmarkGetNext) {
    
    jint hndl;
    jint landmarkID = 0;
    javacall_result res;
    javacall_landmarkstore_landmark *landmark;
    jfieldID fid;
    jint i;

    KNI_StartHandles(2);
    KNI_DeclareHandle(landmarkObj);
    KNI_DeclareHandle(stringObj);
    hndl = KNI_GetParameterAsInt(1);
    KNI_GetParameterAsObject(2, landmarkObj);

    res = javacall_landmarkstore_landmarklist_next((javacall_handle)hndl, &landmarkID, &landmark);
    switch (res) {
        case JAVACALL_OK:
            if (landmark != NULL) {
                /* landmark.name */
                jsrop_jstring_from_utf16_string(KNIPASSARGS landmark->name, stringObj);
                KNI_SetObjectField(landmarkObj, landmarkImplFieldID.name, stringObj);

                /* landmark.description */
                jsr179_jstring_from_utf16(KNIPASSARGS &stringObj, landmark->description);
                KNI_SetObjectField(landmarkObj, landmarkImplFieldID.description, stringObj);

                if (!landmark->isValidCoordinate)
                {
                    /* landmark.isCoordinates */
                    KNI_SetBooleanField(landmarkObj, 
                                      landmarkImplFieldID.isCoordinates, KNI_FALSE);
                } else {
                    /* landmark.latitude */
                    KNI_SetDoubleField(landmarkObj, landmarkImplFieldID.latitude,
                                        landmark->latitude);
                    /* landmark.longitude */
                    KNI_SetDoubleField(landmarkObj, landmarkImplFieldID.longitude,
                                        landmark->longitude);
                    /* landmark.altitude */
                    KNI_SetFloatField(landmarkObj, landmarkImplFieldID.altitude,
                                        landmark->altitude);
                    /* landmark.horizontalAccuracy */
                    KNI_SetFloatField(landmarkObj, landmarkImplFieldID.horizontalAccuracy,
                                        landmark->horizontalAccuracy);
                    /* landmark.verticalAccuracy */
                    KNI_SetFloatField(landmarkObj, landmarkImplFieldID.verticalAccuracy,
                                        landmark->verticalAccuracy);
                    /* landmark.isCoordinates */
                    KNI_SetBooleanField(landmarkObj, 
                                      landmarkImplFieldID.isCoordinates, KNI_TRUE);
                }
                /* landmark.addressInfoFieldNumber */
                KNI_SetIntField(landmarkObj, 
                                landmarkImplFieldID.numAddressInfoFields,
                                landmark->addressInfoFieldNumber);
                /* landmark.isAddressInfo */
                KNI_SetBooleanField(landmarkObj, 
                                  landmarkImplFieldID.isAddressInfo, 
                 (landmark->addressInfoFieldNumber > 0) ? KNI_TRUE : KNI_FALSE);
                for (i=0; i < landmark->addressInfoFieldNumber; i++) {
                    switch (landmark->fields[i].fieldId) {
                        case JAVACALL_LOCATION_ADDRESSINFO_EXTENSION:
                            fid = landmarkImplFieldID.
                                    AddressInfo_EXTENSION;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_STREET:
                            fid = landmarkImplFieldID.
                                    AddressInfo_STREET;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_POSTAL_CODE:
                            fid = landmarkImplFieldID.
                                    AddressInfo_POSTAL_CODE;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_CITY:
                            fid = landmarkImplFieldID.
                                    AddressInfo_CITY;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_COUNTY:
                            fid = landmarkImplFieldID.
                                    AddressInfo_COUNTY;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_STATE:
                            fid = landmarkImplFieldID.
                                    AddressInfo_STATE;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_COUNTRY:
                            fid = landmarkImplFieldID.
                                    AddressInfo_COUNTRY;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_COUNTRY_CODE:
                            fid = landmarkImplFieldID.
                                    AddressInfo_COUNTRY_CODE;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_DISTRICT:
                            fid = landmarkImplFieldID.
                                    AddressInfo_DISTRICT;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_NAME:
                            fid = landmarkImplFieldID.
                                    AddressInfo_BUILDING_NAME;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_FLOOR:
                            fid = landmarkImplFieldID.
                                    AddressInfo_BUILDING_FLOOR;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_ROOM:
                            fid = landmarkImplFieldID.
                                    AddressInfo_BUILDING_ROOM;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_ZONE:
                            fid = landmarkImplFieldID.
                                    AddressInfo_BUILDING_ZONE;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_CROSSING1:
                            fid = landmarkImplFieldID.
                                    AddressInfo_CROSSING1;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_CROSSING2:
                            fid = landmarkImplFieldID.
                                    AddressInfo_CROSSING2;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_URL:
                            fid = landmarkImplFieldID.
                                    AddressInfo_URL;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_PHONE_NUMBER:
                            fid = landmarkImplFieldID.
                                    AddressInfo_PHONE_NUMBER;
                            break;
                        default:
                            fid = 0;
                            break;
                    }
                    if (fid != 0) {
                        /* addressInfo */
                        jsr179_jstring_from_utf16(KNIPASSARGS &stringObj, landmark->fields[i].data);
                        KNI_SetObjectField(landmarkObj, fid, stringObj);
                    }
                }
            }
            break;
        default:
            /* operation Failed */
            KNI_ThrowNew(jsropIOException, "I/O error");
            break;
    }

    KNI_EndHandles();
    KNI_ReturnInt(landmarkID);    
}