1 20 21 22 package org.snmp4j.agent.mo.snmp; 23 24 import org.snmp4j.agent.mo.MOScalar; 25 import org.snmp4j.agent.mo.MOAccessImpl; 26 import org.snmp4j.smi.Integer32; 27 import org.snmp4j.smi.OID; 28 import org.snmp4j.agent.request.SubRequest; 29 import org.snmp4j.mp.SnmpConstants; 30 import org.snmp4j.agent.request.RequestStatus; 31 32 public class TestAndIncr extends MOScalar { 33 34 public TestAndIncr(OID oid) { 35 super(oid, MOAccessImpl.ACCESS_READ_WRITE, new Integer32(0)); 36 } 37 38 public void commit(SubRequest request) { 39 RequestStatus status = request.getStatus(); 40 int v = ((Integer32)getValue()).getValue(); 41 request.setUndoValue(getValue()); 42 if (v == Integer.MAX_VALUE) { 43 v = 0; 44 } 45 else { 46 v++; 47 } 48 setValue(new Integer32(v)); 49 status.setPhaseComplete(true); 50 } 51 52 public void prepare(SubRequest request) { 53 super.prepare(request); 54 if (!request.hasError()) { 55 Integer32 value = (Integer32) request.getVariableBinding().getVariable(); 56 if (!getValue().equals(value)) { 57 request.getStatus(). 58 setErrorStatus(SnmpConstants.SNMP_ERROR_INCONSISTENT_VALUE); 59 } 60 } 61 } 62 63 public int isValueOK(SubRequest request) { 64 Integer32 value = (Integer32) request.getVariableBinding().getVariable(); 65 if (value.getValue() < 0) { 66 return SnmpConstants.SNMP_ERROR_WRONG_VALUE; 67 } 68 return SnmpConstants.SNMP_ERROR_SUCCESS; 69 } 70 71 } 72 | Popular Tags |