package org.pollux3d.tuio;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.tuio.TuioClient;
import org.tuio.TuioCursor;
import org.tuio.TuioListener;
import org.tuio.TuioObject;
import org.tuio.TuioTime;
public class TuioDeviceNetwork implements TuioListener, TuioDevice {
protected static final Logger logger = Logger.getLogger(TuioDeviceNetwork.class.getName());
protected Map<Long,TuioObject> objectList = new ConcurrentHashMap<Long,TuioObject>();
protected Map<Long,TuioCursor> cursorList = new ConcurrentHashMap<Long,TuioCursor>();
protected TuioClient client;
public void destroy() {
client.disconnect();
}
public Map<Long, TuioCursor> getCursors() {
return cursorList;
}
public Map<Long, TuioObject> getObjects() {
return objectList;
}
public void initialize(String windowName) {
client = new TuioClient();
client.addTuioListener(this);
try {
connect();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
protected void connect() throws InterruptedException {
client.connect();
if (client.isConnected()) {
logger.log(Level.INFO, "Tuio Device is connected");
} else {
logger.log(Level.SEVERE, "Tuio Device couldn't connect");
}
}
public void addTuioCursor(TuioCursor tcur) {
if (!cursorList.containsKey(tcur.getSessionID())) {
cursorList.put(tcur.getSessionID(), tcur);
}
}
public void addTuioObject(TuioObject tobj) {
if (!objectList.containsKey(tobj.getSessionID())) {
objectList.put(tobj.getSessionID(),tobj);
}
}
public void refresh(TuioTime ftime) {
}
public void removeTuioCursor(TuioCursor tcur) {
cursorList.remove(tcur.getSessionID());
}
public void removeTuioObject(TuioObject tobj) {
objectList.remove(tobj.getSessionID());
}
public void updateTuioCursor(TuioCursor tcur) {
}
public void updateTuioObject(TuioObject tobj) {
}
}