private void reportStatus(String message, Status status) { if (!status.isSuccess()) { logger.log(Level.WARNING, message + ": " + status.getMessage()); // for developers String dump = status.getStackDump(); if (dump != null && !dump.isEmpty()) logger.log(Level.FINER, message + ": " + status.getMessage() + ", cause:\n" + dump); } }
// ChannelPutRequester @Override public void putDone(final Status status, final ChannelPut channelPut) { if (status.isSuccess()) logger.log(Level.FINE, "Write {0} = {1} completed", new Object[] {pv.getName(), new_value}); else { error = new Exception( "Write " + pv.getName() + " = " + new_value + " failed, " + status.toString()); logger.log(Level.WARNING, "", error); } updates.countDown(); channelPut.destroy(); }
/* (non-Javadoc) * @see org.epics.pvdata.monitor.MonitorRequester#monitorConnect(org.epics.pvdata.pv.Status, org.epics.pvdata.monitor.Monitor, org.epics.pvdata.pv.Structure) */ @Override public void monitorConnect(Status status, Monitor monitor, Structure structure) { reportStatus("Failed to create monitor", status); if (status.isSuccess()) { // this.monitor = monitor; monitor.start(); } }
/* (non-Javadoc) * @see org.epics.pvaccess.client.ChannelPutRequester#putDone(org.epics.pvdata.pv.Status) */ @Override public void putDone(Status status) { reportStatus("Failed to put value", status); WriteRequest writeRequest; synchronized (writeRequests) { writeRequest = writeRequests.poll(); } if (writeRequest != null) { if (status.isSuccess()) { writeRequest.getCallback().channelWritten(null); } else { writeRequest.getCallback().channelWritten(new Exception(status.getMessage())); } doNextWrite(); } }
/* (non-Javadoc) * @see org.epics.pvaccess.client.GetFieldRequester#getDone(org.epics.pvdata.pv.Status, org.epics.pvdata.pv.Field) */ @Override public void getDone(Status status, Field field) { reportStatus("Failed to instrospect channel '" + channel.getChannelName() + "'", status); if (status.isSuccess()) { channelType = field; Field valueField = ((Structure) channelType).getField("value"); if (valueField != null && valueField.getID().equals("enum_t")) { isChannelEnumType = true; // TODO could create a monitor just to get value.choices } else isChannelEnumType = false; } processConnection(this); }
// ChannelPutRequester @Override public void channelPutConnect( final Status status, final ChannelPut channelPut, final Structure structure) { if (!status.isSuccess()) { error = new Exception("Failed to connect 'put' for " + pv.getName() + ": " + status); updates.countDown(); return; } try { final PVStructure write_structure = PVDataFactory.getPVDataCreate().createPVStructure(structure); final BitSet bit_set = new BitSet(write_structure.getNumberFields()); // Locate the value field at deepest level in structure PVField field = null; PVStructure search = write_structure; while (search != null) { final PVField[] fields = search.getPVFields(); if (fields.length != 1) throw new Exception( "Can only write to simple struct.element.value path, got " + structure); if (fields[0].getFieldName().equals("value")) { field = fields[0]; break; } else if (fields[0] instanceof PVStructure) search = (PVStructure) fields[0]; else search = null; } if (field == null) throw new Exception("Cannot locate 'value' to write in " + structure); // Enumerated? Write to value.index if (field instanceof PVStructure && "enum_t".equals(field.getField().getID())) field = ((PVStructure) field).getSubField("index"); // Indicate what's changed & change it bit_set.set(field.getFieldOffset()); PVStructureHelper.setField(field, new_value); // Perform write channelPut.put(write_structure, bit_set); } catch (Exception ex) { logger.log(Level.WARNING, "Failed to write " + pv.getName() + " = " + new_value, ex); error = new Exception("Failed to write " + pv.getName() + " = " + new_value, ex); updates.countDown(); } }
/* (non-Javadoc) * @see org.epics.pvaccess.client.ChannelPutRequester#channelPutConnect(org.epics.pvdata.pv.Status, org.epics.pvaccess.client.ChannelPut, org.epics.pvdata.pv.PVStructure, org.epics.pvdata.misc.BitSet) */ @Override public void channelPutConnect( Status status, ChannelPut channelPut, PVStructure pvStructure, BitSet bitSet) { reportStatus("Failed to create ChannelPut instance", status); if (status.isSuccess()) { this.channelPut = channelPut; if (isChannelEnumType) { // handle inconsistent behavior this.channelPutValueField = pvStructure.getSubField("value"); if (this.channelPutValueField instanceof PVStructure) this.channelPutValueField = ((PVStructure) pvStructure).getSubField("index"); } else { this.channelPutValueField = pvStructure.getSubField("value"); } // set BitSet bitSet.clear(); // re-connect case if (this.channelPutValueField != null) bitSet.set(channelPutValueField.getFieldOffset()); } doNextWrite(); }