SnmpExtensionInit

Below is a the SnmpExtensionInit API implementation for the Toaster MIB. The variable dwTimeZeroReference is passed into the API from the extension agent so that the extension agent has a zero reference point. If for some reason the extension agent needs to determine how long it has been running, it can determine this by subtracting this value from the value returned by GetCurrentTime(). Many MIBs need the concept of uptime, or the length of time this device has been up since last reboot or reinitialization. In addition, any MIB that supports traps will need the uptime value since this is included in the trap PDU.

The hPollForTrap event is the event that this extension agent will signal when it is ready to send a trap. Keep in mind that, because the extension agent consists of subroutines called by the extendible agent, the extension agent won't necessarily be actively processing a request when it realizes it needs to send a trap. Take, for example, a trap that is based on some outside event like an out-of-paper signal from a printer. If no management station is currently querying the printers MIB, then the printer MIB DLL needs to somehow notify that extendible agent that it needs to be called to do some processing. One obvious method that could be employed is for the extendible agent to periodically poll for traps. This method is much more efficient if the developer can somehow associate the signal from the printer with an event; then the extension agent will be notified when the signal occurs and will call into the SnmpExtensionTrap API supplied by the DLL.

Finally, the supportedView argument is simply an OID that identifies the prefix of the MIB or MIB view that this DLL supports.


BOOL WINAPI SnmpExtensionInit(
    IN  DWORD               dwTimeZeroReference,
    OUT HANDLE              *hPollForTrapEvent,
    OUT AsnObjectIdentifier *supportedView)
    {
    // Record the time reference provided by the Extendible
    // Agent.

    dwTimeZero = dwTimeZeroReference;

    // Create an Event that will be used to communicate the 
    // occurence of trap to the Extendible Agent.  The Extension 
    // Agent will assert this Event when a trap has occured.  
    // This    is explained further later in this file.

    if ((*hPollForTrapEvent = CreateEvent(NULL, FALSE, FALSE, 
        NULL)) == NULL)
    {
        *hPollForTrapEvent = NULL;
        *supportedView = NULL;
        return FALSE;
    }

    // Indicate the MIB view supported by this Extension Agent, 
    // an object identifier representing the sub root of the MIB 
    // that is supported.

    *supportedView = MIB_OidPrefix; // NOTE!  structure copy

    // Record the trap Event.  
    hSimulateTrap = *hPollForTrapEvent;

    // Indicate that Extension Agent initialization was 
    // sucessfull.
    return TRUE;

    } // end SnmpExtensionInit()