Example #1
0
File: emul.c Project: sfsy1989/j2me
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_jsr82emul_EmulationClient_getLocalIP() {
    char value[4 * 4];

    KNI_StartHandles(1);
    KNI_DeclareHandle(result);

    if (JAVACALL_OK == javacall_network_get_local_ip_address_as_string(value)) {
        KNI_NewStringUTF(value, result);
    } else {
        KNI_ReleaseHandle(result);
    }
    
    KNI_EndHandlesAndReturnObject(result); 
}
Example #2
0
File: emul.c Project: sfsy1989/j2me
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_jsr82emul_EmulationClient_getServerIP() {
    char *value = getenv("JSR82_EMUL_IP");
    
    KNI_StartHandles(1);
    KNI_DeclareHandle(result);

    if (NULL != value) {
        KNI_NewStringUTF(value, result);
    } else {
        KNI_ReleaseHandle(result);
    }
    
    KNI_EndHandlesAndReturnObject(result); 
}
Example #3
0
/*
 * Checks refId for validity, gets its handle value, and stores it
 * into obj.  An error message incorporating msg is emitted if refId is 
 * invalid or if the handle returns is null.
 */
static void
getReference(int refId, char *msg, jobject obj)
{
    if (refId == INVALID_REFERENCE_ID) {
        midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
            "invalid reference ID in %s", msg);
        REPORT_CRIT(LC_CORE, gKNIBuffer);
        KNI_ReleaseHandle(obj);
    } else {
        SNI_GetReference(refId, obj);
        if (KNI_IsNullHandle(obj)) {
            midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                "null reference from SNI_GetReference in %s", msg);
            REPORT_CRIT(LC_CORE, gKNIBuffer);
        }
    }
}
/**
 * Get one of supported device locales (by number).
 * <p>
 * Java declaration:
 * <pre>
 *     getDevLocaleName(I)Ljava/lang/String
 * </pre>
 *
 * @param index  index of locale to select
 * @return locale name
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
KNIDECL(com_sun_j2me_global_DevResourceManagerFactory_getDevLocaleName) {
	jint len=MAX_LOCALE_LENGTH, res;
    jint index = KNI_GetParameterAsInt(1);
    jchar locale_name[MAX_LOCALE_LENGTH];

    KNI_StartHandles(1);
    KNI_DeclareHandle(hloc);
	res = jsr238_get_resource_locale_name(index,locale_name,&len);
    if (res < 0 ) {
        KNI_ReleaseHandle(hloc);
		KNI_ThrowNew(jsropRuntimeException,"Get locale name");
    } else {
        KNI_NewString(locale_name, len - 1, hloc);
    }
    KNI_EndHandlesAndReturnObject(hloc);
}
Example #5
0
/**
 * Get one of supported locales (by number).
 * <p>
 * Java declaration:
 * <pre>
 *     getCollationLocale(I)Ljava/lang/String
 * </pre>
 *
 * @param index  index of locale to select
 * @return locale
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_j2me_global_CollationAbstractionLayerImpl_getCollationLocaleName() {
	jint len=MAX_LOCALE_LENGTH, res;
    jint index = KNI_GetParameterAsInt(1);
    jchar locale_name[MAX_LOCALE_LENGTH];

    KNI_StartHandles(1);
    KNI_DeclareHandle(hloc);
	res = jsr238_get_collation_locale_name(index,locale_name,&len);
    if (res < 0 ) {
        KNI_ReleaseHandle(hloc);
		KNI_ThrowNew(midpRuntimeException,"Get locale name");
    } else {
        KNI_NewString(locale_name, len - 1, hloc);
    }
    KNI_EndHandlesAndReturnObject(hloc);
}
Example #6
0
/**
 * Gets the local IP number.
 * <p>
 * Java declaration:
 * <pre>
 *     static getHost0(V)Ljava/lang/String;
 * </pre>
 *
 * @return the local IP address as a dotted-quad <tt>String</tt>
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_io_j2me_datagram_Protocol_getHost0(void) {
    char value[MAX_HOST_LENGTH];
    int status;

    KNI_StartHandles(1);
    KNI_DeclareHandle(result);

    status = pcsl_network_getLocalIPAddressAsString(value);

    if ((status == PCSL_NET_SUCCESS) && (value != NULL)) {
        KNI_NewStringUTF(value, result);
    } else {
        KNI_ReleaseHandle(result);
    }

    KNI_EndHandlesAndReturnObject(result);
}
KNI_RETURNTYPE_OBJECT
KNIDECL(com_sun_midp_security_Permissions_loadGroupPermissions)
{
    int lines, i1;
	unsigned int str_len;
    void *array;
    jchar jbuff[64];
    char  group_name[64];

    KNI_StartHandles(3);
    KNI_DeclareHandle(members);
    KNI_DeclareHandle(tmpString);
    KNI_DeclareHandle(group);

    KNI_GetParameterAsObject(1, group);
    if (!KNI_IsNullHandle(group)) {
        str_len = KNI_GetStringLength(group);
        if (str_len <= sizeof(group_name)-1) {
            KNI_GetStringRegion(group, 0, str_len, jbuff);
            jchar_to_char(jbuff, group_name, str_len);
            lines = permissions_load_group_permissions(&array, group_name);
            if (lines > 0) {
                char **list = (char**)array;
                SNI_NewArray(SNI_STRING_ARRAY,  lines, members);
                if (KNI_IsNullHandle(members))
                    KNI_ThrowNew(midpOutOfMemoryError, NULL);
                else
                    for (i1 = 0; i1 < lines; i1++) {
                        KNI_NewStringUTF(list[i1], tmpString);
                        KNI_SetObjectArrayElement(members, (jint)i1,
                                                            tmpString);
                    }
                permissions_dealloc(array);
            } else
                KNI_ReleaseHandle(members);  /* set object to NULL */
        }
    } else
        KNI_ThrowNew(midpNullPointerException, "null group parameter");


    KNI_EndHandlesAndReturnObject(members);
}
/*  private native String _eglQueryString ( int display , int name ) ; */
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_javax_microedition_khronos_egl_EGL10Impl__1eglQueryString() {

    jint display = KNI_GetParameterAsInt(1);
    jint name = KNI_GetParameterAsInt(2);
    const char *string;
    
    KNI_StartHandles(1);
    KNI_DeclareHandle(stringHandle);
    
    string = eglQueryString((EGLDisplay)display, (EGLint)name);
#ifdef DEBUG
    printf("eglQueryString(0x%x, %d) = %s\n", display, name, string);
#endif
    
    if (string) {
        KNI_NewStringUTF(string, stringHandle);
    } else {
        /* Set stringHandle to null. */
        KNI_ReleaseHandle(stringHandle);
    }
    KNI_EndHandlesAndReturnObject(stringHandle);
}
Example #9
0
/**
 * java call:
 *     private native String loadFieldValues0(String handlerId, int fieldId);
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_content_RegistryStore_loadFieldValues0(void) {
    int fieldId;
    pcsl_string id = PCSL_STRING_NULL_INITIALIZER;
    JSR211_RESULT_STRARRAY result = _JSR211_RESULT_INITIALIZER_;

    KNI_StartHandles(1);
    KNI_DeclareHandle(strObj);       /* string object */

    KNI_GetParameterAsObject(1, strObj); /* handlerId */
    if (PCSL_STRING_OK == midp_jstring_to_pcsl_string(strObj, &id)) {
        fieldId = KNI_GetParameterAsInt(2);
        jsr211_get_handler_field(&id, fieldId, &result);
        pcsl_string_free(&id);
        result2string((_JSR211_INTERNAL_RESULT_BUFFER_*)&result, strObj);
    } else {
        KNI_ThrowNew(midpOutOfMemoryError, 
                   "RegistryStore_loadFieldValues0 no memory for handler ID");
        KNI_ReleaseHandle(strObj);
    }

    KNI_EndHandlesAndReturnObject(strObj);
}
Example #10
0
void
JSR239_getGraphicsSource(jobject graphicsHandle, jobject resultHandle) {

#ifdef DEBUG
    printf("JSR239_getGraphicsSource\n");
#endif

    (void)graphicsHandle;

    KNI_StartHandles(1);
    KNI_DeclareHandle(sourceHandle);

    // IMPL_NOTE: retrieve real source handle
    KNI_ReleaseHandle(sourceHandle);

    KNI_SetObjectArrayElement(resultHandle, 0, sourceHandle);

#ifdef DEBUG
    printf("getGraphicsWidth: source = 0x%x\n", sourceHandle);
#endif

    KNI_EndHandles();
}
/**
 * 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);
}
Example #12
0
/**
 * 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;
}
Example #13
0
/**
 * 
 * Gets an InvocationImpl from the store using a MIDlet suiteId
 * and optional classname.
 * Getting an Invocation from the store removes it from the store.
 * If an OutOfMemory exception is thrown the matched Invocation
 * is NOT removed from the queue. If the heap memory can be
 * replenished then the operation can be retried.
 *
 * @param invoc an Invocation Object to fill in
 * @param suiteId to match a pending invocation
 * @param classname to match a pending invocation
 * @param mode one of {@link #MODE_REQUEST}, {@link #MODE_RESPONSE},
 *    or {@link #MODE_CLEANUP}
 * @param blocking true to block until a matching invocation is available
 * @return 1 if a matching invocation was found and returned 
 *    in its entirety; zero if there was no matching invocation;
 *    -1 if the sizes of the arguments or parameter array were wrong
 * @see StoredInvoc
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_content_InvocationStore_get0(void) {
    int ret = 0;          /* return value = nothing matched */
    KNI_StartHandles(4);
    KNI_DeclareHandle(obj);      /* multipurpose handle */
    KNI_DeclareHandle(argsObj);      /* handle for argument array */
    KNI_DeclareHandle(invocObj);  /* Arg1: Invocation object; non-null */
    KNI_DeclareHandle(classname); /* Arg3: non-null classname */
    int mode = MODE_REQUEST;      /* Arg4: mode for get */
    jboolean blocking = KNI_FALSE; /* Arg5: true if should block */

    /* Argument indices must match Java native method declaration */
#define getInvokeObjArg 1
#define getSuiteIdArg 2
#define getClassnameArg 3
#define getModeArg 4
#define getBlockingArg 5

    StoredLink* match = NULL;

    SuiteIdType desiredSuiteId;
    pcsl_string desiredClassname = PCSL_STRING_NULL_INITIALIZER;

    do {/* Block to break out of on exceptions */
        /* Check if blocked invocation was cancelled. */
        if (isThreadCancelled()) {
            /* blocking is always false to cleanup and exit immediately */
            break;
        }
    
        /* Get the desired blocking mode. */
        blocking = KNI_GetParameterAsBoolean(getBlockingArg);
    
        if (!isEmpty()) {
            /* Queue is not empty, get InvocationImpl obj and init. */
            KNI_GetParameterAsObject(getInvokeObjArg, invocObj);
            init(invocObj, obj);
    
            /* Get the desired type of invocation. */
            mode = KNI_GetParameterAsInt(getModeArg);
            if (mode == MODE_TID || 
                mode == MODE_TID_NEXT ||
                mode == MODE_TID_PREV) {
                int tid = KNI_GetIntField(invocObj, tidFid);
                if (tid != 0) {
                    match = invocFindTid(tid);
                } else {
                    /* start with the root */
                    match = invocQueue;
                }
                if (match != NULL) {
                    /* Link to the next or previous depending on the mode. */
                    if (mode == MODE_TID_NEXT) {
                        match = match->flink;
                    } else if (mode == MODE_TID_PREV) {
                        match = match->blink;
                    }
                }
            } else {
                desiredSuiteId = KNI_GetParameterAsInt(getSuiteIdArg);
                KNI_GetParameterAsObject(getClassnameArg, classname);
                if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(classname, 
                                        &desiredClassname)) {
                    KNI_ThrowNew(midpOutOfMemoryError, 
                       "InvocationStore_get0 no memory for [desiredClassname]");
                    break;
                }
                match = invocFind(desiredSuiteId, &desiredClassname, mode);
            }
        }
    } while (KNI_FALSE);

    /* Always free strings allocated */
    pcsl_string_free(&desiredClassname);

    if (match != NULL) {
        StoredInvoc *invoc = match->invoc;
        int st = copyOut(invoc, mode, invocObj, argsObj, obj);
        switch (st) {
        case 1:
            /* If a match was found and successfully copied;
             * do final set of actions on the Invocation selected.
             */
            switch (mode) {
            case MODE_REQUEST:
                if (invoc->status == STATUS_INIT) {
                    /* 
                     * Returning new request, change status to ACTIVE
                     * Keep this entry in the queue.
                     */
                    invoc->status = STATUS_ACTIVE;
                    KNI_SetIntField(invocObj, statusFid, invoc->status);
                }
                break;
            case MODE_RESPONSE:
                if (invoc->status >= STATUS_OK &&
                    invoc->status <= STATUS_INITIATED) {
                    /*
                     * Remove responses from the list and free.
                     */
                    removeEntry(match);
                    invocFree(invoc);
                }
                break;
            case MODE_LREQUEST:
            case MODE_LRESPONSE:
            case MODE_CLEANUP:
            case MODE_TID:
            case MODE_TID_NEXT:
            case MODE_TID_PREV:
            default:
                /* No additional action */
                break;
            }
            /* Returning an Invocation */
            ret = 1;
            break;
        case 0:
            /* Insufficient memory for strings. */
            KNI_ThrowNew(midpOutOfMemoryError, "invocStore returning strings");
            KNI_ReleaseHandle(invocObj);
            ret = 0;
            break;
        case -1:
            /* Either args array or data array is incorrect size. */
            ret = -1;
        }
    } else {
        /* No match found. */
        /* If blocking, setup to block. */
        if (blocking) {
            blockThread();
            /* Fall into the return to manage handles correctly */
        }
        ret = 0;
    }
    KNI_EndHandles();
    KNI_ReturnInt(ret);
}