Developers guide
116
} else if(outletInt == SNMP_OUTLET_OFF ) {
return OUTLET_OFF;
} else if(outletInt == SNMP_OUTLET_REBOOT ) {
return OUTLET_REBOOT;
} else if(outletInt == SNMP_OUTLET_UNKNOWN ) {
return OUTLET_UNKNOWN;
} else if(outletInt == SNMP_OUTLET_ON_WITH_DELAY ) {
return OUTLET_ON_WITH_DELAY;
} else if(outletInt == SNMP_OUTLET_OFF_WITH_DELAY ) {
return OUTLET_OFF_WITH_DELAY;
} else if(outletInt == SNMP_OUTLET_REBOOT_WITH_DELAY ) {
return OUTLET_REBOOT_WITH_DELAY;
} else {
log.log(Level.WARNING, "Undefined outlet state: "+outletInt);
return "UNDEFINED";
}
}
public synchronized String setOutletName(int outlet, String newName) throws MasterswitchException {
checkOutlet(outlet);
if( newName == null ) {
throw new NullPointerException("Must specify a newName");
}
String oid = mibModule.getNode(sPDUOutletName).getOID().toJavaValue() + "."+outlet;
log.log(Level.FINE, "OID = "+oid);
// Try to set the value
doSNMPSet(oid, new SnmpOctetString( newName.getBytes() ) );
// Get the value to check that the set was successful
// --> it will fail if another user is logged in
String returnVal = (doSNMPGet(oid )).toString();
if( ! returnVal.equals( newName) ) {
log.log(Level.WARNING, "Request ignored by apt.masterswitch.masterswitch. Another user is probably
logged in");
}
return returnVal;
}
public synchronized String setOutletState(int outlet, String outletState) throws MasterswitchException {
checkOutlet(outlet);
int snmpState;
if( outletState.equals( OUTLET_ON ) ) {
snmpState = SNMP_OUTLET_ON;
} else if( outletState.equals( OUTLET_OFF ) ){
snmpState = SNMP_OUTLET_OFF;
} else if( outletState.equals( OUTLET_REBOOT ) ){
snmpState = SNMP_OUTLET_REBOOT;
} else if( outletState.equals( OUTLET_UNKNOWN ) ) {
snmpState = SNMP_OUTLET_UNKNOWN;
} else if( outletState.equals( OUTLET_ON_WITH_DELAY ) ) {
snmpState = SNMP_OUTLET_ON_WITH_DELAY;
} else if( outletState.equals( OUTLET_OFF_WITH_DELAY ) ) {
snmpState = SNMP_OUTLET_OFF_WITH_DELAY;
} else if( outletState.equals( OUTLET_REBOOT_WITH_DELAY ) ) {
snmpState = SNMP_OUTLET_REBOOT_WITH_DELAY;
} else {
// The user has tried to set the outlet to an undefined state
throw new MasterswitchException("Cannot set outlet to state \""+outletState+"\", it is undefined");
}
String oid = mibModule.getNode(sPDUOutletCtl).getOID().toJavaValue() + "."+outlet;
log.log(Level.FINE, "OID = "+oid);
// Try to set the value
doSNMPSet(oid, new SnmpInt32(snmpState ));
// Get the value to check that it was set
SnmpInt32 returnedVal = (SnmpInt32)doSNMPGet(oid);
if( returnedVal.getValue() != snmpState ) {










