From 8360956315227692b2e25e7a8de59dc4d0f83220 Mon Sep 17 00:00:00 2001 From: Davide Perini Date: Thu, 9 Jan 2025 10:22:19 +0100 Subject: [PATCH] ping device under dbug --- .../java/org/dpsoftware/FireflyLuciferin.java | 2 +- .../java/org/dpsoftware/NativeExecutor.java | 21 +--------------- .../dpsoftware/grabber/GrabberManager.java | 25 +++++-------------- 3 files changed, 8 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/dpsoftware/FireflyLuciferin.java b/src/main/java/org/dpsoftware/FireflyLuciferin.java index 8e3a9168..33a70b3f 100644 --- a/src/main/java/org/dpsoftware/FireflyLuciferin.java +++ b/src/main/java/org/dpsoftware/FireflyLuciferin.java @@ -282,7 +282,7 @@ public void start(Stage stage) throws Exception { } } grabberManager.getFPS(); - grabberManager.pingDevices(); + grabberManager.pingDevice(); imageProcessor.calculateBorders(); // If this instance spawns new instances, don't launch grabbers here. if (!(MainSingleton.getInstance().spawnInstances && MainSingleton.getInstance().config.getMultiMonitor() > 1)) { diff --git a/src/main/java/org/dpsoftware/NativeExecutor.java b/src/main/java/org/dpsoftware/NativeExecutor.java index 2345fa96..ac44aa6f 100644 --- a/src/main/java/org/dpsoftware/NativeExecutor.java +++ b/src/main/java/org/dpsoftware/NativeExecutor.java @@ -60,10 +60,9 @@ public final class NativeExecutor { * * @param cmdToRunUsingArgs Command to run and args, in an array * @param waitForOutput Example: If you need to exit the app you don't need to wait for the output or the app will not exit (millis) - * @param throwException throws exception on error * @return A list of string containing the output, empty list if command does not exist */ - public static List runNative(String[] cmdToRunUsingArgs, int waitForOutput, boolean throwException) { + public static List runNative(String[] cmdToRunUsingArgs, int waitForOutput) { ArrayList cmdOutput = new ArrayList<>(); try { log.trace("Executing cmd={}", Arrays.stream(cmdToRunUsingArgs).toList()); @@ -87,32 +86,14 @@ public static List runNative(String[] cmdToRunUsingArgs, int waitForOutp } else { log.error("The command {} has exceeded the time limit and has been terminated.", Arrays.toString(cmdToRunUsingArgs)); process.destroy(); - if (throwException) { - throw new RuntimeException(); - } } } } catch (Exception e) { log.error(e.getMessage()); - if (throwException) { - throw new RuntimeException(e); - } } return cmdOutput; } - /** - * This is the real runner that executes command. - * Don't use this method directly and prefer the runNativeWaitForOutput() or runNativeNoWaitForOutput() shortcut. - * - * @param cmdToRunUsingArgs Command to run and args, in an array - * @param waitForOutput Example: If you need to exit the app you don't need to wait for the output or the app will not exit (millis) - * @return A list of string containing the output, empty list if command does not exist - */ - public static List runNative(String[] cmdToRunUsingArgs, int waitForOutput) { - return runNative(cmdToRunUsingArgs, waitForOutput, false); - } - /** * Spawn new Luciferin Native instance * diff --git a/src/main/java/org/dpsoftware/grabber/GrabberManager.java b/src/main/java/org/dpsoftware/grabber/GrabberManager.java index 25d0ce10..de393b00 100644 --- a/src/main/java/org/dpsoftware/grabber/GrabberManager.java +++ b/src/main/java/org/dpsoftware/grabber/GrabberManager.java @@ -254,31 +254,18 @@ public void getFPS() { scheduledExecutorService.scheduleAtFixedRate(framerateTask, 0, 5, TimeUnit.SECONDS); } - // TODO - private static void ping(String ip) { - List pingCmd = new ArrayList<>(Arrays.stream(NativeExecutor.isWindows() ? Constants.PING_WINDOWS : Constants.PING_LINUX).toList()); - pingCmd.add(ip); - NativeExecutor.runNative(pingCmd.toArray(String[]::new), 3000); - } - - // TODO /** - * Ping devices + * Ping device */ - public void pingDevices() { - if (MainSingleton.getInstance().config.isFullFirmware()) { + public void pingDevice() { + if (MainSingleton.getInstance().config.isFullFirmware() && log.isDebugEnabled()) { ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1); Runnable framerateTask = () -> { -// if (!CommonUtility.getDeviceToUseWithSatellites().isEmpty()) { -// for (GlowWormDevice sat : CommonUtility.getDeviceToUseWithSatellites()) { -// if (sat != null && sat.getDeviceIP() != null && NetworkManager.isValidIp(sat.getDeviceIP())) { -// ping(sat.getDeviceIP()); -// } -// } -// } if (CommonUtility.getDeviceToUse() != null && CommonUtility.getDeviceToUse().getDeviceIP() != null && NetworkManager.isValidIp(CommonUtility.getDeviceToUse().getDeviceIP())) { - ping(CommonUtility.getDeviceToUse().getDeviceIP()); + List pingCmd = new ArrayList<>(Arrays.stream(NativeExecutor.isWindows() ? Constants.PING_WINDOWS : Constants.PING_LINUX).toList()); + pingCmd.add(CommonUtility.getDeviceToUse().getDeviceIP()); + NativeExecutor.runNative(pingCmd.toArray(String[]::new), 3000); } }; scheduledExecutorService.scheduleAtFixedRate(framerateTask, 0, 5, TimeUnit.SECONDS);