Quick Start – Working with MIB Tables
One of the more common tasks in developing agents is to create a table. The xAgentBuilder generates code specific to the tables defined in the mib. To help the developer a demo row is inserted in table by the code generator. Every table class has a method called CreateDemoRow()’. This is called from the ‘Initialize’ method in the generated code. The ‘CreateDemoRow()’ method inserts a single row in the table. The code is given below for the vehilclesTable of the Garage mib.
void DVehiclesTable::CreateDemoRow()
{
Entry* pRow = new Entry;
BObjectIdentifier oidIx;
// [1]vehicleIndex
oidIx. Append(pRow->m_nVehicleIndex);
if ( !InsertRow(oidIx, pRow) )
{
delete pRow;
}
}
Code is added to this method to insert a second row. This will demonstrate how easy it is to add another row to the table by adding to generated code. Please see the comment //Insert second row. A new row
is dynamically allocated to pRow. The columns of the row are initialized and then the row is inserted in the table.
void DVehiclesTable::CreateDemoRow()
{
Entry* pRow = new Entry;
BObjectIdentifier oidIx;
// [1]vehicleIndex
oidIx. Append(pRow->m_nVehicleIndex);
if ( !InsertRow(oidIx, pRow) )
{
delete pRow;
}
// Insert second row
oidIx.Clear();
pRow = new Entry;
pRow->m_nVehicleIndex = 2;
pRow->m_strVehicleLicencePlate = “NDT-2”;
pRow->m_strVehicleModel = “Pontiac”;
oidIx.Append(pRow->m_nVehicleIndex);
if ( !InsertRow(oidIx, pRow) )
{
delete pRow;
}
}
For a more detailed discussion on Tables and Dynamic Row creation, please see the Tutorials.
The Quick Start continues on Quick Start – Init() and Cleanup() Explained.