2N/A/* -*- Mode: Java; tab-width: 4 -*-
2N/A *
2N/A * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
2N/A *
2N/A * Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
2N/A * ("Apple") in consideration of your agreement to the following terms, and your
2N/A * use, installation, modification or redistribution of this Apple software
2N/A * constitutes acceptance of these terms. If you do not agree with these terms,
2N/A * please do not use, install, modify or redistribute this Apple software.
2N/A *
2N/A * In consideration of your agreement to abide by the following terms, and subject
2N/A * to these terms, Apple grants you a personal, non-exclusive license, under Apple's
2N/A * copyrights in this original Apple software (the "Apple Software"), to use,
2N/A * reproduce, modify and redistribute the Apple Software, with or without
2N/A * modifications, in source and/or binary forms; provided that if you redistribute
2N/A * the Apple Software in its entirety and without modifications, you must retain
2N/A * this notice and the following text and disclaimers in all such redistributions of
2N/A * the Apple Software. Neither the name, trademarks, service marks or logos of
2N/A * Apple Computer, Inc. may be used to endorse or promote products derived from the
2N/A * Apple Software without specific prior written permission from Apple. Except as
2N/A * expressly stated in this notice, no other rights or licenses, express or implied,
2N/A * are granted by Apple herein, including but not limited to any patent rights that
2N/A * may be infringed by your derivative works or by other works in which the Apple
2N/A * Software may be incorporated.
2N/A *
2N/A * The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
2N/A * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
2N/A * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2N/A * PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
2N/A * COMBINATION WITH YOUR PRODUCTS.
2N/A *
2N/A * IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
2N/A * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
2N/A * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2N/A * ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
2N/A * OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
2N/A * (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
2N/A * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2N/A
2N/Aident "%Z%%M% %I% %E% SMI"
2N/A
2N/A */
2N/A
2N/A
2N/Aimport javax.swing.*;
2N/Aimport com.apple.dnssd.*;
2N/A
2N/A
2N/A/** Use this to schedule QueryListener callbacks via SwingUtilities.invokeAndWait(). */
2N/A
2N/Apublic class SwingQueryListener implements Runnable, QueryListener
2N/A{
2N/A /** Create a listener for DNSSD that will call your listener on the Swing/AWT event thread. */
2N/A public SwingQueryListener( QueryListener listener)
2N/A { fListener = listener; }
2N/A
2N/A public void operationFailed( DNSSDService service, int errorCode)
2N/A {
2N/A fQuery = service;
2N/A fErrorCode = errorCode;
2N/A this.schedule();
2N/A }
2N/A
2N/A /** (Clients should not call this method directly.) */
2N/A public void queryAnswered( DNSSDService query, int flags, int ifIndex, String fullName,
2N/A int rrtype, int rrclass, byte[] rdata, int ttl)
2N/A {
2N/A fQuery = query;
2N/A fFlags = flags;
2N/A fIndex = ifIndex;
2N/A fFullName = fullName;
2N/A fType = rrtype;
2N/A fClass = rrclass;
2N/A fData = rdata;
2N/A fTTL = ttl;
2N/A this.schedule();
2N/A }
2N/A
2N/A /** (Clients should not call this method directly.) */
2N/A public void run()
2N/A {
2N/A if ( fErrorCode != 0)
2N/A fListener.operationFailed( fQuery, fErrorCode);
2N/A else
2N/A fListener.queryAnswered( fQuery, fFlags, fIndex, fFullName, fType, fClass, fData, fTTL);
2N/A }
2N/A
2N/A protected void schedule()
2N/A {
2N/A try {
2N/A SwingUtilities.invokeAndWait( this);
2N/A }
2N/A catch ( Exception e)
2N/A {
2N/A e.printStackTrace();
2N/A }
2N/A }
2N/A
2N/A protected QueryListener fListener;
2N/A
2N/A protected DNSSDService fQuery;
2N/A protected int fFlags;
2N/A protected int fIndex;
2N/A protected int fErrorCode;
2N/A protected String fFullName;
2N/A protected int fType;
2N/A protected int fClass;
2N/A protected byte[] fData;
2N/A protected int fTTL;
2N/A}
2N/A