[Fwd: RE: implementing a large table over a database]
Martin Janzen
janzen____pixelmetrix.com
Tue Apr 8 04:31:18 CEST 2003
Dave Barratt wrote:
> Thanks for your excellent posting on dynamic tables, its saving me alot of
> headaches.
Glad to hear it!
> As a newbie to Agent development I was wondering if you could
> expand on what the following methods you reference in your examples below
> would actually do...
>
> bool MyDatabaseTable::loadRow(const Oidx& indexOid)
> {
// This extracts the database key from the index OID, and updates
// the columns of the corresponding row in the MIB table. If your
// MIB design corresponds fairly closely to your database schema,
// this ought to be easy:
// Make sure the caller has handled all the special cases.
assert(indexOID.len() == 1); // (adjust for number of keys)
// Extract key(s) from the index OID.
int key1 = indexOID[0];
if ( /* key1 is invalid */ ) return false;
return fillRow(key1);
> }
> bool MyDatabaseTable::fillRow(int slot)
> {
// Look up the necessary data in the database. In this case,
// 'slot' is the database key.
[...]
// Create a new row, then fill it in.
Agentpp::Oidx indexOID;
indexOID += slot; // set the row index
Agentpp::MibTableRow* pRow = mTable.add_row(indexOID);
mTable.set_row(pRow, /* data values for columns... */);
return true;
> }
The set_row() method is generated by AgentPro, but if you're not using
that, typically you just need something like this to fill the columns:
void tspTransportStreamEntry::set_row(
MibTableRow* r, unsigned long p0, long p1, [...])
{
r->get_nth(0)->replace_value(new Gauge32(p0));
r->get_nth(1)->replace_value(new SnmpInt32(p1));
[...]
}
> bool MyDatabaseTable::checkSlotIndex(int slot, Oidx indexOid, int i)
Just an implementation detail. I have lots of objects keyed by 'slot',
so this does the key extraction and validity check described above.
Should have deleted it from the example.
HTH...
--
Martin Janzen
janzen at pixelmetrix dot com
More information about the AGENTPP
mailing list