suitestore_otanotifier_db.c

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

C
602
字号
                            SuiteIdType suiteId,                            const pcsl_string* url_str) {    MidpPendingNotification* pList;    int numberOfElements;    MidpPendingNotification temp;    numberOfElements = getNotifications(filename_str, &pList);    if (numberOfElements < 0) {        return;    }    temp.retries = 0;    temp.suiteId = suiteId;    temp.url = *url_str;    saveNotifications(filename_str, pList, numberOfElements, temp);    midpFreeNotificationList(pList, numberOfElements);}/** * Removes a pending notification. * * @param filename full path the the notification file * @param suiteId suite ID of the notification to remove */static void removeNotification(const pcsl_string* filename_str,                               SuiteIdType suiteId) {    MidpPendingNotification* pList;    int numberOfElements;    int i;    MidpPendingNotification temp;    numberOfElements = getNotifications(filename_str, &pList);    if (numberOfElements <= 0) {        return;    }    for (i = 0; i < numberOfElements; i++) {        if (pList[i].suiteId == suiteId) {            pList[i].retries = -1;            temp.retries = -1;            saveNotifications(filename_str, pList, numberOfElements, temp);            break;        }    }    midpFreeNotificationList(pList, numberOfElements);}/** * Frees a notification's data. Will not free the notification itself. * * @param notification notification data to free */static void freeNotificationData(MidpPendingNotification* pNotification) {    pcsl_string_free(&pNotification->url);    initNotification(pNotification);}/** * Frees a list of pending notifications. * * @param pList point to an array of notifications * @param numberOfElements number of elements in pList */void midpFreeNotificationList(MidpPendingNotification* pList,                              int numberOfElements) {    int i;    for (i = 0; i < numberOfElements; i++) {        freeNotificationData(&pList[i]);    }    midpFree(pList);}/** * Queues provider's URL to send a delete notification message * during the next OTA session. * * @param suiteId suite the notification belongs to * @param url target url for the status message */void midpAddDeleteNotification(SuiteIdType suiteId,                               const pcsl_string* url_str) {    pcsl_string filename_str;    pcsl_string_status rc;    rc = pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID),                         &DELETE_NOTIFY_FILENAME, &filename_str);    if (PCSL_STRING_OK != rc) {        return;    }    addNotification(&filename_str, suiteId, url_str);    pcsl_string_free(&filename_str);}/** * Removes a pending delete notification. * * @param suiteId suite ID of the notification to remove */void midpRemoveDeleteNotification(SuiteIdType suiteId) {    pcsl_string filename;    pcsl_string_status rc;    rc = pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID),                         &DELETE_NOTIFY_FILENAME, &filename);    if (PCSL_STRING_OK != rc) {        return;    }    removeNotification(&filename, suiteId);    pcsl_string_free(&filename);}/** * Retrieves the number of URLs queued delete in the notification list. * * @return the number of delete notifications */int midpGetNumberOfDeleteNotifications() {    pcsl_string filename;    pcsl_string_status rc;    int numberOfElements = 0;    rc = pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID),                         &DELETE_NOTIFY_FILENAME, &filename);    if (PCSL_STRING_OK != rc) {        return 0;    }    numberOfElements = getNumberOfNotifications(&filename);    midpFree(filename.data);    return numberOfElements;}/** * Retrieves the queued delete notification list from storage. * * @param paList pointer to a pointer of notifications, free with * freeNotifications * * @return number of notifications in paList, *         negative in case of error */int midpGetDeleteNotifications(MidpPendingNotification** paList) {    pcsl_string filename;    pcsl_string_status rc;    int numberOfElements = 0;    *paList = NULL;    rc = pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID),                         &DELETE_NOTIFY_FILENAME, &filename);    if (PCSL_STRING_OK != rc) {        return 0;    }    numberOfElements = getNotifications(&filename, paList);    pcsl_string_free(&filename);    return numberOfElements;}/** * Save the given list of delete notifications to persistent storage. * * @param pList array as the one returned by getDeleteNotifications() * @param numberOfElements number of elements in pList */void midpSaveDeleteNotifications(MidpPendingNotification* pList,                                 int numberOfElements) {    pcsl_string filename;    pcsl_string_status rc;    MidpPendingNotification temp;    rc = pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID),                         &DELETE_NOTIFY_FILENAME, &filename);    if (PCSL_STRING_OK != rc) {        return;    }    temp.retries = -1;    saveNotifications(&filename, pList, numberOfElements, temp);    pcsl_string_free(&filename);}/** * Queues provider's URL to send a install notification message * during the next OTA session. * * @param suiteId suite the notification belongs to * @param url target url for the status message */void midpAddInstallNotification(SuiteIdType suiteId, const pcsl_string* url) {    pcsl_string filename;    pcsl_string_status rc;    rc = pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID),                         &INSTALL_NOTIFY_FILENAME, &filename);    if (PCSL_STRING_OK != rc) {        return;    }    addNotification(&filename, suiteId, url);    pcsl_string_free(&filename);}/** * Removes a pending install notification. * * @param suiteId suite ID of the notification to remove */void midpRemoveInstallNotification(SuiteIdType suiteId) {    pcsl_string filename;    pcsl_string_status rc;    rc = pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID),                         &INSTALL_NOTIFY_FILENAME, &filename);    if (PCSL_STRING_OK != rc) {        return;    }    removeNotification(&filename, suiteId);    pcsl_string_free(&filename);}/** * Retrieves the number of URLs queued install in the notification list. * * @return the number of install notifications */int midpGetNumberOfInstallNotifications() {    pcsl_string filename;    pcsl_string_status rc;    int numberOfElements = 0;    rc = pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID),                         &INSTALL_NOTIFY_FILENAME, &filename);    if (PCSL_STRING_OK != rc) {        return 0;    }    numberOfElements = getNumberOfNotifications(&filename);    pcsl_string_free(&filename);    return numberOfElements;}/** * Retrieves the queued install notification list from storage. * * @param paList pointer to a pointer of notifications, free with * freeNotifications * * @return number of notifications in paList, *         negative in case of error */int midpGetInstallNotifications(MidpPendingNotification** paList) {    pcsl_string filename;    pcsl_string_status rc;    int numberOfElements = 0;    *paList = NULL;    rc = pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID),                         &INSTALL_NOTIFY_FILENAME, &filename);    if (PCSL_STRING_OK != rc) {        return 0;    }    numberOfElements = getNotifications(&filename, paList);    pcsl_string_free(&filename);    return numberOfElements;}/** * Save the given list of install notifications to persistent storage. * * @param pList array as the one returned by getInstallNotifications() * @param numberOfElements number of elements in pList */void midpSaveInstallNotifications(MidpPendingNotification* pList,                                  int numberOfElements) {    pcsl_string filename;    pcsl_string_status rc;    MidpPendingNotification temp;    rc = pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID),                         &INSTALL_NOTIFY_FILENAME, &filename);    if (PCSL_STRING_OK != rc) {        return;    }    temp.retries = -1;    saveNotifications(&filename, pList, numberOfElements, temp);    pcsl_string_free(&filename);}

⌨️ 快捷键说明

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