Quick Start Lesson 4

Quick Start – Inserting Code in OnSet functions

When an SNMP set request is received by an agent, the onSet function of the specified object is called to satisfy that request.  The onSet function of GarageCOLevelRisingThreshold is shown below;

SNMP_ERRSTAT DGarageObjects::OnSet_GarageCOLevelRisingThreshold(ESnmpSetOpCodeeOpCode, tUint32 transactionId, const tASN_INT& nVal, void** ppContextInfo)

{

       switch (eOpCode)

       {

       case eSNMP_SET_TEST:

              {

                 //store variable in the *ppContextInfo

                 *ppContextInfo = new tASN_INT(m_nGarageCOLevelRisingThreshold);

                 return eSNMP_ERRSTAT_NO_ERROR;

              }

       case eSNMP_SET_COMMIT:

              {

                 m_nGarageCOLevelRisingThreshold = nVal;

                 return eSNMP_ERRSTAT_NO_ERROR;

              }

       case eSNMP_SET_UNDO:

              {

                 //restore variable from the *ppContextInfo

                 m_nGarageCOLevelRisingThreshold= *((tASN_INT*)*ppContextInfo);

                 return eSNMP_ERRSTAT_NO_ERROR;

              }

       case eSNMP_SET_CLEANUP:

              {

                 if(*ppContextInfo)

                    delete (tASN_INT*)(*ppContextInfo);

          return eSNMP_ERRSTAT_NO_ERROR;

              }

       }

       return eSNMP_ERRSTAT_GENERAL_ERR;

}

 

In this particular case, the user wants to set a threshold for CO rising level.  If  CO rises above this level, a notification is sent to the user.  This function stores this threshold value in ‘m_nGarageCOLevelRisingThreshold’.  In this particular case, no additional code needs to be added to the generated code.  This function is called a number of times with different eOpCode values to satisfy the SNMP requirement of multi-step set.  The actual threshold value is stored when the function is called with eOpCode:eSNMP_SET_COMMIT.  For a detailed discussion on multi-step SET, please see the Tutorials section. 

Please proceed to Quick Start – Sending Notifications.

 

Previous    Next