/**
 * Deconstruct the entire list and free all memory.
 *
 * @param head The first element of the list to be deconstructed.
 */
void jsr120_list_destroy(ListElement* head) {

    /* If the list doesn't exist, exit now. */
    if (head == NULL) {
        return;
    }

    /* If the next element exists, recursively destroy. */
    if (head->next) {
        jsr120_list_destroy(head->next);
    }

    /* Release any string ID memory. */
    pcsl_mem_free(head->strid);

    /* Release the memory required by the list element. */
    pcsl_mem_free(head);
}
Exemple #2
0
/**
 * Retrieves the next (oldest) message from the pool that matches the message
 * identifier. Removes the entry from the message pool, but doesn't free the
 * memory associated with the message. The result MUST be deleted by the
 * caller using <code>jsr120_cbs_delete_msg</code>.
 *
 * @param msgID The message identifier to be matched.
 *
 * @return The message or <code>NULL</code> if no message could be retrieved.
 */
CbsMessage* jsr120_cbs_pool_retrieve_next_msg(jchar msgID) {
    ListElement* elem;

    /* The result of the search */
    CbsMessage* result = NULL;

    elem = jsr120_list_remove_first_by_number(&CBSPool_messages, msgID);
    if (elem) {

        result = elem->userData;

        /* Delete element from pool while preserving user data. */
        jsr120_list_destroy(elem);
        jsr120_cbs_pool_decrease_count();
    }

    /* Result MUST be deleted by caller using CbsMessage_delete() */
    return result;
}
Exemple #3
0
/**
 * Retrieve the next (oldest) message from the pool that matches the application
 * number. Removes the entry from the message pool, but doesn't free the memory
 * associated with the message. The result MUST be deleted by caller using
 * <code>MmsMessage_delete()</code>.
 *
 * @param appID The application identifier to be matched.
 *
 * @return The message, or <code>NULL</code> if no message could be retrieved.
 */
MmsMessage* jsr205_mms_pool_retrieve_next_msg(unsigned char* appID) {
    ListElement* elem;

    /* The result of the search */
    MmsMessage* msg = NULL;

    elem = jsr120_list_remove_first_by_name(&MMSPool_messages, appID);
    if (elem) {

        msg = elem->userData;

        /* Delete element from pool while preserving user data. */
        jsr120_list_destroy(elem);
        jsr205_mms_pool_decrease_msg_count();
    }

    /* Result MUST be deleted by caller using MmsMessage_delete() */
    return msg;
}
Exemple #4
0
/**
 * Deletes the oldest CBS message.
 *
 * @return <code>WMA_OK</code> if the oldest message was found and deleted;
 *     <code>WMA_ERR</code>, otherwise.
 */
WMA_STATUS jsr120_cbs_pool_delete_next_msg() {
    ListElement* elem;

    /* Assume there was no message to delete. */
    WMA_STATUS found = WMA_ERR;

    elem = jsr120_list_remove_first(&CBSPool_messages);
    if (elem) {

        /* Free the memory used for the message. */
        CbsMessage* cbs = elem->userData;
        jsr120_cbs_delete_msg(cbs);

        /* Update the pool list and count. */
        jsr120_list_destroy(elem);
        jsr120_cbs_pool_decrease_count();

        /* The first (oldest) message was found and deleted. */
        found = WMA_OK;
    }
    return found;
}