Beispiel #1
0
/**
 * Creates a server connection object.
 *
 * Note: the method sets native connection handle directly to
 * <code>handle<code> field of <code>L2CAPNotifierImpl</code> object.
 *
 * @param imtu receive MTU or <code>-1</code> if not specified
 * @param omtu transmit MTU or <code>-1</code> if not specified
 * @param auth   <code>true</code> if authication is required
 * @param authz  <code>true</code> if authorization is required
 * @param enc    <code>true</code> indicates
 *                what connection must be encrypted
 * @param master <code>true</code> if client requires to be
 *               a connection's master
 * @return reserved PSM to listen for incoming connections on
 * @throws IOException if any I/O error occurs
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_io_j2me_btl2cap_L2CAPNotifierImpl_create0(void) {
    int imtu = (int)KNI_GetParameterAsInt(1);
    int omtu = (int)KNI_GetParameterAsInt(2);
    javacall_bool auth  = (KNI_GetParameterAsBoolean(3) == KNI_TRUE)
        ? JAVACALL_TRUE : JAVACALL_FALSE;
    javacall_bool authz  = (KNI_GetParameterAsBoolean(4) == KNI_TRUE)
        ? JAVACALL_TRUE : JAVACALL_FALSE;
    javacall_bool enc  = (KNI_GetParameterAsBoolean(5) == KNI_TRUE)
        ? JAVACALL_TRUE : JAVACALL_FALSE;
    javacall_bool master  = (KNI_GetParameterAsBoolean(6) == KNI_TRUE)
        ? JAVACALL_TRUE : JAVACALL_FALSE;

    javacall_handle handle = BT_INVALID_HANDLE;
    int psm = BT_L2CAP_INVALID_PSM;

    REPORT_INFO(LC_PROTOCOL, "btl2cap_notif::create");

    // Need revisit: add resource counting
/*
    if (midpCheckResourceLimit(RSC_TYPE_BT_SER, 1) == 0) {
        const char* pMsg = "Resource limit exceeded for BT server sockets";
        REPORT_INFO(LC_PROTOCOL, pMsg);
        KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
    } else {
*/

    /* create L2CAP server connection */
    if (javacall_bt_l2cap_create_server(imtu, omtu, auth, authz, enc, master,
            &handle, &psm) == JAVACALL_FAIL) {
        REPORT_ERROR(LC_PROTOCOL,
            "L2CAP notifier creation failed in btl2cap_notif::create");
        KNI_ThrowNew(midpIOException,
            EXCEPTION_MSG("Can not create L2CAP notifier "));
        KNI_ReturnInt(BT_L2CAP_INVALID_PSM);
    }

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisHandle);
    KNI_GetThisPointer(thisHandle);

    /* store native connection handle to Java object */
    KNI_SetIntField(thisHandle, notifHandleID, (jint)handle);

    // Need revisit: add resource counting
/*
    if (midpIncResourceCount(RSC_TYPE_BT_SER, 1) == 0) {
        REPORT_INFO(LC_PROTOCOL, "BT Server: Resource limit update error");
    }
*/

//    }

    REPORT_INFO2(LC_PROTOCOL, "btl2cap_notif::create notifier created"
        ", port = %d, handle = %d\n", psm, handle);

    KNI_EndHandles();
    KNI_ReturnInt(psm);
}
Beispiel #2
0
/**
 * Creates a server connection object.
 *
 * Note: the method sets native connection handle directly to
 * <code>handle<code> field of <code>BTSPPNotifierImpl</code> object.
 *
 * @param auth   <code>true</code> if authication is required
 * @param authz  <code>true</code> if authorization is required
 * @param enc    <code>true</code> indicates
 *                what connection must be encrypted
 * @param master <code>true</code> if client requires to be
 *               a connection's master
 * @return selected channel number to listen for incoming connections on
 * @throws IOException if any I/O error occurs
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_io_j2me_btspp_BTSPPNotifierImpl_create0(void) {
    bt_bool_t auth  = (KNI_GetParameterAsBoolean(1) == KNI_TRUE)
        ? BT_BOOL_TRUE : BT_BOOL_FALSE;
    bt_bool_t authz  = (KNI_GetParameterAsBoolean(2) == KNI_TRUE)
        ? BT_BOOL_TRUE : BT_BOOL_FALSE;
    bt_bool_t enc  = (KNI_GetParameterAsBoolean(3) == KNI_TRUE)
        ? BT_BOOL_TRUE : BT_BOOL_FALSE;
    bt_bool_t master  = (KNI_GetParameterAsBoolean(4) == KNI_TRUE)
        ? BT_BOOL_TRUE : BT_BOOL_FALSE;

    bt_handle_t handle = BT_INVALID_HANDLE;
    int cn = BT_RFCOMM_INVALID_CN;

    REPORT_INFO(LC_PROTOCOL, "btspp_notif::create0");

    // IMPL_NOTE: add resource counting
/*
    if (midpCheckResourceLimit(RSC_TYPE_BT_SER, 1) == 0) {
        const char* pMsg = "Resource limit exceeded for BT server sockets";
        REPORT_INFO(LC_PROTOCOL, pMsg);
        KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
    } else {
*/

    /* create RFCOMM server connection */
    if (bt_rfcomm_create_server(auth, authz, enc, master, &handle, &cn)
            == BT_RESULT_FAILURE) {
        REPORT_ERROR(LC_PROTOCOL,
            "RFCOMM notifier creation failed in btspp_notif::create");
        KNI_ThrowNew(midpIOException,
            EXCEPTION_MSG("Can not create RFCOMM notifier"));
        KNI_ReturnInt(BT_RFCOMM_INVALID_CN);
    }

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisHandle);
    KNI_GetThisPointer(thisHandle);

    /* store native connection handle to Java object */
    KNI_SetIntField(thisHandle, notifHandleID, (jint)handle);

    // IMPL_NOTE: add resource counting
/*
    if (midpIncResourceCount(RSC_TYPE_BT_SER, 1) == 0) {
        REPORT_INFO(LC_PROTOCOL, "BT Server: Resource limit update error");
    }
*/

//    }

    REPORT_INFO2(LC_PROTOCOL, "btspp_notif::create notifier created"
        ", port = %d, handle = %d\n", cn, handle);

    KNI_EndHandles();
    KNI_ReturnInt(cn);
}
/*  protected native int nSetMute ( int mediaType , boolean mute ) ; */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
KNIDECL(com_sun_mmedia_DirectVolume_nSetMute) {

    jint handle = KNI_GetParameterAsInt(1);
    jboolean mute = KNI_GetParameterAsBoolean(2);
    jboolean returnValue = KNI_FALSE;
    javacall_result ret = JAVACALL_FAIL;
    javacall_bool setMuted;

    KNIPlayerInfo* pKniInfo = (KNIPlayerInfo*)handle;

    MMP_DEBUG_STR1("[kni_volume] +nSetMute %d\n", mute);

    if (pKniInfo && pKniInfo->pNativeHandle) {
        setMuted = (mute == KNI_TRUE) ? JAVACALL_TRUE : JAVACALL_FALSE;
        ret = javacall_media_set_mute(pKniInfo->pNativeHandle, setMuted);
    } else {
        MMP_DEBUG_STR("[nSetMute] Invalid native handle");
    }
    if (ret == JAVACALL_OK) {
        returnValue = (setMuted == JAVACALL_TRUE) ? KNI_TRUE : KNI_FALSE;
    }

    KNI_ReturnBoolean(returnValue);
}
/**
 * Initializes the native peer of this <tt>Font</tt>.
 * <p>
 * Java declaration:
 * <pre>
 *     init(III)V
 * </pre>
 *
 * @param face The face of the font to initialize
 * @param style The style of the font to initialize
 * @param size The point size of the font to initialize
 */
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(javax_microedition_lcdui_Font_init) {
    jboolean free_size = KNI_GetParameterAsBoolean(4);
    int size  = (int)KNI_GetParameterAsInt(3);
    int style = (int)KNI_GetParameterAsInt(2);
    int face  = (int)KNI_GetParameterAsInt(1);
    int ascent, descent, leading;

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);

    if (free_size == KNI_FALSE) {
        /* size is one of the SIZE_XXX constants */
        size = OEM_FONT_SIZE(size);
    }

    KNI_GetParameterAsObject(0, thisObject);

    gx_get_fontinfo(face, style, size, &ascent, &descent, &leading);

    SNI_BEGIN_RAW_POINTERS;

    GET_FONT_PTR(thisObject)->baseline = (jint)ascent;
    GET_FONT_PTR(thisObject)->height = (jint)(ascent + descent + leading);
    GET_FONT_PTR(thisObject)->size = (jint)size;
    GET_FONT_PTR(thisObject)->sizeRounded = (jint) LCDUI_FONT_SIZE(size);

    SNI_END_RAW_POINTERS;

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Beispiel #5
0
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(javax_microedition_lcdui_TextFieldLFImpl_enableNativeEditor) {
    int x = KNI_GetParameterAsInt(1);
    int y = KNI_GetParameterAsInt(2);
    int w = KNI_GetParameterAsInt(3);
    int h = KNI_GetParameterAsInt(4);
    jboolean multiline = KNI_GetParameterAsBoolean(5);

    if (multiline) {
        hwndTextActive = hwndTextBox;
    } else {
        hwndTextActive = hwndTextField;
    }

    editCHX = x;
    editCHY = y;
    editCHW = w;
    editCHH = h;

    if (!JWC_WINCE_SMARTPHONE) {
        int diff = (rcVisibleDesktop.right - rcVisibleDesktop.left)
                   - CHAM_WIDTH;
        if (diff > 0) {
            x += diff / 2;
        }
    }

    editBoxShown = 1;
    SetWindowPos(hwndTextActive, HWND_TOP, x, y, w, h, SWP_SHOWWINDOW);
    SetFocus(hwndTextActive);
    KNI_ReturnVoid();
}
Beispiel #6
0
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_jsr82emul_DeviceEmul_inquiryCompleted() {
    jboolean success = (int)KNI_GetParameterAsBoolean(1);
    LOG("DeviceEmul_inquiryCompleteted()");
    
    javanotify_bt_inquiry_complete(success ? JAVACALL_TRUE : JAVACALL_FALSE);
    KNI_ReturnVoid();
}
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(com_sun_midp_main_IndicatorManager_toggleHomeIcon0) {

    jboolean isHomeOn = KNI_GetParameterAsBoolean(1);

    anc_toggle_home_icon(isHomeOn);

    KNI_ReturnVoid();
}
/**
 * Creates a copy of a region of the specified <tt>ImageData</tt> and
 * stores the copied image in passed in immutable <tt>ImageData</tt> object.
 * <p>
 * Java declaration:
 * <pre>
 *     createImmutableImageDataRegion(Ljavax/microedition/lcdui/ImageData;Ljavax/microedition/lcdui/ImageData;IIIII)V
 * </pre>
 *
 * @param dest The <tt>ImageData</tt> to copy to
 * @param source The <tt>ImageData</tt> to copy
 * @param x The x coordinate of the upper left corner of the
 *          region to copy
 * @param y The y coordinate of the upper left corner of the
 *          region to copy
 * @param width The width of the region to copy
 * @param height The height of the region to copy
 * @param transform The transform to apply to the selected region.
 * @param isMutable <tt>true</tt> if <tt>img</tt> is mutable, otherwise
 *                  <tt>false</tt>
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_lcdui_ImageDataFactory_createImmutableImageDataRegion() {
    jboolean ismutable = KNI_GetParameterAsBoolean(8);
    int      transform = KNI_GetParameterAsInt(7);
    int         height = KNI_GetParameterAsInt(6);
    int          width = KNI_GetParameterAsInt(5);
    int              y = KNI_GetParameterAsInt(4);
    int              x = KNI_GetParameterAsInt(3);
    img_native_error_codes creationError = IMG_NATIVE_IMAGE_NO_ERROR;

    /* pointer to native image structure */
    gxpport_image_native_handle srcImagePtr;
    gxpport_image_native_handle newImagePtr;

    KNI_StartHandles(2);
    KNI_DeclareHandle(srcImg);
    KNI_DeclareHandle(destImg);

    KNI_GetParameterAsObject(2, srcImg);
    KNI_GetParameterAsObject(1, destImg);

    /* get src image's midpNative data */
    srcImagePtr = gxp_get_imagedata(srcImg);

    if (KNI_FALSE == ismutable) {
	/* immutable image */
        gxpport_createimmutable_from_immutableregion(srcImagePtr,
						     x, y, width, height,
						     transform,
						     &newImagePtr,
						     &creationError);
    } else {
	/* mutable image */
	gxpport_createimmutable_from_mutableregion(srcImagePtr,
						   x, y, width, height,
						   transform,
						   &newImagePtr,
						   &creationError);
    }

    if (IMG_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR == creationError) {
	KNI_ThrowNew(midpOutOfMemoryError, NULL);
    } else if (IMG_NATIVE_IMAGE_RESOURCE_LIMIT == creationError) {
	KNI_ThrowNew(midpOutOfMemoryError,
		     "Resource limit exceeded for immutable image");
    } else if (IMG_NATIVE_IMAGE_NO_ERROR != creationError) {
	KNI_ThrowNew(midpIllegalArgumentException, NULL);
    } else {
	IMGAPI_GET_IMAGEDATA_PTR(destImg)->nativeImageData = (jint)newImagePtr;
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
/**
 * IMPL_NOTE:(Deoxy - Consider using internal)
 *
 * FUNCTION:      drawTrustedIcon(II)V
 * CLASS:         javax.microedition.lcdui.Display
 * TYPE:          virtual native function
 * OVERVIEW:      set the drawing of the trusted MIDlet icon
 * INTERFACE (operand stack manipulation):
 *   parameters:  displayId The display ID associated with the caller Display
 *                drawTrusted     
 *   returns:     <nothing>
 */
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(javax_microedition_lcdui_Display_drawTrustedIcon0) {
    jboolean drawTrusted = KNI_GetParameterAsBoolean(2);
    jint displayId = KNI_GetParameterAsInt(1);

    if (midpHasForeground(displayId)) {
      /* Call platform dependent implementation */
      anc_show_trusted_indicator(drawTrusted);
    }
  
    KNI_ReturnVoid();
}
/**
 * Garbage collect any zombie Images to free up their resources.
 * <p>
 * Java declaration:
 * <pre>
 *     garbageCollectImages(Z)V
 * </pre>
 *
 * @param doFullGC boolean indicating whether to do a full GC or not
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_lcdui_ImageDataFactory_garbageCollectImages() {
    jboolean doFullGC = KNI_GetParameterAsBoolean(1);

    if (doFullGC == KNI_TRUE) {
	JVM_GarbageCollect(0, 0);
    } else {
	JVM_GarbageCollect(JVM_COLLECT_YOUNG_SPACE_ONLY, 0);
    }

    KNI_ReturnVoid();
}
/**
 * Garbage collect any zombie Objects to free up their resources.
 * <p>
 * Java declaration:
 * <pre>
 *     garbageCollect(Z)V
 * </pre>
 *
 * @param fullGC boolean indicating whether to do a full GC or not
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_khronos_egl_EGL10Impl__1garbageCollect() {
    jboolean doFullGC = KNI_GetParameterAsBoolean(1);

    if (doFullGC == KNI_TRUE) {
        JVM_GarbageCollect(0, 0);
    } else {
        JVM_GarbageCollect(JVM_COLLECT_YOUNG_SPACE_ONLY, 0);
    }

    KNI_ReturnVoid();
}
/**
 * FUNCTION:      setSuppressKeyEvents(Ljavax/microedition/lcdui/Canvas;Z)V
 * CLASS:         javax.microedition.lcdui.game.GameCanvas
 * TYPE:          virtual native function
 * OVERVIEW:      Sets a private field in a public class defined in a 
 *                 different package.
 * INTERFACE (operand stack manipulation):
 *   parameters:  c                  the object whose field we are to set
 *                suppressKeyEvents  value to set the private field to
 *   returns:     <nothing>
 */
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(javax_microedition_lcdui_game_GameCanvas_setSuppressKeyEvents) {
    KNI_StartHandles(1);
    KNI_DeclareHandle(canvas);

    KNI_GetParameterAsObject(1, canvas);

    GET_GAMECANVAS_PTR(canvas)->suppressKeyEvents = 
        KNI_GetParameterAsBoolean(2);

    KNI_EndHandles();
    KNI_ReturnVoid();
}
/**
 * @internal
 *
 * Internal native implementation of Java function vibrate0()
 *
 * @verbatim 
 * FUNCTION:      vibrate0(II)Z 
 * CLASS:         com.sun.midp.lcdui.DisplayDeviceAccess
 * TYPE:          native function to play vibration
 * OVERVIEW:      turn on the vibrator mechanism if <code>onOff</code>
 *                is true, or off if it is false.
 *                return false if this <code>Display</code> does not have foreground.
 * INTERFACE (operand stack manipulation):
 *   parameters:  display the display ID associated with the Display object
 *                onOff start/stop vibrator
 *   returns:     KNI_TRUE if the device supports vibrate and Display has
 *                foreground,
 *                KNI_FALSE otherwise
 * @endverbatim
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
KNIDECL(com_sun_midp_lcdui_DisplayDeviceAccess_vibrate0) {
    jboolean onoff = KNI_GetParameterAsBoolean(2);
    int displayId = KNI_GetParameterAsInt(1);
	
	if(/*!midpHasForeground(displayId) || */anc_stop_vibrate() == KNI_FALSE){
        KNI_ReturnBoolean(KNI_FALSE);
    } else if (KNI_FALSE == onoff) {
        KNI_ReturnBoolean(anc_stop_vibrate());
    } else {
        KNI_ReturnBoolean(anc_start_vibrate());
    }
	
}
/*
 * Creates a client connection object.
 *
 * Note: the method sets native connection handle directly to
 * <code>handle<code> field of <code>RFCOMMConnectionImpl</code> object.
 *
  * @param auth   <code>true</code> if authication is required
 * @param enc    <code>true</code> indicates
 *                what connection must be encrypted
 * @param master <code>true</code> if client requires to be
 *               a connection's master
 * @throws IOException if any I/O error occurs
 */
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(com_sun_jsr082_bluetooth_btspp_BTSPPConnectionImpl_create0) {
    javacall_bool auth  = (KNI_GetParameterAsBoolean(1) == KNI_TRUE)
        ? JAVACALL_TRUE : JAVACALL_FALSE;
    javacall_bool enc  = (KNI_GetParameterAsBoolean(2) == KNI_TRUE)
        ? JAVACALL_TRUE : JAVACALL_FALSE;
    javacall_bool master  = (KNI_GetParameterAsBoolean(3) == KNI_TRUE)
        ? JAVACALL_TRUE : JAVACALL_FALSE;

    javacall_handle handle = JAVACALL_BT_INVALID_HANDLE;

    REPORT_INFO(LC_PROTOCOL, "btspp::create");

    /* create RFCOMMC server connection */
    if (javacall_bt_rfcomm_create_client(auth, enc, master, &handle)
            == JAVACALL_FAIL) {
        REPORT_ERROR(LC_PROTOCOL,
            "Connection creation failed during btspp::create");
        KNI_ThrowNew(jsropIOException,
            EXCEPTION_MSG("Can not create RFCOMM connection"));
        KNI_ReturnVoid();
    }

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisHandle);
    KNI_GetThisPointer(thisHandle);

    /* store native connection handle to Java object */
    KNI_SetIntField(thisHandle, connHandleID, (jint)handle);

    REPORT_INFO1(LC_PROTOCOL,
        "btspp::create0 handle=%d connection created", handle);

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Beispiel #15
0
/**
 * KNI function that sets selected state on an element with passed in index
 * in the native resource corresponding to the current ChoiceGroup.
 *
 * Java declaration:
 * <pre>
 *     setSelectedIndex0(III)V
 * </pre>
 * @param nativeId - id of the native resource corresponding to the current
 *                   ChoiceGroup
 * @param elementNum - index of an element which content should be changed
 * @param selected  - current selection state of the element
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_lcdui_ChoiceGroupLFImpl_setSelectedIndex0() {
  MidpError err = KNI_OK;
  MidpItem *cgPtr = (MidpItem *)KNI_GetParameterAsInt(1);
  int elementNum = KNI_GetParameterAsInt(2);
  jboolean selected = KNI_GetParameterAsBoolean(3);

  err = lfpport_choicegroup_set_selected_index(cgPtr, elementNum, selected);

  if (err == KNI_ENOMEM) {
    KNI_ThrowNew(midpOutOfMemoryError, NULL);
  }
  
  KNI_ReturnVoid();  
}
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(com_sun_midp_midletsuite_MIDletSuiteImpl_lockMIDletSuite) {
    jboolean isUpdate;
    SuiteIdType suiteId;
    int status;

    suiteId  = KNI_GetParameterAsInt(1);
    isUpdate = KNI_GetParameterAsBoolean(2);
    /* Throw an exception here if we have an error */
    status = lock_storage(suiteId, isUpdate);
    if (status < 0) {
        if (status == OUT_OF_MEM_LEN) {
            KNI_ThrowNew(midpOutOfMemoryError, NULL);
        } else if (status == SUITE_LOCKED) {
            KNI_ThrowNew(midletsuiteLocked, NULL);
        }
    }
    KNI_ReturnVoid();
}
/**
 * Gets all registered push connections associated with the given MIDlet
 * suite.
 * <p>
 * Java declaration:
 * <pre>
 *     list0([BZ[BI)I
 * </pre>
 *
 * @param midlet The MIDlet suite to get push registry entries
 * @param available Which connections to return. If <tt>true</tt>,
 *                  only return the connections with available input.
 *                  Otherwise, return all connection.
 * @param connectionlist A comma separated string of connections stored
 *                       as a byte array.
 * @param listsz The maximum length of the byte array that will be
 *               accepted for <tt>connectionlist</tt>
 *
 * @return <tt>0</tt> if successful, otherwise <tt>-1</tt>
 *
 * @throw IllegalArgumentException If the length <tt>midlet</tt> is
 *                                 too long.
 */
KNIEXPORT KNI_RETURNTYPE_INT
KNIDECL(com_sun_midp_io_j2me_push_ConnectionRegistry_list0) {
    char *midletName = NULL;
    int available;
    int connsize;
    int nameLength;
    char *conn;
    int ret = -1;

    available = KNI_GetParameterAsBoolean(2);
    connsize = KNI_GetParameterAsInt(4);

    KNI_StartHandles(2);

    KNI_DeclareHandle(name);
    KNI_DeclareHandle(connections);
    KNI_GetParameterAsObject(1, name);
    KNI_GetParameterAsObject(3, connections);

    nameLength = KNI_GetArrayLength(name);
    midletName = (char*)midpMalloc(nameLength);
    if (midletName == NULL) {
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    }
    else {
        KNI_GetRawArrayRegion(name, 0, nameLength, (jbyte*)midletName);

        conn = pushfindsuite(midletName, available);

        if (conn != NULL) {
            KNI_SetRawArrayRegion(connections, 0, strlen(conn), (jbyte*)conn);
            midpFree(conn);
            ret = 0;
        }

        midpFree(midletName);
    }

    KNI_EndHandles();

    KNI_ReturnInt(ret);
}
Beispiel #18
0
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_jsr82emul_ConnectionEmul_notifyOpen() {
    int myHandle = KNI_GetParameterAsInt(1);
    jboolean success = KNI_GetParameterAsBoolean(2);
    connection_info_t *info = &emul_data.handled_info[myHandle].conn;

    LOG1("ConnectionEmul_notifyOpen(%d)", myHandle);

    if (success == KNI_FALSE) {
        info->connect_status = JAVACALL_FAIL;
    } else {
        info->imtu = KNI_GetParameterAsInt(3);
        info->omtu = KNI_GetParameterAsInt(4);
        info->connect_status = JAVACALL_OK;
    }
    
    javanotify_bt_protocol_event(JAVACALL_EVENT_BT_CONNECT_COMPLETE, 
        (javacall_handle)myHandle, info->connect_status);
  
    KNI_ReturnVoid();
}
Beispiel #19
0
/**
 * KNI function that inserts new element with passed in string and image 
 *  into the native resource corresponding to the current ChoiceGroup.
 *
 * Java declaration:
 * <pre>
 *     insert0(IISOB)V
 * </pre>
 * @param nativeId - id of the native resource corresponding to the current
 *                   ChoiceGroup
 * @param elementNum - location at which new element should be inserted
 * @param stringPart - string part of the element to be inserted
 * @param imagePart - image part of the element to be inserted
 * @param selected  - current selection state of the inserted element
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_lcdui_ChoiceGroupLFImpl_insert0() {
  MidpError err = KNI_OK;
  MidpItem *cgPtr = (MidpItem *)KNI_GetParameterAsInt(1);
  MidpChoiceGroupElement cgElement;
  pcsl_string_status perr;
  int elementNum = KNI_GetParameterAsInt(2);
  

  KNI_StartHandles(2);
  KNI_DeclareHandle(stringPartJString);
  KNI_DeclareHandle(imgPartJImage);
  
  KNI_GetParameterAsObject(3, stringPartJString);
  KNI_GetParameterAsObject(4, imgPartJImage);

  if (KNI_IsNullHandle(imgPartJImage) == KNI_TRUE) {
    cgElement.image = NULL;
  } else {
    cgElement.image = gxp_get_imagedata(imgPartJImage);
  }

  perr = midp_jstring_to_pcsl_string(stringPartJString, &cgElement.string);
  cgElement.selected = KNI_GetParameterAsBoolean(5);
  cgElement.font = NULL;

  KNI_EndHandles();

  if (PCSL_STRING_OK == perr) {
    err = lfpport_choicegroup_insert(cgPtr, elementNum, cgElement);
  }
  
  pcsl_string_free(&cgElement.string);
  
  if (err == KNI_ENOMEM) {
    KNI_ThrowNew(midpOutOfMemoryError, NULL);
  }
  
  KNI_ReturnVoid();
}
Beispiel #20
0
/**
 * KNI function that create native resource for current Gauge.
 * Class: javax.microedition.lcdui.GaugeLFImpl
 * Java prototype:
 * private native int createNativeResource0(int ownerId,
 *	    		String label, int layout, 
 *                      boolean interactive,
 *			int maxValue, int initialValue)
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_lcdui_GaugeLFImpl_createNativeResource0() {
    
    MidpError err = KNI_OK;
    MidpItem *gaugePtr = NULL;
    MidpDisplayable *ownerPtr;
    int maxValue, initialValue, layout;
    jboolean interactive;

    KNI_StartHandles(1);

    ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1);
    GET_PARAMETER_AS_PCSL_STRING(2, label)
    layout = KNI_GetParameterAsInt(3);
    interactive = KNI_GetParameterAsBoolean(4);
    maxValue = KNI_GetParameterAsInt(5);
    initialValue = KNI_GetParameterAsInt(6);
    {
        gaugePtr = MidpNewItem(ownerPtr,
                   interactive ? MIDP_INTERACTIVE_GAUGE_TYPE
                           : MIDP_NON_INTERACTIVE_GAUGE_TYPE);
        if (gaugePtr == NULL) {
            err = KNI_ENOMEM;
        } else {
            err = lfpport_gauge_create(gaugePtr, ownerPtr, &label, layout,
                           interactive, maxValue, initialValue);
        }
        /* cleanup: */
        if (err != KNI_OK) {
            MidpDeleteItem(gaugePtr);
            KNI_ThrowNew(midpOutOfMemoryError, NULL);
        }
    }
    RELEASE_PCSL_STRING_PARAMETER
    KNI_EndHandles();

    KNI_ReturnInt(gaugePtr);
}
Beispiel #21
0
/* void stop(int exit_code, int exit_reason); */
void Java_com_sun_cldc_isolate_Isolate_stop(JVM_SINGLE_ARG_TRAPS) {
  UsingFastOops fast_oops;
  IsolateObj::Fast isolate_obj = GET_PARAMETER_AS_OOP(0);
  Task::Fast task = isolate_obj().task();
  const int exit_code = KNI_GetParameterAsInt(1);
  const int exit_reason = KNI_GetParameterAsBoolean(2);

  switch (isolate_obj().status()) {
  case Task::TASK_NEW:
    isolate_obj().terminate(exit_code JVM_NO_CHECK_AT_BOTTOM);
    // Isolate was never started, so no threads to kill.
    break;

  case Task::TASK_STARTED:
    GUARANTEE(task.not_null(), "Task must exist for running Isolate");
    task().stop(exit_code, exit_reason JVM_NO_CHECK_AT_BOTTOM);
    break;

  default:
    // OK to call stop() multiple times. Just ignore it.
    break;
  }
}
Beispiel #22
0
/**
 * Gets the requested IP number.
 * <p>
 * Java declaration:
 * <pre>
 *     getHost(Z)Ljava/lang/String;
 * </pre>
 *
 * @param local <tt>true</tt> to get the local host IP address, or
 *              <tt>false</tt> to get the remote host IP address.
 *
 * @return the IP address as a dotted-quad <tt>String</tt>
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT 
Java_com_sun_midp_io_j2me_socket_Protocol_getHost0(void) {
    int local;
    void *pcslHandle;
    char value[MAX_HOST_LENGTH];
    int status = PCSL_NET_INVALID;

    local = (int)KNI_GetParameterAsBoolean(1);

    memset(value, '\0', MAX_HOST_LENGTH);

    KNI_StartHandles(2);
    KNI_DeclareHandle(result);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle);

    if (INVALID_HANDLE == pcslHandle) {
        KNI_ThrowNew(midpIOException, 
                     "invalid handle during socket::getHost");
    } else {
        if (local) {
            status = pcsl_socket_getlocaladdr(pcslHandle, value);
        } else {
            status = pcsl_socket_getremoteaddr(pcslHandle, value);
        }

        if (status == PCSL_NET_SUCCESS) {
            KNI_NewStringUTF(value, result);
        } else {
            KNI_ThrowNew(midpIOException, NULL);
        }
    }

    KNI_EndHandlesAndReturnObject(result);
}
Beispiel #23
0
/**
 * 
 * Listens for  an InvocationImpl from the store using a MIDlet suiteId
 * and optional, and status. Each Invocation must be returned only
 * once.  When an Invocation is returned; it is marked as being
 * notified.
 *
 * @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 true if an Invocation is found with 
 *  the same MIDlet suiteId and classname; false is returne dotherwise
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
Java_com_sun_midp_content_InvocationStore_listen0(void) {
    StoredLink* match = NULL;
    SuiteIdType desiredSuiteId;
    pcsl_string desiredClassname = PCSL_STRING_NULL_INITIALIZER;

    KNI_StartHandles(1);
    KNI_DeclareHandle(classname); /* Arg2: non-null classname */
    int mode;                  /* Arg3: requested invocation mode */
    jboolean blocking = KNI_FALSE; /* Arg4: true if should block */

    /* Argument indices must match Java native method declaration */
#define listenSuiteIdArg 1
#define listenClassnameArg 2
#define listenModeArg 3
#define listenBlockingArg 4

    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(listenBlockingArg);
    
        if (!isEmpty()) {
            /* Queue is not empty
             * Need a string copy of the desired suiteID and classname
             * to use for comparisons
             */
            desiredSuiteId = KNI_GetParameterAsInt(listenSuiteIdArg);
    
                KNI_GetParameterAsObject(listenClassnameArg, classname);
            if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(classname, 
                               &desiredClassname)) {
                KNI_ThrowNew(midpOutOfMemoryError, 
                    "InvocationStore_listen0 no memory for [desiredClassname]");
                break;
            }

            /* Get the desired request mode. */
            mode = KNI_GetParameterAsInt(listenModeArg);
            match = invocFind(desiredSuiteId, &desiredClassname, mode);
        }
    } while (KNI_FALSE);

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

    if (match != NULL) {
        match->invoc->notified = KNI_TRUE;
    } else {
        if (blocking) {
            /* No found; block the thread in the VM */
            blockThread();
            /* Fall into the return to manage handles correctly */
        }
    }

    KNI_EndHandles();
    KNI_ReturnBoolean(match != NULL);
}
Beispiel #24
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);
}
/**
 * Populates a passed in immutable <tt>ImageData</tt>
 * from the given ARGB integer
 * array. The array consists of values in the form of 0xAARRGGBB.
 * <p>
 * Java declaration:
 * <pre>
 *     createImmutableImageDecodeRGBImage([Ljavax/microedition/lcdui/ImageData;III)V
 * </pre>
 *
 * @param imageData The <tt>ImadgeData</tt> to be populated
 * @param rgbData The array of argb image data
 * @param width The width of the new image
 * @param height The height of the new image
 * @param processAlpha If <tt>true</tt>, alpha channel bytes will
 *                     be used, otherwise, alpha channel bytes will
 *                     be ignored
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_lcdui_ImageDataFactory_createImmutableImageDecodeRGBImage() {
    jboolean processAlpha = KNI_GetParameterAsBoolean(5);
    int height = KNI_GetParameterAsInt(4);
    int width = KNI_GetParameterAsInt(3);
    jint *imageBuffer = NULL;
    int buflen;
    img_native_error_codes creationError = IMG_NATIVE_IMAGE_NO_ERROR;

    /* pointer to native image structure */
    gxpport_image_native_handle newImagePtr;

    KNI_StartHandles(2);
    KNI_DeclareHandle(rgbData);
    KNI_DeclareHandle(imageData);

    KNI_GetParameterAsObject(2, rgbData);
    KNI_GetParameterAsObject(1, imageData);

    do {
        if (KNI_IsNullHandle(rgbData)) {
            KNI_ThrowNew(midpNullPointerException, NULL);
            break;
        }

        if ((width <= 0) || (height <= 0)) {
            KNI_ThrowNew(midpIllegalArgumentException, NULL);
            break;
        }

        buflen = KNI_GetArrayLength(rgbData);
        if ((width * height) > buflen) {
            KNI_ThrowNew(midpArrayIndexOutOfBoundsException, NULL);
            break;
        }

        imageBuffer = JavaIntArray(rgbData);

	SNI_BEGIN_RAW_POINTERS;

        gxpport_decodeimmutable_from_argb(imageBuffer, width, height,
					  processAlpha,
					  &newImagePtr, &creationError);

	SNI_END_RAW_POINTERS;

        if (IMG_NATIVE_IMAGE_NO_ERROR == creationError) {
	    java_imagedata * dstImageDataPtr = IMGAPI_GET_IMAGEDATA_PTR(imageData);

            dstImageDataPtr->height = (jint)height;
            dstImageDataPtr->width = (jint)width;
            dstImageDataPtr->nativeImageData = (jint)newImagePtr;
            break;
        }

        if (IMG_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR == creationError) {
            KNI_ThrowNew(midpOutOfMemoryError, NULL);
            break;
        }

        if (IMG_NATIVE_IMAGE_RESOURCE_LIMIT == creationError) {
            KNI_ThrowNew(midpOutOfMemoryError,
                         "Resource limit exceeded for immutable image");
            break;
        }

        KNI_ThrowNew(midpIllegalArgumentException, NULL);
    } while (0);

    KNI_EndHandles();
    KNI_ReturnVoid();
}