install_peer_midlet_kni.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 509 行 · 第 1/2 页
C
509 行
/* * * * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */#include <kni.h>#include <sni.h>#include <midpError.h>#include <midpEvents.h>#include <midp_thread.h>#include <midpUtilKni.h>#include <midpServices.h>#include <string.h>#include <suitestore_common.h>#include <suitestore_kni_util.h>#include <pcsl_memory.h> /* to have definition of NULL */#include <javacall_defs.h>#include <javacall_memory.h>#include <javacall_ams_installer.h>#include <javacall_ams_platform.h>/* * IMPL_NOTE: this request code is not used in * java[call|notify]_ams_install_ask/answer * and is treated as other requests for handiness. If this value is changed, * the corresponding value in InstallerMIDletPeer class must also be changed. */#define RQ_UPDATE_STATUS 6/* IMPL_NOTE: for now we assume that only one installer may run at a time. */int g_installerIsolateId = -1;/** * These fields are set up by the javacall_ams_install_answer() callback. */jboolean g_fAnswer = JAVACALL_FALSE, g_fAnswerReady = JAVACALL_FALSE;/** * Extracts strings from the given java array and places them into * an array of javacall strings. * * Note: the caller is responsible for freeing memory allocated for * javacall strings in this function. * Even if the function has returned an error, *pArraySize will * hold the number of entries actually allocated in the output array. * * @param javaObj [in] java array of strings * @param tmpHandle [in] temporary KNI handle * @param pArraySize [out] on exit will hold the size * of the allocated string array * @param ppArray [out] on exit will hold a pointer * to the array of javacall strings * * @return JAVACALL_OK if succeeded, JAVACAL_FAIL otherwise */static javacall_resultjava_str_array2javacall_impl(jobject javaObj, jobject tmpHandle, javacall_int32* pArraySize, javacall_utf16_string** ppArray) { javacall_int32 tmpArrSize; javacall_utf16_string* pTmpArray = NULL; javacall_result jcRes = JAVACALL_OK; tmpArrSize = (javacall_int32)KNI_GetArrayLength(javaObj); do { if (tmpArrSize > 0) { jint i; pTmpArray = (javacall_utf16_string*)javacall_malloc( tmpArrSize * sizeof(javacall_utf16_string)); if (pTmpArray == NULL) { jcRes = JAVACALL_OUT_OF_MEMORY; break; } for (i = 0; i < tmpArrSize; i++) { jsize strLen; KNI_GetObjectArrayElement(javaObj, i, tmpHandle); strLen = KNI_GetStringLength(tmpHandle); if (strLen >= 0) { pTmpArray[i] = (javacall_utf16_string) javacall_malloc((strLen + 1) * sizeof(jchar)); if (pTmpArray[i] == NULL) { /* * save the current number of strings in the array * to free them later */ tmpArrSize = i; jcRes = JAVACALL_OUT_OF_MEMORY; break; } if (strLen > 0) { KNI_GetStringRegion(tmpHandle, 0, strLen, pTmpArray[i]); } else { /* empty string */ pTmpArray[i][0] = 0; } } else { pTmpArray[i] = NULL; } } if (jcRes != JAVACALL_OK) { break; } } else { tmpArrSize = 0; pTmpArray = NULL; } } while (0); *pArraySize = tmpArrSize; *ppArray = pTmpArray; return jcRes;}/** * Sends a request of type defined by the given request code to * the party that uses this installer via the native callback. * * Note: only some of parameters are used, depending on the request code * * IMPL_NOTE: the request code passed to this method as an argument must * be the same as the corresponding JAVACALL_INSTALL_REQUEST_* * value defined in javacall_ams_installer.h. * * @param requestCode code of the request to the native callback * @param installState current installation state * @param installStatus current status of the installation, -1 if not used * @param newLocation new url of the resource to install; null if not used * * @return 0 if no errors, a platform-specific error code otherwise */KNIEXPORT KNI_RETURNTYPE_INTKNIDECL(com_sun_midp_installer_InstallerPeerMIDlet_sendNativeRequest0) { javacall_ams_install_state jcInstallState; javacall_ams_install_data jcRequestData; javacall_result jcRes = JAVACALL_OK; javacall_utf16_string jcProperties = NULL; javacall_ams_install_request_code requestCode = (javacall_ams_install_request_code) KNI_GetParameterAsInt(1); pcsl_string pcslJarUrl = PCSL_STRING_NULL_INITIALIZER, pcslSuiteName = PCSL_STRING_NULL_INITIALIZER; jint propertiesLen; KNI_StartHandles(6); KNI_DeclareHandle(javaInstallState); KNI_DeclareHandle(javaProperties); KNI_DeclareHandle(javaAuthPath); KNI_DeclareHandle(clazz); KNI_DeclareHandle(tmpHandle); KNI_GetParameterAsObject(2, javaInstallState); if (KNI_IsNullHandle(javaInstallState)) { KNI_ReturnInt(JAVACALL_FAIL); } /* The request is not sent yet, so the answer is not received. */ g_fAnswerReady = JAVACALL_FALSE; jcRequestData.installStatus = (javacall_ams_install_status) KNI_GetParameterAsInt(3); /* * Converting javaInstallState state object into * the Javacall structure. */ /* * This is needed because KNI_SAVE_PCSL_STRING_FIELD() macro * calls pcsl_mem_free(destString) for some reason. */ memset((char*)&jcInstallState, 0, sizeof(jcInstallState)); jcRes = JAVACALL_FAIL; do { pcsl_string_status pcslRes; jsize strSize, convertedLength; jint appId, suiteId, jarSize, exceptionCode; KNI_GetObjectClass(javaInstallState, clazz); KNI_SAVE_INT_FIELD(javaInstallState, clazz, "appId", appId); jcInstallState.appId = (javacall_app_id)appId; KNI_SAVE_INT_FIELD(javaInstallState, clazz, "suiteId", suiteId); jcInstallState.suiteId = (javacall_suite_id)suiteId; KNI_SAVE_INT_FIELD(javaInstallState, clazz, "jarSize", jarSize); jcInstallState.jarSize = (javacall_int32)jarSize; KNI_SAVE_INT_FIELD(javaInstallState, clazz, "exceptionCode", exceptionCode); jcInstallState.exceptionCode = (javacall_ams_install_exception_code)exceptionCode; KNI_SAVE_PCSL_STRING_FIELD(javaInstallState, clazz, "jarUrl", &pcslJarUrl, tmpHandle); strSize = pcsl_string_utf16_length(&pcslJarUrl); if (strSize > 0) { strSize++; /* for terminating NULL */ jcInstallState.jarUrl = javacall_malloc(strSize << 1); pcslRes = pcsl_string_convert_to_utf16(&pcslJarUrl, (jchar*)jcInstallState.jarUrl, strSize, &convertedLength); if (pcslRes != PCSL_STRING_OK) { jcRes = JAVACALL_OUT_OF_MEMORY; break; } } else { jcInstallState.jarUrl = NULL; } KNI_SAVE_PCSL_STRING_FIELD(javaInstallState, clazz, "suiteName", &pcslSuiteName, tmpHandle); strSize = pcsl_string_utf16_length(&pcslSuiteName); if (strSize > 0) { strSize++; /* for terminating NULL */ jcInstallState.suiteName = javacall_malloc(strSize << 1); pcslRes = pcsl_string_convert_to_utf16(&pcslSuiteName, (jchar*)jcInstallState.suiteName, strSize, &convertedLength); if (pcslRes != PCSL_STRING_OK) { jcRes = JAVACALL_OUT_OF_MEMORY; break; } } else {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?