Hi

I don't know if I should send this in this list (and this is a long mail),
but it may be important. I think I found a bug in the EventGenerator class,
in OpenCard 1.2.
It concerns the removal events.

Say that one card is inserted before you run your application.
If you create one CardServiceScheduler at the beginning of the application,
and after you register one of your class (say MyEventListener) using
addCTListener to receive events, then there will be 2 objects in the list of
listeners (located in the private member EventGenerator.listeners) :
  1 - the CardServiceScheduler
  2 - MyEventListener
Ok, no problem so far.
The problem is when you remove the card. Then the EventGenerator, in the
updateCards method, will iterate (using an Enumeration) through its list of
listeners and call the cardRemoved method of each listener. The cardRemoved
method of the CardServiceScheduler is called first, since it is first in the
list. Then the CardServiceScheduler, in its cardRemoved method, removes
itself from the list of listeners (using removeCTListener) then there is
only one element left in the list of listeners :
  1 - MyEventListener
And then the cardRemoved method returns to the EventGenerator.updateCards
method. But the Enumeration used to iterate points to the second element,
and because the first elemt has been removed, the iteration stops without
calling MyEventListener.cardRemoved.

The result is : you don't receive the removal event.

Well, maybe my explanations were a little bit fuzzy. Here is a sample
application which demonstrates the bug :

import opencard.core.event.*;
import opencard.core.service.*;
import opencard.core.terminal.*;
import opencard.core.util.*;

public class BugTester implements CTListener {

  private static Object monitor    = "synchronization monitor";

  public static void main (String [] args) throws InterruptedException {
    System.out.println("Initializing...");
    try {
      SmartCard.start ();
      System.out.println("Getting a card...");
      SmartCard card=SmartCard.waitForCard(new
CardRequest(CardRequest.ANYCARD, null, null)); /* this creates a
CardServiceScheduler */
      System.out.println("Found a card.");
      System.out.println("Adding a listener to the EventGenerator...");
      EventGenerator.getGenerator().addCTListener (new BugTester() );
      synchronized (monitor) {
        System.out.println ("Please remove the card !\n");
        monitor.wait();
      }
      SmartCard.shutdown ();
    }
    catch (OpenCardPropertyLoadingException plfe) {
      System.out.println ("OpenCardPropertyLoadingException: ");
      System.out.println (plfe.getMessage () );
    }
    catch (ClassNotFoundException cnfe) {
      System.out.println ("ClassNotFoundException: ");
      System.out.println (cnfe.getMessage () );
    }
    catch (CardServiceException cse) {
      System.out.println ("CardServiceException: ");
      System.out.println (cse.getMessage () );
    }
    catch (CardTerminalException cte) {
      System.out.println ("CardTerminalException: ");
      System.out.println (cte.getMessage () );
    }
    System.out.println ("Finished.");
  }

  public void cardInserted (CardTerminalEvent ctEvent) {}

  public void cardRemoved (CardTerminalEvent ctEvent) {
    System.out.println ("card was removed\n");
    synchronized (monitor) {
      monitor.notifyAll();
    }
  }

}

Try to run this with having just one card inserted (in the case you own
several readers and if you have several cards inserted, you have to remove
the good one - the one which has been retrieved with the waitForCard - to
demonstrate the bug).
When you remove the card, nothing happens !
But if you insert it again and remove it again, then you will receive the
event, because the list of listeners doesn't change anymore.

I hope somebody will be able to do something about that.

Regards,

Dimitri.




---
> Visit the OpenCard web site at http://www.opencard.org/ for more
> information on OpenCard---binaries, source code, documents.
> This list is being archived at http://www.opencard.org/archive/opencard/

! To unsubscribe from the [EMAIL PROTECTED] mailing list send an email
! to
!                           [EMAIL PROTECTED]
! containing the word
!                           unsubscribe 
! in the body.

Reply via email to