Ulrich,
 
U have to use static functions if using C++.  The function prototypes of c 
functions and static c++ functions are the same; however, the prototypes of c++ 
method functions are different (the actual class becomes part of the signature 
or something like that).  So it gets a bit tricky because anything that the 
static functions access have to be static as well.  I ended up creating c++ 
classes whose members were all static.  So why not just use C?  Although you 
lose most of the OOA/OOD concepts we enjoy, you keep scope with namespaces.  
I'm sure there are other reasons...
 
Here is an example header file and init function...

#ifndef MyDataHandler_H
#define MyDataHandler_H

#include "net-snmp/net-snmp-config.h"
#include "net-snmp/net-snmp-includes.h"
#include "net-snmp/agent/net-snmp-agent-includes.h"

class MyDataHandler{

public :

    // Destructor
    ~MyDataHandler();

    static void init();

    static int handleAttribute1(
        netsnmp_mib_handler* handler,
        netsnmp_handler_registration* reginfo,
        netsnmp_agent_request_info* reqinfo,
        netsnmp_request_info* requests);

    static int handleAttribute1(
        netsnmp_mib_handler* handler,
        netsnmp_handler_registration* reginfo,
        netsnmp_agent_request_info* reqinfo,
        netsnmp_request_info* requests);

private :
    // Constructor
    MyDataHandler

    static MyData myData;

};

#endif // MyDataHandler_H


void MyDataHandler::init() {
    static oid attribute1_oid[] = { 1,3,6,1,4,1,#,1 };
    static oid attribute2_oid[] = { 1,3,6,1,4,1,#,2 };

    DEBUGMSGTL(("myData", "Initializing\n"));

    netsnmp_register_scalar(
        netsnmp_create_handler_registration(
            "attribute1",
            MyDataHandler::handleAttribute1,
            attribute1_oid,
            OID_LENGTH(attribute1_oid),
            HANDLER_CAN_RWRITE
        ));

    netsnmp_register_scalar(
        netsnmp_create_handler_registration(
            "attribute2",
            MyDataHandler::handleAttribute2,
            attribute2_oid,
            OID_LENGTH(attribute2_oid),
            HANDLER_CAN_RWRITE
        ));
}

 
You pass the MyDataHandler::init() function when you register your sub agent.  
I have a handler for each data type and a sub agent singleton that handles the 
registering of the individual mib handlers.
 
Hope this helps.

> Subject: Passing methods as handlers?
> Date: Thu, 29 Oct 2009 11:41:42 +0100
> From: ulrich.schmidt-goe...@plath.de
> To: net-snmp-users@lists.sourceforge.net
> 
> Hi,
> 
> I am trying to add agent functionality to my program. Since I use OOP,
> I'd like to make the handlers methods of my agent class. However, so far
> my attempts have met the following error (on the line where I do
> netsnmp_register_scalar()):
> 
> argument of type 'int (SnmpAgent::)(netsnmp_mib_handler*,
> netsnmp_handler_registration*, netsnmp_agent_request_info*,
> netsnmp_request_info*)' does not match 'int (*)(netsnmp_mib_handler*,
> netsnmp_handler_registration*, netsnmp_agent_request_info*,
> netsnmp_request_info*)'
> 
> SnmpAgent is my own class. The handlers themselves and the
> netsnmp_register_scalar() invocations are just as mib2c generated them
> (with concrete data inserted, of course.)
> 
> Is there any way to make this work?
> 
> Best regards,
> Ulrich
> 
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay 
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Net-snmp-users mailing list
> Net-snmp-users@lists.sourceforge.net
> Please see the following page to unsubscribe or change other options:
> https://lists.sourceforge.net/lists/listinfo/net-snmp-users                   
>                   
_________________________________________________________________
Windows 7: I wanted more reliable, now it's more reliable. Wow!
http://microsoft.com/windows/windows-7/default-ga.aspx?h=myidea?ocid=PID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_myidea:102009
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to