ds.ov2.test
Class Data_protocol_host

java.lang.Object
  extended by ds.ov2.test.Data_protocol_host

 class Data_protocol_host
extends Object

Host driver for the data protocols that check/measure the protocol layer. An instance of this class owns an instance of the description class of the data protocols. Because of the size changes of the Resizable_buffer's therein this description instance must only exist once (more precisely one instance in the host driver and one instance inside the applet). Therefore this class is an enforced singleton class.

CPP Preprocessing
no cpp preprocessing needed
Execution Environment:
host
Author:
Hendrik Tews
Version:
$Revision: 1.17 $
Last Commit:
$Date: 2009-06-02 13:27:57 $ by $Author: tews $

Nested Class Summary
(package private) static class Data_protocol_host.Data_error
          Exception to indicate that an error in the protocol layer has been detected when checking the results from the applet.
 
Field Summary
private  CardChannel card_channel
          Channel to the applet.
private  Data_protocol_description description
          Description instance of the data protocols.
private  PrintWriter out
          Channel for debug and progress messages.
private static Data_protocol_host singleton
          Reference holding the single instance of this class.
private  Data_protocol_stubs stubs
          Stubs for the data protocols.
 
Constructor Summary
protected Data_protocol_host(Data_protocol_description data_protocol, CardChannel card_channel, PrintWriter out)
          Constructor.
 
Method Summary
private  byte check_buffer(Resizable_buffer b, byte count)
          Check the enumberation of resulting Resizable_buffer that we received from the card.
 long check_data(boolean performance_test)
          Run the data protocol once for testing the protocol layer.
private  byte fill_buffer(Resizable_buffer b, byte count)
          Enumerate the bytes in a Resizable_buffer.
 Data_protocol_stubs get_stubs()
          Accessor for the stubs instance.
static Data_protocol_host makeit(Data_protocol_description data_protocol, CardChannel card_channel, PrintWriter out)
          Return the signleton instance of this class.
 void set_size(int[] new_sizes, boolean performance_test)
          Set the sizes of the Resizable_buffer's that are used as arguments and results in the data protocol.
 void set_size(int a1, int a2, int a3, int a4, int a5, int r1, int r2, int r3, int r4, int r5, boolean performance_test)
          Same as set_size(int[], boolean) but where the 10 sizes are passed as separate arguments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

card_channel

private CardChannel card_channel
Channel to the applet.


description

private Data_protocol_description description
Description instance of the data protocols.


out

private PrintWriter out
Channel for debug and progress messages.


stubs

private Data_protocol_stubs stubs
Stubs for the data protocols.


singleton

private static Data_protocol_host singleton
Reference holding the single instance of this class.

Constructor Detail

Data_protocol_host

protected Data_protocol_host(Data_protocol_description data_protocol,
                             CardChannel card_channel,
                             PrintWriter out)
Constructor. Initialize all fields and the singleton reference singleton.

Asserts that singleton is null before assigning to it.

Parameters:
data_protocol - description instance of the data protocols
card_channel - channel to the applet
out - progress/debug message channel
Method Detail

get_stubs

public Data_protocol_stubs get_stubs()
Accessor for the stubs instance.

Returns:
the stubs for the data protocols

makeit

public static Data_protocol_host makeit(Data_protocol_description data_protocol,
                                        CardChannel card_channel,
                                        PrintWriter out)
Return the signleton instance of this class. If no instance exists yet, it is created. If it does exist, it is checked (via an assertion) wheter its card channel is identical to the card_channel argument of this method.

Parameters:
data_protocol - description instance of the data protocols
out - progress/debug message channel
Returns:
card_channel channel to the applet

fill_buffer

private byte fill_buffer(Resizable_buffer b,
                         byte count)
Enumerate the bytes in a Resizable_buffer. Start with count. Return the count for the following Resizable_buffer.

Parameters:
b - buffer to fill
count - starting counter
Returns:
count for the following Resizable_buffer

check_buffer

private byte check_buffer(Resizable_buffer b,
                          byte count)
                   throws Data_protocol_host.Data_error
Check the enumberation of resulting Resizable_buffer that we received from the card. Throws Data_protocol_host.Data_error if an error is detected.

Parameters:
b - the buffer to check
count - the starting count for the first byte
Returns:
count for the next result
Throws:
Data_protocol_host.Data_error - for any detected enumeration error

check_data

public long check_data(boolean performance_test)
                throws CardException,
                       Data_protocol_host.Data_error
Run the data protocol once for testing the protocol layer. Sends 5 arguments to the card and receives 5 results. Their sizes must have been configured before with one of the set_size methods (set_size or set_size). This method uses the sizes of the buffers in the description instance of the data protocols.

Parameters:
performance_test - if true do neither enumerate arguments nor check results
Returns:
duration of the data transmission (including the protocol layer overhead) in nanoseconds
Throws:
Data_protocol_host.Data_error - for any detected error in the protocol layer
CardException - for communication errors

set_size

public void set_size(int[] new_sizes,
                     boolean performance_test)
              throws CardException
Set the sizes of the Resizable_buffer's that are used as arguments and results in the data protocol. The maximal possible size for all buffers in the applet is given by a compile time constant. If bigger sizes are requested the applet ignores the size request. The resulting buffer sizes are returned in any case and this method uses them to set the buffers in the description instance of the host driver to the same size as on the card. A message is printed to out if the requested size was not set on the applet.

Parameters:
new_sizes - array of 10 positive shorts with the requested sizes
performance_test - performance test flag to set or clear in the applet
Throws:
CardException - on communication errors

set_size

public void set_size(int a1,
                     int a2,
                     int a3,
                     int a4,
                     int a5,
                     int r1,
                     int r2,
                     int r3,
                     int r4,
                     int r5,
                     boolean performance_test)
              throws CardException
Same as set_size(int[], boolean) but where the 10 sizes are passed as separate arguments.

Parameters:
a1 - requested size for the first argument
a2 - requested size for the second argument
a3 - requested size for the third argument
a4 - requested size for the fourth argument
a5 - requested size for the fifth argument
r1 - requested size for the first result
r2 - requested size for the second result
r3 - requested size for the third result
r4 - requested size for the fourth result
r5 - requested size for the fifth result
performance_test - performance test flag to set or clear in the applet
Throws:
CardException - for communication errors