Exemplo n.º 1
0
static void readControlStringField(KNIDECLARGS kjobject objectHandle,
                                   jfieldID fieldID) {
    int len, i;
    jchar *data;
    (void) _arguments;
    (void) _p_mb;

    read(controlPipe[0], &len, sizeof(int));

    data = (jchar*)midpMalloc(len * sizeof(jchar));
    if (data != NULL) {
        read(controlPipe[0], data, len * sizeof(jchar));
    } else {
        for (i=0; i<len; i++) {
            jchar dummy;
            read(controlPipe[0], &dummy, sizeof(jchar));
        }
        len = 0; /* IMPL_NOTE: throw out of memory */
    }

    KNI_StartHandles(1);
    KNI_DeclareHandle(stringObj);

    KNI_NewString(data, len, stringObj);
    KNI_SetObjectField(objectHandle, fieldID, stringObj);

    KNI_EndHandles();
}
Exemplo n.º 2
0
/**
 * 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;
}
Exemplo n.º 3
0
static void
setContents(jobject linkMessageObj, jobject contentsObj)
{
    jfieldID contentsField;

    KNI_StartHandles(1);
    KNI_DeclareHandle(linkMessageClass);

    KNI_GetObjectClass(linkMessageObj, linkMessageClass);
    contentsField = KNI_GetFieldID(linkMessageClass, "contents",
        "Ljava/lang/Object;");
    KNI_SetObjectField(linkMessageObj, contentsField, contentsObj);

    KNI_EndHandles();
}
Exemplo n.º 4
0
/**
 * Set a jobject field from Java native functions.
 *
 * Always use KNI to set an object field instead of setting it directly
 * using SNI access, since there is more to setting a object in a field
 * than just moving a reference, there is a flag to tell the the garbage
 * collector that the field is set to an object and if this flag is not
 * set then the collector not count the field as a reference which can
 * lead to premature collection of the object the field is referencing
 * and then a crash since the field will reference will not be null, it
 * will be unchanged and invalid.
 *
 * @param obj a handle to Java object whose field will be set
 * @param fieldName field name
 * @param fieldSignature field signature string
 * @param newValue a handle to the new Java value of the field
 */
void midp_set_jobject_field(KNIDECLARGS jobject obj,
			    const char *fieldName, const char *fieldSignature,
			    jobject newValue) {

    if (KNI_IsNullHandle(obj)) {
        return;
    }

    KNI_StartHandles(1);
    KNI_DeclareHandle(clazz);

    KNI_GetObjectClass(obj, clazz);

    KNI_SetObjectField(obj,
		       midp_get_field_id(KNIPASSARGS 
					 clazz, fieldName, fieldSignature),
		       newValue);

    KNI_EndHandles();
}
Exemplo n.º 5
0
/**
 * Implementation of native method to set the status of an Invocation.
 * If the status is set to a response status then the "finish"
 * behavior is performed.  If a response is required, the Invocation
 * is requeued to the invoking application. Otherwise, the Invocation
 * is discarded.
 *
 * @param invoc the InvocationImpl to update the native status
 * @see StoredInvoc
 * @see #invocQueue
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_content_InvocationStore_setStatus0(void) {
    StoredLink* link;
    StoredInvoc* invoc;
    int tid;

    KNI_StartHandles(3);
    KNI_DeclareHandle(invocObj);
    KNI_DeclareHandle(obj1);
    KNI_DeclareHandle(obj2);

    KNI_GetParameterAsObject(1, invocObj);
    init(invocObj, obj1);

    /* Find the matching entry in the queue */
    tid = KNI_GetIntField(invocObj, tidFid);
    link = invocFindTid(tid);
    if (link != NULL) {
        invoc = link->invoc;
        /* Update the status */
        invoc->status = KNI_GetIntField(invocObj, statusFid);
    
        switch (invoc->status) {
        case STATUS_OK:
        case STATUS_CANCELLED:
        case STATUS_ERROR:
        case STATUS_INITIATED:
            /* 
             * If a response is required, switch the target
             * application; if not then discard the Invocation.
             */
            if (invoc->responseRequired) {
                /* Swap the source and target suite and classname */
                SuiteIdType tmpSuiteId = invoc->invokingSuiteId;
                SuiteIdType tmpSuiteId2;
                pcsl_string tmpClassname = invoc->invokingClassname;
                invoc->invokingSuiteId = invoc->suiteId;
                invoc->invokingClassname = invoc->classname;
                invoc->suiteId = tmpSuiteId;
                invoc->classname = tmpClassname;
        
                /* Unmark the response it is "new" to the target */
                invoc->cleanup = KNI_FALSE;
                invoc->notified = KNI_FALSE;
        
                /* Swap the references in the Invocation object. */
                tmpSuiteId = KNI_GetIntField(invocObj, suiteIdFid);
                tmpSuiteId2 = KNI_GetIntField(invocObj, invokingSuiteIdFid);
                KNI_SetIntField(invocObj, invokingSuiteIdFid, tmpSuiteId);
                KNI_SetIntField(invocObj, suiteIdFid, tmpSuiteId2);

                KNI_GetObjectField(invocObj, invokingClassnameFid, obj1);
                KNI_GetObjectField(invocObj, classnameFid, obj2);
                KNI_SetObjectField(invocObj, classnameFid, obj1);
                KNI_SetObjectField(invocObj, invokingClassnameFid, obj2);
        
                /* Unblock any waiting threads so they can retrieve this. */
                unblockWaitingThreads(STATUS_OK);
                break;
            }
            /* If no response; Fall into DISPOSE */
    
        case STATUS_DISPOSE:
            /*
             * Free the Invocation, clean the Tid in the Invocation
             */
            invoc->tid = 0;
            KNI_SetIntField(invocObj, tidFid, 0);
            removeEntry(link);
            invocFree(invoc);
            break;
        case STATUS_ACTIVE:
        case STATUS_HOLD:
        case STATUS_WAITING:
            /* No Action. */
            break;
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Exemplo n.º 6
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);    
}