Cpp Lesson 5

Tutorial for Visual xAgentBuilder for C++

Lesson 5: Multiprotocol Agent

In this lesson we’ll combine SNMP and HTTP agent into a single executable.


int main(int argc, char*


   BTime tm;

   BMibHandlerEx mh;

   mh.Init(&tm, NULL);

   BAgents agents(tm);

   BSNMPAgent snmpAgent(tm, &mh, NULL, NULL);


   BWebAgent webAgent(tm, &mh, NULL);


   tInt32 err = agents.Init();

   if (err != NDERR_NO_ERROR)

       return err;

   BCommunity& cmt = snmpAgent.CBSecSubsystem().Community();

   cmt.Add(“public”, eMaxAccessReadOnly);

   cmt.Add(“private”, eMaxAccessReadCreate);

   BCLI cli( &mh );


   for (int i=0; i<agents.GetNumAgents(); i++ )


   err = agents.Start();

   if (err != NDERR_NO_ERROR)

       return err;


   cli.Start(“ndmp# “);



   return 0;



Both SNMP and HTTP agent are crated and registered with “agents” object. “agents” is instance of BAgents class, which is simply a collection of BAgent derived objects. While nothing prevents us from simply combining Lesson3 and Lesson4 code, using BAgents collection makes it easier to extend with future protocol agents.

There is no much to say in this lesson since behavior of both agents was explained in previous two lessons.

There is one thing worth noting here. Both agents are initialized in the following call

   tInt32 err = agents.Init();

BAgents’sInit method simply calls Init method on all registered agent.
Since no parameters are provided (and can not be provided), agents are initialized with default parameters.

For SNMP agent it means: version SNMPv2c and port 161.

For HTTP agent default parameters are: port 80, root directory is the same as application’s working directory and default page is “Home.html”.


Please proceed to Lesson 6: Non-Volatile Storage topic.

Previous    Next