X-Git-Url: https://git.saurik.com/apple/mdnsresponder.git/blobdiff_plain/c9d2d929f6ad52e6996754033ee77c725b90d1d4..8ec81f6c99056f5c63e0045ca48a7c405058254b:/Clients/Java/BrowserApp.java diff --git a/Clients/Java/BrowserApp.java b/Clients/Java/BrowserApp.java index 0b55fa5..8f51215 100644 --- a/Clients/Java/BrowserApp.java +++ b/Clients/Java/BrowserApp.java @@ -1,4 +1,5 @@ -/* +/* -*- Mode: Java; tab-width: 4 -*- + * * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. * * Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. @@ -53,7 +54,7 @@ import javax.swing.event.*; import com.apple.dnssd.*; -class BrowserApp implements ListSelectionListener, ResolveListener +class BrowserApp implements ListSelectionListener, ResolveListener, Runnable { static BrowserApp app; JFrame frame; @@ -62,6 +63,8 @@ class BrowserApp implements ListSelectionListener, ResolveListener JList domainPane, servicesPane, servicePane; DNSSDService servicesBrowser, serviceBrowser, domainBrowser; JLabel hostLabel, portLabel; + String hostNameForUpdate; + int portForUpdate; public BrowserApp() { @@ -169,22 +172,43 @@ class BrowserApp implements ListSelectionListener, ResolveListener serviceList.getNthServiceName( newSel), serviceList.getNthRegType( newSel), serviceList.getNthDomain( newSel), - new SwingResolveListener( this)); + this); } } } catch ( Exception ex) { terminateWithException( ex); } } + public void run() + { + hostLabel.setText( hostNameForUpdate); + portLabel.setText( String.valueOf( portForUpdate)); + } + public void serviceResolved( DNSSDService resolver, int flags, int ifIndex, String fullName, String hostName, int port, TXTRecord txtRecord) { - hostLabel.setText( hostName); - portLabel.setText( String.valueOf( port)); + // We want to update GUI on the AWT event dispatching thread, but we can't stop + // the resolve from that thread, since stop() is synchronized with this callback. + // So, we stop the resolve on this thread, then invokeAndWait on the AWT event thread. + + resolver.stop(); + + hostNameForUpdate = hostName; + portForUpdate = port; + + try { + SwingUtilities.invokeAndWait(this); + } + catch ( Exception e) + { + e.printStackTrace(); + } } public void operationFailed( DNSSDService service, int errorCode) { + service.stop(); // handle failure here }