45 UdevListener udevListener = new UdevListener() { 46 @Override 47 public void udevEvent(String action, Map<String, String> event) { 48 String subsystem = event.get("SUBSYSTEM"); 49 String devPath = event.get("DEVPATH"); 50 String devName = event.get("DEVNAME"); 51 if (subsystem != null && subsystem.equals("input") 52 && devPath != null && devName != null) { 53 try { 54 File sysPath = new File("/sys", devPath); 55 if (action.equals("add") 56 || (action.equals("change") 57 && !deviceMap.containsKey(sysPath))) { 58 File devNode = new File(devName); 59 LinuxInputDevice device = createDevice( 60 devNode, sysPath, event); 61 if (device != null) { 62 deviceMap.put(sysPath, device); 63 } 64 } else if (action.equals("remove")) { 65 LinuxInputDevice device = deviceMap.get(devPath); 66 deviceMap.remove(devPath); 67 if (device != null) { 68 devices.remove(device); 69 } 70 } 71 } catch (IOException e) { 72 e.printStackTrace(); 73 } 74 } 75 } 76 }; 77 Udev.getInstance().addListener(udevListener); 78 // Request updates for existing devices 79 SysFS.triggerUdevNotification("input"); 80 } 81 82 private LinuxInputDevice createDevice(File devNode, 83 File sysPath, 84 Map<String, String> udevManifest) 85 throws IOException { 86 LinuxInputDevice device = new LinuxInputDevice( | 45 UdevListener udevListener = new UdevListener() { 46 @Override 47 public void udevEvent(String action, Map<String, String> event) { 48 String subsystem = event.get("SUBSYSTEM"); 49 String devPath = event.get("DEVPATH"); 50 String devName = event.get("DEVNAME"); 51 if (subsystem != null && subsystem.equals("input") 52 && devPath != null && devName != null) { 53 try { 54 File sysPath = new File("/sys", devPath); 55 if (action.equals("add") 56 || (action.equals("change") 57 && !deviceMap.containsKey(sysPath))) { 58 File devNode = new File(devName); 59 LinuxInputDevice device = createDevice( 60 devNode, sysPath, event); 61 if (device != null) { 62 deviceMap.put(sysPath, device); 63 } 64 } else if (action.equals("remove")) { 65 LinuxInputDevice device = deviceMap.get(sysPath); 66 deviceMap.remove(sysPath); 67 if (device != null) { 68 devices.remove(device); 69 } 70 } 71 } catch (IOException e) { 72 e.printStackTrace(); 73 } 74 } 75 } 76 }; 77 Udev.getInstance().addListener(udevListener); 78 // Request updates for existing devices 79 SysFS.triggerUdevNotification("input"); 80 } 81 82 private LinuxInputDevice createDevice(File devNode, 83 File sysPath, 84 Map<String, String> udevManifest) 85 throws IOException { 86 LinuxInputDevice device = new LinuxInputDevice( |