Commit 16ba572e authored by Nicolas Gilmard's avatar Nicolas Gilmard

Fix issue #22. Closing socket problem

parent ebd6f453
......@@ -124,29 +124,28 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
Vector<Point> tempPath = new Vector<>();
tuioObject.getPath().forEach(path -> tempPath.addElement(new Point(path.getX(), path.getY(), path.getAngle(tuioObject))));
tuioObject.getPath().forEach(path -> tempPath.addElement(new Point(path.getX(), path.getY(), tuioObject.getAngle())));
// path.getAngle(tuioObject)
TangibleObject convertedTangibleObject = new TangibleObjectBuilder(tuioObject.getSymbolID(), Type.OBJECT, tuioObject.getPath().lastElement().getX(), tuioObject.getPath().lastElement().getY()).withSeconds(tuioObject.getTuioTime().getSeconds()).withMicroSeconds(tuioObject.getTuioTime().getMicroseconds()).withxSpeed(tuioObject.getXSpeed()).withySpeed(tuioObject.getYSpeed()).withMotionSpeed(tuioObject.getMotionSpeed()).withMotionAccel(tuioObject.getMotionAccel()).withRotationSpeed(tuioObject.getRotationSpeed()).withRotationAccel(tuioObject.getRotationAccel()).withPath(tempPath).withState(tuioObject.getTuioState()).build();
return convertedTangibleObject;
}
/**
* Convert a TUIO cursor into a tangibleObject
*
* @param tangibleCursor
* @param tuioCursor
* != null
* @pre tangibleCursor != null
* @return tangibleObject with TuioCursor's values
*/
private TangibleObject convertTuioCursorToTangibleObject(TuioCursor tangibleCursor) {
Preconditions.checkArgument(tangibleCursor != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$
private TangibleObject convertTuioCursorToTangibleObject(TuioCursor tuioCursor) {
Preconditions.checkArgument(tuioCursor != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$
Vector<Point> tempPath = new Vector<>();
tangibleCursor.getPath().forEach(path -> tempPath.addElement(new Point(path.getX(), path.getY(), 0)));
tuioCursor.getPath().forEach(path -> tempPath.addElement(new Point(path.getX(), path.getY(), 0)));
TangibleObject convertedTangibleObject = new TangibleObjectBuilder(IDMapper.remapCursorID(tangibleCursor.getCursorID()), Type.CURSOR, tangibleCursor.getPath().lastElement().getX(), tangibleCursor.getPath().lastElement().getY()).withSeconds(tangibleCursor.getTuioTime().getSeconds()).withMicroSeconds(tangibleCursor.getTuioTime().getMicroseconds()).withxSpeed(tangibleCursor.getXSpeed()).withySpeed(tangibleCursor.getYSpeed()).withMotionSpeed(tangibleCursor.getMotionSpeed()).withMotionAccel(tangibleCursor.getMotionAccel()).withPath(tempPath).withState(tangibleCursor.getTuioState()).build();
TangibleObject convertedTangibleObject = new TangibleObjectBuilder(IDMapper.remapCursorID(tuioCursor.getCursorID()), Type.CURSOR, tuioCursor.getPath().lastElement().getX(), tuioCursor.getPath().lastElement().getY()).withSeconds(tuioCursor.getTuioTime().getSeconds()).withMicroSeconds(tuioCursor.getTuioTime().getMicroseconds()).withxSpeed(tuioCursor.getXSpeed()).withySpeed(tuioCursor.getYSpeed()).withMotionSpeed(tuioCursor.getMotionSpeed()).withMotionAccel(tuioCursor.getMotionAccel()).withPath(tempPath).withState(tuioCursor.getTuioState()).build();
return convertedTangibleObject;
}
......
......@@ -45,10 +45,10 @@ public class BluetoothClient extends ClientAdapter {
protected String uuidService;
/**
* Default constructor
* Default constructor which assign uuidService.
*
* @param uuidService
* != null
* is the uuid of the service to connect to.
*/
public BluetoothClient(String uuidService) {
this.uuidService = uuidService;
......@@ -66,10 +66,10 @@ public class BluetoothClient extends ClientAdapter {
DiscoveryAgent discoveryAgent;
discoveryAgent = LocalDevice.getLocalDevice().getDiscoveryAgent();
String mConnect = null;
mConnect = discoveryAgent.selectService(serviceId, ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
if (mConnect != null) {
client = (StreamConnection) Connector.open(mConnect);
String serviceConnect = null;
serviceConnect = discoveryAgent.selectService(serviceId, ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
if (serviceConnect != null) {
client = (StreamConnection) Connector.open(serviceConnect);
inputStream = client.openInputStream();
outputStream = client.openOutputStream();
}
......
......@@ -51,10 +51,10 @@ public class BluetoothServer extends ServerAdapter {
protected String uuidService;
/**
* Default constructor
* Default constructor which assign uuidService.
*
* @param uuidService
* != null
* is the uuid of the service to connect to.
* @throws IOException
*/
public BluetoothServer(String uuidService) throws IOException {
......@@ -84,17 +84,7 @@ public class BluetoothServer extends ServerAdapter {
*/
@Override
public void closeServer() throws IOException {
// TODO Auto-generated method stub
if (outputStream != null) {
outputStream.close();
}
if (inputStream != null) {
inputStream.close();
}
if (client != null) {
client.close();
}
closeClient();
if (server != null) {
server.close();
}
......
......@@ -66,9 +66,15 @@ public class TcpServer extends ServerAdapter {
*/
@Override
public void acceptClient() throws IOException {
client = server.accept();
outputStream = client.getOutputStream();
inputStream = client.getInputStream();
try {
client = server.accept();
outputStream = client.getOutputStream();
inputStream = client.getInputStream();
} catch (IOException e) {
if (server != null) {
server.close();
}
}
}
/**
......
......@@ -92,7 +92,7 @@ public class TangibleApplicationTest2 {
try {
application = new TestTangibleApplication(propertiesLocation);
fail("Expected exit25"); //$NON-NLS-1$
fail("Expected exit"); //$NON-NLS-1$
} catch (ExitSecurityException e) {
int status = e.getStatus();
assertEquals(42, status);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment