rename class and pass in from higher so send can be done in the right

place.
This commit is contained in:
Andy2 2011-08-11 06:49:44 -07:00
parent 985f254660
commit 6f22cbd8c9
3 changed files with 38 additions and 35 deletions

View file

@ -851,7 +851,7 @@ public class GameUtils {
}
public static boolean feedMessages( Context context, String relayID,
byte[][] msgs )
byte[][] msgs, RelayMsgSink sink )
{
boolean draw = false;
long rowid = DBUtils.getRowIDFor( context, relayID );
@ -859,10 +859,9 @@ public class GameUtils {
int gamePtr = XwJNI.initJNI();
CurGameInfo gi = new CurGameInfo( context );
FeedUtilsImpl feedImpl = new FeedUtilsImpl( context, rowid );
CommsTransportStub xpstub = new CommsTransportStub();
GameLock lock = new GameLock( rowid, true );
if ( lock.tryLock() ) {
loadMakeGame( context, gamePtr, gi, feedImpl, xpstub, lock );
loadMakeGame( context, gamePtr, gi, feedImpl, sink, lock );
for ( byte[] msg : msgs ) {
draw = XwJNI.game_receiveMessage( gamePtr, msg ) || draw;

View file

@ -24,7 +24,7 @@ import junit.framework.Assert;
import org.eehouse.android.xw4.jni.*;
public class CommsTransportStub implements TransportProcs {
public class RelayMsgSink implements TransportProcs {
public int transportSend( byte[] buf, final CommsAddrRec addr )
{

View file

@ -48,37 +48,7 @@ public class RelayService extends Service {
Thread thread = new Thread( null, new Runnable() {
public void run() {
int[] nBytes = new int[1];
String[] ids = collectIDs( nBytes );
if ( null != ids && 0 < ids.length ) {
byte[][][] msgs =
NetUtils.queryRelay( RelayService.this,
ids, nBytes[0] );
int nameCount = ids.length;
if ( null != msgs ) {
ArrayList<String> idsWMsgs =
new ArrayList<String>( nameCount );
for ( int ii = 0; ii < nameCount; ++ii ) {
// if game has messages, open it and feed 'em
// to it.
if ( null != msgs[ii] ) {
if ( GameUtils.feedMessages( RelayService.this,
ids[ii],
msgs[ii] ) ) {
idsWMsgs.add( ids[ii] );
}
}
}
if ( 0 < idsWMsgs.size() ) {
String[] relayIDs = new String[idsWMsgs.size()];
idsWMsgs.toArray( relayIDs );
if ( !DispatchNotify.tryHandle( relayIDs ) ) {
setupNotification( relayIDs );
}
}
}
}
fetchAndProcess();
RelayService.this.stopSelf();
}
}, getClass().getName() );
@ -134,5 +104,39 @@ public class RelayService extends Service {
nBytes[0] = len;
return ids;
}
private void fetchAndProcess()
{
int[] nBytes = new int[1];
String[] ids = collectIDs( nBytes );
if ( null != ids && 0 < ids.length ) {
RelayMsgSink sink = new RelayMsgSink();
byte[][][] msgs =
NetUtils.queryRelay( this, ids, nBytes[0] );
int nameCount = ids.length;
if ( null != msgs ) {
ArrayList<String> idsWMsgs =
new ArrayList<String>( nameCount );
for ( int ii = 0; ii < nameCount; ++ii ) {
// if game has messages, open it and feed 'em
// to it.
if ( null != msgs[ii] ) {
if ( GameUtils.feedMessages( this, ids[ii],
msgs[ii], sink ) ) {
idsWMsgs.add( ids[ii] );
}
}
}
if ( 0 < idsWMsgs.size() ) {
String[] relayIDs = new String[idsWMsgs.size()];
idsWMsgs.toArray( relayIDs );
if ( !DispatchNotify.tryHandle( relayIDs ) ) {
setupNotification( relayIDs );
}
}
}
}
}
}