1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
class SocketManager
{
public static final int INVALID_SOCKET = -1;
int curId = 0;
Hashtable<Integer,BluetoothSocket> sockets = new Hashtable<Integer,BlutoothSocket>();
SocketManager() { }
private static SocketManager _instance = null;
public static synchronized SocketManager getInstance()
{
if (_instance == null)
_instance = new SocketManager();
return _instance;
}
public BluetoothSocket getSocket(int socketId)
{
return (socketId == SocketManager.INVALID_SOCKET) ? null : this.sockets.get(Integer.valueOf(socketId));
}
public synchronized void closeSocket(int socketId)
{
...
this.sockets.remove(Integer.valueOf(socketId));
}
public synchronized Integer openSocket()
{
...
Integer ret = Integer.valueOf(++this.curId);
this.sockets.put(ret,socket);
return ret;
}
} |
Partager