|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.SwingWorker<Void,Runnable>
ds.ov2.gui.Terminal_thread
class Terminal_thread
Worker thread that performs all card related tasks. The GUI can
only be controlled from one thread, the GUI thread or, in SUN Java
speak, the event dispatch thread. Because the GUI thread should not
contain long running methods all the real work must be done in a
separate thread, the terminal thread or, in SUN Java speak, the
worker thread. The terminal thread is called terminal thread,
because most of the code it executes talks to a Java Card terminal.
The code of this class is executed on two threads: the GUI thread
and the terminal thread. Many methods can only be executed on one
thread. The method documentation indicates to which thread each
method belongs. The GUI starts the terminal thread by calling the
inherited method execute
, which then executes
doInBackground()
in a different thread.
The GUI and the terminal thread communicate in the following way. The
GUI sets the next_action
that the terminal thread should
execute and, if necessary, interrupts the terminal thread (via
set_next_action
). The terminal thread
performs an endless loop that always executes the action that is
found in next_action
. To simplify the logic here, each
role of the GUI has its own waiting action, which runs when the GUI
is waiting for the user to press some buttons. This waiting action
is started when the corresponding role is selected. The waiting
action then enables and disables all the buttons in the GUI as
cards are inserted and removed in an endless loop. The waiting
action only terminates if the terminal thread gets interrupted
because the GUI sets a new action.
The terminal thread publish'es
the actions to be
executed in the GUI. They are then somewhere queued by the swing
framework and get executed in the GUI in the process
method.
For simplicity all the actions that are communicated between the
GUI and the terminal thread are simply Runnable's
.
The action to be executed in the other thread is captured in the
run
method. The thread that creates an action
has to create a suitable anonymous class instance. This instance is
then communicated to the other thread (either via set_next_action
or via publish
).
The other thread then executes the action by calling the run
method. For creating anonymous classes and objects of
the Runnable
interface the Action
class is used.
The Runnable.run()
method does not permit any checked
exceptions, therefore all CardException's
are
wrapped in a Runtime_card_exception
.
If this class were properly written it would use a version of
Runnable
that permits CardException
in its run
method...
messages
field should be moved to Card_protocols
Nested Class Summary | |
---|---|
private static class |
Terminal_thread.Runtime_card_exception
Runtime version of CardException . |
Nested classes/interfaces inherited from class javax.swing.SwingWorker |
---|
SwingWorker.StateValue |
Field Summary | |
---|---|
private Object |
action_lock
Lock for next_action . |
boolean |
card_is_present
Remembers whether we believe that there is currently a card present in the configured card reader. |
private Card_protocols |
card_protocols
Card protocol instance. |
private Action |
clear_applet_list
GUI action to clear the applet list in the applet list dialog. |
private byte[] |
default_applet_name
The AID of the package that seems to be on any card. |
private Ov_demo_gui |
gui
The GUI object. |
private Gui_actions |
gui_actions
GUI actions for the GUI thread. |
(package private) Action |
gui_card_inserted
GUI Action to display "Card inserted" in the status line of the GUI. |
private Action |
gui_clear_message
GUI Action to clear the status line in the GUI. |
private Action |
gui_disable_ptls_actions
GUI Action to disable all the card maintenance buttons in the GUI. |
private Action |
gui_enable_ptls_actions
GUI Action to enable all the card maintenance buttons in the GUI. |
private Action |
gui_proof_finished
GUI Action to display "Proof finished. |
(package private) Action |
gui_wait_for_card
GUI Action to display the line "Waiting for a card ..." in the status line of the GUI. |
private Action |
gui_wait_for_card_removal
GUI Action to display "Please remove card" in the status line of the GUI. |
private Gui_protocol_messages |
messages
Instance for printing progess messages in the GUI. |
private Action |
next_action
Next action to execute in the terminal thread. |
private Action |
proof_failed_warning
GUI action to display a warning when the entry gate check failed. |
private Action |
resign_failed_warning
GUI action to display a warning when resigning fails. |
private Action |
resign_finished_action
GUI action for enabling the PTLS automaton run button and display a finished message in the status line. |
private Thread |
thread
The terminal thread. |
private Action |
wait_in_ptls_automaton
Terminal thread action for waiting in the PTLS automaton tab. |
private Action |
wait_in_ptls_office
Terminal thread wait action for the PTLS office. |
Constructor Summary | |
---|---|
Terminal_thread(Ov_demo_gui gui,
Gui_actions gui_actions,
Card_protocols card_protocols)
Constructor. |
Method Summary | |
---|---|
private Action |
applet_cap_file_warning(IOException e)
Gui action to display a warning if the applet file cannot be opened. |
private Action |
applet_install_failed_warning(cardservices.GlobalPlatformException e)
Gui action to display a warning dialog for applet installation errors. |
private Action |
applet_table_line(String kind,
Printable_aid name)
GUI action for adding an applet/package line to the applet list dialog. |
private Action |
card_communication_error_warning(String message)
Gui action to display a warning if card communication fails for some reason. |
private Action |
card_status(boolean everything)
Terminal thread action for displaying installed applets/packages in the applet list display. |
private Action |
delete_applets(Printable_aid[] aids,
boolean everything)
Terminal thread action to delete some applets/packages and update the applet list dialog afterwards. |
Void |
doInBackground()
Main loop of the terminal thread. |
private Applet_list_window |
get_applet_list_window()
Return the applet list window or throw an assertion if no such window is registered. |
private Action |
get_next_action()
Return the next action for the terminal thread and clear the next_action field. |
private Action |
gui_background_died(Throwable e)
GUI Action to display an error to the user on the fatal event that the terminal thread dies. |
void |
gui_card_message(BigInteger blinded_a,
String message)
GUI action to display a card appearence message. |
void |
gui_message(JTextPane pane,
String message,
boolean bold)
GUI action to display a message in a message text pane. |
void |
gui_progress_message(String message,
boolean bold)
GUI action to display a progress message. |
private Action |
gui_set_entry_run_button(boolean b)
GUI action to enable/disable the run button on the entry gate tab. |
private Action |
gui_set_ptls_automaton_button(boolean b)
GUI action to enable or disable the obtain-new-signature button in the PTLS automaton tab. |
private Action |
gui_status_line_message(String message)
GUI Action to display an arbitrary message in the status line. |
private Action |
install_applet_action(Applet_type applet_type)
Terminal thread action for installing one of the applets. |
private Action |
invalid_card_warning(String message)
Gui action to display a warning dialog if the card is invalid for some reason. |
private Action |
personalize_action(Applet_type applet_type)
Terminal thread action to personalize an applet. |
void |
process(List<Runnable> actions)
Process actions to change the GUI in the GUI thread (event dispatch thread). |
private Action |
proof_action(Applet_type applet_type)
Terminal thread action to run the entry-gate proof-protocol. |
private void |
proof_ex(Applet_type applet_type)
Exception wrapper for proof . |
private void |
proof(Applet_type applet_type)
Run the entry-gate proof-protocol on the card. |
private boolean |
publish_registry(cardservices.AIDRegistry r,
boolean everything)
Display all applets/packages of one registry in the applet list dialog. |
private Action |
reinstall_personalize(Applet_type applet_type)
Terminal thread action for reinstalling the applet with subsequent personalization. |
private Action |
reset_action(Applet_type applet_type)
Terminal thread action to reset an applet. |
private Action |
resign_action(Applet_type applet_type,
BigInteger[] updates)
Terminal thread action for resigning. |
void |
set_next_action(Action next_action)
Set the next action to be executed in the terminal thread and interrupt the action that currently executes on the terminal thread. |
protected void |
set_successor_action(Action successor_action)
Set a successor action for the currently executing action. |
void |
start_card_status_action(boolean everything)
Set card status action. |
void |
start_delete_applets(Printable_aid[] aids,
boolean everything)
Set applet/package deletion as next action in the terminal thread. |
void |
start_install_applet(Applet_type type)
Set the applet install action for the terminal thread. |
void |
start_personalize(Applet_type applet_type)
Set personalization as next action of the terminal thread. |
void |
start_proof(Applet_type applet_type)
Set the proof-protocol action as next action of the terminal thread. |
void |
start_reinstall_personalize(Applet_type applet_type)
Set reinstall + personalize as next action of the terminal thread. |
void |
start_reset_applet(Applet_type applet_type)
Set personalization as next action of the terminal thread. |
void |
start_resign(Applet_type applet_type,
BigInteger[] updates)
Set the resign action as next action to execute in the terminal thread. |
private boolean |
status_entry_filter(cardservices.AIDRegistryEntry e)
Filter the interesting applets/packages to display in the applet list dialog. |
void |
wait_for_card()
Wait until a card is inserted or the terminal thread is interrupted. |
private Action |
wait_in_entry_gate_action(boolean automatic_proof,
Applet_type applet_type)
Terminal thread action for waiting in the entry gate tab. |
void |
wait_in_entry_gate(Applet_type applet_type,
boolean automatic_proof)
Set the entry-gate waiting-action as next action of the terminal thread. |
void |
wait_in_ptls_automaton()
Set the waiting action of the PTLS automaton as next action. |
void |
wait_in_ptls_office()
Set the PTLS waiting action. |
void |
wait_until_card_is_removed()
Wait until the card is removed or the terminal thread is interrupted. |
Methods inherited from class javax.swing.SwingWorker |
---|
addPropertyChangeListener, cancel, done, execute, firePropertyChange, get, get, getProgress, getPropertyChangeSupport, getState, isCancelled, isDone, publish, removePropertyChangeListener, run, setProgress |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final Ov_demo_gui gui
private final Gui_actions gui_actions
private final Gui_protocol_messages messages
Card_protocols
private final Card_protocols card_protocols
private Thread thread
set_next_action
.
private Action gui_clear_message
Action gui_wait_for_card
private Action gui_wait_for_card_removal
Action gui_card_inserted
private Action gui_proof_finished
private Object action_lock
next_action
. All accesses to next_action
must be guarded by locking this object.
private Action next_action
action_lock
.
There are three methods that should be used instead of
accessing this field: get_next_action()
, set_next_action
and set_successor_action
.
public boolean card_is_present
private Action gui_enable_ptls_actions
private Action gui_disable_ptls_actions
private Action wait_in_ptls_office
private Action clear_applet_list
private final byte[] default_applet_name
private Action wait_in_ptls_automaton
private Action resign_failed_warning
private Action resign_finished_action
private Action proof_failed_warning
Constructor Detail |
---|
public Terminal_thread(Ov_demo_gui gui, Gui_actions gui_actions, Card_protocols card_protocols)
Can be executed on any thread.
gui
- the GUI objectgui_actions
- the GUI actionsMethod Detail |
---|
public void process(List<Runnable> actions)
run
method of a Runnable
.
Must be executed on the GUI thread.
process
in class SwingWorker<Void,Runnable>
actions
- actions that have accumulated since the last
call to this method.private Action gui_status_line_message(String message)
message
- the message to displayprivate Action gui_background_died(Throwable e)
Should be executed on the Terminal thread.
public void gui_message(JTextPane pane, String message, boolean bold)
bold
flag is true the message is displayed in the
"bold" style, which therefore should exist on the text pane
pane
.
Should be executed on the Terminal thread.
pane
- the text pane to write tomessage
- the messagebold
- display in bold if truepublic void gui_progress_message(String message, boolean bold)
Should be executed on the Terminal thread.
message
- the messagebold
- display in bold if truepublic void gui_card_message(BigInteger blinded_a, String message)
Should be executed on the Terminal thread.
blinded_a
- the blinded attribute expression of the cardmessage
- the messageprivate Action invalid_card_warning(String message)
Should be executed on the Terminal thread.
message
- more detailed message
private Action card_communication_error_warning(String message)
Should be executed on the Terminal thread.
message
- some more detailed reason
private Action get_next_action()
next_action
field.
Should be executed on the Terminal thread.
public void set_next_action(Action next_action)
Should be executed on the GUI thread.
next_action
- next action for the terminal threadprotected void set_successor_action(Action successor_action)
Should be executed on the Terminal thread.
successor_action
- the successor actionpublic void wait_until_card_is_removed() throws InterruptedException, Terminal_thread.Runtime_card_exception
CardTerminal
does not abort timeouts on interrupts this method performs
busy-waiting and checks every 100 milliseconds whether the
terminal thread has been interrupted. Must be executed on the Terminal thread.
InterruptedException
- in case this thread was
interrupted before a card removal has been detected
Terminal_thread.Runtime_card_exception
- in case of problems with
the card readerpublic void wait_for_card() throws InterruptedException, Terminal_thread.Runtime_card_exception
InterruptedException
is generated if an
interrupt is detected before a card insertion. Because CardTerminal
does not react to interrupts,
this method performs busy waiting and checks every 100
milliseconds whether an interrupt occurred. Must be executed on the Terminal thread.
InterruptedException
- if an interrupt is detected
Terminal_thread.Runtime_card_exception
- for card reader problemspublic void wait_in_ptls_office()
Should be executed on the GUI thread.
private Applet_list_window get_applet_list_window()
Not bound to any thread.
private Action applet_table_line(String kind, Printable_aid name)
Should be executed on the Terminal thread.
kind
- kind of the entryname
- name of the entry
private boolean status_entry_filter(cardservices.AIDRegistryEntry e)
Not bound to any thread.
e
- registry entry describing one applet/package
e
should be displayed without the
everything check box checkedprivate boolean publish_registry(cardservices.AIDRegistry r, boolean everything)
Should be executed on the Terminal thread.
r
- the registry to displayeverything
- if true display all entries, otherwise filter
default entries out
private Action card_status(boolean everything)
wait_in_ptls_office
as successor
action.
The action can throw a Terminal_thread.Runtime_card_exception
for a
low-level communication problem.
Should be executed on the GUI thread.
everything
- if true display all card entries, otherwise
filter default entries out
public void start_card_status_action(boolean everything)
Must be executed on the GUI thread.
everything
- if true display all card entries in the
applet list dialog, otherwise filter default entries outprivate Action applet_install_failed_warning(cardservices.GlobalPlatformException e)
Should be executed on the Terminal thread.
e
- Exception from the global platform service
private Action applet_cap_file_warning(IOException e)
Should be executed on the Terminal thread.
e
- IOException from the global platform service
private Action install_applet_action(Applet_type applet_type)
The action might throw a Terminal_thread.Runtime_card_exception
for
low-level communication problems.
Should be executed on the GUI thread.
applet_type
- the applet to install
Terminal_thread.Runtime_card_exception
- if the operation is
terminated because of a CardException
public void start_install_applet(Applet_type type)
Must be executed on the GUI thread.
type
- the applet to installprivate Action delete_applets(Printable_aid[] aids, boolean everything)
The action may throw a Terminal_thread.Runtime_card_exception
because
of a low-level communication problem.
Should be executed on the GUI thread.
aids
- applets/packages to deleteeverything
- if true display all card entries in the
applet list dialog, otherwise filter default entries out
public void start_delete_applets(Printable_aid[] aids, boolean everything)
Must be executed on the GUI thread.
aids
- applets/packages to deleteeverything
- if true display all card entries in the
applet list dialog, otherwise filter default entries outprivate Action personalize_action(Applet_type applet_type)
The action might throw a Terminal_thread.Runtime_card_exception
for a
low-level communication problem.
Should be executed on the GUI thread.
applet_type
- the applet to personalize
public void start_personalize(Applet_type applet_type)
Must be executed on the GUI thread.
applet_type
- the applet to personalizeprivate Action reinstall_personalize(Applet_type applet_type)
The action might throw a Terminal_thread.Runtime_card_exception
for a
low-level communication problem.
Should be executed on the GUI thread.
applet_type
- the applet to reinstall and personlize
public void start_reinstall_personalize(Applet_type applet_type)
Must be executed on the GUI thread.
applet_type
- the applet to reinstall and personalizeprivate Action reset_action(Applet_type applet_type)
The action might throw a Terminal_thread.Runtime_card_exception
for a
low-level communication problem.
Should be executed on the GUI thread.
applet_type
- the applet to resetpublic void start_reset_applet(Applet_type applet_type)
Must be executed on the GUI thread.
applet_type
- the applet to resetprivate Action gui_set_ptls_automaton_button(boolean b)
Should be executed on the Terminal thread.
b
- if true enable the button, otherwise disable it
public void wait_in_ptls_automaton()
Must be executed on the GUI thread.
private Action resign_action(Applet_type applet_type, BigInteger[] updates)
The action might throw a Terminal_thread.Runtime_card_exception
for a
low-level communication problem.
Should be executed on the GUI thread.
applet_type
- the applet that should be selected for
resigningupdates
- user selected attribute updates or null for
using random attribute updates
public void start_resign(Applet_type applet_type, BigInteger[] updates)
Must be executed on the GUI thread.
applet_type
- the applet to select for resigningupdates
- user selected attribute updates or null for
using random attribute updatesprivate void proof(Applet_type applet_type) throws CardException
Must be executed on the Terminal thread.
applet_type
- the applet to select and to run the protocol
with
CardException
- on low-level communication errorsprivate void proof_ex(Applet_type applet_type) throws Terminal_thread.Runtime_card_exception
proof
. Runs the entry-gate
protocol and turn various exceptions into gui visible warnings.
Must be executed on the Terminal thread.
applet_type
- the applet to select and to run the protocol
with
Terminal_thread.Runtime_card_exception
- in case of unhandled
communication errorsprivate Action gui_set_entry_run_button(boolean b)
Should be executed on the Terminal thread.
b
- enable the button if true, otherwise disable the button
private Action wait_in_entry_gate_action(boolean automatic_proof, Applet_type applet_type)
The action might throw a Terminal_thread.Runtime_card_exception
for a
low-level communication problem.
Should be executed on the GUI thread. The returned actions sould be executed in the terminal thread.
automatic_proof
- if true start the proof protocol
automatically when a card is insertedapplet_type
- applet to select and to run the proof
protocol on
public void wait_in_entry_gate(Applet_type applet_type, boolean automatic_proof)
Must be executed on the GUI thread.
automatic_proof
- if true start the proof protocol
automatically when a card is insertedapplet_type
- applet to select and to run the proof
protocol onprivate Action proof_action(Applet_type applet_type)
The action might throw a Terminal_thread.Runtime_card_exception
for a
low-level communication problem.
Should be executed on the GUI thread.
applet_type
- the applet to select and to run the proof
protocol on
public void start_proof(Applet_type applet_type)
Must be executed on the GUI thread.
applet_type
- the applet to select and to run the proof
protocol onpublic Void doInBackground()
SwingWorker
machinery in a thread different from the GUI
thread. The main loop continuously executes the actions it
finds in next_action
. Such actions can be set from the
GUI or by actions themselves.
doInBackground
in class SwingWorker<Void,Runnable>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |