mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-29 10:26:36 +01:00
add the alternative send proc to the java transportprocs interface,
and call through to it from the jni. Add another implemenation of the interface and pass that when opening games in the background.
This commit is contained in:
parent
f6bf91de36
commit
ea05c34d8f
5 changed files with 83 additions and 6 deletions
|
@ -115,12 +115,22 @@ static XP_Bool
|
|||
and_xport_sendNoConn( const XP_U8* buf, XP_U16 len,
|
||||
const XP_UCHAR* relayID, void* closure )
|
||||
{
|
||||
LOG_FUNC();
|
||||
jboolean result = false;
|
||||
AndTransportProcs* aprocs = (AndTransportProcs*)closure;
|
||||
if ( NULL != aprocs && NULL != aprocs->jxport ) {
|
||||
JNIEnv* env = *aprocs->envp;
|
||||
|
||||
const char* sig = "([BLjava/lang/String;)Z";
|
||||
jmethodID mid = getMethodID( env, aprocs->jxport,
|
||||
"relayNoConnProc", sig );
|
||||
jbyteArray jbytes = makeByteArray( env, len, (jbyte*)buf );
|
||||
jstring str = (*env)->NewStringUTF( env, relayID );
|
||||
result = (*env)->CallBooleanMethod( env, aprocs->jxport, mid,
|
||||
jbytes, str );
|
||||
(*env)->DeleteLocalRef( env, jbytes );
|
||||
(*env)->DeleteLocalRef( env, str );
|
||||
}
|
||||
LOG_RETURNF( "%s", "false" );
|
||||
return XP_FALSE;
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -415,4 +415,11 @@ public class CommsTransport implements TransportProcs,
|
|||
{
|
||||
m_handler.tpmRelayErrorProc( relayErr );
|
||||
}
|
||||
|
||||
public boolean relayNoConnProc( byte[] buf, String relayID )
|
||||
{
|
||||
Utils.logf( "CommsTransport.relayNoConnProc()=>false" );
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/* -*- compile-command: "cd ../../../../../; ant install"; -*- */
|
||||
/*
|
||||
* Copyright 2009-2010 by Eric House (xwords@eehouse.org). All
|
||||
* rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.jni.*;
|
||||
|
||||
public class CommsTransportStub implements TransportProcs {
|
||||
|
||||
public int transportSend( byte[] buf, final CommsAddrRec addr )
|
||||
{
|
||||
Assert.fail();
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void relayStatus( CommsRelayState newState )
|
||||
{
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
public void relayErrorProc( XWRELAY_ERROR relayErr )
|
||||
{
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
public void relayConnd( String room, int devOrder, boolean allHere,
|
||||
int nMissing )
|
||||
{
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
public boolean relayNoConnProc( byte[] buf, String relayID )
|
||||
{
|
||||
Utils.logf( "relayNoConnProc got %d bytes for %s; send 'em!!!",
|
||||
buf.length, relayID );
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -308,12 +308,12 @@ public class GameUtils {
|
|||
public static void loadMakeGame( Context context, int gamePtr,
|
||||
CurGameInfo gi, GameLock lock )
|
||||
{
|
||||
loadMakeGame( context, gamePtr, gi, null, lock );
|
||||
loadMakeGame( context, gamePtr, gi, null, null, lock );
|
||||
}
|
||||
|
||||
public static void loadMakeGame( Context context, int gamePtr,
|
||||
CurGameInfo gi, UtilCtxt util,
|
||||
GameLock lock )
|
||||
TransportProcs tp, GameLock lock )
|
||||
{
|
||||
byte[] stream = savedGame( context, lock );
|
||||
XwJNI.gi_from_stream( gi, stream );
|
||||
|
@ -858,9 +858,10 @@ 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, lock );
|
||||
loadMakeGame( context, gamePtr, gi, feedImpl, xpstub, lock );
|
||||
|
||||
for ( byte[] msg : msgs ) {
|
||||
draw = XwJNI.game_receiveMessage( gamePtr, msg ) || draw;
|
||||
|
|
|
@ -53,6 +53,8 @@ public interface TransportProcs {
|
|||
};
|
||||
void relayErrorProc( XWRELAY_ERROR relayErr );
|
||||
|
||||
boolean relayNoConnProc( byte[] buf, String relayID );
|
||||
|
||||
public interface TPMsgHandler {
|
||||
public void tpmRelayConnd( String room, int devOrder, boolean allHere,
|
||||
int nMissing );
|
||||
|
|
Loading…
Reference in a new issue