javacall_ams_suitestore.c

来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,908 行 · 第 1/5 页

C
1,908
字号
/* * * * 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 <midpEvents.h>#include <pcsl_string.h>#include <pcsl_memory.h>#include <suitestore_common.h>#include <suitestore_installer.h>#include <suitestore_task_manager.h>#include <suitestore_secure.h>#include <suitestore_intern.h>#include <javautil_unicode.h>#include <javacall_memory.h>#include <suitestore_javacall.h>#define FREE_JC_STRING(str) if (str != NULL) { \                                javacall_free(str); \                            }static javacall_result midp_error2javacall(MIDPError midpErr);static MIDPError midp_javacall_str2pcsl_str(    javacall_const_utf16_string pSrcStr, pcsl_string* pDstStr);static MIDPError midp_pcsl_str2javacall_str(const pcsl_string* pSrcStr,                                            javacall_utf16_string* pDstStr);static MIDPError parse_midlet_attr(const pcsl_string* pMIDletAttrValue,                                   javacall_utf16_string* pDisplayName,                                   javacall_utf16_string* pIconName,                                   javacall_utf16_string* pClassName);static javacall_ams_permission midp_permission2javacall(int midpPermissionId);static javacall_ams_permission_valmidp_permission_val2javacall(jbyte midpPermissionVal);static int javacall_permission2midp(javacall_ams_permission jcPermission);static jbytejavacall_permission_val2midp(javacall_ams_permission_val jcPermissionVal);static MIDPErrorpcsl_string_array2javacall_impl(const pcsl_string* pPcslStrArray,                                jint srcArrSize,                                javacall_utf16_string** ppOutArray,                                javacall_int32* pOutArraySize);/*----------------------- Suite Storage: Common API -------------------------*//** * Initializes the SuiteStore subsystem. * * @return <tt>JAVACALL_OK</tt> on success, *         <tt>JAVACALL_FAIL</tt> otherwise */javacall_resultjavanotify_ams_suite_storage_init() {    return midp_error2javacall(midp_suite_storage_init());}/** * Finalizes the SuiteStore subsystem. * * @return <tt>JAVACALL_OK</tt> on success, *         <tt>JAVACALL_FAIL</tt> otherwise */javacall_resultjavanotify_ams_suite_storage_cleanup() {    midp_suite_storage_cleanup();    return JAVACALL_OK;}/** * Converts the given suite ID to javacall_string. * * NOTE: this function returns a pointer to a static buffer! * * @param value suite id to convert * * @return javacall_utf16_string representation of the given suite ID */const javacall_utf16_stringjavanotify_ams_suite_suiteid2javacall_string(javacall_suite_id value) {    static javacall_utf16 jsSuiteId[GET_SUITE_ID_LEN(value) + 1];    jsize convertedLen;    pcsl_string_status pcslRes;    const pcsl_string* pPcslStrVal =        midp_suiteid2pcsl_string((SuiteIdType)value);    pcslRes = pcsl_string_convert_to_utf16(pPcslStrVal, jsSuiteId,        (jsize)(sizeof(jsSuiteId) / sizeof(javacall_utf16)), &convertedLen);    if (pcslRes != PCSL_STRING_OK) {        jsSuiteId[0] = 0;    }    return jsSuiteId;}/** * Converts the given suite ID to array of chars. * * NOTE: this function returns a pointer to a static buffer! * * @param value suite id to convert * * @return char[] representation of the given suite ID *         or NULL in case of error */const char*javanotify_ams_suite_suiteid2chars(javacall_suite_id value) {    return midp_suiteid2chars((SuiteIdType)value);}/** * Tells if a suite with the given ID exists. * * @param suiteId ID of a suite * * @return <tt>JAVACALL_OK</tt> if a suite exists, *         <tt>JAVACALL_FILE_NOT_FOUND</tt> if not, *         <tt>JAVACALL_OUT_OF_MEMORY</tt> if out of memory, *         <tt>JAVACALL_IO_ERROR</tt> if IO error, *         <tt>JAVACALL_FAIL</tt> if the suite is found in the list, *         but it's corrupted */javacall_resultjavanotify_ams_suite_exists(javacall_suite_id suiteId) {    return midp_error2javacall(midp_suite_exists((SuiteIdType)suiteId));}/** * Gets location of the class path for the suite with the specified suiteId. * * Note that memory for the in/out parameter classPath is * allocated by the callee. The caller is responsible for * freeing it using javacall_free(). * * @param suiteId The application suite ID * @param storageId storage ID, INTERNAL_STORAGE_ID for the internal storage * @param checkSuiteExists true if suite should be checked for existence or not * @param pClassPath The in/out parameter that contains returned class path * * @return error code that should be one of the following: * <pre> *     JAVACALL_OK, JAVACALL_OUT_OF_MEMORY, JAVACALL_FILE_NOT_FOUND, *     JAVACALL_INVALID_ARGUMENT, JAVACALL_FAIL (for SUITE_CORRUPTED_ERROR) * </pre> */javacall_resultjavanotify_ams_suite_get_class_path(javacall_suite_id suiteId,                                    javacall_storage_id storageId,                                    javacall_bool checkSuiteExists,                                    javacall_utf16_string* pClassPath) {    pcsl_string pcslStrClassPath;    MIDPError status = midp_suite_get_class_path((SuiteIdType)suiteId,                          (StorageIdType)storageId,                          (checkSuiteExists == JAVACALL_TRUE) ?                              KNI_TRUE : KNI_FALSE,                          &pcslStrClassPath);    if (status != ALL_OK) {        return midp_error2javacall(status);    }    status = midp_pcsl_str2javacall_str(&pcslStrClassPath, pClassPath);    pcsl_string_free(&pcslStrClassPath);    return midp_error2javacall(status);}#if ENABLE_MONET/** * Only for MONET--Gets the class path to binary application image * for the suite with the specified MIDlet suite id. * * It is different from "usual" class path in that class path points to a * jar file, while this binary application image path points to a MONET bundle. * * Note that memory for the in/out parameter classPath is * allocated by the callee. The caller is responsible for * freeing it using javacall_free(). * * @param suiteId The application suite ID * @param storageId storage ID, INTERNAL_STORAGE_ID for the internal storage * @param checkSuiteExists true if suite should be checked for existence or not * @param pClassPath The in/out parameter that contains returned class path * * @return error code that should be one of the following: * <pre> *     JAVACALL_OK, JAVACALL_OUT_OF_MEMORY, JAVACALL_FILE_NOT_FOUND, *     JAVACALL_INVALID_ARGUMENT, JAVACALL_FAIL (for SUITE_CORRUPTED_ERROR) * </pre>*/javacall_resultjavanotify_ams_suite_get_bin_app_path(javacall_suite_id suiteId,                                      javacall_storage_id storageId,                                      javacall_utf16_string* pClassPath) {    pcsl_string pcslStrClassPath;    MIDPError status = midp_suite_get_bin_app_path((SuiteIdType)suiteId,                          (StorageIdType)storageId,                          &pcslStrClassPath);    if (status != ALL_OK) {        return midp_error2javacall(status);    }    status = midp_pcsl_str2javacall_str(&pcslStrClassPath, pClassPath);    pcsl_string_free(&pcslStrClassPath);    return midp_error2javacall(status);}#endif /* ENABLE_MONET *//** * Retrieves an ID of the storage where the midlet suite with the given suite ID * is stored. * * @param suiteId    [in]  unique ID of the MIDlet suite * @param pStorageId [out] receives an ID of the storage where *                         the suite is stored * * @return <tt>JAVACALL_OK</tt> on success, an error code otherwise */javacall_resultjavanotify_ams_suite_get_storage(javacall_suite_id suiteId,                                 javacall_storage_id* pStorageId) {    StorageIdType midpStorageId;    MIDPError status = midp_suite_get_suite_storage((SuiteIdType)suiteId,                                                    &midpStorageId);    if (status != ALL_OK) {        return midp_error2javacall(status);    }    *pStorageId = (javacall_storage_id)midpStorageId;    return JAVACALL_OK;}/** * Retrieves a path to the root of the given storage. * * Note that memory for the in/out parameter pStorageRootPath is * allocated by the callee. The caller is responsible for * freeing it using javacall_free(). * * @param storageId        [in]  unique ID of the storage where *                               the midlet suite resides * @param pStorageRootPath [out] receives a path to the given storage's root * * @return <tt>JAVACALL_OK</tt> on success, an error code otherwise */javacall_resultjavanotify_ams_storage_get_root(javacall_storage_id storageId,                                javacall_utf16_string* pStorageRootPath) {    MIDPError status;                              const pcsl_string* pRoot = storage_get_root(storageId);    if (pRoot == NULL || pRoot == &PCSL_STRING_EMPTY) {        return JAVACALL_FAIL;    }    status = midp_pcsl_str2javacall_str(pRoot, pStorageRootPath);    return midp_error2javacall(status);}/** * Retrieves the specified property value of the suite. * * @param suiteId     [in]  unique ID of the MIDlet suite * @param key         [in]  property name * @param value       [out] buffer to conatain returned property value * @param maxValueLen [in]  buffer length of value * * @return <tt>JAVACALL_OK</tt> on success, an error code otherwise */javacall_resultjavanotify_ams_suite_get_property(javacall_suite_id suiteId,                                  javacall_const_utf16_string key,                                  javacall_utf16_string value,                                  int maxValueLen) {    pcsl_string pcslStrKey, pcslStrValue;    MIDPError status;    status = midp_javacall_str2pcsl_str(key, &pcslStrKey);    if (status != ALL_OK) {        return midp_error2javacall(status);    }    status = midp_get_suite_property((SuiteIdType)suiteId,                        &pcslStrKey, &pcslStrValue);    return JAVACALL_OK;}/*----------------- Suite Storage: interface to Installer -------------------*//** * Installer invokes this function. If the suite exists, this function * returns an unique identifier of MIDlet suite. Note that suite may be * corrupted even if it exists. If the suite doesn't exist, a new suite * ID is created. * * @param name     [in]  name of suite * @param vendor   [in]  vendor of suite * @param pSuiteId [out] suite ID of the existing suite or a new suite ID * * @return <tt>JAVACALL_OK</tt> on success, an error code otherwise */javacall_resultjavanotify_ams_suite_get_id(javacall_const_utf16_string vendor,                            javacall_const_utf16_string name,                            javacall_suite_id* pSuiteId) {    SuiteIdType midpSuiteId;    MIDPError status;    pcsl_string pcslStrVendor, pcslStrName;    status = midp_javacall_str2pcsl_str(vendor, &pcslStrVendor);    if (status != ALL_OK) {        return midp_error2javacall(status);    }    status = midp_javacall_str2pcsl_str(name, &pcslStrName);    if (status != ALL_OK) {        pcsl_string_free(&pcslStrVendor);        return midp_error2javacall(status);    }    status = midp_get_suite_id(&pcslStrVendor, &pcslStrName, &midpSuiteId);    pcsl_string_free(&pcslStrVendor);    pcsl_string_free(&pcslStrName);    if (status != ALL_OK && status != NOT_FOUND) {        return midp_error2javacall(status);    }    *pSuiteId = (javacall_suite_id)midpSuiteId;    return JAVACALL_OK;}/** * Returns a new unique identifier of MIDlet suite. * * @param pSuiteId [out] receives a new unique MIDlet suite identifier * * @return <tt>JAVACALL_OK</tt> on success, an error code otherwise */javacall_resultjavanotify_ams_suite_create_id(javacall_suite_id* pSuiteId) {    SuiteIdType midpSuiteId;    MIDPError status;    status = midp_create_suite_id(&midpSuiteId);    if (status != ALL_OK) {        return midp_error2javacall(status);    }    *pSuiteId = (javacall_suite_id)midpSuiteId; 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?