示例#1
0
/**
 *  The function unblocks threads waiting for Transaction Store
 */
void unlock() {
    int i, n;
    JVMSPI_BlockedThreadInfo *blocked_threads;
    MidpReentryData* pThreadReentryData;

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    if ((locked == KNI_TRUE) && 
            (getStorageOpenFlag(thisObject)->isOpen == KNI_TRUE)) {
        blocked_threads = SNI_GetBlockedThreads(&n);
        getStorageOpenFlag(thisObject)->isOpen = KNI_FALSE;
        locked = KNI_FALSE;
        for (i = 0; i < n; i++) {

            pThreadReentryData =
                (MidpReentryData*)(blocked_threads[i].reentry_data);

            if (pThreadReentryData == NULL) {
                continue;
            }
     
            if (pThreadReentryData->waitingFor != 
                    PAYMENT_TRANSACTION_STORE_SIGNAL) {
                continue;
            }

            pThreadReentryData->status = KNI_TRUE;
 
            midp_thread_unblock(blocked_threads[i].thread_id);
        }

    }

    KNI_EndHandles();
}
示例#2
0
/**
 * Checks out (takes ownership of) an active server connection maintained
 * by push subsystem.
 *
 * @param url URL used during registration of the push entry
 * @param suiteId suite id
 * @return true if the operation succeeds, false otherwise
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
Java_com_sun_midp_io_j2me_btspp_BTSPPNotifierImpl_pushCheckout(void) {
    jboolean retval = KNI_FALSE;
    SuiteIdType suiteId;
    MidpString wsUrl;
    char *szUrl;
    bt_port_t port;

    KNI_StartHandles(2);
    KNI_DeclareHandle(thisHandle);
    KNI_DeclareHandle(urlHandle);
    KNI_GetThisPointer(thisHandle);
    KNI_GetParameterAsObject(1, urlHandle);
    suiteId = KNI_GetParameterAsInt(2);

    wsUrl = midpNewString(urlHandle);
    szUrl = midpJcharsToChars(wsUrl);

    if (bt_push_parse_url(szUrl, &port, NULL) == BT_RESULT_SUCCESS) {
        if (pushcheckout(szUrl, 0, (char*)midp_suiteid2chars(suiteId)) == -2) {
            KNI_ThrowNew(midpIOException, "Port already in use.");
        } else {
            bt_handle_t handle;
            bt_pushid_t pushid = bt_push_checkout_server(&port, &handle, NULL);
            if (pushid != BT_INVALID_PUSH_HANDLE) {
                KNI_SetIntField(thisHandle, pushHandleID, (jint)pushid);
                KNI_SetIntField(thisHandle, notifHandleID, (jint)handle);
                retval = KNI_TRUE;
            }
        }
    }

    midpFree(szUrl);
    MIDP_FREE_STRING(wsUrl);
    KNI_EndHandles();
    KNI_ReturnBoolean(retval);
}
示例#3
0
/**
 * Releases any native resources used by the datagram connection.
 * <p>
 * Java declaration:
 * <pre>
 *     finalize(V)V
 * </pre>
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_io_j2me_datagram_Protocol_finalize(void) {
    void *handle;
    int status;
    void *context = NULL;

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    handle = (void *)getMidpDatagramProtocolPtr(thisObject)->nativeHandle;

    if (handle != INVALID_HANDLE) {
        if (pushcheckin((int)handle) == -1) {
            status = pcsl_datagram_close_start(handle, &context);
            if (status == PCSL_NET_SUCCESS) {
                if (midpDecResourceCount(RSC_TYPE_UDP, 1) == 0) {
                    REPORT_INFO(LC_PROTOCOL,
                        "Datagrams: resource limit update error");
                }
            } else if (status == PCSL_NET_IOERROR) {
                REPORT_INFO2(LC_PROTOCOL,
                    "datagram::finalize handle 0x%x I/O error code %d",
                    (int)handle, pcsl_network_error(handle));
            } else if (status == PCSL_NET_WOULDBLOCK) {
                REPORT_ERROR1(LC_PROTOCOL,
                    "datagram::finalize handle 0x%x WOULDBLOCK not supported",
                    (int)handle);
            }
            getMidpDatagramProtocolPtr(thisObject)->nativeHandle =
                (jint)INVALID_HANDLE;
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
/**
 * Creates a copy of the specified <tt>ImageData</tt> and stores the
 * copied image in this object.
 * <p>
 * Java declaration:
 * <pre>
 *     createImmutableImageDataCopy(Ljavax/microedition/lcdui/ImageData;
 *                                  Ljavax/microedition/lcdui/ImageData;)V
 * </pre>
 *
 * @param dest  The <tt>ImageData </tt>where to make a copy
 * @param source The mutable <tt>ImageData</tt> to copy
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_lcdui_ImageDataFactory_createImmutableImageDataCopy() {

    img_native_error_codes creationError = IMG_NATIVE_IMAGE_NO_ERROR;

    /* mutable image */
    gxpport_image_native_handle srcImage;

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

    KNI_StartHandles(2);
    KNI_DeclareHandle(dest);
    KNI_DeclareHandle(source);

    KNI_GetParameterAsObject(2, source);
    KNI_GetParameterAsObject(1, dest);

    srcImage = gxp_get_imagedata(source);

    gxpport_createimmutable_from_mutable(srcImage, &newImage, &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(dest)->nativeImageData = (jint)newImage;
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
示例#5
0
/**
 * Gets the number of bytes that can be read without blocking.
 * <p>
 * Java declaration:
 * <pre>
 *     available0(V)I
 * </pre>
 *
 * @return number of bytes that can be read without blocking
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_io_j2me_socket_Protocol_available0(void) {
    void *pcslHandle;
    int bytesAvailable = 0;

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);
    
    pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle);

    KNI_EndHandles();

    REPORT_INFO1(LC_PROTOCOL, "socket::available0 fd=%d\n", (int)pcslHandle);

    if (INVALID_HANDLE == pcslHandle) {
        KNI_ThrowNew(midpIOException, "invalid handle during socket::available");
    } else {
        int status;

        status = pcsl_socket_available(pcslHandle, &bytesAvailable);
        /* status is only PCSL_NET_SUCCESS or PCSL_NET_IOERROR */
        if (status == PCSL_NET_IOERROR) {
            bytesAvailable = 0;
            midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "IOError %d during socket::available0", 
                    pcsl_network_error(pcslHandle));
            KNI_ThrowNew(midpIOException, gKNIBuffer);
        }
    }

    REPORT_INFO1(LC_PROTOCOL, "socket::available0 bytesAvailable=%d\n", 
                 bytesAvailable);

    KNI_ReturnInt((jint)bytesAvailable);
}
示例#6
0
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf() {
  int result = -1;
  SocketBufferParameter *p;

  if (!ANI_Start()) {
    ANI_Wait();
    KNI_ReturnInt(-1);
  }
  KNI_StartHandles(1);
  KNI_DeclareHandle(buffer_object);
  KNI_GetParameterAsObject(2, buffer_object);

  p = (SocketBufferParameter *) ANI_GetParameterBlock(NULL);
  if (p == NULL) {
    int buffer_size = KNI_GetParameterAsInt(4);
    p = new_buffer_parameter(/*fd*/ KNI_GetParameterAsInt(1), buffer_size);

    if (!ANI_UseFunction(asynchronous_socket_read,
                         /*try_non_blocking*/ KNI_FALSE)) {
      ANI_BlockThread();
      goto EXIT;
    }
  }

  if ((result = p->buffer_size) > 0) {
    jint offset = KNI_GetParameterAsInt(3);
    KNI_SetRawArrayRegion(buffer_object, offset, p->buffer_size,
                          (jbyte *) p->buffer);
  }

EXIT:
  KNI_EndHandles();
  ANI_End();
  KNI_ReturnInt(result);
}
/*
 * 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();
}
示例#8
0
/**
 * Get the maximum length of a datagram.
 * <p>
 * Java declaration:
 * <pre>
 *     getMaximumLength0(V)I
 * </pre>
 *
 * @return maximum length of a datagram
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_io_j2me_datagram_Protocol_getMaximumLength0(void) {
    void *socketHandle;
    int len = -1;

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    socketHandle =
        (void *)getMidpDatagramProtocolPtr(thisObject)->nativeHandle;

    if (socketHandle != INVALID_HANDLE) {
        int status;

        /*
         * IMPL NOTE:
         * Option=3 represents SO_RCVBUF
         * The SO_RCVBUF option is used by the the network implementation
         * as a hint to size the underlying network I/O buffers.
         */
        status = pcsl_network_getsockopt(socketHandle, 3, &len);
        if (status != PCSL_NET_SUCCESS) {
            KNI_ThrowNew(midpIOException, NULL);
        }
    } else {
        KNI_ThrowNew(midpIOException, "socket closed");
    }

    REPORT_INFO2(LC_PROTOCOL,
        "datagram::getMaximumLength0 handle=%d len=%d %d\n",
        (int)socketHandle, len);

    KNI_EndHandles();
    KNI_ReturnInt((jint)len);
}
示例#9
0
/**
 * 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) {
    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);

    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);

    SNI_END_RAW_POINTERS;
    
    KNI_EndHandles();
    KNI_ReturnVoid();
}
示例#10
0
/**
 * Gets an ARGB integer array from this <tt>ImmutableImage</tt>. The
 * array consists of values in the form of 0xAARRGGBB.
 * <p>
 * Java declaration:
 * <pre>
 *     getRGB([IIIIIII)V
 * </pre>
 *
 * @param rgbData The target integer array for the ARGB data
 * @param offset Zero-based index of first ARGB pixel to be saved
 * @param scanlen Number of intervening pixels between pixels in
 *                the same column but in adjacent rows
 * @param x The x coordinate of the upper left corner of the
 *          selected region
 * @param y The y coordinate of the upper left corner of the
 *          selected region
 * @param width The width of the selected region
 * @param height The height of the selected region
 */
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(javax_microedition_lcdui_Image_getRGB) {
    int height = KNI_GetParameterAsInt(7);
    int width = KNI_GetParameterAsInt(6);
    int y = KNI_GetParameterAsInt(5);
    int x = KNI_GetParameterAsInt(4);
    int scanlength = KNI_GetParameterAsInt(3);
    int offset = KNI_GetParameterAsInt(2);
    int buflen;
    int *rgbBuffer;
    int img_width;
    int img_height;
    jboolean iae = KNI_FALSE;
    java_imagedata * srcImageDataPtr = NULL;

    KNI_StartHandles(2);
    KNI_DeclareHandle(rgbData);
    KNI_DeclareHandle(thisObject);

    KNI_GetParameterAsObject(1, rgbData);
    KNI_GetThisPointer(thisObject);

    srcImageDataPtr = GET_IMAGE_PTR(thisObject)->imageData;

    img_width  = srcImageDataPtr->width;
    img_height = srcImageDataPtr->height;

    /* see if absolute value of scanlength is greater than or equal to width */
    if (scanlength >= 0 && scanlength < width) {
        iae = KNI_TRUE;
    } else if (scanlength < 0 && (0 - scanlength) < width) {
        iae = KNI_TRUE;
    }
    if (KNI_IsNullHandle(rgbData)) {
        KNI_ThrowNew(midpNullPointerException, NULL);
    } else if((y < 0) || (x < 0) || (x + width > img_width) ||
              (y + height > img_height) || iae == KNI_TRUE) {
        KNI_ThrowNew(midpIllegalArgumentException, NULL);
    } else if (height < 0 || width < 0 ) {
        /* spec says noop in this case */
    } else {
        buflen = KNI_GetArrayLength(rgbData);
        if (offset < 0
            || offset + ((height - 1) * scanlength) + width > buflen
            || offset + ((height - 1) * scanlength) < 0) {
            KNI_ThrowNew(midpArrayIndexOutOfBoundsException, NULL);
        } else {
  	    gxutl_native_image_error_codes error = GXUTL_NATIVE_IMAGE_NO_ERROR;

	    SNI_BEGIN_RAW_POINTERS;

            rgbBuffer = JavaIntArray(rgbData);
	    gx_get_argb(srcImageDataPtr, rgbBuffer,
		       offset, scanlength,
		       x, y, width, height, &error);

	    SNI_END_RAW_POINTERS;

	    if (error != GXUTL_NATIVE_IMAGE_NO_ERROR) {
		KNI_ThrowNew(midpOutOfMemoryError, NULL);
	    }
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
示例#11
0
/**
 * Renders the given region of this <tt>ImmutableImage</tt> onto the
 * given <tt>Graphics</tt> object.
 * <p>
 * Java declaration:
 * <pre>
 *     renderRegion(Ljavax/microedition/lcdui/ImageImpl;IIIIIIII)V
 * </pre>
 *
 * @param g The <tt>Graphics</tt> object to be drawn
 * @param x_src The x coordinate of the upper-left corner of the
 *              source region
 * @param y_src The y coordinate of the upper-left corner of the
 *              source region
 * @param width The width of the source region
 * @param height The height of the source region
 * @param transform The transform to apply to the selected region.
 * @param x_dest The x coordinate of the destination anchor point
 * @param y_dest The y coordinate of the destination anchor point
 * @param anchor The anchor point for positioning the destination
 *               <tt>Image</tt>
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
KNIDECL(javax_microedition_lcdui_Image_renderRegion) {
    int anchor    = KNI_GetParameterAsInt(9);
    int y_dest    = KNI_GetParameterAsInt(8);
    int x_dest    = KNI_GetParameterAsInt(7);
    int transform = KNI_GetParameterAsInt(6);
    int height    = KNI_GetParameterAsInt(5);
    int width     = KNI_GetParameterAsInt(4);
    int y_src     = KNI_GetParameterAsInt(3);
    int x_src     = KNI_GetParameterAsInt(2);
    jboolean success = KNI_TRUE;

    KNI_StartHandles(3);
    KNI_DeclareHandle(img);
    KNI_DeclareHandle(g);
    KNI_DeclareHandle(gImg);

    KNI_GetParameterAsObject(1, g);
    KNI_GetThisPointer(img);
    
    if (GRAPHICS_OP_IS_ALLOWED(g)) {
      if (KNI_IsNullHandle(img)) {
        /* null checking is performed in the Java code, but check just in case */
        success = KNI_FALSE; //KNI_ThrowNew(midpNullPointerException, NULL);
      } else if ((transform < 0) || (transform > 7)) {
        success = KNI_FALSE; //KNI_ThrowNew(midpIllegalArgumentException, NULL);
      } else if (!gxutl_normalize_anchor(&x_dest, &y_dest,
					 width, height, anchor)) {
        success = KNI_FALSE; //KNI_ThrowNew(midpIllegalArgumentException, NULL);
      } else {
	const java_imagedata * srcImageDataPtr = GET_IMAGE_PTR(img)->imageData;
        jint img_width = srcImageDataPtr->width;
        jint img_height = srcImageDataPtr->height;

        GET_IMAGE_PTR(gImg) = (struct Java_javax_microedition_lcdui_Image *)
	                      (GXAPI_GET_GRAPHICS_PTR(g)->img);
        if (KNI_IsSameObject(gImg, img) || 
           (height < 0) || (width < 0) || (x_src < 0) || (y_src < 0) ||
           ((x_src + width) > img_width) || 
           ((y_src + height) > img_height)) {
          success = KNI_FALSE; //KNI_ThrowNew(midpIllegalArgumentException, NULL);
        } else {
	  jshort clip[4]; /* Defined in Graphics.java as 4 shorts */

	  const java_imagedata * dstMutableImageDataPtr = 
	    GXAPI_GET_IMAGEDATA_PTR_FROM_GRAPHICS(g);

	  GXAPI_TRANSLATE(g, x_dest, y_dest);
	  GXAPI_GET_CLIP(g, clip);

	  gx_render_imageregion(srcImageDataPtr, dstMutableImageDataPtr,
				clip, 
				x_src, y_src, 
				width, height,
				x_dest, y_dest, 
				transform);
        }
      }
    }

    KNI_EndHandles();
    KNI_ReturnBoolean(success);
}
示例#12
0
/**
 * Open a serial port by system dependent device name.
 *
 * @param name device name of the port
 * @param baud baud rate to set the port at
 * @param flags options for the serial port
 *
 * @return handle to a native serial port
 *
 * @exception  IOException  if an I/O error occurs.
 */
KNIEXPORT KNI_RETURNTYPE_INT
    Java_com_sun_midp_io_j2me_comm_Protocol_native_1openByName() {

    int    flags = (int)KNI_GetParameterAsInt(3);
    int    baud = (int)KNI_GetParameterAsInt(2);
    int    nameLen;
    char   szName[MAX_NAME_LEN];
    jchar* temp;
    int    hPort = (int)INVALID_HANDLE;
    int    i;
    int status = PCSL_NET_IOERROR;
    void* context = NULL;
    MidpReentryData* info;

    KNI_StartHandles(1);
    KNI_DeclareHandle(nameObject);
    KNI_GetParameterAsObject(1, nameObject);
    
    info = (MidpReentryData*)SNI_GetReentryData(NULL);
    if (info == NULL) {
        nameLen = KNI_GetStringLength(nameObject);
        if (nameLen > MAX_NAME_LEN) {
            midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                "Serial device name has wrong length: %d\n", nameLen);
            REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer);
            KNI_ThrowNew(midpIllegalArgumentException, gKNIBuffer);
        } else {
            temp = (jchar*)szName;
            KNI_GetStringRegion(nameObject, 0, nameLen, temp);

            /* device names are in ASCII */
            for (i = 0; i < nameLen; i++) {
                szName[i] = (char)temp[i];
            }
            szName[nameLen] = 0;
		
            status = openPortByNameStart(szName, baud, flags, &hPort, &context);
        }
    } else {
        /* reinvocation */
        hPort = info->descriptor;
        context = info->pResult;
        status = openPortByNameFinish(szName, baud, flags, &hPort, context);	
    }

    switch (status) {
        case PCSL_NET_SUCCESS:			
            /* do nothing and return normally */
            break;
        case PCSL_NET_INTERRUPTED:			
            midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                "Opening port %s has been interrupted\n", szName);
            REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer);
            KNI_ThrowNew(midpInterruptedIOException, gKNIBuffer);
            break;
        case PCSL_NET_WOULDBLOCK:			
            midp_thread_wait(COMM_OPEN_SIGNAL, hPort, context);
            break;
        default:	   
            midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                "Opening port %s was failed\n", szName);
            REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer);
            KNI_ThrowNew(midpIOException, gKNIBuffer);
    }

    KNI_EndHandles();
    KNI_ReturnInt((jint)hPort);
}
示例#13
0
/**
 * Write to a serial port without blocking.
 *
 * @param hPort handle to a native serial port
 * @param b I/O buffer
 * @param off starting offset for data
 * @param len length of data
 *
 * @return number of bytes that were written
 *
 * @exception  IOException  if an I/O error occurs.
 */
KNIEXPORT KNI_RETURNTYPE_INT
    Java_com_sun_midp_io_j2me_comm_Protocol_native_1writeBytes() {

    int  length = (int)KNI_GetParameterAsInt(4);
    int  offset = (int)KNI_GetParameterAsInt(3);
    int  hPort  = (int)KNI_GetParameterAsInt(1);
    int   bytesWritten = 0;
    int status = PCSL_NET_IOERROR;
    void* context = NULL;
    MidpReentryData* info;

    KNI_StartHandles(1);
    KNI_DeclareHandle(bufferObject);
    KNI_GetParameterAsObject(2, bufferObject);

    info = (MidpReentryData*)SNI_GetReentryData(NULL);
    if (info == NULL) {

        if (hPort < 0) {
            midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                "Write to port: handle %d is invalid\n", hPort);
            REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer);
            KNI_ThrowNew(midpIllegalArgumentException, gKNIBuffer);
        } else {        		
            SNI_BEGIN_RAW_POINTERS;
            status = writeToPortStart(hPort,
                (char*)&(JavaByteArray(bufferObject)[offset]),
                length, &bytesWritten, &context);
            SNI_END_RAW_POINTERS;
        }
    } else {
        /* reinvocation */
        hPort = info->descriptor;
        context = info->pResult;
        SNI_BEGIN_RAW_POINTERS;
        status = writeToPortFinish(hPort,
            (char*)&(JavaByteArray(bufferObject)[offset]),
            length, &bytesWritten, context);
        SNI_END_RAW_POINTERS;
    }

    switch (status) {
        case PCSL_NET_SUCCESS:			
            /*do nothing and return normally */
            break;
        case PCSL_NET_INTERRUPTED:			
            midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                "Writing to port %d has been interrupted\n", hPort);
            REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer);
            KNI_ThrowNew(midpInterruptedIOException, gKNIBuffer);
            break;
        case PCSL_NET_WOULDBLOCK:			
            midp_thread_wait(COMM_WRITE_SIGNAL, hPort, context);
            break;
        default:	   
            midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                "Writing to  port %d was failed\n", hPort);
            REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer);
            KNI_ThrowNew(midpIOException, gKNIBuffer);
    }
    	    
    KNI_EndHandles();
    KNI_ReturnInt((jint)bytesWritten);
    
}
示例#14
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();
}
示例#15
0
/**
 * Implementation of native method to queue a new Invocation.
 * The state of the InvocationImpl is copied to the heap
 * and inserted in the head of the invocation queue.
 * An StoredInvoc struct is allocated on the native heap and 
 * the non-null strings for each field of the InvocationImpl class
 * are copied to the heap.
 * A new transaction ID is assigned to this Invocation
 * and returned in the tid field of the InvocationImpl.
 * @param invoc the InvocationImpl to store
 * @throws OutOfMemoryError if the memory allocation fails
 * @see StoredInvoc
 * @see #invocQueue
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_content_InvocationStore_put0(void) {
    StoredInvoc* invoc = NULL;

    KNI_StartHandles(4);
    KNI_DeclareHandle(invocObj);
    KNI_DeclareHandle(classObj);
    KNI_DeclareHandle(argsObj);
    KNI_DeclareHandle(str);

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

    do {
        /* On any error break out of this block */
        /* Allocate a new zero'ed struct to save the values in */
        invoc = (StoredInvoc*) pcsl_mem_calloc(1, sizeof (StoredInvoc));
        if (invoc == NULL) {
            KNI_ThrowNew(midpOutOfMemoryError, 
                                "InvocationStore_put0 no memory for [invoc]");
            break;
        }
    
        /* Assign a new transaction id and set it */
        invoc->tid = invocNextTid();
        KNI_SetIntField(invocObj, tidFid, invoc->tid);
    
        /*
         * Copy all the parameters to native
         * Includes ID, type,url, action, args, data
         */
        if (KNI_TRUE != setParamsFromObj(invoc, invocObj, str, argsObj))
            break;
    
        invoc->previousTid = KNI_GetIntField(invocObj, previousTidFid);
    
        invoc->status = KNI_GetIntField(invocObj, statusFid);
        invoc->responseRequired =
            KNI_GetBooleanField(invocObj, responseRequiredFid);
    
        invoc->suiteId = KNI_GetIntField(invocObj, suiteIdFid);
    
        KNI_GetObjectField(invocObj, classnameFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->classname))
            break;
    
        KNI_GetObjectField(invocObj, invokingAuthorityFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, 
                                                    &invoc->invokingAuthority))
            break;
    
        KNI_GetObjectField(invocObj, invokingAppNameFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, 
                                                    &invoc->invokingAppName))
            break;
    
        invoc->invokingSuiteId = KNI_GetIntField(invocObj, invokingSuiteIdFid);
    
        KNI_GetObjectField(invocObj, invokingClassnameFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, 
                                                    &invoc->invokingClassname))
            break;
    
        KNI_GetObjectField(invocObj, invokingIDFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->invokingID))
            break;
    
        KNI_GetObjectField(invocObj, usernameFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->username))
            break;
    
        KNI_GetObjectField(invocObj, passwordFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->password))
            break;
    
        /* Insert the new Invocation at the end of the queue */
        if (!invocPut(invoc))
            break;
    
        unblockWaitingThreads(STATUS_OK);
    
        /* Clear to skip cleanup and throwing exception */
        invoc = NULL;
    } while (0);

    if (invoc != NULL) {
        /* An allocation error occurred; free any remaining */
        invocFree(invoc);
        KNI_ThrowNew(midpOutOfMemoryError, "invocStore.c allocation failed");
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
示例#16
0
/* Copy engine buffer back to MIDP */
void
JSR239_putWindowContents(jobject graphicsHandle,
                         jint delta_height,
                         JSR239_Pixmap *src, jint flipY) {

    void* s;
    void* d;

    KNI_StartHandles(1);
    KNI_DeclareHandle(GraphicsClassHandle);

#ifdef DEBUG
    printf("JSR239_putWindowContents >>\n");
#endif

    KNI_FindClass("javax/microedition/lcdui/Graphics", GraphicsClassHandle);
    if (!KNI_IsInstanceOf(graphicsHandle, GraphicsClassHandle)) {
#ifdef DEBUG
        printf("JSR239_putWindowContents only implemented for graphicsHandle "
               "instanceof Graphics!\n");
#endif
    } else {
        gxj_screen_buffer sbuf;
        gxj_screen_buffer* gimg;

        // Obtain the dimensions of the destination.
        jint dest_width = lcdlf_get_screen_width();
        jint dest_height = lcdlf_get_screen_height();

        jint min_height = 0;
        
        gimg = GXJ_GET_GRAPHICS_SCREEN_BUFFER(graphicsHandle, &sbuf);
        if (gimg != NULL) {
            dest_width = gimg->width;
            dest_height= gimg->height;
        }

#ifdef DEBUG
        printf("JSR239_putWindowContents:\n"); 
        printf("  src Bpp    = %d\n", src->pixelBytes);
        printf("  src width  = %d\n", src->width);
        printf("  src height = %d\n", src->height);
        printf("  min height = %d\n", min_height);
#endif

        /* IMPL_NOTE: get clip sizes into account. */
        copyToScreenBuffer(src, delta_height, flipY);

        /* src->screen_buffer is an output of copyToScreenBuffer function. */
        s = (void*)src->screen_buffer;
        d = (void*)getGraphicsBuffer(graphicsHandle);

        min_height = (dest_height > src->height) ? src->height : dest_height;

        if ((src->width  != dest_width) ||
            (sizeof(gxj_pixel_type) != 2)) {
#ifdef DEBUG
        printf("JSR239: offscreen buffer data is incorrect.\n");
#endif
        } else {
            /* Source data must be in 16bit 565 format. */
            JSR239_memcpy(d, s,
                dest_width * min_height * sizeof(gxj_pixel_type));
        }
    }

#ifdef DEBUG
    printf("JSR239_putWindowContents <<\n");
#endif

    KNI_EndHandles();
}
示例#17
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);
}
KNIEXPORT KNI_RETURNTYPE_OBJECT
KNIDECL(com_sun_midp_chameleon_skins_resources_LoadedSkinData_readStringArray) {
    int arrayLength;
    int i;

    KNI_StartHandles(2);
    KNI_DeclareHandle(returnArray);
    KNI_DeclareHandle(stringHandle);

    do {
        /*
         * First, read array length
         */
        ENSURE_SKIN_DATA_AVAILABILITY(sizeof(jint));
        memcpy((void*)&arrayLength, (void*)gsSkinFileDataPos, sizeof(jint));
        gsSkinFileDataPos += sizeof(jint);


        /*
         * Then create array
         */
        SNI_NewArray(SNI_STRING_ARRAY, arrayLength, returnArray);
        if (KNI_IsNullHandle(returnArray)) {
            KNI_ThrowNew(midpOutOfMemoryError, NULL);
            break;
        }

        /*
         * And finally populate it with strings
         */
        for (i = 0; i < arrayLength; ++i) {
            unsigned char dataLength;
            unsigned char encoding;

            /* read data length */
            ENSURE_SKIN_DATA_AVAILABILITY(sizeof(char));
            dataLength = *((unsigned char*)gsSkinFileDataPos);
            gsSkinFileDataPos += 1;

            /* read encoding */
            ENSURE_SKIN_DATA_AVAILABILITY(sizeof(char));
            encoding = *((unsigned char*)gsSkinFileDataPos);
            gsSkinFileDataPos += 1;

            ENSURE_SKIN_DATA_AVAILABILITY(dataLength * sizeof(char));

            if (encoding == STRING_ENCODING_USASCII) {    
                int j;

                /* 
                 * In case of USASCII encoding, each byte of 
                 * string data corresponds to one string char
                 */
                int stringLength = dataLength;

                /* use gKNIBuffer for storing string chars */
                jchar* stringChars = (jchar*)gKNIBuffer;
                
                /* 
                 * Safety measure to prevent gKNIBuffer overflow 
                 * (which should never happens unless something is broken) 
                 */
                if (stringLength > (int)(KNI_BUFFER_SIZE/sizeof(jchar))) {
                    stringLength = (int)(KNI_BUFFER_SIZE/sizeof(jchar));
                    REPORT_WARN(LC_HIGHUI, 
                            "gKNIBuffer is too small for skin string");
                }

                /* fill string chars array */
                for (j = 0; j < stringLength; ++j) {
                    stringChars[j] = gsSkinFileDataPos[j];
                }

                /* and create string from it */
                KNI_NewString(stringChars, stringLength, stringHandle);
            } else if (encoding == STRING_ENCODING_UTF8) {
                KNI_NewStringUTF((char*)gsSkinFileDataPos, stringHandle);
            } else {
                KNI_ThrowNew(midpIllegalStateException, 
                        "Illegal skin string encoding");
                break;
            }
            
            KNI_SetObjectArrayElement(returnArray, i, stringHandle);

            gsSkinFileDataPos += dataLength;
        }

    } while (0);

    KNI_EndHandlesAndReturnObject(returnArray);
}
示例#19
0
/*  private native int _eglCreatePbufferSurface ( int display , int config , int [ ] attrib_list ) ; */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_khronos_egl_EGL10Impl__1eglCreatePbufferSurface() {

    jint display = KNI_GetParameterAsInt(1);
    jint config = KNI_GetParameterAsInt(2);
    EGLint *attrib_list = (EGLint *)0;

    jint returnValue = (jint)EGL_NO_SURFACE;

    KNI_StartHandles(2);
    KNI_DeclareHandle(attrib_listHandle);
    KNI_DeclareHandle(thisHandle);

    KNI_GetParameterAsObject(3, attrib_listHandle);
    KNI_GetThisPointer(thisHandle);

    /* Construct attrib_list as a copy of attrib_listHandle if non-null */
    if (!KNI_IsNullHandle(attrib_listHandle)) {
        jint attrib_list_length, attrib_list_size;

	attrib_list_length = KNI_GetArrayLength(attrib_listHandle);
	attrib_list_size = attrib_list_length*sizeof(jint);
	attrib_list = (EGLint *)JSR239_malloc(attrib_list_size);
	if (!attrib_list) {
            KNI_ThrowNew("java.lang.OutOfMemoryException",
			 "eglCreatePbufferSurface");
	    goto exit;
	}
	KNI_GetRawArrayRegion(attrib_listHandle, 0, attrib_list_size,
			      (jbyte *) attrib_list);
    }

#ifdef DEBUG
    {
        int idx = 0;
        int attr;
     
#ifdef DEBUG
        printf("In eglCreatePbufferSurface:\n");
#endif
        if (!attrib_list) {
#ifdef DEBUG
            printf("attrib_list is null!\n");
#endif
        } else {
            while (1) {
                attr = attrib_list[idx++];
#ifdef DEBUG
                printf("attr[%d] = 0x%x\n", idx, attr);
#endif
                if (attr == EGL_NONE) {
                    break;
                }
            }
        }
    }
#endif
        
    returnValue = (jint)eglCreatePbufferSurface((EGLDisplay)display,
						(EGLConfig)config,
						(EGLint const *) attrib_list);

#ifdef DEBUG
    if (returnValue > 0) {
        ++surfaces;
    }

    printf("eglCreatePbufferSurface(0x%x, 0x%x, attrib_list) = %d, surfaces = %d\n",
	   display, config, returnValue, surfaces);

    {
        EGLint error; /* debugging */
        error = eglGetError();
        if (error != EGL_SUCCESS) {
            printf("egl error = 0x%x\n", error);
        }
    }
#endif

 exit:
    if (attrib_list) {
	JSR239_free(attrib_list);
    }

    KNI_EndHandles();
    KNI_ReturnInt(returnValue);
}
示例#20
0
/*  private native int _eglGetConfigs ( int display , int [ ] configs , int config_size , int [ ] num_config ) ; */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_khronos_egl_EGL10Impl__1eglGetConfigs() {

    jint display = KNI_GetParameterAsInt(1);
    jint config_size = KNI_GetParameterAsInt(3);
    
    EGLConfig *configs = (EGLConfig *)0;
    EGLint num_config = 0;

    jint returnValue = EGL_FALSE;

    KNI_StartHandles(2);
    KNI_DeclareHandle(configsHandle);
    KNI_DeclareHandle(num_configHandle);

    KNI_GetParameterAsObject(2, configsHandle);
    KNI_GetParameterAsObject(4, num_configHandle);

    if (!KNI_IsNullHandle(configsHandle)) {
	configs = (EGLConfig *)JSR239_malloc(config_size*sizeof(EGLint));
	if (!configs) {
            KNI_ThrowNew("java.lang.OutOfMemoryException", "eglGetConfigs");
	    goto exit;
	}
    }

    returnValue = (jint)eglGetConfigs((EGLDisplay)display,
				      configs,
				      (EGLint)config_size,
				      &num_config);

#ifdef DEBUG
    printf("num_config = %d\n", num_config);
#endif

#ifdef ALL_WINDOWS_ARE_PIXMAPS
    {
      EGLBoolean ok;
      EGLint surfaceType;
      int i, j;

        // Remove all configs that are for windows only
        if (returnValue && configs) {
            for (i = 0; i < num_config; i++) {
                ok = eglGetConfigAttrib((EGLDisplay)display, configs[i],
                                        EGL_SURFACE_TYPE, &surfaceType);
                if ((surfaceType & (EGL_PIXMAP_BIT | EGL_PBUFFER_BIT)) == 0) {
                    for (j = i; j < num_config - 1; j++) {
                        configs[j] = configs[j + 1];
                    }
                    configs[--num_config] = 0;
#ifdef DEBUG
                    printf("Deleting a config, num_config = %d\n", num_config);
#endif
                }
            }
        }
    }
#endif

#ifdef DEBUG
    printf("eglGetConfigs(0x%x, configs, %d, num_config<-%d) = %d\n",
	   display, config_size, num_config, returnValue);
#endif
    
    if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(configsHandle)) {
	KNI_SetRawArrayRegion(configsHandle, 0, config_size*sizeof(EGLint),
			      (const jbyte *)configs);
    }
    if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(num_configHandle)) {
        KNI_SetIntArrayElement(num_configHandle, 0, num_config);
    }
    
 exit:
    if (configs) {
	JSR239_free(configs);
    }
    KNI_EndHandles();
    KNI_ReturnInt(returnValue);
}
示例#21
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);
}
示例#22
0
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_INT
    Java_com_sun_j2me_location_PlatformLocationProvider_open() {

    MidpReentryData *info = NULL;
    ProviderInfo *pInfo = NULL;
    jsr179_result res;
    jsr179_handle pProvider = NULL;
    jint provider = 0;
    
    KNI_StartHandles(1);
    GET_PARAMETER_AS_PCSL_STRING(1, name)
    info = (MidpReentryData*)SNI_GetReentryData(NULL);
    if (info == NULL) {
        res = jsr179_provider_open(name, &pProvider);
        switch (res) {
            case JSR179_STATUSCODE_OK:
                /* handler returned immediatelly */
                provider = (jint)pProvider;
                register_provider(provider);
                break;
            case JSR179_STATUSCODE_INVALID_ARGUMENT:
                /* wrong provider name */
                KNI_ThrowNew(midpIllegalArgumentException, 
                            "wrong provider name");
                break;
            case JSR179_STATUSCODE_FAIL:
                /* fail */
                KNI_ThrowNew(midpIOException, "open failed");
                break;
            case JSR179_STATUSCODE_WOULD_BLOCK:
                /* wait for javanotify */
                provider = (jint)pProvider;
                pInfo = register_provider(provider);
                if (pInfo != NULL) {
                    pInfo->locked = KNI_TRUE;
                }
                lock_thread(JSR179_EVENT_OPEN_COMPLETED, provider);
                break;
            default:
                break;
        }
    } else {
        /* Second call for this thread - finish open */
        if (info->status == JSR179_STATUSCODE_OK) {
            /* Provider opened successfully */
            provider = info->descriptor;
            pInfo = getProviderInfo(provider);
            if (pInfo != NULL) {
                pInfo->locked = KNI_FALSE;
            }
        } else {
            /* Provider open failed*/
            unregister_provider(provider);
            provider = 0;
        }
    }

    RELEASE_PCSL_STRING_PARAMETER
    KNI_EndHandles();
    KNI_ReturnInt(provider);
}
示例#23
0
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_cldc_io_j2me_socket_Protocol_open0() {
  init_sockets();

  SocketOpenParameter *p = (SocketOpenParameter*) SNI_GetReentryData(NULL);
  if (p == NULL) {
    p = (SocketOpenParameter*) SNI_AllocateReentryData(sizeof(*p));
    p->fd = -1;

    struct hostent *phostent;
    KNI_StartHandles(1);
    KNI_DeclareHandle(hostname_object);
    KNI_GetParameterAsObject(1, hostname_object);

    // hostname is always NUL terminated. See socket/Protocol.java for detail.
    char *hostname = (char*) SNI_GetRawArrayPointer(hostname_object);
    phostent = (struct hostent*)jvm_gethostbyname(hostname);
    KNI_EndHandles();

    if (phostent == NULL) {
      KNI_ReturnInt(-1);
    }
    struct sockaddr_in destination_sin;
    destination_sin.sin_family = AF_INET;
    int port = KNI_GetParameterAsInt(2);
    destination_sin.sin_port = jvm_htons(port);
    jvm_memcpy((char *) &destination_sin.sin_addr, phostent->h_addr,
                phostent->h_length);

    p->fd = jvm_socket(AF_INET, SOCK_STREAM, 0);
    if (p->fd < 0) {
       KNI_ReturnInt(-1);
    }
    if (!set_blocking_flags(&p->fd, /*is_blocking*/ KNI_FALSE)) {
      KNI_ReturnInt(-1);
    }

    if (jvm_connect(p->fd, (struct sockaddr *) &destination_sin,
                    sizeof(destination_sin)) < 0) {
      int err_code = GET_LAST_ERROR();
      if (err_code == EINPROGRESS) {
        // When the socket is ready for connect, it becomes *writable*
        // (according to BSD socket spec of select())
        p->check_flags = CHECK_WRITE | CHECK_EXCEPTION;
        SNI_BlockThread();
      } else {
        jvm_shutdown(p->fd, 2);
        closesocket(p->fd);
        p->fd = -1;
      }
    }
    KNI_ReturnInt(p->fd);
  } else {
    // When we come to here, a CheckEvent() call has reported one of the
    // following:
    // [1] connect() has succeeded. In this case we return the socket fd.
    // [2] connect() has failed. In this case CheckEvent has already closed
    //     the socket and set p->fd to -1. So we'd be returning -1.
    KNI_ReturnInt(p->fd);
  }
}
示例#24
0
/**
 * 
 * Resets the request or response flags for listener notification.
 * Each request or response is marked as not having been notified.
 *
 * @param suiteId to match a pending invocation
 * @param classname to match a pending invocation
 * @param mode one of {@link #MODE_LREQUEST}, {@link #MODE_LRESPONSE}
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_content_InvocationStore_setListenNotify0(void) {
    StoredLink* link;
    StoredInvoc* invoc;
    SuiteIdType desiredSuiteId;
    pcsl_string desiredClassname = PCSL_STRING_NULL_INITIALIZER;

    KNI_StartHandles(2);
    KNI_DeclareHandle(classname); /* Arg2: non-null classname */
    int mode;                  /* Arg3: requested invocation mode */

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

    do {/* Block to break out of on exceptions */
        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_setListenNotify0 no memory for [desiredClassname]");
                break;
            }
    
            /* Get the desired request mode. */
            mode = KNI_GetParameterAsInt(listenModeArg);
    
            /* Inspect the queue of Invocations and pick one that
             * matches the suiteId and classname
             */
            for (link = invocQueue; link != NULL; link = link->flink) {
                invoc = link->invoc;
                /*
                 * If the status matches the request
                 * and the suite matches and the classname matches.
                 */
                if (mode == MODE_LREQUEST &&
                    invoc->status == STATUS_INIT) {
                       /* This invocation is a match; check classname and suite below */
                } else if (mode == MODE_LRESPONSE &&
                       (invoc->status >= STATUS_OK &&
                        invoc->status <= STATUS_INITIATED)) {
                    /* A pending response; check classname and suite below */
                } else {
                    /* Not this invocation; on to the next */
                    continue;
                }
                /* Check if this is the right class and suite */
                if (desiredSuiteId == invoc->suiteId &&
                    pcsl_string_equals(&desiredClassname, &invoc->classname)) {
                    /* Reset the flag so this Invocation will notify. */
                    invoc->notified = KNI_FALSE;
                }
            }
        }
    } while (KNI_FALSE);

    /* TBD: MidpMalloc failure not reported; not found is returned */

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

    KNI_EndHandles();
    KNI_ReturnVoid();
}
示例#25
0
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
    Java_com_sun_j2me_location_PlatformLocationProvider_waitForNewLocation() {

    jboolean ret = KNI_FALSE;
    MidpReentryData *info = NULL;
    ProviderInfo *pInfo = NULL;
    jsr179_result res;
    jint provider;
    jlong timeout;
    KNI_StartHandles(1);
    provider = KNI_GetParameterAsInt(1);
    timeout = KNI_GetParameterAsLong(2);
    pInfo = getProviderInfo(provider);
    if(pInfo != NULL) {
        info = (MidpReentryData*)SNI_GetReentryData(NULL);
        if (info == NULL) {
            /* First call -request */
            if(pInfo->locked == KNI_TRUE) {
                lock_thread(JSR179_EVENT_UPDATE_ONCE, provider);
            } else {
                /* request new location */
                res = jsr179_update_set((jsr179_handle)provider, timeout);
                switch (res) {
                    case JSR179_STATUSCODE_WOULD_BLOCK:
                        /* wait for javanotify */
                        pInfo->locked = KNI_TRUE;
                        lock_thread(JSR179_EVENT_UPDATE_ONCE, provider);
                        break;
                    case JSR179_STATUSCODE_OK:
                        /* location updated successfully */
                        pInfo->locked = KNI_FALSE;
			            pInfo->newLocationAvailable = KNI_TRUE;
                        ret = KNI_TRUE;
                        break;
                    case JSR179_STATUSCODE_FAIL:
                        /* fail */
                        pInfo->locked = KNI_FALSE;
                        /* wrong provider name */
                        KNI_ThrowNew(midpIllegalArgumentException, 
                                    "wrong provider");
                        break;
                    default:
                        /* fail */
                        pInfo->locked = KNI_FALSE;
                        break;
                }
            }
        } else {
            /* Response */
            if (info->status == JSR179_STATUSCODE_OK) {
                /* location updated successfully */
				pInfo->newLocationAvailable = KNI_TRUE;
                ret = KNI_TRUE;
            } else {
                /* location updated failed */
                ret = KNI_FALSE;
            }
            pInfo->locked = KNI_FALSE;
        }
    }
    KNI_EndHandles();
    KNI_ReturnBoolean(ret);
}
示例#26
0
/*
 * Accepts incoming client connection request.
 *
 * Note: the method gets native connection handle directly from
 * <code>handle<code> field of <code>BTSPPNotifierImpl</code> object.
 *
 * Note: new native connection handle to work with accepted incoming
 * client connection is setted directly to <code>handle</code> field of
 * appropriate <code>RFCOMMConnectionImpl</code> object.
 *
 * @throws IOException if an I/O error occurs
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_jsr082_bluetooth_btspp_BTSPPNotifierImpl_accept0(void) {
    javacall_handle handle = JAVACALL_BT_INVALID_HANDLE;
    javacall_handle peer_handle = JAVACALL_BT_INVALID_HANDLE;
    MidpReentryData* info;
    int status = JAVACALL_FAIL;
    int processStatus = KNI_FALSE;
    void *context = NULL;
    javacall_bt_address peer_addr;
    jfieldID notifHandleID = NULL;
    jfieldID peerHandleID  = NULL;
    jfieldID peerAddrID    = NULL;
    jfieldID pushHandleID  = NULL;

    KNI_StartHandles(3);
    KNI_DeclareHandle(thisHandle);
    KNI_DeclareHandle(arrayHandle);
    KNI_DeclareHandle(classHandle);
    KNI_GetClassPointer(classHandle);

    GET_FIELDID(classHandle, "handle", "I", notifHandleID)
    GET_FIELDID(classHandle, "peerHandle", "I", peerHandleID)
    GET_FIELDID(classHandle, "peerAddress", "[B", peerAddrID)
    GET_FIELDID(classHandle, "pushHandle", "I", pushHandleID)
    KNI_GetThisPointer(thisHandle);
    handle = (javacall_handle)KNI_GetIntField(thisHandle, notifHandleID);
    KNI_GetObjectField(thisHandle, peerAddrID, arrayHandle);

    if (handle == JAVACALL_BT_INVALID_HANDLE) {
        REPORT_ERROR(LC_PROTOCOL,
            "RFCOMM notifier was closed before btspp_notif::accept");
        KNI_ThrowNew(midpInterruptedIOException, EXCEPTION_MSG(
            "RFCOMM notifier was closed"));
    } else {
#ifndef NO_PUSH
        bt_pushid_t pushid = KNI_GetIntField(thisHandle, pushHandleID);
        if (pushid != BT_INVALID_PUSH_HANDLE) {
            if (bt_push_checkout_client(pushid, &peer_handle, peer_addr,
                    NULL, NULL) == JAVACALL_OK) {
                pushcheckoutaccept((int)handle);
                processStatus = KNI_TRUE;
                status = JAVACALL_OK;
            }
        }
#endif
        if (peer_handle == JAVACALL_BT_INVALID_HANDLE) {

        info = (MidpReentryData*)SNI_GetReentryData(NULL);
		if (info == NULL) {   /* First invocation */
            REPORT_INFO1(LC_PROTOCOL,
                "btspp_notif::accept handle=%d\n", handle);

            // Need revisit: add resource counting
            /*
             * An incoming socket connection counts against the client socket
             * resource limit.
             */
/*
            if (midpCheckResourceLimit(RSC_TYPE_BT_CLI, 1) == 0) {
                const char* pMsg =
                    "Resource limit exceeded for BT client sockets";
                REPORT_INFO(LC_PROTOCOL, pMsg);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
*/
//            } else {
                status = javacall_bt_rfcomm_accept(
                    handle, &peer_handle, &peer_addr);
				processStatus = KNI_TRUE;
//            }
		} else {  /* Reinvocation after unblocking the thread */
			if ((javacall_handle)info->descriptor != handle) {
                midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "btspp_notif::accept handles mismatched %d != %d\n",
                    handle, info->descriptor);
                REPORT_CRIT(LC_PROTOCOL, gKNIBuffer);
                KNI_ThrowNew(midpIllegalStateException, EXCEPTION_MSG(
                    "Internal error in btspp_notif::accept"));
            } else {
                // Need revisit: add resource counting
/*
                if (midpCheckResourceLimit(RSC_TYPE_BT_CLI, 1) == 0) {
                    const char* pMsg =
                        "Resource limit exceeded for BT client sockets"
                    REPORT_INFO(LC_PROTOCOL, pMsg);
                    KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
                } else {
*/
                    context = info->pResult;
				    status = javacall_bt_rfcomm_accept(
                        handle, &peer_handle, &peer_addr);
					processStatus = KNI_TRUE;
//                }
            }
        }

        }

        if (processStatus) {
            REPORT_INFO1(LC_PROTOCOL,
                "btspp_notif::accept server handle=%d\n", handle);
            if (status == JAVACALL_OK) {

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

                // store client native connection handle for temporary storing
                KNI_SetIntField(thisHandle, peerHandleID, (jint)peer_handle);

                // copy address to Java object field
                KNI_SetRawArrayRegion(arrayHandle, 0, JAVACALL_BT_ADDRESS_SIZE, (jbyte*) peer_addr);

                REPORT_INFO(LC_PROTOCOL,
                    "btspp_notif::accept incoming connection accepted!");
            } else if (status == JAVACALL_WOULD_BLOCK) {
                midp_thread_wait(NETWORK_READ_SIGNAL, (int)handle, context);
            } else if (status == JAVACALL_FAIL) {
                char* pError;
                javacall_bt_rfcomm_get_error(handle, &pError);
                midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "IO error in btspp_notif::accept (%s)\n", pError);
                REPORT_INFO(LC_PROTOCOL, gKNIBuffer);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(gKNIBuffer));

            } else {
                char* pMsg = "Unknown error during btspp_notif::accept";
                REPORT_INFO(LC_PROTOCOL, pMsg);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
            }
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
示例#27
0
/*  private native int _eglChooseConfig ( int display , int [ ] attrib_list , int [ ] configs , int config_size , int [ ] num_config ) ; */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_khronos_egl_EGL10Impl__1eglChooseConfig() {
    
    jint display = KNI_GetParameterAsInt(1);
    jint config_size = KNI_GetParameterAsInt(4);
    EGLint *attrib_list = (EGLint *)0;
    EGLConfig *configs = (EGLConfig *)0;
    EGLint num_config;

    jint returnValue = EGL_FALSE;

    KNI_StartHandles(3);
    KNI_DeclareHandle(attrib_listHandle);
    KNI_DeclareHandle(configsHandle);
    KNI_DeclareHandle(num_configHandle);

    KNI_GetParameterAsObject(2, attrib_listHandle);
    KNI_GetParameterAsObject(3, configsHandle);
    KNI_GetParameterAsObject(5, num_configHandle);

    if (!KNI_IsNullHandle(attrib_listHandle)) {
        jint attrib_list_length, attrib_list_size;
        /* Construct attrib_list as a copy of attrib_listHandle */
        attrib_list_length = KNI_GetArrayLength(attrib_listHandle);
        attrib_list_size = (attrib_list_length + 2)*sizeof(jint);
        attrib_list = (EGLint *)JSR239_malloc(attrib_list_size);
        if (!attrib_list) {
            KNI_ThrowNew("java.lang.OutOfMemoryException", "eglChooseConfig");
            goto exit;
        }
        KNI_GetRawArrayRegion(attrib_listHandle, 0, attrib_list_size,
                              (jbyte *)attrib_list);
    }

#ifdef ALL_WINDOWS_ARE_PIXMAPS
    // Force queries with SURFACE_TYPE == WINDOW to actually query pixmap
    if (attrib_list) {
        jint attr, val, idx;

        idx = 0;
        while (1) {
            attr = attrib_list[idx];
#ifdef DEBUG
            printf("attr[%d] = %d\n", idx, attr);
#endif
            if (attr == EGL_NONE) {
#ifdef DEBUG
                printf("attr = EGL_NONE, done\n");
#endif
                break;
            }
            if (attr == EGL_SURFACE_TYPE) {
#ifdef DEBUG
                printf("attr = EGL_SURFACE_TYPE\n");
#endif
                val = attrib_list[idx + 1];
                if ((val & EGL_WINDOW_BIT) != 0) {
#ifdef DEBUG
                    printf("Switching WINDOW_BIT to PIXMAP_BIT\n");
#endif
                    val |= EGL_PIXMAP_BIT;
                    val &= ~EGL_WINDOW_BIT;
                }   
            }
            idx += 2;
        }
    }
#endif

    /* Allocate config_size elements if configsHandle is non-null */
    if (!KNI_IsNullHandle(configsHandle)) {
	configs = (EGLConfig *)JSR239_malloc(config_size*sizeof(EGLint));
	if (!configs) {
            KNI_ThrowNew("java.lang.OutOfMemoryException", "eglChooseConfig");
	    goto exit;
	}
    }
    
    returnValue = (jint)eglChooseConfig((EGLDisplay)display, attrib_list,
					configs, config_size, &num_config);
#ifdef DEBUG
    printf("eglChooseConfig(0x%x, attrib_list, configs, %d, num_config<-%d) = %d\n",
	   display, config_size, num_config, returnValue);
#endif

    /* Copy configs back to Java */
    if (returnValue == EGL_TRUE && !KNI_IsNullHandle(configsHandle)) {
	KNI_SetRawArrayRegion(configsHandle, 0, config_size*sizeof(EGLint),
			      (const jbyte *)configs);
    }
    /* Set output parameter via num_configHandle */
    if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(num_configHandle)) {
        KNI_SetIntArrayElement(num_configHandle, 0, num_config);
    }

 exit:
    if (attrib_list) {
	JSR239_free(attrib_list);
    }
    if (configs) {
	JSR239_free(configs);
    }

    KNI_EndHandles();
    KNI_ReturnInt(returnValue);
}
示例#28
0
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_VOID
    Java_com_sun_j2me_location_LocationInfo_initNativeClass() {

    KNI_StartHandles(1);
    KNI_DeclareHandle(class_obj);

    KNI_GetClassPointer(class_obj);
    if(!KNI_IsNullHandle(class_obj)) {
        locationInfoFieldID.isValid = 
            KNI_GetFieldID(class_obj, "isValid", "Z");
        locationInfoFieldID.timestamp = 
            KNI_GetFieldID(class_obj, "timestamp", "J");
        locationInfoFieldID.latitude = 
            KNI_GetFieldID(class_obj, "latitude", "D");
        locationInfoFieldID.longitude = 
            KNI_GetFieldID(class_obj, "longitude", "D");
        locationInfoFieldID.altitude = 
            KNI_GetFieldID(class_obj, "altitude", "F");
        locationInfoFieldID.horizontalAccuracy = 
            KNI_GetFieldID(class_obj, "horizontalAccuracy", "F");
        locationInfoFieldID.verticalAccuracy = 
            KNI_GetFieldID(class_obj, "verticalAccuracy", "F");
        locationInfoFieldID.speed = 
            KNI_GetFieldID(class_obj, "speed", "F");
        locationInfoFieldID.course = 
            KNI_GetFieldID(class_obj, "course", "F");
        locationInfoFieldID.method = 
            KNI_GetFieldID(class_obj, "method", "I");
        locationInfoFieldID.isAddressInfo = 
            KNI_GetFieldID(class_obj, "isAddressInfo", "Z");
        locationInfoFieldID.AddressInfo_EXTENSION = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_EXTENSION", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_STREET = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_STREET", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_POSTAL_CODE = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_POSTAL_CODE", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_CITY = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_CITY", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_COUNTY = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_COUNTY", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_STATE = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_STATE", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_COUNTRY = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_COUNTRY", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_COUNTRY_CODE = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_COUNTRY_CODE", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_DISTRICT = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_DISTRICT", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_BUILDING_NAME = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_BUILDING_NAME", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_BUILDING_FLOOR = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_BUILDING_FLOOR", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_BUILDING_ROOM = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_BUILDING_ROOM", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_BUILDING_ZONE = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_BUILDING_ZONE", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_CROSSING1 = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_CROSSING1", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_CROSSING2 = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_CROSSING2", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_URL = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_URL", "Ljava/lang/String;");
        locationInfoFieldID.AddressInfo_PHONE_NUMBER = 
            KNI_GetFieldID(class_obj, 
                "AddressInfo_PHONE_NUMBER", "Ljava/lang/String;");
        locationInfoFieldID.extraInfoNMEA = 
            KNI_GetFieldID(class_obj, "extraInfoNMEA", "Ljava/lang/String;");
        locationInfoFieldID.extraInfoLIF = 
            KNI_GetFieldID(class_obj, "extraInfoLIF", "Ljava/lang/String;");
        locationInfoFieldID.extraInfoPlain = 
            KNI_GetFieldID(class_obj, "extraInfoPlain", "Ljava/lang/String;");
        locationInfoFieldID.extraInfoOther = 
            KNI_GetFieldID(class_obj, "extraInfoOther", "Ljava/lang/String;");
        locationInfoFieldID.extraInfoOtherMIMEType = 
            KNI_GetFieldID(class_obj, "extraInfoOtherMIMEType", "Ljava/lang/String;");
    } else {
        KNI_ThrowNew(midpNullPointerException, NULL);
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
示例#29
0
/*  private native int _eglCopyBuffers ( int display , int surface , Graphics target ) ; */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_khronos_egl_EGL10Impl__1eglCopyBuffers() {
    EGLDisplay display = (EGLDisplay) KNI_GetParameterAsInt(1);
    EGLSurface surface = (EGLSurface) KNI_GetParameterAsInt(2);
    jint width = KNI_GetParameterAsInt(4);
    jint height = KNI_GetParameterAsInt(5);
    jint delta_height = KNI_GetParameterAsInt(6);
    jint clipX = KNI_GetParameterAsInt(7);
    jint clipY = KNI_GetParameterAsInt(8);
    jint clipWidth = KNI_GetParameterAsInt(9);
    jint clipHeight = KNI_GetParameterAsInt(10);
    JSR239_Pixmap* pixmap;

    // eglCopyBuffers copies the EGL surface color buffer to a native pixmap.
    // As the native pixmaps the Graphics opbject are used. Thus eglCopyBuffers
    // can not be used as the destination buffer can be of a different size as
    // the source surface. In these case call to eglCopyBuffers may lead to
    // the memory corruption.
    // Of course it is more efficient ot use eglCopyBuffers instead of workaround
    // with glReadPixels, but we should do additional checks to do it safely.

    // Let glReadPixels return the data in the following format: 
    const jint bytesPerPixel = 4;
    
    // for data type for glReadPixels we use GL_UNSIGNED_BYTE, one
    // byte for each component
    const jint alphaSize = 8;
    const jint redSize = 8;
    const jint greenSize = 8;
    const jint blueSize = 8;

    KNI_StartHandles(1);
    KNI_DeclareHandle(graphicsHandle);
    KNI_GetParameterAsObject(3, graphicsHandle);

    pixmap = JSR239_getImagePixmap(graphicsHandle, width, height,
                                   bytesPerPixel,
                                   alphaSize, redSize, greenSize, blueSize);

    if (!pixmap) {
        KNI_ThrowNew("java.lang.OutOfMemoryException", "eglCopyBuffers");
        goto exit;
    }

    // Enforce RGBA order of glReadPixels
    pixmap->aOffset = redSize + greenSize + blueSize;
    pixmap->bOffset = greenSize + blueSize;
    pixmap->gOffset = blueSize;
    pixmap->rOffset = 0;

    eglCopyBuffersWorkaround((EGLDisplay)display, (EGLSurface)surface, pixmap);

    // glReadPixels returns pixel data from the color buffer, starting with the
    // pixel whose lower left corner is at location (x, y), into client memory
    // starting at location pixels. Thus we should flip the data returned by
    // glReadPixels
    JSR239_putWindowContents(graphicsHandle, delta_height, 
                             pixmap, 
                             clipX, clipY, clipWidth, clipHeight,
                             1 /*should do flip*/);
    JSR239_destroyPixmap(pixmap);
    
 exit:
    KNI_EndHandles();
    KNI_ReturnInt(EGL_TRUE);
}
示例#30
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);
}