1 /*
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
28 * @author Andreas Sterbenz
29 * @run main/manual TestExclusive
30 */
31
32 // This test requires special hardware.
33
34 import javax.smartcardio.Card;
35 import javax.smartcardio.CardChannel;
36 import javax.smartcardio.CardException;
37 import javax.smartcardio.CardTerminal;
38 import javax.smartcardio.CommandAPDU;
39
40 public class TestExclusive extends Utils {
41
42 static volatile boolean exclusive;
43
44 static volatile boolean otherOK;
45
46 public static void main(String[] args) throws Exception {
47 CardTerminal terminal = getTerminal(args);
48
49 // establish a connection with the card
50 Card card = terminal.connect("T=0");
51 System.out.println("card: " + card);
52
53 Thread thread = new Thread(new OtherThread(card));
54 thread.setDaemon(true);
55 thread.start();
56
57 card.beginExclusive();
58 exclusive = true;
59
60 Thread.sleep(1000);
61 System.out.println("=1=resuming...");
62
63 CardChannel channel = card.getBasicChannel();
64
65 System.out.println("=1=Transmitting...");
66 transmitTestCommand(channel);
67 System.out.println("=1=OK");
|
1 /*
2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
28 * @author Andreas Sterbenz
29 * @run main/manual TestExclusive
30 */
31
32 // This test requires special hardware.
33
34 import javax.smartcardio.Card;
35 import javax.smartcardio.CardChannel;
36 import javax.smartcardio.CardException;
37 import javax.smartcardio.CardTerminal;
38 import javax.smartcardio.CommandAPDU;
39
40 public class TestExclusive extends Utils {
41
42 static volatile boolean exclusive;
43
44 static volatile boolean otherOK;
45
46 public static void main(String[] args) throws Exception {
47 CardTerminal terminal = getTerminal(args);
48 if (terminal == null) {
49 System.out.println("Skipping the test: " +
50 "no card terminals available");
51 return;
52 }
53
54 // establish a connection with the card
55 Card card = terminal.connect("T=0");
56 System.out.println("card: " + card);
57
58 Thread thread = new Thread(new OtherThread(card));
59 thread.setDaemon(true);
60 thread.start();
61
62 card.beginExclusive();
63 exclusive = true;
64
65 Thread.sleep(1000);
66 System.out.println("=1=resuming...");
67
68 CardChannel channel = card.getBasicChannel();
69
70 System.out.println("=1=Transmitting...");
71 transmitTestCommand(channel);
72 System.out.println("=1=OK");
|