suitestore_midletsuitestorage_kni.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,872 行 · 第 1/4 页
C
1,872 行
/* * * * 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 <string.h>#include <sni.h>#include <midpError.h>#include <midpMalloc.h>#include <midpStorage.h>#include <midpServices.h>#include <midpUtilKni.h>#include <midp_ams_status.h>#include <suitestore_intern.h>#include <suitestore_installer.h>#include <suitestore_task_manager.h>#include <suitestore_rms.h>#include <suitestore_kni_util.h>#if ENABLE_ICON_CACHE#include <suitestore_icon_cache.h>#endif#if ENABLE_IMAGE_CACHE#include <imageCache.h>#endif#if ENABLE_MONET#if VERIFY_ONCE#error Contradictory build settings: ENABLE_MONET=true and VERIFY_ONCE=true.#endif /* VERIFY_ONCE */#endif /* ENABLE_MONET *//* ---------------------- IMPL_NOTE: remove midpport_... ---------------------- *//** * Gets the handle for accessing MIDlet suite properties. * Also returns the number of name/value pairs read using that handle. * * @param suiteId The suite id of the MIDlet suite * @param numProperties [out] The number of properties * @param propHadle [out] The property handle for accessing * MIDlet suite properties * @return one of the error codes: * <pre> * MIDP_ERROR_NONE, MIDP_ERROR_OUT_MEM, * MIDP_ERROR_SUITE_NOT_FOUND, MIDP_ERROR_SUITE_CORRUPTED * </pre> */MIDP_ERROR midpport_suite_open_properties(SuiteIdType suiteId, jint *numProperties, jint *propHandle) { pcsl_string filename = PCSL_STRING_NULL; jint numStrings = 0; MIDP_ERROR errorCode = MIDP_ERROR_NONE; char* pszError = NULL; *propHandle = -1; *numProperties = 0; do { errorCode = get_property_file(suiteId, KNI_TRUE, &filename); if (errorCode != MIDP_ERROR_NONE) { break; } *propHandle = storage_open(&pszError, &filename, OPEN_READ); if (pszError != NULL) { storageFreeError(pszError); errorCode = MIDP_ERROR_AMS_SUITE_CORRUPTED; break; } storageRead(&pszError, *propHandle, (char*)&numStrings, sizeof(jint)); if (pszError != NULL) { storageFreeError(pszError); errorCode = MIDP_ERROR_AMS_SUITE_CORRUPTED; break; } *numProperties = numStrings/2; } while (0); pcsl_string_free(&filename); return errorCode;}/** * Retrieves the next MIDlet suite property associated with the passed in * property handle. Note that the memory for in/out parameters * key and property MUST be allocated using midpMalloc(). * The caller is responsible for freeing memory associated * with key and value. If NULL is returned for key and value then there are * no more properties to retrieve. * * @param propHandle MIDlet suite property handle * @param key An in/outparameter that will return * the key part of the property * (NULL is a valid return value) * @param keyLength The length of the key string * @param value An in/out parameter that will return * the value part of the property * (NULL is a valid return value). * @param valueLength The length of the value string * @return one of the error codes: * <pre> * MIDP_ERROR_NONE, MIDP_ERROR_OUT_MEM, * MIDP_ERROR_SUITE_CORRUPTED, * </pre> */MIDP_ERROR midpport_suite_next_property(jint propHandle, jchar **key, jint *keyLength, jchar **value, jint *valueLength) { char* pszError = NULL; int bytesRead = 0; jchar *tempStr = NULL; jint tempLen = 0; *key = NULL; *value = NULL; *keyLength = 0; *valueLength = 0; /* load the key string */ storageRead(&pszError, propHandle, (char*)&tempLen, sizeof (jint)); if (pszError != NULL) { storageFreeError(pszError); return MIDP_ERROR_AMS_SUITE_CORRUPTED; } tempStr = (jchar*)midpMalloc(tempLen * sizeof (jchar)); if (tempStr == NULL) { return MIDP_ERROR_OUT_MEM; } bytesRead = storageRead(&pszError, propHandle, (char*)tempStr, tempLen * sizeof (jchar)); if (pszError != NULL || (bytesRead != (signed)(tempLen * sizeof (jchar)))) { midpFree(tempStr); storageFreeError(pszError); return MIDP_ERROR_AMS_SUITE_CORRUPTED; } *key = tempStr; *keyLength = tempLen; /* load the value string */ storageRead(&pszError, propHandle, (char*)&tempLen, sizeof (jint)); if (pszError != NULL) { storageFreeError(pszError); return MIDP_ERROR_AMS_SUITE_CORRUPTED; } tempStr = (jchar*)midpMalloc(tempLen * sizeof (jchar)); if (tempStr == NULL) { return MIDP_ERROR_OUT_MEM; } bytesRead = storageRead(&pszError, propHandle, (char*)tempStr, tempLen * sizeof (jchar)); if (pszError != NULL || (bytesRead != (signed)(tempLen * sizeof (jchar)))) { midpFree(tempStr); storageFreeError(pszError); return MIDP_ERROR_AMS_SUITE_CORRUPTED; } *value = tempStr; *valueLength = tempLen; return MIDP_ERROR_NONE;}/** * Closes the passed in MIDlet suite property handle. * It will be called with a valid propHandle returned * by midpport_suite_open_properties(). * * @param propHandle The MIDlet suite property handle * @return one of the error codes: * <pre> * MIDP_ERROR_NONE, MIDP_ERROR_SUITE_CORRUPTED * </pre> */MIDP_ERROR midpport_suite_close_properties(jint propHandle) { char* pszError = NULL; storageClose(&pszError, propHandle); if (pszError != NULL) { storageFreeError(pszError); return MIDP_ERROR_AMS_SUITE_CORRUPTED; } return MIDP_ERROR_NONE;}/* --------------------------- midpport_... end --------------------------- *//** * Java interface for midp_suiteid2pcsl_string(). * * @param suiteId unique ID of the suite * * @return string representation of the given suiteId */KNIEXPORT KNI_RETURNTYPE_OBJECTKNIDECL(com_sun_midp_midletsuite_MIDletSuiteStorage_suiteIdToString) { pcsl_string nullStr = PCSL_STRING_NULL_INITIALIZER; const pcsl_string* pPcslStrSuiteId = &nullStr; int suiteId; KNI_StartHandles(1); KNI_DeclareHandle(hStrSuiteId); /* assert(sizeof(SuiteIdType) == sizeof(jint)); */ suiteId = KNI_GetParameterAsInt(1); pPcslStrSuiteId = midp_suiteid2pcsl_string(suiteId); do { GET_PCSL_STRING_DATA_AND_LENGTH(pPcslStrSuiteId) if (PCSL_STRING_PARAMETER_ERROR(pPcslStrSuiteId)) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { KNI_NewString(pPcslStrSuiteId_data, pPcslStrSuiteId_len, hStrSuiteId); } RELEASE_PCSL_STRING_DATA_AND_LENGTH } while (0); KNI_EndHandlesAndReturnObject(hStrSuiteId);}/** * Get the application binary image path for a suite. * * @param suiteId unique ID of the suite * * @return class path or null if the suite does not exist */KNIEXPORT KNI_RETURNTYPE_OBJECTKNIDECL(com_sun_midp_midletsuite_MIDletSuiteStorage_getMidletSuiteAppImagePath) {#if ENABLE_MONET pcsl_string class_path_str = PCSL_STRING_NULL_INITIALIZER; pcsl_string* const class_path = &class_path_str; SuiteIdType suiteId; StorageIdType storageId; MIDPError merr; KNI_StartHandles(1); KNI_DeclareHandle(tempHandle); /* assert(sizeof(SuiteIdType) == sizeof(jint)); */ suiteId = KNI_GetParameterAsInt(1); do { merr = midp_suite_get_suite_storage(suiteId, &storageId); if (merr != ALL_OK) { /* the suite was not found */ break; } merr = midp_suite_get_bin_app_path(suiteId, storageId, class_path); if (merr == OUT_OF_MEMORY) { KNI_ThrowNew(midpOutOfMemoryError, NULL); break; } else if (merr == SUITE_CORRUPTED_ERROR) { KNI_ThrowNew(midpIOException, NULL); break; } if (merr != ALL_OK) { break; } GET_PCSL_STRING_DATA_AND_LENGTH(class_path) if (PCSL_STRING_PARAMETER_ERROR(class_path)) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { KNI_NewString(class_path_data, class_path_len, tempHandle); } RELEASE_PCSL_STRING_DATA_AND_LENGTH } while (0); pcsl_string_free(&class_path_str); KNI_EndHandlesAndReturnObject(tempHandle);#else KNI_StartHandles(1); KNI_DeclareHandle(tempHandle); KNI_EndHandlesAndReturnObject(tempHandle);#endif /* ENABLE_MONET */}/** * Get the class path for a suite. * * @param suiteId unique ID of the suite * * @return class path or null if the suite does not exist */KNIEXPORT KNI_RETURNTYPE_OBJECTKNIDECL(com_sun_midp_midletsuite_MIDletSuiteStorage_getMidletSuiteJarPath) { SuiteIdType suiteId; MIDPError status; pcsl_string classPath = PCSL_STRING_NULL; KNI_StartHandles(1); KNI_DeclareHandle(resultHandle); suiteId = KNI_GetParameterAsInt(1); status = get_jar_path(COMPONENT_REGULAR_SUITE, (jint)suiteId, &classPath); if (status != ALL_OK) { KNI_ThrowNew(midpRuntimeException, NULL); KNI_ReleaseHandle(resultHandle); } else { midp_jstring_from_pcsl_string(KNIPASSARGS &classPath, resultHandle); pcsl_string_free(&classPath); } KNI_EndHandlesAndReturnObject(resultHandle);}/** * Get the storage id for a suite. * * @param suiteId unique ID of the suite * * @return storage id or UNUSED_STORAGE_ID if the suite does not exist */KNIEXPORT KNI_RETURNTYPE_INTKNIDECL(com_sun_midp_midletsuite_MIDletSuiteStorage_getMidletSuiteStorageId) { SuiteIdType suiteId; StorageIdType storageId; MIDPError errorCode; suiteId = KNI_GetParameterAsInt(1); do { errorCode = midp_suite_get_suite_storage(suiteId, &storageId); if (errorCode != ALL_OK) { /* the suite was not found */ storageId = UNUSED_STORAGE_ID; break; } } while (0); KNI_ReturnInt(storageId);}/** * Get the folder id for a suite. * * @param suiteId unique ID of the suite * * @return folder id or -1 if the suite does not exist */KNIEXPORT KNI_RETURNTYPE_INTKNIDECL(com_sun_midp_midletsuite_MIDletSuiteStorage_getMidletSuiteFolderId) { SuiteIdType suiteId; FolderIdType folderId; MIDPError errorCode; suiteId = KNI_GetParameterAsInt(1); do { errorCode = midp_suite_get_suite_folder(suiteId, &folderId); if (errorCode != ALL_OK) { /* the suite was not found */ folderId = -1; break; } } while (0); KNI_ReturnInt(folderId);}/** * Native method String getSuiteID(String, String) of * com.sun.midp.midletsuite.MIDletSuiteStorage. * <p> * Gets the unique identifier of the MIDlet suite defined by vendor and name. * * @param vendor name of the vendor that created the suite, * as given in a JAD file * @param name name of the suite, as given in a JAD file * * @return ID of the midlet suite given by vendor and name or * MIDletSuite.UNUSED_SUITE_ID if the suite doesn not exist */KNIEXPORT KNI_RETURNTYPE_INTKNIDECL(com_sun_midp_midletsuite_MIDletSuiteStorage_getSuiteID) { MIDPError error; SuiteIdType suiteId = UNUSED_SUITE_ID; KNI_StartHandles(2); GET_PARAMETER_AS_PCSL_STRING(1, vendor) GET_PARAMETER_AS_PCSL_STRING(2, name) error = midp_get_suite_id(&vendor, &name, &suiteId); switch(error) { case OUT_OF_MEMORY: KNI_ThrowNew(midpOutOfMemoryError, NULL); break; case SUITE_CORRUPTED_ERROR: KNI_ThrowNew(midpIOException, NULL); break; case NOT_FOUND: /* this is ok, a new suite ID was created */ default: break; } RELEASE_PCSL_STRING_PARAMETER RELEASE_PCSL_STRING_PARAMETER KNI_EndHandles(); KNI_ReturnInt(suiteId);}/** * Native method boolean suiteExists(int) for class * com.sun.midp.midletsuite.MIDletSuiteStorage. * <p> * Tells if a suite exists. * * @param suiteId ID of a suite * * @return true if a suite of the given storage name * already exists on the system */KNIEXPORT KNI_RETURNTYPE_BOOLEANKNIDECL(com_sun_midp_midletsuite_MIDletSuiteStorage_suiteExists) { jboolean exists = KNI_FALSE; int status; /* assert(sizeof(SuiteIdType) == sizeof(jint)); */ SuiteIdType suiteId = KNI_GetParameterAsInt(1); status = midp_suite_exists(suiteId); if (status == ALL_OK) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?