Esempio n. 1
0
 public synchronized List<CardTerminal> list(State state) throws CardException {
   // System.out.println("list");
   if (state == null) {
     throw new NullPointerException();
   }
   try {
     String[] readerNames = SCardListReaders(contextId);
     List<CardTerminal> list = new ArrayList<CardTerminal>(readerNames.length);
     if (stateMap == null) {
       // If waitForChange() has never been called, treat event
       // queries as status queries.
       if (state == CARD_INSERTION) {
         state = CARD_PRESENT;
       } else if (state == CARD_REMOVAL) {
         state = CARD_ABSENT;
       }
     }
     for (String readerName : readerNames) {
       CardTerminal terminal = implGetTerminal(readerName);
       ReaderState readerState;
       switch (state) {
         case ALL:
           list.add(terminal);
           break;
         case CARD_PRESENT:
           if (terminal.isCardPresent()) {
             list.add(terminal);
           }
           break;
         case CARD_ABSENT:
           if (terminal.isCardPresent() == false) {
             list.add(terminal);
           }
           break;
         case CARD_INSERTION:
           readerState = stateMap.get(readerName);
           if ((readerState != null) && readerState.isInsertion()) {
             list.add(terminal);
           }
           break;
         case CARD_REMOVAL:
           readerState = stateMap.get(readerName);
           if ((readerState != null) && readerState.isRemoval()) {
             list.add(terminal);
           }
           break;
         default:
           throw new CardException("Unknown state: " + state);
       }
     }
     return Collections.unmodifiableList(list);
   } catch (PCSCException e) {
     throw new CardException("list() failed", e);
   }
 }
Esempio n. 2
0
  public void mapdata(Message msg) {
    long now = System.currentTimeMillis();
    int pktid = msg.int32();
    int off = msg.uint16();
    int len = msg.uint16();
    Defrag fragbuf;
    synchronized (fragbufs) {
      if ((fragbuf = fragbufs.get(pktid)) == null) {
        fragbuf = new Defrag(len);
        fragbufs.put(pktid, fragbuf);
      }
      fragbuf.add(msg.blob, 8, msg.blob.length - 8, off);
      fragbuf.last = now;
      if (fragbuf.done()) {
        mapdata2(fragbuf.msg());
        fragbufs.remove(pktid);
      }

      /* Clean up old buffers */
      for (Iterator<Map.Entry<Integer, Defrag>> i = fragbufs.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry<Integer, Defrag> e = i.next();
        Defrag old = e.getValue();
        if (now - old.last > 10000) i.remove();
      }
    }
  }
Esempio n. 3
0
 public Grid getgrid(Coord gc) {
   synchronized (grids) {
     if ((cached == null) || !cached.gc.equals(cached)) {
       cached = grids.get(gc);
       if (cached == null) {
         request(gc);
         throw (new LoadingMap());
       }
     }
     return (cached);
   }
 }
Esempio n. 4
0
  public synchronized boolean waitForChange(long timeout) throws CardException {
    // System.out.println("enter WaitforChange");
    // Thread.dumpStack();

    if (timeout < 0) {
      throw new IllegalArgumentException("Timeout must not be negative: " + timeout);
    }
    if (stateMap == null) {
      // We need to initialize the state database.
      // Do that with a recursive call, which will return immediately
      // because we pass SCARD_STATE_UNAWARE.
      // After that, proceed with the real call.
      stateMap = new HashMap<String, ReaderState>();
      waitForChange(0);
    }
    if (timeout == 0) {
      timeout = TIMEOUT_INFINITE;
    }
    try {
      String[] readerNames = SCardListReaders(contextId);
      int n = readerNames.length;
      if (n == 0) {
        throw new IllegalStateException("No terminals available");
      }
      int[] status = new int[n];
      ReaderState[] readerStates = new ReaderState[n];
      for (int i = 0; i < readerNames.length; i++) {
        String name = readerNames[i];
        ReaderState state = stateMap.get(name);
        if (state == null) {
          state = new ReaderState();
        }
        readerStates[i] = state;
        status[i] = state.get();
      }
      status = SCardGetStatusChange(contextId, timeout, status, readerNames);
      stateMap.clear(); // remove any readers that are no longer available
      for (int i = 0; i < n; i++) {
        ReaderState state = readerStates[i];
        state.update(status[i]);
        stateMap.put(readerNames[i], state);
      }
      // System.out.println("exit WaitforChange");
      return true;
    } catch (PCSCException e) {
      if (e.code == SCARD_E_TIMEOUT) {
        // System.out.println("exit WaitforChange");
        return false;
      } else {
        throw new CardException("waitForChange() failed", e);
      }
    }
  }
Esempio n. 5
0
 public void mapdata2(Message msg) {
   Coord c = msg.coord();
   synchronized (grids) {
     synchronized (req) {
       if (req.containsKey(c)) {
         Grid g = grids.get(c);
         if (g == null) grids.put(c, g = new Grid(c));
         g.fill(msg);
         req.remove(c);
         olseq++;
       }
     }
   }
 }
  ArgumentImpl argument(String name, Map arguments) throws IllegalConnectorArgumentsException {

    ArgumentImpl argument = (ArgumentImpl) arguments.get(name);
    if (argument == null) {
      throw new IllegalConnectorArgumentsException("Argument missing", name);
    }
    String value = argument.value();
    if (value == null || value.length() == 0) {
      if (argument.mustSpecify()) {
        throw new IllegalConnectorArgumentsException("Argument unspecified", name);
      }
    } else if (!argument.isValid(value)) {
      throw new IllegalConnectorArgumentsException("Argument invalid", name);
    }

    return argument;
  }
  /**
   * Returns, the <tt>TransportManager</tt> instance for the channel-bundle with ID
   * <tt>channelBundleId</tt>. If no instance exists and <tt>create</tt> is <tt>true</tt>, one will
   * be created.
   *
   * @param channelBundleId the ID of the channel-bundle for which to return the
   *     <tt>TransportManager</tt>.
   * @param create whether to create a new instance, if one doesn't exist.
   * @return the <tt>TransportManager</tt> instance for the channel-bundle with ID
   *     <tt>channelBundleId</tt>.
   */
  IceUdpTransportManager getTransportManager(String channelBundleId, boolean create) {
    IceUdpTransportManager transportManager;

    synchronized (transportManagers) {
      transportManager = transportManagers.get(channelBundleId);
      if (transportManager == null && create && !isExpired()) {
        try {
          // FIXME: the initiator is hard-coded
          // We assume rtcp-mux when bundle is used, so we make only
          // one component.
          transportManager = new IceUdpTransportManager(this, true, 1);
        } catch (IOException ioe) {
          throw new UndeclaredThrowableException(ioe);
        }
        transportManagers.put(channelBundleId, transportManager);
      }
    }

    return transportManager;
  }
Esempio n. 8
0
 public void invalidate(Coord cc) {
   synchronized (req) {
     if (req.get(cc) == null) req.put(cc, new Request());
   }
 }
 public static Palette getPalette(Bitmap bitmap) {
   return CACHE.get(bitmap);
 }