From 66fbc91f614ba67390e8b0d6b0408bc2ece5a269 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Sun, 5 Feb 2012 11:44:51 -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). Applies to CUPS 1.5.1 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 3a975bb..a56b5d9 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 <= 5) { switch (supplies[i].type) @@ -955,6 +972,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