From ee5af65d49572f92694531b24dad836d50e7ed9d Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Wed, 1 Feb 2012 10:34:25 -0500 Subject: [PATCH 3/3] Fix status reports when supply levels grow Supply levels can be reported as growing toward limit (rather than shrinking to 0). As enumerated in RFC 1759, this condition is indicated when prtMarkerSuppliesClass value = 4 (receptacle that is filled). For the purposes of evaluating supply status only, normalize supply values that grow toward max_capacity to decrease to 0 instead. Also, do not evaluate supply status for 'other' supply classes (ie., neither consumed nor filled). Signed-off-by: Peter Hurley --- backend/snmp-supplies.c | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-) diff --git a/backend/snmp-supplies.c b/backend/snmp-supplies.c index a6cff9a..c58bf12 100644 --- a/backend/snmp-supplies.c +++ b/backend/snmp-supplies.c @@ -56,6 +56,7 @@ typedef struct /**** Printer supply data ****/ color[8]; /* Color: "#RRGGBB" or "none" */ int colorant, /* Colorant index */ type, /* Supply type */ + class, /* Supply class (consumed/filled) */ units, /* Supply units (capacity & level)*/ max_capacity, /* Maximum capacity */ level; /* Current level value */ @@ -154,6 +155,13 @@ static const int prtMarkerSuppliesSupplyUnit[] = (sizeof(prtMarkerSuppliesSupplyUnit) / sizeof(prtMarkerSuppliesSupplyUnit[0])); /* Offset to supply index */ +static const int prtMarkerSuppliesClass[] = + { CUPS_OID_prtMarkerSuppliesClass, -1 }, + /* Type OID */ + prtMarkerSuppliesClassOffset = + (sizeof(prtMarkerSuppliesClass) / + sizeof(prtMarkerSuppliesClass[0])); + /* Offset to supply index */ static const backend_state_t const printer_states[] = { @@ -261,6 +269,15 @@ backendSNMPSupplies( sprintf(ptr, "%d", percent); + /* normalize percent (for status purposes) if supply is filled (rather + * than consumed) and don't evaluate status for supply types that are + * neither consumed nor filled + */ + if (supplies[i].class == CUPS_TC_receptacleThatIsFilled && percent >= 0) + percent = (percent < 100) ? 100 - percent : 0; + else if (supplies[i].class == CUPS_TC_other) + continue; + if (percent >= 0 && percent <= 10) { switch (supplies[i].type) @@ -954,6 +971,25 @@ backend_walk_cb(cups_snmp_t *packet, /* I - SNMP packet */ supplies[i - 1].units = packet->object_value.integer; } + else if (_cupsSNMPIsOIDPrefixed(packet, prtMarkerSuppliesClass)) + { + /* + * Get marker class... + */ + + i = packet->object_name[prtMarkerSuppliesClassOffset]; + if (i < 1 || i > CUPS_MAX_SUPPLIES || + packet->object_type != CUPS_ASN1_INTEGER) + return; + + fprintf(stderr, "DEBUG2: prtMarkerSuppliesClass.1.%d = %d\n", i, + packet->object_value.integer); + + if (i > num_supplies) + num_supplies = i; + + supplies[i - 1].class = packet->object_value.integer; + } } -- 1.7.5.4