forked from jbagg/QtZeroConf
committed by
Jonathan Bagg
parent
3f5650388c
commit
966877a9a0
@@ -28,6 +28,7 @@
|
|||||||
package qtzeroconf;
|
package qtzeroconf;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -52,6 +53,10 @@ public class QZeroConfNsdManager {
|
|||||||
private NsdManager.RegistrationListener registrationListener;
|
private NsdManager.RegistrationListener registrationListener;
|
||||||
private String registrationName; // The original service name that was given for registration, it might change on collisions
|
private String registrationName; // The original service name that was given for registration, it might change on collisions
|
||||||
|
|
||||||
|
// There can only be one resolver at a time per application, we'll need to queue the resolving
|
||||||
|
static private ArrayList<NsdServiceInfo> resolverQueue = new ArrayList<NsdServiceInfo>();
|
||||||
|
static private NsdServiceInfo pendingResolve = null;
|
||||||
|
|
||||||
public QZeroConfNsdManager(int id, Context context) {
|
public QZeroConfNsdManager(int id, Context context) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@@ -103,7 +108,7 @@ public class QZeroConfNsdManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceFound(NsdServiceInfo service) {
|
public void onServiceFound(NsdServiceInfo service) {
|
||||||
nsdManager.resolveService(service, initializeResolveListener());
|
enqueueResolver(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -133,7 +138,12 @@ public class QZeroConfNsdManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
|
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
|
||||||
Log.d(TAG, "Resolving failed for: " + serviceInfo.getServiceName() + " " + serviceInfo.getServiceType() + ": " + errorCode);
|
Log.w(TAG, "Resolving failed for: " + serviceInfo.getServiceName() + " " + serviceInfo.getServiceType() + ": " + errorCode);
|
||||||
|
if (errorCode == NsdManager.FAILURE_ALREADY_ACTIVE) {
|
||||||
|
enqueueResolver(pendingResolve);
|
||||||
|
}
|
||||||
|
pendingResolve = null;
|
||||||
|
processResolverQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -146,6 +156,8 @@ public class QZeroConfNsdManager {
|
|||||||
serviceInfo.getPort(),
|
serviceInfo.getPort(),
|
||||||
serviceInfo.getAttributes()
|
serviceInfo.getAttributes()
|
||||||
);
|
);
|
||||||
|
pendingResolve = null;
|
||||||
|
processResolverQueue();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -177,4 +189,21 @@ public class QZeroConfNsdManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enqueueResolver(NsdServiceInfo serviceInfo) {
|
||||||
|
resolverQueue.add(serviceInfo);
|
||||||
|
processResolverQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processResolverQueue() {
|
||||||
|
if (resolverQueue.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pendingResolve != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pendingResolve = resolverQueue.get(0);
|
||||||
|
resolverQueue.remove(0);
|
||||||
|
nsdManager.resolveService(pendingResolve, initializeResolveListener());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user