📄 placelab.java
字号:
/* * Created on 27-Aug-2004 * */package org.placelab.client;import java.util.Enumeration;import java.util.Vector;import org.placelab.client.tracker.BeaconTracker;import org.placelab.client.tracker.Estimate;import org.placelab.client.tracker.EstimateListener;import org.placelab.client.tracker.Tracker;import org.placelab.core.Measurement;import org.placelab.mapper.Mapper;import org.placelab.spotter.Spotter;import org.placelab.spotter.SpotterException;import org.placelab.spotter.SpotterListener;public class Placelab implements EstimateListener { protected Vector spotterList; protected BeaconTracker tracker; protected Mapper mapper; protected Estimate latestEstimate; protected Placelab() { } public Placelab(Vector spotterList, Mapper mapper, BeaconTracker tracker) { this.spotterList = spotterList; this.mapper = mapper; this.tracker = tracker; } public BeaconTracker getTracker() { return tracker; } public Mapper getMapper() { return mapper; } public void addEstimateListener(EstimateListener el) { if (tracker != null && el != null) tracker.addEstimateListener(el); } public void removeEstimateListener(EstimateListener el) { if (tracker != null && el != null) tracker.removeEstimateListener(el); } public synchronized void addSpotterListener(SpotterListener sl) { if (sl == null || spotterList == null) return; Enumeration i = spotterList.elements(); while (i.hasMoreElements()) { Spotter s = (Spotter) i.nextElement(); s.addListener(sl); } } public synchronized void removeSpotterListener(SpotterListener sl) { if (sl == null || spotterList == null) return; Enumeration i = spotterList.elements(); while (i.hasMoreElements()) { Spotter s = (Spotter) i.nextElement(); s.removeListener(sl); } } private boolean started = false; public synchronized void start() throws PlacelabException { if(started) return; try { started=true; if(mapper != null) { if(!mapper.open()) throw new PlacelabException("Cannot start Mapper"); } if (tracker != null) { tracker.reset(); tracker.addEstimateListener(this); } if (spotterList != null) { Enumeration i = spotterList.elements(); while (i.hasMoreElements()) { Spotter s = (Spotter) i.nextElement(); if (tracker != null) { s.addListener(tracker); } s.open(); s.startScanning(); } } } catch (Throwable t) { throw new PlacelabException("Error during start: " + t); } } public synchronized void stop() throws PlacelabException { if(!started) return; try { started=false; if(mapper != null) { mapper.close(); } if (tracker != null) { tracker.removeEstimateListener(this); } if (spotterList != null) { Enumeration i = spotterList.elements(); while (i.hasMoreElements()) { try { Spotter s = (Spotter) i.nextElement(); if (tracker != null) { s.removeListener(tracker); } s.stopScanning(); s.close(); } catch(SpotterException se) { } } } } catch (Throwable t) { throw new PlacelabException("Error during stop: " + t); } } public Estimate getLatestEstimate() throws PlacelabException { if(!started) throw new PlacelabException("getLatestEstimate: Placelab not started"); try { if (tracker == null) return latestEstimate; tracker.updateWithoutMeasurement(tracker.getLastUpdatedTime()); return latestEstimate; } catch (Exception e) { throw new PlacelabException("Error during getLatestEstimate: " + e); } } public void estimateUpdated(Tracker t, Estimate e, Measurement m) { latestEstimate = e; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -