Home
About NuDesign
Sales
Support
Eval Download
Partners
Testimonials
SNMP Links
Tutorials
News

Tutorial for Visual xAgentBuilder for C++

Lesson 5: Multiprotocol Agent

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

 

int main(int argc, char* argv[])

{

   BTime tm;

 

   BMibHandlerEx mh;

   mh.Init(&tm, NULL);

 

   BAgents agents(tm);

 

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

   agents.Register("SNMP", &snmpAgent);

 

   BWebAgent webAgent(tm, &mh, NULL);

   agents.Register("HTTP", &webAgent);

 

   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 );

 

   cli.Register(&agents);

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

       cli.Register(agents.AgentAt(i));

 

   err = agents.Start();

   if (err != NDERR_NO_ERROR)

       return err;

 

   cli.Stream().Write(HEADING);

   cli.Start("ndmp# ");

 

   agents.Stop();

 

   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’s Init 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  try it out and when finished proceed to Lesson 6: Non-Volatile Storage topic.

 

Previous    Next