use of iso.std.iso_iec._24727.tech.schema.IFDStatusType in project open-ecard by ecsec.
the class IfdEventManager method wait.
@Nonnull
protected List<IFDStatusType> wait(@Nonnull List<IFDStatusType> lastKnown) throws WSException {
Wait wait = new Wait();
wait.setContextHandle(ctx);
wait.getIFDStatus().addAll(lastKnown);
WaitResponse resp = env.getIFD().wait(wait);
WSHelper.checkResult(resp);
List<IFDStatusType> result = resp.getIFDEvent();
return result;
}
use of iso.std.iso_iec._24727.tech.schema.IFDStatusType in project open-ecard by ecsec.
the class IfdEventRunner method ifdStatus.
@Nonnull
private List<IFDStatusType> ifdStatus() throws WSException {
LOG.debug("Requesting terminal names.");
ListIFDs listReq = new ListIFDs();
listReq.setContextHandle(ctxHandle);
ListIFDsResponse ifds = env.getIFD().listIFDs(listReq);
WSHelper.checkResult(ifds);
LOG.debug("Requesting status for all terminals found.");
ArrayList<IFDStatusType> result = new ArrayList<>();
for (String ifd : ifds.getIFDName()) {
GetStatus status = new GetStatus();
status.setContextHandle(ctxHandle);
status.setIFDName(ifd);
GetStatusResponse statusResponse = env.getIFD().getStatus(status);
try {
WSHelper.checkResult(statusResponse);
result.addAll(statusResponse.getIFDStatus());
} catch (WSException ex) {
String msg = "Failed to request status from terminal, assuming no card present.";
LOG.error(msg, ex);
IFDStatusType is = new IFDStatusType();
is.setIFDName(ifd);
result.add(is);
}
}
return result;
}
use of iso.std.iso_iec._24727.tech.schema.IFDStatusType in project open-ecard by ecsec.
the class IfdEventRunner method fireEvents.
private void fireEvents(@Nonnull List<IFDStatusType> diff) {
for (IFDStatusType term : diff) {
String ifdName = term.getIFDName();
// find out if the terminal is new, or only a slot got updated
IFDStatusType oldTerm = getCorresponding(ifdName, currentState);
boolean terminalAdded = oldTerm == null;
IFDCapabilitiesType slotCapabilities = getCapabilities(ifdName);
if (terminalAdded) {
// TERMINAL ADDED
// make copy of term
oldTerm = new IFDStatusType();
oldTerm.setIFDName(ifdName);
oldTerm.setConnected(true);
// add to current list
currentState.add(oldTerm);
// create event
ConnectionHandleType h = makeConnectionHandle(ifdName, null, slotCapabilities);
LOG.debug("Found a terminal added event ({}).", ifdName);
env.getEventDispatcher().notify(EventType.TERMINAL_ADDED, new IfdEventObject(h));
}
// check each slot
for (SlotStatusType slot : term.getSlotStatus()) {
SlotStatusType oldSlot = getCorresponding(slot.getIndex(), oldTerm.getSlotStatus());
boolean cardPresent = slot.isCardAvailable();
boolean cardWasPresent = oldSlot != null && oldSlot.isCardAvailable();
if (cardPresent && !cardWasPresent) {
// CARD INSERTED
// copy slot and add to list
SlotStatusType newSlot = oldSlot;
if (newSlot == null) {
newSlot = new SlotStatusType();
oldTerm.getSlotStatus().add(newSlot);
}
newSlot.setIndex(slot.getIndex());
newSlot.setCardAvailable(true);
newSlot.setATRorATS(slot.getATRorATS());
// create event
LOG.debug("Found a card insert event ({}).", ifdName);
LOG.info("Card with ATR={} inserted.", ByteUtils.toHexString(slot.getATRorATS()));
ConnectionHandleType handle = makeUnknownCardHandle(ifdName, newSlot, slotCapabilities);
env.getEventDispatcher().notify(EventType.CARD_INSERTED, new IfdEventObject(handle));
try {
SingleThreadChannel ch = cm.openMasterChannel(ifdName);
if (evtManager.isRecognize()) {
String proto = ch.getChannel().getCard().getProtocol().toUri();
evtManager.threadPool.submit(new Recognizer(env, handle, proto));
}
} catch (NoSuchTerminal | SCIOException ex) {
LOG.error("Failed to connect card, nevertheless sending CARD_INSERTED event.", ex);
}
} else if (!terminalAdded && !cardPresent && cardWasPresent) {
// this makes only sense when the terminal was already there
// CARD REMOVED
// remove slot entry
BigInteger idx = oldSlot.getIndex();
Iterator<SlotStatusType> it = oldTerm.getSlotStatus().iterator();
while (it.hasNext()) {
SlotStatusType next = it.next();
if (idx.equals(next.getIndex())) {
it.remove();
break;
}
}
LOG.debug("Found a card removed event ({}).", ifdName);
ConnectionHandleType h = makeConnectionHandle(ifdName, idx, slotCapabilities);
env.getEventDispatcher().notify(EventType.CARD_REMOVED, new IfdEventObject(h));
}
}
// terminal removed event comes after card removed events
boolean terminalPresent = term.isConnected();
if (!terminalPresent) {
// TERMINAL REMOVED
Iterator<IFDStatusType> it = currentState.iterator();
while (it.hasNext()) {
IFDStatusType toDel = it.next();
if (toDel.getIFDName().equals(term.getIFDName())) {
it.remove();
}
}
ConnectionHandleType h = makeConnectionHandle(ifdName, null, slotCapabilities);
LOG.debug("Found a terminal removed event ({}).", ifdName);
env.getEventDispatcher().notify(EventType.TERMINAL_REMOVED, new IfdEventObject(h));
}
}
}
use of iso.std.iso_iec._24727.tech.schema.IFDStatusType in project open-ecard by ecsec.
the class EventWatcher method convert.
@Nonnull
private IFDStatusType convert(@Nonnull TerminalState next) {
IFDStatusType result = new IFDStatusType();
result.setIFDName(next.getName());
result.setConnected(true);
SlotStatusType slot = new SlotStatusType();
result.getSlotStatus().add(slot);
slot.setIndex(BigInteger.ZERO);
slot.setCardAvailable(next.isCardPresent());
return result;
}
use of iso.std.iso_iec._24727.tech.schema.IFDStatusType in project open-ecard by ecsec.
the class EventWatcher method clone.
@Nonnull
private static IFDStatusType clone(@Nonnull IFDStatusType orig) {
IFDStatusType newStat = new IFDStatusType();
newStat.setIFDName(orig.getIFDName());
newStat.setConnected(orig.isConnected());
for (SlotStatusType next : orig.getSlotStatus()) {
newStat.getSlotStatus().add(clone(next));
}
return newStat;
}
Aggregations