Product Documentation

FairCom DB API for C

Previous Topic

Next Topic

CTDB_ON_TABLE_OPEN

A CTDB_ON_TABLE_OPEN callback is invoked after the FairCom DB data and index files are open, but before ctdbOpenTable() returns. The handle passed as a parameter with this callback is a table handle and you can safely typecast the handle parameter to a pCTDBTABLE structure pointer.

The open table callback can be used as an indication that the table is active and that table and records operations may occur.

Below is an example demonstrating how to obtain the record callbacks when the table open callback is called.

FairCom DB API C API Example


typedef struct

{

pCTDBSESSION pSession;

pCTDBTABLE pTable;

pDATOBJ dodaptr;

VRLEN doda_size;

VRLEN dodacount;

NINT fixlen;

} LOCALTABLE, ctMEM* pLOCALTABLE;

CTDBRET ctdbDECL OnTableOpen(CTHANDLE Handle)

{

CTDBRET Retval = CTDBRET_OK;

pCTDBTABLE pTable = (pCTDBTABLE)Handle;

pCTDBSESSION pSession;

pLOCALTABLE pLocal = NULL;

/* check the table handle */

if (!pTable)

{

Retval = CTDBRET_NOTTABLE;

goto Exit;

}

pSession = (pCTDBSESSION)pTable->pSession;

/* check the table name for our table */

if (strcmp(pTable->name, "table") != 0)

{

/* this is not the table we are looking for */

goto Exit;

}

/* allocate the local data for the table handle */

pLocal = (pLOCALTABLE)pSession->onAlloc(sizeof(LOCALTABLE));

if (!pLocal)

{

Retval = CTDBRET_NOMEMORY;

goto Exit;

}

/* initialize the local table data */

pLocal->pSession = pSession;

pLocal->pTable = pTable;

pLocal->dodaptr = NULL;

pLocal->doda_size = 0;

pLocal->dodacount = 0;

pTable->localTag = (pVOID)pLocal;

pLocal = NULL;

/* set the other callbacks for this table */

if ((Retval = ctdbSetCallback(Handle, CTDB_ON_TABLE_OPEN, OnTableOpen)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(Handle, CTDB_ON_TABLE_GET_DODA, OnTableGetDoda)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(Handle, CTDB_ON_TABLE_GET_RECLEN, OnTableGetReclen)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(Handle, CTDB_ON_TABLE_CLOSE, OnTableClose)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(Handle, CTDB_ON_RECORD_INIT, OnRecordInit)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(Handle, CTDB_ON_RECORD_RESET, OnRecordReset)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(Handle, CTDB_ON_RECORD_BEFORE_READ, OnRecordBeforeRead)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(Handle, CTDB_ON_RECORD_AFTER_READ, OnRecordAfterRead)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(Handle, CTDB_ON_RECORD_BEFORE_BUILD_KEY, OnRecordBeforeBuildKey)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(Handle, CTDB_ON_RECORD_AFTER_BUILD_KEY, OnRecordAfterBuildKey)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(Handle, CTDB_ON_RECORD_BEFORE_WRITE, OnRecordBeforeWrite)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(Handle, CTDB_ON_RECORD_AFTER_WRITE, OnRecordAfterWrite)) != CTDBRET_OK) goto Exit;

/* set the callback for any records already allocated */

if (pTable->records)

{

NINT i;

for (i = 0; i < pTable->records->count; i++)

{

CTHANDLE recHandle = (CTHANDLE)_ctdbListItem(pTable->records, i);

if (recHandle)

{

if ((Retval = ctdbSetCallback(recHandle, CTDB_ON_RECORD_INIT, OnRecordInit)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(recHandle, CTDB_ON_RECORD_RESET, OnRecordReset)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(recHandle, CTDB_ON_RECORD_BEFORE_READ, OnRecordBeforeRead)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(recHandle, CTDB_ON_RECORD_AFTER_READ, OnRecordAfterRead)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(recHandle, CTDB_ON_RECORD_BEFORE_BUILD_KEY, OnRecordBeforeBuildKey)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(recHandle, CTDB_ON_RECORD_AFTER_BUILD_KEY, OnRecordAfterBuildKey)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(recHandle, CTDB_ON_RECORD_BEFORE_WRITE, OnRecordBeforeWrite)) != CTDBRET_OK) goto Exit;

if ((Retval = ctdbSetCallback(recHandle, CTDB_ON_RECORD_AFTER_WRITE, OnRecordAfterWrite)) != CTDBRET_OK) goto Exit;

}

}

}

Exit:

if (pLocal)

if (pSession)

pSession->onFree(pLocal);

return Retval;

}

TOCIndex