14.12.2012 Views

OpenCard Framework 1.2 Programmer's Guide - OpenSCDP

OpenCard Framework 1.2 Programmer's Guide - OpenSCDP

OpenCard Framework 1.2 Programmer's Guide - OpenSCDP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5. Advanced programming with OCF<br />

In this chapter, we’ll show you some more advanced programming concepts of the<br />

OPENCARD FRAMEWORK.<br />

Working with <strong>OpenCard</strong> events<br />

<strong>OpenCard</strong> uses the Observer design pattern to inform listeners about events that<br />

happen in the framework.<br />

In the OPENCARD FRAMEWORK reference implementation, there are a number of<br />

objects that can be the source of <strong>OpenCard</strong>Event objects that other framework<br />

components or the application itself might be interested in. The implementation of<br />

the event notification is based on EventObject class and EventListener interface of<br />

the java.util package.<br />

Objects that are interested in receiving event notifications must implement some<br />

extension of the EventListener interface and register with the proper object by<br />

adding themselves as listeners.<br />

As an application programmer, you may be interested in the following types of<br />

OPENCARD FRAMEWORK events:<br />

v events signalling that a card was inserted or removed into a card terminal,<br />

v events signalling that a tracer issued a tracing message.<br />

CardTerminalEvent<br />

In previous versions of OCF the CardTerminalRegistry was responsible to emit<br />

card insertion/removal events. This function is now moved to class<br />

EventGenerator in the events package to have a clearer separation between the<br />

events and terminal package. The EventGenerator continuously monitors the state<br />

of physical card reader devices and emits CardTerminalEvents if the state changes.<br />

The CTListener interface defines two methods, cardInserted() and cardRemoved(),<br />

through which CardTerminalEvents can be communicated to objects interested in<br />

these events.<br />

You can register objects that are interested in receiving CardTerminalEvents<br />

provided they implement the CTListener interface. You can register your<br />

CTListener with the system-wide EventGenerator instance using the addListener()<br />

and removeListener() methods. The registered objects will then receive all<br />

CardTerminalEvents produced by all currently-registered CardTerminal objects.<br />

Locking a CardTerminal<br />

Once you hava a SmartCard object you can gain exclusive access using the<br />

SmartCard.beginMutex() methods. This is described under “Gaining exclusive<br />

access to the smart card” on page 35<br />

There are other scenarios like transferring money from one smartcard to another<br />

one where you need to maintain a lock on an individual slot or the whole<br />

CardTerminal across card insertions and card removals.<br />

29

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!