include hwAddr as well as device name in bt section of address

This commit is contained in:
Eric House 2012-01-31 18:48:59 -08:00
parent af2fcc76e0
commit b4b7609894
3 changed files with 24 additions and 7 deletions

View file

@ -341,6 +341,7 @@ setJAddrRec( JNIEnv* env, jobject jaddr, const CommsAddrRec* addr )
break; break;
case COMMS_CONN_BT: case COMMS_CONN_BT:
setString( env, jaddr, "bt_hostName", addr->u.bt.hostName ); setString( env, jaddr, "bt_hostName", addr->u.bt.hostName );
setString( env, jaddr, "bt_btAddr", addr->u.bt.btAddr.chars );
break; break;
default: default:
XP_ASSERT(0); XP_ASSERT(0);
@ -378,6 +379,8 @@ getJAddrRec( JNIEnv* env, CommsAddrRec* addr, jobject jaddr )
case COMMS_CONN_BT: case COMMS_CONN_BT:
getString( env, jaddr, "bt_hostName", addr->u.bt.hostName, getString( env, jaddr, "bt_hostName", addr->u.bt.hostName,
VSIZE(addr->u.bt.hostName) ); VSIZE(addr->u.bt.hostName) );
getString( env, jaddr, "bt_btAddr", addr->u.bt.btAddr.chars,
VSIZE(addr->u.bt.btAddr.chars) );
break; break;
default: default:
XP_ASSERT(0); XP_ASSERT(0);

View file

@ -27,9 +27,10 @@ import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothServerSocket; import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket; import android.bluetooth.BluetoothSocket;
import android.bluetooth.BluetoothDevice;
import junit.framework.Assert; import junit.framework.Assert;
import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.CommsAddrRec;
@ -186,6 +187,7 @@ public class BTService extends Service {
new BTSenderThread().start(); new BTSenderThread().start();
} else { } else {
DbgUtils.logf( "not starting threads: BT not available" ); DbgUtils.logf( "not starting threads: BT not available" );
stopSelf();
} }
} }
@ -545,7 +547,8 @@ public class BTService extends Service {
os.flush(); os.flush();
socket.close(); socket.close();
CommsAddrRec addr = new CommsAddrRec( this, host.getName() ); CommsAddrRec addr = new CommsAddrRec( this, host.getName(),
host.getAddress() );
if ( BoardActivity.feedMessage( gameID, buffer, addr ) ) { if ( BoardActivity.feedMessage( gameID, buffer, addr ) ) {
DbgUtils.logf( "BoardActivity.feedMessage took it" ); DbgUtils.logf( "BoardActivity.feedMessage took it" );

View file

@ -24,6 +24,7 @@ import java.net.InetAddress;
import android.content.Context; import android.content.Context;
import org.eehouse.android.xw4.Utils; import org.eehouse.android.xw4.Utils;
import org.eehouse.android.xw4.DbgUtils;
public class CommsAddrRec { public class CommsAddrRec {
@ -50,7 +51,7 @@ public class CommsAddrRec {
// bt case // bt case
public String bt_hostName; public String bt_hostName;
public byte[] bt_btAddr; // array of 6 bytes on the C side public String bt_btAddr;
// sms case // sms case
// public String sms_phone; // public String sms_phone;
@ -72,10 +73,11 @@ public class CommsAddrRec {
this( context, CommsConnType.COMMS_CONN_RELAY ); this( context, CommsConnType.COMMS_CONN_RELAY );
} }
public CommsAddrRec( Context context, String btHost ) public CommsAddrRec( Context context, String btHost, String btAddr )
{ {
this( context, CommsConnType.COMMS_CONN_BT ); this( context, CommsConnType.COMMS_CONN_BT );
bt_hostName = btHost; bt_hostName = btHost;
bt_btAddr = btAddr;
} }
public CommsAddrRec( final CommsAddrRec src ) public CommsAddrRec( final CommsAddrRec src )
@ -87,9 +89,17 @@ public class CommsAddrRec {
{ {
boolean matter = conType != other.conType; boolean matter = conType != other.conType;
if ( !matter ) { if ( !matter ) {
switch( conType ) {
case COMMS_CONN_RELAY:
matter = ! ip_relay_invite.equals( other.ip_relay_invite ) matter = ! ip_relay_invite.equals( other.ip_relay_invite )
|| ! ip_relay_hostName.equals( other.ip_relay_hostName ) || ! ip_relay_hostName.equals( other.ip_relay_hostName )
|| ip_relay_port != other.ip_relay_port; || ip_relay_port != other.ip_relay_port;
break;
default:
DbgUtils.logf( "changesMatter: not handling case: %s",
conType.toString() );
break;
}
} }
return matter; return matter;
} }
@ -104,5 +114,6 @@ public class CommsAddrRec {
ip_relay_advertiseRoom = src.ip_relay_advertiseRoom; ip_relay_advertiseRoom = src.ip_relay_advertiseRoom;
bt_hostName = src.bt_hostName; bt_hostName = src.bt_hostName;
bt_btAddr = src.bt_btAddr;
} }
} }