Skip to content

Commit

Permalink
Small fixes in discovery service
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jan 11, 2013
1 parent e2b93b5 commit 940dfe3
Showing 1 changed file with 18 additions and 11 deletions.
Expand Up @@ -204,36 +204,35 @@ public void run() {
// if any left in old ones it means that devices has been removed
if (oldones.size() > 0) {

List<Webcam> notified = new ArrayList<Webcam>();

for (WebcamDevice device : oldones) {
for (Webcam webcam : webcams) {
if (webcam.getDevice().getName().equals(device.getName())) {
notifyWebcamGone(webcam, listeners);
notified.add(webcam);
break;
}
}
}

webcams = toWebcams(tmpnew);
setCurrentWebcams(tmpnew);

if (Webcam.isHandleTermSignal()) {
WebcamDeallocator.unstore();
WebcamDeallocator.store(webcams.toArray(new Webcam[webcams.size()]));
for (Webcam webcam : notified) {
notifyWebcamGone(webcam, listeners);
webcam.dispose();
}
}

// if any left in new ones it means that devices has been added
if (newones.size() > 0) {

webcams = toWebcams(tmpnew);

if (Webcam.isHandleTermSignal()) {
WebcamDeallocator.unstore();
WebcamDeallocator.store(webcams.toArray(new Webcam[webcams.size()]));
}
setCurrentWebcams(tmpnew);

for (WebcamDevice device : newones) {
for (Webcam webcam : webcams) {
if (webcam.getDevice().getName().equals(device.getName())) {
notifyWebcamFound(webcam, listeners);
break;
}
}
}
Expand All @@ -242,6 +241,14 @@ public void run() {
} while (running);
}

private void setCurrentWebcams(List<WebcamDevice> devices) {
webcams = toWebcams(devices);
if (Webcam.isHandleTermSignal()) {
WebcamDeallocator.unstore();
WebcamDeallocator.store(webcams.toArray(new Webcam[webcams.size()]));
}
}

private static void notifyWebcamGone(Webcam webcam, WebcamDiscoveryListener[] listeners) {
WebcamDiscoveryEvent event = new WebcamDiscoveryEvent(webcam, WebcamDiscoveryEvent.REMOVED);
for (WebcamDiscoveryListener l : listeners) {
Expand Down

0 comments on commit 940dfe3

Please sign in to comment.