Commit e1195ab4 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/snmpd: add template for scalar groups

To avoid multiple copies of the same/simillar code template for scalar groups
is introduced. File wrsGroupTemplate.h should be included into file defining
scalar group.

pickinfo and FIELD definition was moved to wrsSnmp.h
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 2fa02f9f
static int group_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int obj; /* the final index */
struct pickinfo *pi;
void *ptr;
int len;
/*
* Retrieve information from ppsi itself. But this function
* is called once for every item, so only query the whole set
* once every 2 seconds.
*/
GT_DATA_FILL_FUNC();
switch (reqinfo->mode) {
case MODE_GET:
/* "- 2" because last is 0 for all scalars, I suppose */
obj = requests->requestvb->name[
requests->requestvb->name_length - 2];
obj--; /* we are 0-based */
if (obj < 0 || obj >= ARRAY_SIZE(GT_PICKINFO)) {
snmp_log(LOG_ERR,
"wrong index (%d) in "GT_GROUP_NAME"\n",
obj + 1);
return SNMP_ERR_GENERR;
}
pi = GT_PICKINFO + obj;
ptr = (void *)&GT_DATA_STRUCT + pi->offset;
len = pi->len;
if (len > 8) /* special case for strings */
len = strnlen(ptr, len);
snmp_set_var_typed_value(requests->requestvb,
pi->type, ptr, len);
break;
default:
snmp_log(LOG_ERR, "unknown mode (%d) in "GT_GROUP_NAME"\n",
reqinfo->mode);
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
/* init function */
void GT_INIT_FUNC(void)
{
const oid wrsGT_oid[] = { GT_OID };
netsnmp_handler_registration *hreg;
/* do the registration for the scalars/globals */
hreg = netsnmp_create_handler_registration(
GT_GROUP_NAME, group_handler,
wrsGT_oid, OID_LENGTH(wrsGT_oid),
HANDLER_CAN_RONLY);
netsnmp_register_scalar_group(
hreg, 1 /* min */, ARRAY_SIZE(GT_PICKINFO) /* max */);
}
......@@ -41,13 +41,6 @@ static struct wrs_shm_head *ppsi_head;
static struct pp_globals *ppg;
struct wr_servo_state_t *ppsi_servo;
#define FIELD(_struct, _type, _field) { \
.type = _type, \
.offset = offsetof(struct _struct, _field), \
.len = sizeof(_struct._field), \
}
/* Our data: globals */
static struct wrs_p_globals {
ClockIdentity gm_id; /* FIXME: not implemented */
......
......@@ -85,4 +85,15 @@ extern void init_wrsDate(void);
#define WRS_OID 1, 3, 6, 1, 4, 1, 96, 100
struct pickinfo {
/* Following fields are used to format the output */
int type; int offset; int len;
};
#define FIELD(_struct, _type, _field) { \
.type = _type, \
.offset = offsetof(struct _struct, _field), \
.len = sizeof(_struct._field), \
}
#endif /* WRS_SNMP_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment