extern "C" void
gxpport_destroy_mutable(gxpport_mutableimage_native_handle imagePtr) {

    /* we know : 
       non-null QPixmap object has been allocated */  
    QPixmap* qpixmap = (QPixmap *)(imagePtr);

    /* make sure there is a valid qpixmap */
    if (qpixmap == NULL) {
	return;
    }

    MScreen * mscreen = qteapp_get_mscreen();
    if (mscreen->isCurrentPaintDevice(qpixmap)) { 
        // remove pixmap as the current painting device 
        short clip[] = {0, 0, 0, 0}; 
        mscreen->setupGC(-1, -1, clip, NULL, 0); 
    } 

    /* Update the resource count */
    if (midpDecResourceCount(RSC_TYPE_IMAGE_MUT, ImgRscSize(qpixmap)) == 0) {
        REPORT_INFO(LC_LOWUI,"Error in updating resource limit for" 
                             " Mutable image");
    }

    /* RELEASE QT RESOURCES HELD */
    delete qpixmap;
}
void gxpport_destroy_immutable(gxpport_image_native_handle imagePtr) {

    _Platform_ImmutableImage* immutableImage = 
        (_Platform_ImmutableImage*)imagePtr;

    if (NULL != immutableImage) {
        if (NULL != immutableImage->qimage) {
            int rscSize = ImgRscSize(immutableImage->qimage);

            /* Update the resource count */
            if (midpDecResourceCount(RSC_TYPE_IMAGE_IMMUT, rscSize) == 0) {
                REPORT_ERROR(LC_LOWUI,"Error in updating resource limit for"
                             " Immutable image");
            }

            delete immutableImage->qimage;
        }

        if (NULL != immutableImage->qpixmap) {
            delete immutableImage->qpixmap;
        }

	midpFree(immutableImage);
    }
}
Exemple #3
0
/*
 * Close a opened by storage_open. Does no block.
 *
 * If not successful *ppszError will set to point to an error string,
 * on success it will be set to NULL.
 */
void
storageClose(char** ppszError, int handle) {
    int status;

    *ppszError = NULL;
    status = pcsl_file_close((void *)handle);

    REPORT_INFO2(LC_CORE, "storageClose on file_desc %d returns %d\n",
          handle, status);

    if (status < 0) {
        *ppszError = getLastError("storageClose()");
    }

    /* File is successfully closed, decrement the count */
    if (midpDecResourceCount(RSC_TYPE_FILE, 1) == 0) {
        REPORT_INFO(LC_CORE, "FILE: resource"
                             " limit update error");
    }
}
Exemple #4
0
/**
 * Releases any native resources used by the socket connection.
 * <p>
 * Java declaration:
 * <pre>
 *     finalize(V)V
 * </pre>
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_io_j2me_socket_Protocol_finalize(void) {
    void *pcslHandle;
    int status = PCSL_NET_INVALID;
    void* context = NULL;

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

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

    REPORT_INFO1(LC_PROTOCOL, "socket::finalize handle=%d\n", pcslHandle);

    if (INVALID_HANDLE != pcslHandle) {
        status = pcsl_socket_close_start(pcslHandle, &context);

        getMidpSocketProtocolPtr(thisObject)->handle = (jint)INVALID_HANDLE;
        if (midpDecResourceCount(RSC_TYPE_TCP_CLI, 1) == 0) {
            REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); 
        }

        if (status == PCSL_NET_IOERROR) { 
            midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "IOError in socket::finalize error=%d\n", 
                    (int)pcsl_network_error(pcslHandle));
            REPORT_ERROR1(LC_PROTOCOL, "%s", gKNIBuffer);
        } else if (status == PCSL_NET_WOULDBLOCK) {
            /* blocking during finalize is not supported */
            REPORT_CRIT1(LC_PROTOCOL, "socket::finalize = 0x%x blocked\n", 
                         pcslHandle);
        }
    }
    FINISH_NETWORK_INDICATOR;

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Exemple #5
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();
}
Exemple #6
0
/**
 * Opens a TCP connection to a server.
 * <p>
 * Java declaration:
 * <pre>
 *     open([BI)V
 * </pre>
 *
 * @param ipBytes Byte array that represents a raw IP address
 * @param port TCP port at host
 *
 * @return a native handle to the network connection.
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_io_j2me_socket_Protocol_open0(void) {
    int   port;
    void *pcslHandle = INVALID_HANDLE;
    int status;
    void* context = NULL;
    MidpReentryData* info;

    port = (int)KNI_GetParameterAsInt(2);

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

    info = (MidpReentryData*)SNI_GetReentryData(NULL);
    if (info == NULL) {   /* First invocation */
       getMidpSocketProtocolPtr(thisObject)->handle = (jint)INVALID_HANDLE;

       /**
         * Verify that the resource is available well within limit as per 
         * the policy in ResourceLimiter
         */
        if (midpCheckResourceLimit(RSC_TYPE_TCP_CLI, 1) == 0) {
            REPORT_INFO(LC_PROTOCOL,
                "Resource limit exceeded for TCP client sockets"); 
            KNI_ThrowNew(midpIOException,
                "Resource limit exceeded for TCP client sockets");
        } else {
            SNI_BEGIN_RAW_POINTERS;
            status = pcsl_socket_open_start(
                     (unsigned char*)JavaByteArray(bufferObject),
                     port, &pcslHandle, &context);
            SNI_END_RAW_POINTERS;

            if (status == PCSL_NET_SUCCESS) {
                getMidpSocketProtocolPtr(thisObject)->handle = (jint)pcslHandle;
                if (midpIncResourceCount(RSC_TYPE_TCP_CLI, 1) == 0) {
                    REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); 
                }
            } else if (status == PCSL_NET_IOERROR) {
                midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                        "IOError in socket::open = %d\n",
                        (int)pcsl_network_error(pcslHandle));
                REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer);
                KNI_ThrowNew(midpIOException, gKNIBuffer);
            } else if (status == PCSL_NET_CONNECTION_NOTFOUND) {
                midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, 
                        "ConnectionNotFound error in socket::open :" 
                        " error = %d\n", (int)pcsl_network_error(pcslHandle));
                REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer); 
                KNI_ThrowNew(midpConnectionNotFoundException, gKNIBuffer);
            } else if (status == PCSL_NET_WOULDBLOCK) {
                INC_NETWORK_INDICATOR;
                getMidpSocketProtocolPtr(thisObject)->handle = (jint)pcslHandle;
                if (midpIncResourceCount(RSC_TYPE_TCP_CLI, 1) == 0) {
                    REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); 
                }
                REPORT_INFO1(LC_PROTOCOL, " handle = %d\n", pcslHandle);
                midp_thread_wait(NETWORK_WRITE_SIGNAL, (int)pcslHandle,
                    context);
            } else {
                REPORT_INFO(LC_PROTOCOL, "Unknown error during socket::open"); 
                KNI_ThrowNew(midpIOException, NULL);
            }
        }
    } else {  /* Reinvocation after unblocking the thread */
        pcslHandle = (void *) info->descriptor;
        context = (void *)info->status;

        if (getMidpSocketProtocolPtr(thisObject)->handle != (jint)pcslHandle) {
            REPORT_CRIT2(LC_PROTOCOL, 
                         "socket::open Handles mismatched 0x%x != 0x%x\n", 
                         pcslHandle,
                         getMidpSocketProtocolPtr(thisObject)->handle);
        }

        status = pcsl_socket_open_finish(pcslHandle, context);

        if (status == PCSL_NET_SUCCESS) {
            DEC_NETWORK_INDICATOR;
        } else if (status == PCSL_NET_WOULDBLOCK) {
            midp_thread_wait(NETWORK_WRITE_SIGNAL, (int)pcslHandle, context);
        } else  {
            DEC_NETWORK_INDICATOR;
            getMidpSocketProtocolPtr(thisObject)->handle = (jint)INVALID_HANDLE;
            if (midpDecResourceCount(RSC_TYPE_TCP_CLI, 1) == 0) {
                REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); 
            }
            midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "error %d in socket::open",
                    (int)pcsl_network_error(pcslHandle));
            REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer); 
            KNI_ThrowNew(midpConnectionNotFoundException, gKNIBuffer);
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Exemple #7
0
/**
 * Closes the socket connection.
 * <p>
 * Java declaration:
 * <pre>
 *     close0(V)V
 * </pre>
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_io_j2me_socket_Protocol_close0(void) {
    void *pcslHandle;
    int status = PCSL_NET_INVALID;
    void* context = NULL;
    MidpReentryData* info;

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


    info = (MidpReentryData*)SNI_GetReentryData(NULL);
    if (info == NULL) {
        /* initial invocation */
        pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle);

        if (INVALID_HANDLE == pcslHandle) {
            KNI_ThrowNew(midpIOException,
                "invalid handle during socket::close");
        } else {
            status = pcsl_socket_close_start(pcslHandle, &context);

            getMidpSocketProtocolPtr(thisObject)->handle =
                (jint)INVALID_HANDLE;

            midp_thread_signal(NETWORK_READ_SIGNAL, (int)pcslHandle, 0);
            midp_thread_signal(NETWORK_WRITE_SIGNAL, (int)pcslHandle, 0);
        }
    } else {
        /* reinvocation */
        pcslHandle = (void *)(info->descriptor);
        context = info->pResult;
        status = pcsl_socket_close_finish(pcslHandle, context);
    }
 
    REPORT_INFO1(LC_PROTOCOL, "socket::close handle=%d\n", pcslHandle);

    if (INVALID_HANDLE != pcslHandle) {
        if (status == PCSL_NET_SUCCESS) {
            if (midpDecResourceCount(RSC_TYPE_TCP_CLI, 1) == 0) {
                REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); 
            }
        } else if (status == PCSL_NET_WOULDBLOCK) {
            REPORT_INFO1(LC_PROTOCOL, "socket::close = 0x%x blocked\n", 
                         pcslHandle);
            /* IMPL NOTE: unclear whether this is the right signal */
            midp_thread_wait(NETWORK_READ_SIGNAL, (int)pcslHandle, context);
        } else {
            /* must be PCSL_NET_IOERROR */
            midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "IOError in socket::close = %d\n", 
                    (int)pcsl_network_error(pcslHandle));
            REPORT_INFO1(LC_PROTOCOL, "%s", gKNIBuffer);
            KNI_ThrowNew(midpIOException, gKNIBuffer);
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Exemple #8
0
/**
 * Closes the datagram connection.
 * <p>
 * Java declaration:
 * <pre>
 *     close0(V)V
 * </pre>
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_io_j2me_datagram_Protocol_close0(void) {
    void *socketHandle;
    MidpReentryData *info;

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

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

    info = (MidpReentryData*)SNI_GetReentryData(NULL);

    REPORT_INFO1(LC_PROTOCOL, "datagram::close handle=0x%x",
        (int)socketHandle);

    if (socketHandle != INVALID_HANDLE) {
        int status;

        status = pushcheckin((int)socketHandle);
        if (status == -1) {
            void *context = NULL;

            if (info == NULL) {
                /* first invocation */
                INC_NETWORK_INDICATOR;
                status = pcsl_datagram_close_start(socketHandle, &context);

                getMidpDatagramProtocolPtr(thisObject)->nativeHandle =
                    (jint)INVALID_HANDLE;

                midp_thread_signal(NETWORK_READ_SIGNAL, (int)socketHandle, 0);
                midp_thread_signal(NETWORK_WRITE_SIGNAL, (int)socketHandle, 0);
            } else {
                /* reinvocation */
                socketHandle = (void *)(info->descriptor);
                context = info->pResult;
                status = pcsl_datagram_close_finish(socketHandle, context);
            }

            if (status == PCSL_NET_WOULDBLOCK) {
                /* IMPL NOTE: unclear whether this is the right signal */
                midp_thread_wait(NETWORK_READ_SIGNAL, (int)socketHandle,
                    context);
            } else {
                /* PCSL_NET_SUCCESS or PCSL_NET_IOERROR */
                DEC_NETWORK_INDICATOR;
                if (midpDecResourceCount(RSC_TYPE_UDP, 1) == 0) {
                    REPORT_INFO(LC_PROTOCOL,
                        "datagram::close0 resource limit update error");
                }
                if (status != PCSL_NET_SUCCESS) {
                    midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                        "error code %d", pcsl_network_error(socketHandle));
                    REPORT_INFO1(LC_PROTOCOL, "datagram::close %s",
                        gKNIBuffer);
                    KNI_ThrowNew(midpIOException, gKNIBuffer);
                }
            }
        } else {
            /* it was checked into push; don't really close the socket
               but notify a possible listeners to be unblocked */
            getMidpDatagramProtocolPtr(thisObject)->nativeHandle =
                                                   (jint)INVALID_HANDLE;
            midp_thread_signal(NETWORK_READ_SIGNAL, (int)socketHandle, 0);
            midp_thread_signal(NETWORK_WRITE_SIGNAL, (int)socketHandle, 0);
        }
    } else {
        if (info == NULL) {
            /* first invocation */
            /* already closed, do nothing */
        } else {
            /* reinvocation */
            DEC_NETWORK_INDICATOR;
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}