Permalink
Browse files

added names to devices

the client, when joining, will receive the port number of the emulator.
The device name is fixed to "emulator-<port>"
  • Loading branch information...
1 parent ac44dd6 commit 0b304758bb729332a000a06d2a4a055fa9d23c68 Francesco Zanitti committed Jul 29, 2010
@@ -104,9 +104,10 @@ public String toString() {
* @param uuid
* @param port
*/
- public BluetoothDevice(String btAddr, String tcpAddr) {
+ public BluetoothDevice(String btAddr, String tcpAddr, String name) {
this.addr = btAddr;
this.tcpAddr = tcpAddr;
+ this.name = name;
this.services = new ArrayList<BTService>();
this.btClass = new BluetoothClass(
android.bluetooth.BluetoothClass.Device.PHONE_SMART,
@@ -68,11 +68,11 @@ protected void readResponse(InputStream in) throws IOException {
if(line==null) break;
String[] parts = line.trim().split("--");
- dk.itu.android.bluetooth.BluetoothDevice d = new BluetoothDevice(parts[0], parts[1]);
+ dk.itu.android.bluetooth.BluetoothDevice d = new BluetoothDevice(parts[0], parts[1],parts[2]);
- if(parts.length>2) {
- if(parts[2].length()>0) {
- String[] sParts = parts[2].split("<><>");
+ if(parts.length>3) {
+ if(parts[3].length()>0) {
+ String[] sParts = parts[3].split("<><>");
for(String p : sParts) {
String[] s = p.split("<>");
d.addService(s[0], Integer.parseInt(s[1]));
@@ -1,7 +1,9 @@
package dk.itu.android.btemu.service.cmd;
+import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
@@ -13,7 +15,12 @@ public Join( Socket socket ) {
@Override
protected void readResponse(InputStream in) throws IOException {
- //ok, we don't really care about the response for join
+ //get the emulator port number
+ BufferedReader br = new BufferedReader(new InputStreamReader(in));
+ String p = br.readLine();
+ String name = "emulator-" + p;
+ name = name.trim();
+ dk.itu.android.bluetooth.BluetoothAdapter.getDefaultAdapter().setName(name);
}
@Override
@@ -30,7 +30,7 @@ protected void writeResponse(OutputStream out) throws IOException {
for( Device d : devices ) {
if(d.getBtAddr().equals(btAddr))
continue;
- String cur = d.getBtAddr() + "--" + d.getIpAddr() + "--";
+ String cur = d.getBtAddr() + "--" + d.getIpAddr() + "--" + d.getName() + "--";
boolean f = true;
for(Service s : d.getServices()) {
if(f){f=!f;}else{cur+="<><>";}
@@ -11,6 +11,7 @@
import dk.itu.btemu.state.Device;
public class Join extends BaseCommand {
+ int port = -1;
public Join(Socket s, InputStreamReader in) {
super(s,in);
@@ -30,13 +31,17 @@ protected void work( List<Param> params ) throws Exception {
BTMacForwardingsChecker checker = new BTMacForwardingsChecker();
System.out.println("running checker...");
checker.run();
+ port = device.getEmulatorPort();
} else {
device.setAndroidEmulator(false);
}
}
@Override
protected void writeResponse(OutputStream out) throws IOException {
+ if(port > 0) {
+ out.write( (port+"\n").getBytes("UTF-8") );
+ }
}
@@ -7,6 +7,7 @@
String ipAddr;
String btAddr;
+ String name;
boolean isAndroidEmulator = true;
@@ -44,10 +45,14 @@ public String getBtAddr() {
public String getIpAddr() {
return ipAddr;
}
+ public String getName() {
+ return name;
+ }
public List<Service> getServices() {
return services;
}
public void setEmulatorPort(int emulatorPort) {
+ this.name = "emulator-"+emulatorPort;
this.emulatorPort = emulatorPort;
}
public int getEmulatorPort() {

0 comments on commit 0b30475

Please sign in to comment.