add devOrder (= hostID) to params passed on connect. Fix to pass new

param from jni; use object to pass params into UI thread since there
are now too many for handler.
This commit is contained in:
Andy2 2010-10-29 06:34:39 -07:00
parent ab708e4db1
commit b115ce14ed
4 changed files with 45 additions and 23 deletions

View file

@ -96,17 +96,17 @@ and_xport_relayStatus( void* closure, CommsRelayState newState )
static void
and_xport_relayConnd( void* closure, XP_UCHAR* const room,
XP_Bool allHere, XP_U16 nMissing )
XP_U16 devOrder, XP_Bool allHere, XP_U16 nMissing )
{
AndTransportProcs* aprocs = (AndTransportProcs*)closure;
if ( NULL != aprocs->jxport ) {
JNIEnv* env = *aprocs->envp;
const char* sig = "(Ljava/lang/String;ZI)V";
const char* sig = "(Ljava/lang/String;IZI)V";
jmethodID mid = getMethodID( env, aprocs->jxport, "relayConnd", sig );
jstring str = (*env)->NewStringUTF( env, room );
(*env)->CallVoidMethod( env, aprocs->jxport, mid,
str, allHere, nMissing );
str, devOrder, allHere, nMissing );
(*env)->DeleteLocalRef( env, str );
}
}

View file

@ -607,19 +607,32 @@ public class BoardActivity extends XWActivity implements UtilCtxt {
}
}
// You have started a game in a new room. Once the remaining
// devices have joined your room and you have assigned them tiles
// (which Crosswords does for you) the game can begin.
// You have joined a game on the relay. Once the remaining
// devices have joined your room the game can begin.
// You have joined a game on the relay and the room is now full.
// Next you will receive your initial tiles from the device that
// created the room and play can begin.
private void handleConndMessage( Message msg )
{
CommsTransport.ConndMsg cndmsg =
(CommsTransport.ConndMsg)msg.obj;
Utils.logf( "handleConndMessage: devOrder=%d", cndmsg.m_devOrder );
String str = null;
String fmt;
switch ( msg.arg1 ) {
case CommsTransport.RELAY_CONNND_ALLHERE:
fmt = getString( R.string.msg_relay_all_heref );
str = String.format( fmt, (String)msg.obj );
break;
case CommsTransport.RELAY_CONNND_MISSING:
fmt = getString( R.string.msg_relay_waiting );
str = String.format( fmt, (String)msg.obj, msg.arg2 );
break;
if ( cndmsg.m_allHere ) {
// All players have now joined the game. The device that
// created the room will assign tiles. Then it will be
// the first player's turn
String fmt = getString( R.string.msg_relay_all_heref );
str = String.format( fmt, cndmsg.m_room );
} else if ( cndmsg.m_nMissing > 0 ) {
String fmt = getString( R.string.msg_relay_waiting );
str = String.format( fmt, cndmsg.m_room, cndmsg.m_nMissing );
}
if ( null != str ) {

View file

@ -51,6 +51,20 @@ public class CommsTransport extends Thread implements TransportProcs {
public static final int RELAY_CONNND_ALLHERE = 0;
public static final int RELAY_CONNND_MISSING = 1;
public class ConndMsg {
ConndMsg( String room, int devOrder, boolean allHere, int nMissing )
{
m_room = room;
m_devOrder = devOrder;
m_allHere = allHere;
m_nMissing = nMissing;
}
public String m_room;
public int m_devOrder;
public boolean m_allHere;
public int m_nMissing;
}
private Selector m_selector;
private SocketChannel m_socketChannel;
private int m_jniGamePtr;
@ -353,16 +367,11 @@ public class CommsTransport extends Thread implements TransportProcs {
}
}
public void relayConnd( String room, boolean allHere, int nMissing )
public void relayConnd( String room, int devOrder, boolean allHere,
int nMissing )
{
String message = null;
if ( allHere ) {
Message.obtain( m_handler, RELAY_COND, RELAY_CONNND_ALLHERE,
-1/*ignored*/, room ).sendToTarget();
} else if ( nMissing > 0 ) {
Message.obtain( m_handler, RELAY_COND, RELAY_CONNND_MISSING,
nMissing, room ).sendToTarget();
}
ConndMsg cndmsg = new ConndMsg( room, devOrder, allHere, nMissing );
Message.obtain( m_handler, RELAY_COND, cndmsg ).sendToTarget();
}
public void relayErrorProc( XWRELAY_ERROR relayErr )

View file

@ -32,7 +32,7 @@ public interface TransportProcs {
};
void relayStatus( CommsRelayState newState );
void relayConnd( String room, boolean allHere, int nMissing );
void relayConnd( String room, int devOrder, boolean allHere, int nMissing );
public static enum XWRELAY_ERROR { NONE
,OLDFLAGS