javacall_ams_suitestore.c

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

C
1,908
字号
    pMidpSuiteData = get_suite_data((SuiteIdType)suiteId);    if (pMidpSuiteData == NULL || pMidpSuiteData->numberOfMidlets == 0) {        return JAVACALL_FAIL;    }    *pNumberOfEntries = pMidpSuiteData->numberOfMidlets;    *ppMidletsInfo = javacall_malloc((*pNumberOfEntries) *                                         sizeof(javacall_ams_midlet_info));    if (*ppMidletsInfo == NULL) {        return JAVACALL_FAIL;    }    n = 0;    while (1) {        pcsl_string midletNAttrName, midletNAttrValue, midletNum;        pcsl_string_status err;        err = pcsl_string_dup(&midletStr, &midletNAttrName);	    if (err != PCSL_STRING_OK) {            javanotify_ams_suite_free_midlets_info(*ppMidletsInfo, n);            return JAVACALL_FAIL;        }        err = pcsl_string_convert_from_jint(n + 1, &midletNum);	    if (err != PCSL_STRING_OK) {	        pcsl_string_free(&midletNAttrName);            javanotify_ams_suite_free_midlets_info(*ppMidletsInfo, n);            return JAVACALL_FAIL;        }        err = pcsl_string_append(&midletNAttrName, &midletNum);	    if (err != PCSL_STRING_OK) {	        pcsl_string_free(&midletNum);            javanotify_ams_suite_free_midlets_info(*ppMidletsInfo, n);            return JAVACALL_FAIL;        }        status = midp_get_suite_property(            pMidpSuiteData->suiteId, &midletNAttrName, &midletNAttrValue);        pcsl_string_free(&midletNAttrName);        pcsl_string_free(&midletNum);        if (status != ALL_OK) {            /* NOT_FOUND means OK: the last MIDlet-<n> attribute was handled */            if (status != NOT_FOUND) {                pcsl_string_free(&midletNAttrValue);                javanotify_ams_suite_free_midlets_info(*ppMidletsInfo, n);                return midp_error2javacall(status);            }            break;        }        if (n == pMidpSuiteData->numberOfMidlets) {            /* IMPL_NOTE: an error message should be logged */            pcsl_string_free(&midletNAttrValue);            break;        }        /* filling the structure with the information we've got */        pTmpMidletInfo = &(*ppMidletsInfo)[n];        pTmpMidletInfo->suiteId = pMidpSuiteData->suiteId;        status = parse_midlet_attr(&midletNAttrValue,                                   &pTmpMidletInfo->displayName,                                   &pTmpMidletInfo->iconPath,                                   &pTmpMidletInfo->className);        pcsl_string_free(&midletNAttrValue);        if (status != ALL_OK) {            /* ignore the error, just exit from the cycle */            break;        }        n++;    }    return JAVACALL_OK;}/** * App Manager invokes this function to free an array of structures describing * midlets from the given suite. * * @param pMidletsInfo points to an array with midlets info * @param numberOfEntries number of elements in pMidletsInfo */voidjavanotify_ams_suite_free_midlets_info(javacall_ams_midlet_info* pMidletsInfo,                                       int numberOfEntries) {    if (pMidletsInfo != NULL && numberOfEntries > 0) {        int i;        for (i = 0; i < numberOfEntries; i++) {            javacall_ams_midlet_info* pNextEntry = &pMidletsInfo[i];            if (pNextEntry != NULL) {                FREE_JC_STRING(pNextEntry->displayName);                FREE_JC_STRING(pNextEntry->iconPath);                FREE_JC_STRING(pNextEntry->className);            }        }    }}/** * App Manager invokes this function to get information about the midlet suite * having the given ID. This call is synchronous. * * @param suiteId unique ID of the MIDlet suite * * @param ppSuiteInfo [out] on exit will hold a pointer to a structure where the *                          information about the given midlet suite is stored; *                          the caller is responsible for freeing this structure *                          using javanotify_ams_suite_free_info() when it is not *                          needed anymore * * @return <tt>JAVACALL_OK</tt> on success, an error code otherwise */javacall_resultjavanotify_ams_suite_get_info(javacall_suite_id suiteId,                              javacall_ams_suite_info** ppSuiteInfo) {    MIDPError status;    MidletSuiteData* pMidpSuiteData;    javacall_ams_suite_info* pTmpSuiteInfo;    pTmpSuiteInfo = javacall_malloc(sizeof(javacall_ams_suite_info));    if (pTmpSuiteInfo == NULL) {        return JAVACALL_FAIL;    }    /* IMPL_NOTE: it should be moved from suitestore_intern and renamed */    pMidpSuiteData = get_suite_data((SuiteIdType)suiteId);    if (pMidpSuiteData == NULL) {        javacall_free(pTmpSuiteInfo);        return JAVACALL_FAIL;    }    /* copy data from the midp structure to the javacall one */    pTmpSuiteInfo->suiteId   = (javacall_suite_id) pMidpSuiteData->suiteId;    pTmpSuiteInfo->storageId = (javacall_int32) pMidpSuiteData->storageId;    pTmpSuiteInfo->folderId = (javacall_int32) pMidpSuiteData->folderId;    pTmpSuiteInfo->isEnabled = (javacall_bool) pMidpSuiteData->isEnabled;    pTmpSuiteInfo->isTrusted = (javacall_bool) pMidpSuiteData->isTrusted;    pTmpSuiteInfo->numberOfMidlets =        (javacall_int32) pMidpSuiteData->numberOfMidlets;    pTmpSuiteInfo->installTime = (long) pMidpSuiteData->installTime;    pTmpSuiteInfo->jadSize = (javacall_int32) pMidpSuiteData->jadSize;    pTmpSuiteInfo->jarSize = (javacall_int32) pMidpSuiteData->jarSize;    pTmpSuiteInfo->isPreinstalled =        (pMidpSuiteData->type == COMPONENT_PREINSTALLED_SUITE) ?            JAVACALL_TRUE : JAVACALL_FALSE;    /*     * Convert strings from pMidpSuiteData from pcsl_string to     * javacall_utf16_string and copy them into pTmpSuiteInfo.     */    status = ALL_OK;    do {        if (!pcsl_string_is_null(                &pMidpSuiteData->varSuiteData.midletClassName)) {            status = midp_pcsl_str2javacall_str(                &pMidpSuiteData->varSuiteData.midletClassName,                &pTmpSuiteInfo->midletClassName);            if (status != ALL_OK) {                break;            }        } else {            pTmpSuiteInfo->midletClassName = NULL;        }        if (!pcsl_string_is_null(&pMidpSuiteData->varSuiteData.displayName)) {            status = midp_pcsl_str2javacall_str(                &pMidpSuiteData->varSuiteData.displayName,                &pTmpSuiteInfo->displayName);            if (status != ALL_OK) {                break;            }        } else {            pTmpSuiteInfo->displayName = NULL;        }        if (!pcsl_string_is_null(&pMidpSuiteData->varSuiteData.iconName)) {            status = midp_pcsl_str2javacall_str(                &pMidpSuiteData->varSuiteData.iconName,                &pTmpSuiteInfo->iconPath);            if (status != ALL_OK) {                break;            }        } else {            pTmpSuiteInfo->iconPath = NULL;        }        if (!pcsl_string_is_null(&pMidpSuiteData->varSuiteData.suiteVendor)) {            status = midp_pcsl_str2javacall_str(                &pMidpSuiteData->varSuiteData.suiteVendor,                &pTmpSuiteInfo->suiteVendor);            if (status != ALL_OK) {                break;            }        } else {            pTmpSuiteInfo->suiteVendor = NULL;        }        if (!pcsl_string_is_null(&pMidpSuiteData->varSuiteData.suiteName)) {            status = midp_pcsl_str2javacall_str(                &pMidpSuiteData->varSuiteData.suiteName,                &pTmpSuiteInfo->suiteName);            if (status != ALL_OK) {                break;            }        } else {            pTmpSuiteInfo->suiteName = NULL;        }        /*        if (!pcsl_string_is_null(&pMidpSuiteData->varSuiteData.suiteVersion)) {            status = midp_pcsl_str2javacall_str(                &pMidpSuiteData->varSuiteData.suiteVersion,                &pTmpSuiteInfo->suiteVersion);            if (status != ALL_OK) {                break;            }        } else {            pTmpSuiteInfo->suiteVersion = NULL;        }        */        pTmpSuiteInfo->suiteVersion = NULL;    } while (0);    if (status != ALL_OK) {        FREE_JC_STRING(pTmpSuiteInfo->midletClassName)        FREE_JC_STRING(pTmpSuiteInfo->displayName)        FREE_JC_STRING(pTmpSuiteInfo->iconPath)        FREE_JC_STRING(pTmpSuiteInfo->suiteVendor)        FREE_JC_STRING(pTmpSuiteInfo->suiteName)        FREE_JC_STRING(pTmpSuiteInfo->suiteVersion)        javacall_free(pTmpSuiteInfo);        return midp_error2javacall(status);    }    *ppSuiteInfo = pTmpSuiteInfo;    return JAVACALL_OK;}/** * App Manager invokes this function to free a structure describing * a midlet suite and all fields of this structure. * * @param pSuiteInfo points to a structure holding midlet suite info */voidjavanotify_ams_suite_free_info(javacall_ams_suite_info* pSuiteInfo) {    if (pSuiteInfo != NULL) {        FREE_JC_STRING(pSuiteInfo->midletClassName)        FREE_JC_STRING(pSuiteInfo->displayName)        FREE_JC_STRING(pSuiteInfo->iconPath)        FREE_JC_STRING(pSuiteInfo->suiteVendor)        FREE_JC_STRING(pSuiteInfo->suiteName)        FREE_JC_STRING(pSuiteInfo->suiteVersion)        javacall_free(pSuiteInfo);    }}/** * App Manager invokes this function to get the domain the suite belongs to. * * @param suiteId unique ID of the MIDlet suite * @param pDomainId [out] pointer to the location where the retrieved domain *                        information will be saved * * @return <tt>JAVACALL_OK</tt> on success, an error code otherwise */javacall_resultjavanotify_ams_suite_get_domain(javacall_suite_id suiteId,                                javacall_ams_domain* pDomainId) {    javacall_result jcRes;    javacall_ams_suite_info* pSuiteInfo;    if (pDomainId == NULL) {        return JAVACALL_FAIL;    }    if ((SuiteIdType)suiteId == INTERNAL_SUITE_ID) {        /* internal suites belong to the manufacturer domain */        *pDomainId = JAVACALL_AMS_DOMAIN_MANUFACTURER;        return JAVACALL_OK;    }    jcRes = javanotify_ams_suite_get_info(suiteId, &pSuiteInfo);    if (jcRes != JAVACALL_OK) {        return jcRes;    }    /*     * IMPL_NOTE: instead of revealing the actual domain, here we just check     *            if the domain is trusted or not for simplicity.     */    *pDomainId = (pSuiteInfo->isTrusted == JAVACALL_TRUE ?        JAVACALL_AMS_DOMAIN_THIRDPARTY : JAVACALL_AMS_DOMAIN_UNTRUSTED);    javanotify_ams_suite_free_info(pSuiteInfo);    return JAVACALL_OK;}/** * App Manager invokes this function to disable a suite given its suite ID. * <p> * The method does not stop the suite if is in use. However any future * attepts to run a MIDlet from this suite while disabled should fail. * * @param suiteId ID of the suite * * @return ALL_OK if no errors, *         NOT_FOUND if the suite does not exist, *         SUITE_LOCKED if the suite is locked, *         IO_ERROR if IO error has occured, *         OUT_OF_MEMORY if out of memory */javacall_resultjavanotify_ams_suite_disable(javacall_suite_id suiteId) {    return midp_error2javacall(midp_disable_suite((SuiteIdType)suiteId));}/** * App Manager invokes this function to enable a suite given its suite ID. * <p> * The method does update an suites that are currently loaded for * settings or of application management purposes. * * @param suiteId ID of the suite * * @return ALL_OK if no errors, *         NOT_FOUND if the suite does not exist, *         SUITE_LOCKED if the suite is locked, *         IO_ERROR if IO error has occured, *         OUT_OF_MEMORY if out of memory */javacall_resultjavanotify_ams_suite_enable(javacall_suite_id suiteId) {    return midp_error2javacall(midp_enable_suite((SuiteIdType)suiteId));}/** * App Manager invokes this function to get permissions of the suite. * * Note: memory for pPermissions array is allocated and freed by the caller. * * @param suiteId       [in]     unique ID of the MIDlet suite * @param pPermissions  [in/out] array of JAVACALL_AMS_NUMBER_OF_PERMISSIONS *                               elements that will be filled with the *                               current permissions' values on exit * @return <tt>JAVACALL_OK</tt> on success, an error code otherwise */javacall_resultjavanotify_ams_suite_get_permissions(javacall_suite_id suiteId,                                     javacall_ams_permission_val* pPermissions) {    MIDPError status;    char* pszError = NULL;    jbyte* pMidpPermissions;    int iNumberOfPermissions;    jbyte pushInterruptSetting;    jint pushOptions;    jboolean enabled;    int i;    if (pPermissions == NULL) {        return JAVACALL_FAIL;    }    status = read_settings(&pszError, (SuiteIdType)suiteId,                           &enabled,                           &pushInterruptSetting,                           &pushOptions,                           &pMidpPermissions,                           &iNumberOfPermissions);    if (status != ALL_OK) {        storageFreeError(pszError);        return midp_error2javacall(status);

⌨️ 快捷键说明

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