NuDesign xAgentBuilder code generator is a very powerful tool. It will generate code for your mib and all the SNMP Get/Set/GetNext/GetBulk commands are taken care of. The generated C++ code is structured paralleling the structure of the MIB. The structure of the garage MIB is shown below
The MIB has one table (vehiclesTable), three notifications (noPaidAlarm, coLevelRisingAlarm, coLevelFallingAlarm) and six scalar objects (garageAddress, garageNumVehicles, garageCOLevel, garageCOLevelRisingThreshold and garageCOLevelFallingThreshold).
Now let’s take a look at the generated C++ classes that will handle this MIB.
For each notification, a class has been created with the name of the notification prefixed with ‘N’. Later on, we will show you how easy it is to send a notification using these classes. Each table will have its own class associated with it. The name of the class is the name of the table prefixed with a ‘D’. Similarly, each branch that has scalar objects that belong to it will have a class named after it with a ‘D’ in front of it. With this naming convention and class structure, a large MIB can be easily managed. ‘DGarage’ is the main class of this library that instantiates all the subtree handlers (i.e. ‘DGarageObjects’, ‘DVehiclesTable’ etc.). The initialization and cleanup of the subtree handlers is also handled by this class.
Let’s take a look at class components now. Class ‘DGarageObjects’ is shown below.
You will notice that for each scalar object belonging to DGarageObjects branch, there is a member variable defined for it. Also, OnGet functions have been defined for each object. OnSet functions have only been defined for objects with Read/Write access.
The next step is to add to code to these onGet and onSet functions for each object. For most MIBs, that is all that needs to be done. You will go to the onGet / onSet functions and add your own instrumentation to read/write to the MIB variables.
The next page of this tutorial covers "Inserting Code in OnGet functions". Please see the Quick Start - Inserting Code in OnGet functions for that page.