DLM File

File Read Events

dlm_FileReadEvents()

Generates a stream of callbacks for the events in a file.

Syntax
#include "dlmfile.h"

DlmResult dlm_FileReadEvents
    (
        DlmFileId        id,
        DlmFileCallback  callback,
        DlmUserData      userData
    );
id id of session to read from
callback callback to call for each event
userData callback user data
Description

dlm_FileReadEvents() generates a stream of callbacks for the events in a file as if they were being received from a server in real time. This function allows for off-line monitoring of events, using the same logic as real time monitoring.

dlm_FileReadEvents() does not return until all of the events have been read from the file and all callbacks have been completed.

Return Values

If successful, dlm_FileReadEvents() returns a non-negative value. Otherwise, it returns a negative value indicating the reason it failed. Possible unsuccessful return values are:

See Also

dlm_FileRead()
dlm_FileReleaseEvent()
dlm_FileWrite()

Example
if ((result = dlm_FileOpen(fileName, dlm_FILE_MODE_READ, &id)) < 0)
{
    printf("Error: Failure opening for reading: %s.\n", dlm_ErrorMessage(result));
}
else
{
    printf("\nReading all events from %s:\n", fileName);

    if ((result = dlm_FileReadEvents(id, Callback, NULL)) < 0)
    {
        printf("Error: Failure reading events: %s.\n", dlm_ErrorMessage(result));
    }
    else
    {
        if ((result = dlm_FileClose(id) < 0)
        {
            printf("Error: Failure closing file: %s.\n", dlm_ErrorMessage(result));
        }
        else
        {
            printf("File closed.\n");
        }
    }
}


static
DlmResult
Callback
    (
        DlmMonitorId    id,
        DlmUserData     userData,
        DlmEvent        event
    )
{
    printf("Event: %s %u.\n", dlm_EventMessage(event->type), event->count);
    hex_DUMP(event->buffer, event->count > 16 ? 16 : event->count);

    dlm_FileReleaseEvent(id, event);

    return (dlm_SUCCESS);
}