[AGENT++] How can I use ACE in SNMP++ and Agent++?
Martin Janzen
janzen at pixelmetrix.com
Wed May 12 09:43:09 CEST 2004
Xiao Wu wrote:
> Hi all,
> My task is to write a remote administration interface and I decided to
> use SNMP.
> For some reason, this task must be ACE-based(adaptive communication
> environment) and I also want to use Agent++, so how can I embed ACE
> network API into Agent++? I means how can I get rid of socket function
> calling in agent++ and replace them with ACE but keep down the other
> parts in Agent++?
We're using ACE as the framework for a process which, among other
things, acts as an SNMP agent using the Agent++ code. I would suggest
that you don't mess around with the Agent++ code at all, but instead use
the ACE facilities to do a select() for you and to give you a callback
whenever there is input for the SNMP agent -- something like this:
class MyAgent : public ACE_Event_Handler
{
MyAgent()
{
// Create or find your ACE Reactor.
mReactor = ... ;
// Create Agent++ objects as usual.
mSession = new Agentpp::Snmpx(...);
mMIB = new Agentpp::Mib(...);
mRequestList = new Agentpp::RequestList();
mMIB->set_request_list(mRequestList);
mRequestList->set_snmp(mSession);
// Tell ACE to call us back when an SNMP request is received.
mReactor->register_handler(mSession->get_session_fds(), this,
ACE_Event_Handler::READ_MASK);
}
~MyAgent()
{
// No more callbacks.
mReactor->deregister_handler(mSession->get_session_fds());
// Destroy everything else.
...
}
int handle_input(ACE_HANDLE fd)
{
Agentpp::Request* req = mRequestList->receive(0);
mMIB->process_request(req);
return CONTINUE; // Stay registered for more input.
}
};
Well, that's a bit simplified, but you should get the idea.
(If the request type is an SNMP Set, for instance, you probably want to
call mMIB->save_all() to save the states of any persistent managed
objects, maybe after a timeout in case you get lots of Set requests in a
row. Also, you should call mMIB->cleanup() periodically, to clean up
notReady table rows. But that doesn't have anything to do with ACE...)
Hope that helps!
--
Martin Janzen
janzen at pixelmetrix dot com
More information about the AGENTPP
mailing list