[Zerofile-svn] SF.net SVN: zerofile: [37] trunk/src
Status: Pre-Alpha
Brought to you by:
karl-bengtsson
|
From: <kar...@us...> - 2007-11-07 14:31:58
|
Revision: 37
http://zerofile.svn.sourceforge.net/zerofile/?rev=37&view=rev
Author: karl-bengtsson
Date: 2007-11-07 06:32:01 -0800 (Wed, 07 Nov 2007)
Log Message:
-----------
*) Moved the resolving code into the XMPPLinkLocalHost class - this makes sense if we consider that we will only resolve for one named instance of a presence service at a time, and that this service will be represented by an XMPPLinkLocalHost object.
*) Fixed a small null reference bug in ZeroFileSettings
*) Modified the ZeroconfBrowsing.startBrowse() method to actually post newly discovered hosts to the main contact list of the program.
Modified Paths:
--------------
trunk/src/XMPPLinkLocalHost.java
trunk/src/ZeroFileSettings.java
trunk/src/ZeroconfBrowsing.java
Modified: trunk/src/XMPPLinkLocalHost.java
===================================================================
--- trunk/src/XMPPLinkLocalHost.java 2007-11-07 14:04:37 UTC (rev 36)
+++ trunk/src/XMPPLinkLocalHost.java 2007-11-07 14:32:01 UTC (rev 37)
@@ -1,3 +1,9 @@
+import com.apple.dnssd.DNSSD;
+import com.apple.dnssd.DNSSDException;
+import com.apple.dnssd.DNSSDService;
+import com.apple.dnssd.ResolveListener;
+import com.apple.dnssd.TXTRecord;
+
// Stub class, to represent a compatible XMPP-capable host on the ZeroConf network
public class XMPPLinkLocalHost {
private String _serviceName;
@@ -4,17 +10,25 @@
private String _nickName;
private String _firstName;
private String _lastName;
+ private String _host;
+ private int _port;
+ private static DNSSDService _r;
public XMPPLinkLocalHost(String serviceName)
{
_serviceName = serviceName;
}
- /*public String getIPAddress()
+ public int getPort()
{
- return _ipAddress;
- }*/
+ return _port;
+ }
+ public String getHost()
+ {
+ return _host;
+ }
+
public String getServiceName()
{
return _serviceName;
@@ -40,4 +54,34 @@
else
return _serviceName;
}
+
+ public void updateData()
+ throws DNSSDException, InterruptedException
+ {
+ _r = DNSSD.resolve(0, DNSSD.UNIQUE, _serviceName, "_presence._tcp", "local", new ResolveListener()
+ {
+ public void operationFailed(DNSSDService service,int errorCode)
+ {
+ System.out.println("Resolved failed " + errorCode);
+ System.exit(-1);
+ }
+ public void serviceResolved(DNSSDService resolver, int flags, int ifIndex,
+ String fullName, String hostName, int port, TXTRecord txtRecord)
+ {
+ _host = hostName;
+ _port = port;
+ System.out.println("Host resolved: " + hostName + ":" + port);
+ System.out.println("Flags: " + flags + ", ifIndex: " + ifIndex + ", FQDN: " + fullName);
+ for (int i = 0; i < txtRecord.size(); i++)
+ {
+ String key = txtRecord.getKey(i);
+ String value = txtRecord.getValueAsString(i);
+ if (key.length() > 0)
+ System.out.println("\t" + key + "=" + value);
+ }
+ _r.stop();
+ }
+ });
+ }
+
}
Modified: trunk/src/ZeroFileSettings.java
===================================================================
--- trunk/src/ZeroFileSettings.java 2007-11-07 14:04:37 UTC (rev 36)
+++ trunk/src/ZeroFileSettings.java 2007-11-07 14:32:01 UTC (rev 37)
@@ -5,12 +5,12 @@
import java.io.*;
public class ZeroFileSettings {
- private static String _nickName;
+ //private static String _nickName;
private static String _firstName;
private static String _lastName;
private static String _email;
private static int _mainPort;
- private static Properties _zeroFileProperties;
+ private static Properties _zeroFileProperties = new Properties();
/*public static void saveSettings() throws IOException
{
@@ -62,7 +62,7 @@
public static void setLastName(String l)
{
- _nickName = l;
+ _lastName = l;
}
public static String getEmail()
Modified: trunk/src/ZeroconfBrowsing.java
===================================================================
--- trunk/src/ZeroconfBrowsing.java 2007-11-07 14:04:37 UTC (rev 36)
+++ trunk/src/ZeroconfBrowsing.java 2007-11-07 14:32:01 UTC (rev 37)
@@ -14,7 +14,9 @@
public void serviceFound(DNSSDService browser, int flags, int ifIndex,
String name, String regType, String domain)
{
- System.out.println("Yay, found: " + name + " at interface: " + ifIndex);
+ XMPPLinkLocalHost newHost = new XMPPLinkLocalHost(name);
+ ZeroFileMainWindow.addContact(newHost);
+ /*System.out.println("Yay, found: " + name + " at interface: " + ifIndex);
try
{
ZeroconfResolving.getHost(name);
@@ -22,12 +24,13 @@
catch (Exception e)
{
System.out.println("Error: " + e.getStackTrace());
- }
+ }*/
}
public void serviceLost(DNSSDService browser, int flags, int ifIndex,
String name, String regType, String domain)
{
- System.out.println("Lost: " + name);
+ ZeroFileMainWindow.removeContact("name");
+ //System.out.println("Lost: " + name);
}
});
System.out.println("Starting browsing...");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|