/** * Gets a handle to specific character encoding conversion routine. * <p> * Java declaration: * <pre> * getHandler(Ljava/lang/String;)I * </pre> * * @param encoding character encoding * * @return identifier for requested handler, or <tt>-1</tt> if * the encoding was not supported. */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_cldc_i18n_j2me_Conv_getHandler() { jint result = 0; KNI_StartHandles(1); KNI_DeclareHandle(str); KNI_GetParameterAsObject(1, str); if (!KNI_IsNullHandle(str)) { int strLen = KNI_GetStringLength(str); jchar* strBuf; /* Instead of always multiplying the length by sizeof(jchar), * we shift left by 1. This can be done because jchar has a * size of 2 bytes. */ strBuf = (jchar*)midpMalloc(strLen<<1); if (strBuf != NULL) { KNI_GetStringRegion(str, 0, strLen, strBuf); result = getLcConvMethodsID(strBuf, strLen); midpFree(strBuf); } else { KNI_ThrowNew(midpOutOfMemoryError, NULL); } } KNI_EndHandles(); KNI_ReturnInt(result); }
/** * Sets a property key to the specified value. * * @param props The property set in which to add/modify <tt>key</tt> * @param key The key to set * @param value The value to set <tt>key</tt> to */ static void setProp(Property** props, const char* key , const char* value) { /* Try to find the property in the current pool. */ Property *p; for (p= *props; p; p = p->next) { if (strcmp(key, p->key) == 0) { midpFree((void*)p->value); p->value = midpStrdup(value); /* * if midpStrdup fails we will just return without setting * the value to anything other than NULL */ return; } } /* If the value is not defined, add it now */ p = (Property*)midpMalloc(sizeof(Property)); if (NULL != p){ p->next = *props ; p->key = midpStrdup(key); p->value = midpStrdup(value); if ((p->key == NULL) || (p->value == NULL)) { /* do nothing if there is no memory */ midpFree((void*)p->key); midpFree((void*)p->value); midpFree(p); return; } *props = p ; } }
static void sendControlStringField(KNIDECLARGS kjobject objectHandle, kjobject stringObj, jfieldID fieldID) { int len; jchar *data = NULL; (void) _arguments; (void) _p_mb; (void) _ee; KNI_GetObjectField(objectHandle, fieldID, stringObj); len = KNI_GetStringLength(stringObj); if (len > 0) { data = (jchar*)midpMalloc(len * sizeof(jchar)); if (data == NULL) { len = 0; /* IMPL_NOTE: throw out of memory */ } else { KNI_GetStringRegion(stringObj, 0, len, data); } } write(controlPipe[1], &len, sizeof(int)); if (len > 0) { write(controlPipe[1], data, len * sizeof(jchar)); midpFree(data); } }
/* * Insert a new node to the front of the linked list * * @param suiteId : ID of the suite * @param name : Name of the record store * @param handle : Handle of the opened file * * @return 0 if node is successfully inserted * return OUT_OF_MEM_LEN if memory allocation fails * */ static int recordStoreCreateLock(SuiteIdType suiteId, const pcsl_string * name_str, int handle) { lockFileList* newNodePtr; newNodePtr = (lockFileList *)midpMalloc(sizeof(lockFileList)); if (newNodePtr == NULL) { return OUT_OF_MEM_LEN; } newNodePtr->suiteId = suiteId; /*IMPL_NOTE: check for error codes instead of null strings*/ pcsl_string_dup(name_str, &newNodePtr->recordStoreName); if (pcsl_string_is_null(&newNodePtr->recordStoreName)) { midpFree(newNodePtr); return OUT_OF_MEM_LEN; } newNodePtr->handle = handle; newNodePtr->next = NULL; if (lockFileListPtr == NULL) { lockFileListPtr = newNodePtr; } else { newNodePtr->next = lockFileListPtr; lockFileListPtr = newNodePtr; } return 0; }
extern "C" MidpError QString2pcsl_string(QString &qstring, pcsl_string &pstring) { pcsl_string_status pe; if (qstring.isNull()) { pstring = PCSL_STRING_NULL; } else if (qstring.isEmpty()) { pstring = PCSL_STRING_EMPTY; } else { jint mstring_len = qstring.length(); jchar* mstring_data = (jchar *)midpMalloc(sizeof(jchar) * mstring_len); if (mstring_data == NULL) { pstring = PCSL_STRING_NULL; return KNI_ENOMEM; } else { for (int i = 0; i < mstring_len; i++) { mstring_data[i] = qstring[i].unicode(); } pe = pcsl_string_convert_from_utf16(mstring_data, mstring_len, &pstring); midpFree(mstring_data); if (PCSL_STRING_OK != pe) { return KNI_ENOMEM; } } } return KNI_OK; }
/** * Get index of supported locales for collation by its name. * <p> * Java declaration: * <pre> * getDevLocaleIndex(Ljava/lang/String)I * </pre> * * @param locale name * @return internal index of locale or -1 if locale is not supported */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_j2me_global_CollationAbstractionLayerImpl_getCollationLocaleIndex() { jint result =-1, index = 0; jsize len = 0; int error = 0; jchar* locale_name; KNI_StartHandles(1); KNI_DeclareHandle(hstr1); KNI_GetParameterAsObject(1, hstr1); if (KNI_IsNullHandle(hstr1)) { locale_name = NULL; } else { len = KNI_GetStringLength(hstr1); locale_name = (jchar *)midpMalloc((len + 1) * sizeof(jchar)); if (NULL == locale_name) { KNI_ThrowNew(midpOutOfMemoryError, "Out of memory"); error = 1; } else { KNI_GetStringRegion(hstr1, 0, len, locale_name); locale_name[len]=0; } } if (!error){ result = jsr238_get_collation_locale_index(locale_name, &index); if (result < 0) index =-1; midpFree(locale_name); } KNI_EndHandles(); KNI_ReturnInt(index); }
static void readControlStringField(KNIDECLARGS kjobject objectHandle, jfieldID fieldID) { int len, i; jchar *data; (void) _arguments; (void) _p_mb; read(controlPipe[0], &len, sizeof(int)); data = (jchar*)midpMalloc(len * sizeof(jchar)); if (data != NULL) { read(controlPipe[0], data, len * sizeof(jchar)); } else { for (i=0; i<len; i++) { jchar dummy; read(controlPipe[0], &dummy, sizeof(jchar)); } len = 0; /* IMPL_NOTE: throw out of memory */ } KNI_StartHandles(1); KNI_DeclareHandle(stringObj); KNI_NewString(data, len, stringObj); KNI_SetObjectField(objectHandle, fieldID, stringObj); KNI_EndHandles(); }
/** * Initializes the event system. * <p> * <b>NOTE:</b> The event system must be explicitly initialize so the * VM can shutdown and restart cleanly. * * @return 0 for success, or non-zero if the MIDP implementation is * out of memory */ int InitializeEvents(void) { int sizeInBytes; if (NULL != pEventQueues) { /* already done */ return 0; } #if ENABLE_MULTIPLE_ISOLATES maxIsolates = JVM_MaxIsolates(); #endif sizeInBytes = maxIsolates * sizeof (EventQueue); pEventQueues = midpMalloc(sizeInBytes); if (NULL == pEventQueues) { return -1; } memset(pEventQueues, 0, sizeInBytes); midp_createEventQueueLock(); return 0; }
/** * Gets the length of a specific converted string. * <p> * Java declaration: * <pre> * getByteLength(I[BII)I * </pre> * * @param handler handle returned from getHandler * @param b buffer of bytes to be converted * @param offset offset into the provided buffer * @param len length of data to be processed * * @return length of the converted string, or zero if the * arguments were not valid */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_cldc_i18n_j2me_Conv_getByteLength() { int length = KNI_GetParameterAsInt(4); int offset = KNI_GetParameterAsInt(3); int id = KNI_GetParameterAsInt(1); char* buf; jint result = 0; KNI_StartHandles(1); KNI_DeclareHandle(b); KNI_GetParameterAsObject(2, b); buf = (char*)midpMalloc(length); if (buf == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { KNI_GetRawArrayRegion(b, offset, length, (jbyte*)buf); result = lcConv[id] ? lcConv[id]->byteLen((const unsigned char *) buf, length) : 0; midpFree(buf); } KNI_EndHandles(); KNI_ReturnInt(result); }
/** * Converts an array of bytes to converted array of characters. * <p> * Java declaration: * <pre> * byteToChar(I[BII[CII)I * </pre> * * @param handler handle returned from getHandler * @param input buffer of bytes to be converted * @param in_offset offset into the provided buffer * @param in_len length of data to be processed * @param output buffer of converted bytes * @param out_offset offset into the provided output buffer * @param out_len length of data processed * * @return length of the converted string, or zero if the * arguments were not valid */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_cldc_i18n_j2me_Conv_byteToChar() { int outLength = KNI_GetParameterAsInt(7); int outOffset = KNI_GetParameterAsInt(6); int inLength = KNI_GetParameterAsInt(4); int inOffset = KNI_GetParameterAsInt(3); int id = KNI_GetParameterAsInt(1); char* inBuf; jchar* outBuf; jint result = 0; KNI_StartHandles(2); KNI_DeclareHandle(output); KNI_DeclareHandle(input); KNI_GetParameterAsObject(5, output); KNI_GetParameterAsObject(2, input); inBuf = (char*)midpMalloc(inLength); if (inBuf != NULL) { /* Instead of always multiplying the length by sizeof(jchar), * we shift left by 1. This can be done because jchar has a * size of 2 bytes. */ outBuf = (jchar*)midpMalloc(outLength<<1); if (outBuf != NULL) { KNI_GetRawArrayRegion(input, inOffset, inLength, (jbyte*)inBuf); result = (lcConv[id] ? lcConv[id]->nativeToUnicode((const unsigned char *) inBuf, inLength, outBuf, outLength): 0); KNI_SetRawArrayRegion(output, outOffset<<1, outLength<<1, (jbyte*)outBuf); midpFree(inBuf); midpFree(outBuf); } else { midpFree(inBuf); KNI_ThrowNew(midpOutOfMemoryError, NULL); } } else { KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_EndHandles(); KNI_ReturnInt(result); }
/** * Duplicates a NULL-terminated string. * <p> * <b>NOTE:</b> It is important that the caller of this function * properly dispose of the returned string. * * @param str The string to duplicate * * @return The duplicate string upon success. If the system is out of * memory, <tt>NULL</tt> is returned */ char* strdup(const char* str) { int len = strlen(str); char* p = (char*) midpMalloc(len + 1); if (p != NULL){ memcpy(p, str, len); p[len] = '\0'; } return p; /* null if p could not be allocated */ }
/** Reset the MIDlet proxy list for the next run of the VM. */ void midpMIDletProxyListReset() { #if ENABLE_MULTIPLE_DISPLAYS int sizeInBytes = maxDisplays * sizeof(int); gForegroundDisplayIds = midpMalloc(sizeInBytes); memset(gForegroundDisplayIds, 0, sizeInBytes); #else gForegroundDisplayId = -1; #endif // ENABLE_MULTIPLE_DISPLAYS gForegroundIsolateId = midpGetAmsIsolateId(); }
/** * Opens a file and fills the content of the file in the result_buf. <BR> * This function made memory allocation inside. * * @param filename Path to the file. * @param result_buf Pointer to the buffer that will be filled by content of the file. * @return buffer file size in bytes */ long readJadFile(const pcsl_string * filename, char** result_buf) { int fd = 0; char* err = NULL; long bufsize = -1; int numread = 0; char* res = *result_buf; if (pcsl_string_length(filename) <= 0) { REPORT_INFO(LC_AMS, "readJadFile():No file name."); return BAD_PARAMS; } fd = storage_open(&err, filename, OPEN_READ); if(err != NULL) { REPORT_INFO1(LC_AMS, "readJadFile():Can't open jad file '%s'",err); storageFreeError(err); return NO_JAD_FILE; } bufsize = storageSizeOf(&err, fd); if((bufsize <= 0) || (err != NULL)) { REPORT_INFO1(LC_AMS, "readJadFile():Problem getting file size: %s", err ); storageFreeError(err); return IO_ERROR; } res = (char*)midpMalloc(bufsize+1); if (res == NULL || (err != NULL)) { REPORT_INFO1(LC_AMS, "readJadFile():Can't allocate memory. %s", err); storageFreeError(err); return OUT_OF_MEMORY; } memset(res,0,(bufsize+1)); REPORT_INFO2(LC_AMS, "fd = %d, bufsize = %ld\n", fd, bufsize); numread = storageRead(&err, fd, res, bufsize); if((numread <= 0) || (numread != bufsize) || (err)) { REPORT_INFO3(LC_AMS, "size = %ld, numread = %d, err = %s.", bufsize, numread, err); storageClose(&err, fd); return IO_ERROR; } REPORT_INFO2(LC_AMS, "size = %ld, numread = %d", bufsize, numread); storageClose(&err, fd); if(err != NULL) { REPORT_INFO1(LC_AMS, "Can't close jad file %s\n", err); } *result_buf = res; return bufsize; } /* end of readJadFile */
/** * Starts a new process to handle the given URL. The new process executes * the value of the <tt>com.sun.midp.midlet.platformRequestCommand</tt> * system property. The URL is passed as this process' sole command-line * argument. * * @param pszUrl The 'C' string URL * * @return true if the platform request is configured */ int platformRequest(char* pszUrl) { (void)pszUrl; #if 0 char *execargs[3]; STARTUPINFO si; PROCESS_INFORMATION pi; if (strlen(pszUrl) == 0) { /* * This is a request to cancel. Since a process was already spawned * to handle the previous URL, it too late. */ return 1; } execargs[0] = (char *)getInternalProp(PLATFORM_REQUEST_KEY); if (execargs[0] == NULL) { REPORT_WARN(LC_AMS, "PlatformRequest is not configured."); return 0; } execargs[1] = pszUrl; /* leave room for a space and zero terminator */ execargs[2] = (char*)midpMalloc(strlen(execargs[0]) + strlen(execargs[1]) + 2); if (execargs[2] == NULL) { REPORT_WARN(LC_AMS, "PlatformRequest ran out of memory."); return 0; } strcpy(execargs[2], execargs[0]); strcat(execargs[2], " "); strcat(execargs[2], execargs[1]); memset(&si, 0, sizeof(si)); si.cb = sizeof(si); // spawn the request using the configured URL handler and URL parameter /* * do not inherit handles */ if (CreateProcess(NULL, execargs[2], NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } else { REPORT_WARN(LC_AMS, "Spawning a handler process failed. Check the platformRequest configuration. "); } midpFree(execargs[2]); #endif return 1; }
/** * Sets a property key to the specified value. If the key does * not exist and <tt>useMalloc<tt> is <tt>KNI_TRUE<tt>, use * <tt>midpMalloc()<tt> to make a copy of the contents of * <tt>key<tt>. If the key does not exist and <tt>useMalloc<tt> * is <tt>KNI_FALSE<tt>, make a copy of the pointer to * <tt>key<tt>. If the <tt>key<tt> already exists in the * property lists, modify its associated value. * * @param propertySet The property set in which to add/modify * <tt>key<tt> * @param key The key to set * @param value The value to associate with <tt>key<tt> * @param useMalloc If <tt>KNI_TRUE<tt>, use <tt>midpMalloc()<tt> * to make a copy of the contents of <tt>value<tt>, * otherwise make a copy of the pointer to * <tt>value<tt>. */ static void setProp(Property** propertySet, const char* key, const char* value, jboolean useMalloc) { Property *p; for (p = *propertySet; p; p = p->next) { if (strcmp(key, p->key) == 0) { if (IS_NEW_VALUE(p)) { midpFree((void *)p->value); } if (useMalloc) { SET_NEW_VALUE(p); p->value = midpStrdup(value); } else { UNSET_NEW_VALUE(p); p->value = value; } /* * if midpStrdup fails we will just return without setting * the value to anything other than NULL */ return; } } /* If the value is not defined, add it now */ p = (Property*)midpMalloc(sizeof(Property)); if (NULL != p){ p->next = *propertySet; CLEAR_FLAGS(p); if (useMalloc) { SET_NEW_VALUE(p); SET_NEW_KEY(p); p->key = midpStrdup(key); p->value = midpStrdup(value); } else { UNSET_NEW_VALUE(p); UNSET_NEW_KEY(p); p->value = value; p->key = key; } if ((p->key == NULL) || (p->value == NULL && value != NULL)) { /* do nothing if there is no memory */ if (useMalloc) { midpFree((void *)p->key); midpFree((void *)p->value); } midpFree((void *)p); return; } *propertySet = p ; } }
int midpIterateJarEntries(void *handle, filterFuncT *filter, actionFuncT *action) { MidpJarInfo *pJarInfo = (MidpJarInfo*)handle; JarEntryInfo entryInfo; pcsl_string entryName; unsigned char *nameBuf; int status = 1; pcsl_string_status res; entryInfo = getFirstJarEntryInfo(&pJarInfo->fileObj, &pJarInfo->jarInfo); while (entryInfo.status == 0) { nameBuf = (unsigned char*) midpMalloc(entryInfo.nameLen); if (nameBuf == NULL) { status = MIDP_JAR_OUT_OF_MEM_ERROR; break; } entryInfo.status = getJarEntryName(&pJarInfo->fileObj, &entryInfo, nameBuf); if (entryInfo.status != 0) { status = MIDP_JAR_CORRUPT_ERROR; midpFree(nameBuf); break; } res = pcsl_string_convert_from_utf8((jbyte*)nameBuf, entryInfo.nameLen, &entryName); midpFree(nameBuf); if (PCSL_STRING_OK != res) { status = MIDP_JAR_OUT_OF_MEM_ERROR; break; } if ((*filter)(&entryName)) { /* name match: call action */ if (!(*action)(&entryName)) { status = 0; pcsl_string_free(&entryName); break; } } pcsl_string_free(&entryName); entryInfo = getNextJarEntryInfo(&pJarInfo->fileObj, &pJarInfo->jarInfo, &entryInfo); } return status; }
/** * Deletes an entry from the push registry. * <p> * Java declaration: * <pre> * del0([B[B)I * </pre> * * @param connection The connection to remove from the push registry * @param storage The storage name of the current MIDlet suite * * @return <tt>0</tt> if the connection was successfully deleted. * <tt>-1</tt> if the connection was not found. <tt>-2</tt> * if connection was found, but, it belongs to another * MIDlet suite. */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_midp_io_j2me_push_ConnectionRegistry_del0) { char *szConn = NULL; int connLen; char *szStore = NULL; int storeLen; int ret = -1; KNI_StartHandles(2); KNI_DeclareHandle(conn); KNI_DeclareHandle(storage); /* Get the connection string. */ KNI_GetParameterAsObject(1, conn); connLen = KNI_GetArrayLength(conn); if ((szConn = midpMalloc(connLen)) != NULL) { KNI_GetRawArrayRegion(conn, 0, connLen, (jbyte*)szConn); /* Get the storage name string. */ KNI_GetParameterAsObject(2, storage); storeLen = KNI_GetArrayLength(storage); if ((szStore = midpMalloc(storeLen)) != NULL) { KNI_GetRawArrayRegion(storage, 0, storeLen, (jbyte*)szStore); /* Perform the delete operation. */ ret = pushdel(szConn, szStore); midpFree(szStore); } else { KNI_ThrowNew(midpOutOfMemoryError, NULL); } midpFree(szConn); } else { KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_EndHandles(); KNI_ReturnInt(ret); }
/** Creates new record store listener and adds it to the list of know listeners */ static void createListenerNode( int suiteId, pcsl_string *recordStoreName, int listenerId) { pcsl_string_status rc; RecordStoreListener *newPtr; newPtr = (RecordStoreListener *)midpMalloc( sizeof(RecordStoreListener)); if (newPtr == NULL) { REPORT_CRIT(LC_RMS, "rms_registry: OUT OF MEMORY"); return; } newPtr->listenerId = (int *)midpMalloc(maxTasks * sizeof(int)); if (newPtr->listenerId == NULL) { REPORT_CRIT(LC_RMS, "rms_registry: OUT OF MEMORY"); return; } newPtr->count = 1; newPtr->suiteId = suiteId; newPtr->listenerId[0] = listenerId; rc = pcsl_string_dup(recordStoreName, &newPtr->recordStoreName); if (rc != PCSL_STRING_OK) { midpFree(newPtr); REPORT_CRIT(LC_RMS, "rms_registry: OUT OF MEMORY"); return; } newPtr->next = NULL; if (rootListenerPtr== NULL) { rootListenerPtr= newPtr; } else { newPtr->next = rootListenerPtr; rootListenerPtr = newPtr; } }
/** * Perform the reverse conversion of unicodeToEscapedAscii(). * * @param str a string previously returned by escape() * @return the original string before the conversion by escape(). */ static pcsl_string_status escaped_ascii_to_unicode(const pcsl_string* str, pcsl_string* result) { int result_len=0; jchar* result_data = NULL; pcsl_string_status status = PCSL_STRING_OK; GET_PCSL_STRING_DATA_AND_LENGTH(str) do { int i; result_data = (jchar*)midpMalloc(str_len * sizeof (jchar)); if (result_data == NULL) { status = PCSL_STRING_ENOMEM; break; } for (i = 0, result_len = 0; i < str_len; i++) { jchar c = str_data[i]; if (c == '%') { jchar v = 0; v += hexValue(str_data[i+1]); v <<= 4; v += hexValue(str_data[i+2]); v <<= 4; v += hexValue(str_data[i+3]); v <<= 4; v += hexValue(str_data[i+4]); i += 4; result_data[result_len] = v; result_len++; } else if (c == '#') { /* drop c */ } else { result_data[result_len] = c; result_len++; } } } while(0); RELEASE_PCSL_STRING_DATA_AND_LENGTH if (PCSL_STRING_OK == status) { if (PCSL_STRING_OK != pcsl_string_convert_from_utf16(result_data, result_len, result)) { status = PCSL_STRING_ENOMEM; } } midpFree(result_data); return status; }
DWORD WINAPI CreateWinCEWindow(LPVOID lpParam) { static MidpReentryData newSignal; static MidpEvent newMidpEvent; int screenSize = sizeof(gxj_pixel_type) * CHAM_WIDTH * CHAM_HEIGHT; /* IMPL_NOTE: Need a better way to load the library */ #ifdef CVM_PRELOAD_LIB instanceMain = LoadLibrary(TEXT("cvmi.dll")); #else #ifdef CVM_DEBUG instanceMain = LoadLibrary(TEXT("libmidp_g.dll")); #else instanceMain = LoadLibrary(TEXT("libmidp.dll")); #endif #endif gxj_system_screen_buffer.width = CHAM_WIDTH; gxj_system_screen_buffer.height = CHAM_HEIGHT; gxj_system_screen_buffer.alphaData = 0; gxj_system_screen_buffer.pixelData = (gxj_pixel_type *)midpMalloc(screenSize); memset(gxj_system_screen_buffer.pixelData, 0xff, screenSize); if (!init_windows(GetModuleHandle(NULL), SW_SHOW)) { REPORT_ERROR(LC_AMS, "init_gui() failed"); MessageBox(NULL, TEXT("Failed to start JWC"), TEXT("Bye"), MB_OK); } updateVisibleDesktop(); #if JWC_WINCE_USE_DIRECT_DRAW init_DirectDraw(); #else if (GXOpenDisplay(hwndMain, 0) == 0) { REPORT_ERROR(LC_HIGHUI, "GXOpenDisplay() failed"); } gxDispProps = GXGetDisplayProperties(); #endif createEditors(); #ifdef ENABLE_JSR_184 engine_initialize(); #endif MIDP_EVENT_INITIALIZE(newMidpEvent); while (1) { checkForSystemSignal(&newSignal, &newMidpEvent, 200); } }
extern "C" void gxpport_createimmutable_from_mutable (gxpport_mutableimage_native_handle srcMutableImagePtr, gxpport_image_native_handle *newImmutableImagePtr, gxutl_native_image_error_codes* creationErrorPtr) { /* Convert from source QPixmap to destination QImage */ QPixmap* srcPixmap = gxpportqt_get_mutableimage_pixmap(srcMutableImagePtr); int rscSize = ImgRscSize(srcPixmap); /* new img is the same size */ /* Check resource limit before copying */ if (midpCheckResourceLimit(RSC_TYPE_IMAGE_IMMUT, rscSize) == 0) { /* Exceeds resource limit */ *creationErrorPtr = GXUTL_NATIVE_IMAGE_RESOURCE_LIMIT; return; } _Platform_ImmutableImage* immutableImage = (_Platform_ImmutableImage*)midpMalloc(sizeof(_Platform_ImmutableImage)); if (immutableImage == NULL) { *creationErrorPtr = GXUTL_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR; return; } immutableImage->qimage = new QImage(srcPixmap->convertToImage()); if (NULL == immutableImage->qimage) { midpFree(immutableImage); *creationErrorPtr = GXUTL_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR; return; } if (immutableImage->qimage->isNull()) { delete immutableImage->qimage; midpFree(immutableImage); *creationErrorPtr = GXUTL_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR; return; } /* Copying succeeds */ if (midpIncResourceCount(RSC_TYPE_IMAGE_IMMUT, rscSize) == 0) { REPORT_ERROR(LC_LOWUI, "Error in updating resource limit" " for Immutable image"); } immutableImage->marker = 1; immutableImage->qpixmap = NULL; *newImmutableImagePtr = immutableImage; *creationErrorPtr = GXUTL_NATIVE_IMAGE_NO_ERROR; }
/* * IMPL_NOTE: this function is the same as midpGetJarEntry() in midpJar.c, * but it uses only CLDC stuff */ jboolean midp_readJarEntry(const pcsl_string* jarName, const pcsl_string* entryName, jobject* entry) { JvmPathChar* platformJarName; int i; jboolean noerror = KNI_TRUE; GET_PCSL_STRING_DATA_AND_LENGTH(jarName) /* Entry names in JARs are UTF-8. */ const jbyte * const platformEntryName = pcsl_string_get_utf8_data(entryName); do { if (platformEntryName == NULL) { noerror = KNI_FALSE; break; } /* * JvmPathChars can be either 16 bits or 8 bits so we can't * assume either. */ /* * Conversion to JvmPathChars is only temporary, we should change the VM * should take a jchar array and a length and pass that to * PCSL which will then perform * a platform specific conversion (DBCS on Win32 or UTF8 on Linux) */ platformJarName = midpMalloc((jarName_len + 1) * sizeof (JvmPathChar)); if (platformJarName == NULL) { noerror = KNI_FALSE; break; } for (i = 0; i < jarName_len; i++) { platformJarName[i] = (JvmPathChar)jarName_data[i]; } platformJarName[i] = 0; Jvm_read_jar_entry(platformJarName, (char*)platformEntryName, (jobject)*entry); midpFree(platformJarName); } while(0); pcsl_string_release_utf8_data(platformEntryName, entryName); RELEASE_PCSL_STRING_DATA_AND_LENGTH if (noerror) { return (KNI_IsNullHandle((jobject)*entry) == KNI_TRUE) ? KNI_FALSE : KNI_TRUE; } else { return KNI_FALSE; } }
// Note: the caller is responsible for calling 'midpFree' after use extern "C" char* getNativePathForRoot(const char* root) { DEBUG_PRINT("getNativePathForRoot"); if (si != NULL) { const QString path = si->getPathForRoot(root); if (!path.isEmpty()) { char* res = (char*)midpMalloc(path.length()+1); return strcpy(res, path); } } return NULL; }
/** * Create a new entry and enqueue in data-structure * * @param timeToWakeup the abs time for the timer (used to order the timer queue) * @param userData user specified data * @param userCallback user specified callback * * @return poitner to new element if successful, * NULL if there was an error allocating this timer. */ TimerHandle* new_timer( jlong timeToWakeup, void* userData, fTimerCallback userCallback) { TimerHandle* newTimer = (TimerHandle*)midpMalloc(sizeof(TimerHandle)); if (newTimer != NULL) { REPORT_INFO3(LC_PUSH, "[new_timer] timeToWakeup=%#lx userData=%p userCallback=%p", (long)timeToWakeup, userData, (void *)userCallback); newTimer->next = NULL; newTimer->timeToWakeup = timeToWakeup; newTimer->userData = userData; newTimer->userCallback = userCallback; add_timer(newTimer); } return newTimer; }
/** * Initialize screen buffer for a screen with specified demension, * allocate memory for pixel data. * * @param width width of the screen to initialize buffer for * @param height height of the screen to initialize buffer for * @return ALL_OK if successful, OUT_OF_MEMORY in the case of * not enough memory to allocate the buffer */ MIDPError gxj_init_screen_buffer(int width, int height) { MIDPError stat = ALL_OK; int size = sizeof(gxj_pixel_type) * width * height; gxj_system_screen_buffer.width = width; gxj_system_screen_buffer.height = height; gxj_system_screen_buffer.alphaData = NULL; gxj_system_screen_buffer.pixelData = (gxj_pixel_type *)midpMalloc(size); if (gxj_system_screen_buffer.pixelData != NULL) { memset(gxj_system_screen_buffer.pixelData, 0, size); } else { stat = OUT_OF_MEMORY; } return stat; }
/** * KNI function that sets selected state on element * in the native resource corresponding to the current ChoiceGroup. * * Java declaration: * <pre> * getSelectedFlags0(I[BI)I * </pre> * @param nativeId - id of the native resource corresponding to the current * ChoiceGroup * @param selectedArray_return - return array with selected state * value for the elements * @param numSelectedArray - number of elements in the selectedArray_return * @param - number of elements selected in selectedArray_return */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_lcdui_ChoiceGroupLFImpl_getSelectedFlags0() { MidpError err = KNI_OK; jboolean *selectedArray = NULL; MidpItem *cgPtr = (MidpItem *)KNI_GetParameterAsInt(1); int i, selectedArrayLength = KNI_GetParameterAsInt(3); int numSelected = 0; selectedArray = (jboolean *)midpMalloc(sizeof(jboolean) * selectedArrayLength); if (selectedArray == NULL) { err = KNI_ENOMEM; } else { KNI_StartHandles(1); KNI_DeclareHandle(selectedReturnJObjectArray); KNI_GetParameterAsObject(2, selectedReturnJObjectArray); err = lfpport_choicegroup_get_selected_flags(&numSelected, cgPtr, selectedArray, selectedArrayLength); if (err == KNI_OK) { for (i = 0; i < selectedArrayLength; i++) { KNI_SetBooleanArrayElement(selectedReturnJObjectArray, i, selectedArray[i]); if (selectedArray[i]) { numSelected++; } } } KNI_EndHandles(); midpFree(selectedArray); } if (err == KNI_ENOMEM) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnInt(numSelected); }
extern "C" void gxpport_loadimmutable_from_platformbuffer (unsigned char* srcBuffer, int length, jboolean isStatic, int* ret_imgWidth, int* ret_imgHeight, gxpport_image_native_handle *newImmutableImagePtr, gxutl_native_image_error_codes* creationErrorPtr) { int rscSize; gxutl_image_buffer_raw* dataBuffer = (gxutl_image_buffer_raw*)srcBuffer; /* Check resource limit */ rscSize = ImgRegionRscSize(NULL, dataBuffer->width, dataBuffer->height); if (midpCheckResourceLimit(RSC_TYPE_IMAGE_IMMUT, rscSize) == 0) { /* Exceed Resource limit */ *creationErrorPtr = GXUTL_NATIVE_IMAGE_RESOURCE_LIMIT; return; } _Platform_ImmutableImage* immutableImage = (_Platform_ImmutableImage*)midpMalloc(sizeof(_Platform_ImmutableImage)); if (immutableImage == NULL) { *creationErrorPtr = GXUTL_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR; return; } if (!load_raw(&immutableImage->qimage, dataBuffer, length, isStatic, ret_imgWidth, ret_imgHeight)) { midpFree(immutableImage); *creationErrorPtr = GXUTL_NATIVE_IMAGE_DECODING_ERROR; return; } /* Image creation succeeds */ if (midpIncResourceCount(RSC_TYPE_IMAGE_IMMUT, rscSize) == 0) { REPORT_ERROR(LC_LOWUI, "Error in updating resource limit" " for Immutable image"); } immutableImage->marker = 7; immutableImage->qpixmap = NULL; *newImmutableImagePtr = immutableImage; *creationErrorPtr = GXUTL_NATIVE_IMAGE_NO_ERROR; }
/** * Read pcsl_string from storage. * First read a jint with length, then read the text * of that length in the utf-16 encoding. * * @param ppszError in the case of error, receives address of a string * describing the problem; receives NULL in the case of success * @param handle handle of the file to read from * @param str string to receive the text */ void storage_read_utf16_string(char** ppszError, int handle, pcsl_string* str) { jint bytesRead = 0; jchar *tempStr = NULL; jint tempLen = 0; pcsl_string_status prc; storageRead(ppszError, handle, (char*)&tempLen, sizeof (jint)); if (*ppszError != NULL) { return; } /* special cases: null and empty strings */ if (tempLen < 0) { if(0 == tempLen) { *str = PCSL_STRING_NULL; } else if (-1 == tempLen) { *str = PCSL_STRING_EMPTY; } else { *str = PCSL_STRING_NULL; *ppszError = (char *)STRING_CORRUPT_ERROR; } return; } tempStr = (jchar*)midpMalloc(tempLen * sizeof (jchar)); if (tempStr == NULL) { *ppszError = (char *)OUT_OF_MEM_ERROR; return; } bytesRead = storageRead(ppszError, handle, (char*)tempStr, tempLen * sizeof (jchar)); if (*ppszError != NULL) { /* do nothing: error code already there */ } else if (bytesRead != (signed)(tempLen * sizeof (jchar))) { *ppszError = (char *)STRING_CORRUPT_ERROR; } else if (PCSL_STRING_OK != (prc = pcsl_string_convert_from_utf16(tempStr, tempLen, str))) { *ppszError = PCSL_STRING_ENOMEM == prc ? (char *)OUT_OF_MEM_ERROR : (char *)STRING_CORRUPT_ERROR; } midpFree(tempStr); return; }
/** Create the event queue lock. */ void midp_createEventQueueLock(void) { /* * The Master mode needs a lock since all events put in asynchronously. * But slave mode may not if events can be put in the system GUI event * system. */ HANDLE *mutex; specialId = TlsAlloc(); mutex = midpMalloc(sizeof(HANDLE)); if (mutex == NULL) { return; } TlsSetValue(specialId, mutex); *mutex = CreateMutex(0, KNI_FALSE, TEXT("eventQueueMutex")); }
/** * Gets the MIDlet name for the given registered push connection. * <p> * Java declaration: * <pre> * getEntry0([B[BI)I * </pre> * * @param connection The connection to add to the push registry * @param midlet A byte array to store the MIDlet name * @param midletsize The size of <tt>midlet</tt> * * @return <tt>0</tt> if successful, otherwise <tt>-1</tt> * * @throw IOException if the registry entry is too long. */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_midp_io_j2me_push_ConnectionRegistry_getEntry0) { int midletsize; char *regentry; int regsize ; int ret = -1; int connLen; char *szConn = NULL; midletsize = KNI_GetParameterAsInt(3); KNI_StartHandles(2); KNI_DeclareHandle(conn); KNI_DeclareHandle(regObject); KNI_GetParameterAsObject(1, conn); connLen = KNI_GetArrayLength(conn); ret = -1; if ((szConn = midpMalloc(connLen)) != NULL) { KNI_GetRawArrayRegion(conn, 0, connLen, (jbyte*)szConn); KNI_GetParameterAsObject(2, regObject); regentry = pushfindconn(szConn); if (NULL != regentry) { regsize = strlen(regentry) + 1; if (regsize < midletsize) { KNI_SetRawArrayRegion(regObject, 0, regsize, (jbyte*)regentry); ret = 0; } else { KNI_ThrowNew(midpIOException, "registration too long"); } } midpFree(szConn); } else { KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_EndHandles(); KNI_ReturnInt(ret); }