int GET_SENSOR(AGENT_REQUEST *request, AGENT_RESULT *result) { char *device, *name, *function; int do_task, cnt = 0; double aggr = 0; if (3 < request->nparam) return SYSINFO_RET_FAIL; device = get_rparam(request, 0); name = get_rparam(request, 1); function = get_rparam(request, 2); if (NULL == device || '\0' == *device) return SYSINFO_RET_FAIL; if (NULL == name || '\0' == *name) return SYSINFO_RET_FAIL; if (NULL == function || '\0' == *function) do_task = DO_ONE; else if (0 == strcmp(function, "avg")) do_task = DO_AVG; else if (0 == strcmp(function, "max")) do_task = DO_MAX; else if (0 == strcmp(function, "min")) do_task = DO_MIN; else return SYSINFO_RET_FAIL; if (DO_ONE != do_task && 0 != isdigit(name[strlen(name)-1])) do_task = DO_ONE; if (DO_ONE != do_task && 0 == isalpha(name[strlen(name)-1])) return SYSINFO_RET_FAIL; get_device_sensors(do_task, device, name, &aggr, &cnt); if (0 == cnt) return SYSINFO_RET_FAIL; if (DO_AVG == do_task) SET_DBL_RESULT(result, aggr / cnt); else SET_DBL_RESULT(result, aggr); return SYSINFO_RET_OK; }
int GET_SENSOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char device[MAX_STRING_LEN], name[MAX_STRING_LEN], function[8]; int do_task, cnt = 0; double aggr = 0; if (num_param(param) > 3) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, device, sizeof(device))) return SYSINFO_RET_FAIL; if (0 != get_param(param, 2, name, sizeof(name))) return SYSINFO_RET_FAIL; if (0 != get_param(param, 3, function, sizeof(function))) do_task = DO_ONE; else if (0 == strcmp(function, "avg")) do_task = DO_AVG; else if (0 == strcmp(function, "max")) do_task = DO_MAX; else if (0 == strcmp(function, "min")) do_task = DO_MIN; else return SYSINFO_RET_FAIL; get_device_sensors(do_task, device, name, &aggr, &cnt); if (0 == cnt) return SYSINFO_RET_FAIL; if (DO_AVG == do_task) SET_DBL_RESULT(result, aggr / cnt); else SET_DBL_RESULT(result, aggr); return SYSINFO_RET_OK; }