< prev index next >

tests/system/src/test/java/test/robot/com/sun/glass/ui/monocle/MonocleUInput.java

Print this page
rev 9491 : 8145203: Refactor systemTests for clear separation of tests
Reviewed-by: kcr


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.glass.ui.monocle;
  27 

  28 import com.sun.glass.ui.Application;

  29 import javafx.application.Platform;
  30 
  31 import java.io.IOException;
  32 import java.nio.ByteBuffer;
  33 import java.nio.channels.Pipe;
  34 import java.util.concurrent.CountDownLatch;
  35 import java.util.concurrent.atomic.AtomicReference;

  36 
  37 class MonocleUInput extends NativeUInput {
  38 
  39     private Pipe pipe;
  40     private LinuxInputDevice device;
  41     private final LinuxInputDeviceRegistry registry;
  42 
  43     MonocleUInput() {
  44         super();
  45         registry = (LinuxInputDeviceRegistry)
  46                 NativePlatformFactory.getNativePlatform().getInputDeviceRegistry();
  47     }
  48 
  49     @Override
  50     protected void createDevice() {
  51         try {
  52             pipe = Pipe.open();
  53         } catch (IOException e) {
  54             e.printStackTrace();
  55         }
  56         uevent.put("PRODUCT",
  57                    Integer.toHexString(bus) + "/"
  58                    + Integer.toHexString(vendor) + "/"
  59                    + Integer.toHexString(product) + "/"
  60                    + Integer.toHexString(version));
  61         Application.invokeAndWait(() -> device = registry.addDevice(
  62                 new LinuxInputDevice(capabilities,
  63                                      createAbsCapsMap(),
  64                                      pipe.source(),
  65                                      udevManifest,
  66                                      uevent),
  67                 "Simulated Linux Input Device"));
  68     }
  69 
  70     protected void openConnection() {
  71     }
  72 
  73     @Override
  74     protected void closeConnection() {
  75     }
  76 
  77     @Override
  78     protected void destroyDevice() {
  79         try {
  80             if (pipe != null) {
  81                 pipe.sink().close();
  82                 pipe.source().close();
  83             }
  84         } catch (IOException e) {
  85             e.printStackTrace();
  86         }
  87         pipe = null;
  88         if (device != null) {
  89             final LinuxInputDevice d = device;
  90             if (Platform.isFxApplicationThread()) {
  91                 registry.removeDevice(d);
  92             } else {
  93                 CountDownLatch latch = new CountDownLatch(1);
  94                 Platform.runLater(() -> {
  95                     registry.removeDevice(d);
  96                     latch.countDown();
  97                 });
  98                 try {
  99                     latch.await();
 100                 } catch (InterruptedException e) {
 101                     e.printStackTrace();
 102                 }
 103             }
 104             device = null;
 105         }
 106     }
 107 
 108     @Override
 109     public void setup() {
 110     }
 111 
 112     @Override
 113     public void dispose() {
 114         destroyDevice();
 115         closeConnection();


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.robot.com.sun.glass.ui.monocle;
  27 
  28 import test.robot.com.sun.glass.ui.monocle.TestApplication;
  29 import com.sun.glass.ui.Application;
  30 import com.sun.glass.ui.monocle.LinuxInputDeviceRegistryShim;
  31 import javafx.application.Platform;
  32 
  33 import java.io.IOException;
  34 import java.nio.ByteBuffer;
  35 import java.nio.channels.Pipe;
  36 import java.util.concurrent.CountDownLatch;
  37 import java.util.concurrent.atomic.AtomicReference;
  38 import test.com.sun.glass.ui.monocle.NativeUInput;
  39 
  40 class MonocleUInput extends NativeUInput {
  41 
  42     private Pipe pipe;
  43     private LinuxInputDeviceRegistryShim.LinuxInputDeviceShim device;

  44 
  45     MonocleUInput() {
  46         super();


  47     }
  48 
  49     @Override
  50     protected void createDevice() {
  51         try {
  52             pipe = Pipe.open();
  53         } catch (IOException e) {
  54             e.printStackTrace();
  55         }
  56         uevent.put("PRODUCT",
  57                    Integer.toHexString(bus) + "/"
  58                    + Integer.toHexString(vendor) + "/"
  59                    + Integer.toHexString(product) + "/"
  60                    + Integer.toHexString(version));
  61         Application.invokeAndWait(() -> device
  62                 = LinuxInputDeviceRegistryShim.addDevice(capabilities,
  63                         absCaps,
  64                         pipe.source(),
  65                         udevManifest,
  66                         uevent,
  67                         "Simulated Linux Input Device"));
  68     }
  69 
  70     protected void openConnection() {
  71     }
  72 
  73     @Override
  74     protected void closeConnection() {
  75     }
  76 
  77     @Override
  78     protected void destroyDevice() {
  79         try {
  80             if (pipe != null) {
  81                 pipe.sink().close();
  82                 pipe.source().close();
  83             }
  84         } catch (IOException e) {
  85             e.printStackTrace();
  86         }
  87         pipe = null;
  88         if (device != null) {
  89             final LinuxInputDeviceRegistryShim.LinuxInputDeviceShim d = device;
  90             if (Platform.isFxApplicationThread()) {
  91                 LinuxInputDeviceRegistryShim.removeDevice(d);
  92             } else {
  93                 CountDownLatch latch = new CountDownLatch(1);
  94                 Platform.runLater(() -> {
  95                     LinuxInputDeviceRegistryShim.removeDevice(d);
  96                     latch.countDown();
  97                 });
  98                 try {
  99                     latch.await();
 100                 } catch (InterruptedException e) {
 101                     e.printStackTrace();
 102                 }
 103             }
 104             device = null;
 105         }
 106     }
 107 
 108     @Override
 109     public void setup() {
 110     }
 111 
 112     @Override
 113     public void dispose() {
 114         destroyDevice();
 115         closeConnection();
< prev index next >