> The following is the snippet where all the ***actions*** are:
> my_handler[i] =
> netsnmp_create_handler_registration(
> //"apFrameId", netsnmp_instance_int_handler,
> "apFrameId", netsnmp_scalar_helper_handler,
> apFrameId_oid, OID_LENGTH(apFrameId_oid),
> HANDLER_CAN_RWRITE);
> netsnmp_register_scalar(my_handler[i]);
OK - thanks.
That's helped identify where (some of) the confusion lies.
If nothing else, the 'netsnmp_instance_int_handler' and
'netsnmp_scalar_helper_handler' aren't strictly comparable - they're
tackling slightly different situations.
It also looks as if you're using things in a somewhat unusual
(IMO) manner. So I think I'd want to take a step back and suggest
a slightly different approach.
As a basic rule of thumb, the second parameter of the
netsnmp_create_handler_registration() call is intended for *your*
handler routine. I wouldn't expect to see an internal helper name there.
(Wes and/or Robert may see things differently, but that's how I have
always understood this mechanism).
So (working with a single object) the simplest form of registration
code would be either:
my_handler = netsnmp_create_handler_registration(
"apFrameId", apFrame_handler,
apFrameId_oid, OID_LENGTH(apFrameId_oid),
HANDLER_CAN_RWRITE);
netsnmp_register_scalar(my_handler);
or
my_handler = netsnmp_create_handler_registration(....);
netsnmp_register_instance(my_handler);
with the apFrameId_oid including the trailing '0' subidentifier in
the second case. But the netsnmp_create_handler_registration()
parameters are the same in each case.
Both of these would leave the task of actually providing the value
for "apFrameId.0" up to you - in the routine 'apFrame_handler'.
But this routine would only be called for a valid request - it could
safely ignore questions of error handling.
So that's one approach - where you do the core work, and the helpers
just deal with the support stuff. (Using the internal handlers
netsnmp_scalar_helper_handler and netsnmp_instance_helper_handler)
Another approach is where you get the helpers to provide the value
as well, and you don't need to write *any* code to handle a request
(other than pointing the agent to the appropriate internal variable).
Since there's nothing for you to do, you don't need a user-provided
handler, so the netsnmp_create_handler_registration call will be:
my_handler = netsnmp_create_handler_registration(
"apFrameId", NULL,
apFrameId_oid, OID_LENGTH(apFrameId_oid),
HANDLER_CAN_RWRITE);
i.e. with a NULL second parameter.
This holds for both scalar and instance versions (with the usual
difference in the OID). Both cases then need to register this
structure, together with the internal variable buffer to watch.
But unlike the earlier example, the calls to do this are
significantly different.
For the instance (integer-only) case, there are a family of registration
routines, depending on the type of the internal variable:
netsnmp_register_ulong_instance()
netsnmp_register_long_instance()
netsnmp_register_int_instance()
(plus read-only versions of each of these)
These registration routines actually include the call to
netsnmp_create_handler_registration internally. So you might
implement this object (instance) using something like:
-----
static int apFrameID;
netsnmp_register_int_instance(
"apFrameId",
apFrameId_oid, OID_LENGTH(apFrameId_oid),
&apFrameId, NULL);
-----
(The order of the parameters is slightly different too, with the user
handler moved to the end, but the idea is basically the same).
With a watched *scalar* object, this uses the (single) registration
call 'netsnmp_register_watched_scalar', which is similar to the earlier
two registrations, but takes an extra parameter describing the internal
variable to watch.
So the same implementation would be:
-----
static int apFrameID;
my_handler = netsnmp_create_handler_registration(
"apFrameId", NULL,
apFrameId_oid, OID_LENGTH(apFrameId_oid),
HANDLER_CAN_RWRITE);
winfo = netsnmp_create_watcher_info(
&apFrameId, sizeof(apFrameId),
ASN_INTEGER, WATCHER_FIXED_SIZE);
netsnmp_register_watched_scalar( my_handler, winfo );
-----
As a single call, the 'netsnmp_register_int_instance' style is probably
easier, but the 'netsnmp_register_watched_scalar' is closer in form to
the other helper registrations.
And it can cope with non-integer syntax types as well, by tweaking the
'netsnmp_create_watcher_info' call in the obvious manner. (As well as
handling invalid instances properly)
But you pays your money, and takes your choice.....
Hope this helps.
Dave
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Net-snmp-users mailing list
[EMAIL PROTECTED]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users