Merge branch 'android_branch' into send_in_background

Conflicts:
	xwords4/common/server.c
This commit is contained in:
Andy2 2011-10-19 06:23:16 -07:00
commit f41d3c27e6
9 changed files with 84 additions and 168 deletions

View file

@ -218,16 +218,15 @@ and_util_turnChanged(XW_UtilCtxt* uc)
static void
and_util_informMove( XW_UtilCtxt* uc, XWStreamCtxt* expl, XWStreamCtxt* words )
{
UTIL_CBK_HEADER( "informMove", "(Ljava/lang/String;Ljava/lang/String;)V" );
jstring jexpl = streamToJString( MPPARM(util->util.mpool) env, expl );
jstring jwords = !!words ?
streamToJString( MPPARM(util->util.mpool) env, words ) : NULL;
(*env)->CallVoidMethod( env, util->jutil, mid, jexpl, jwords );
(*env)->DeleteLocalRef( env, jexpl );
if ( !!jwords ) {
if ( !!words ) {
UTIL_CBK_HEADER( "informMove", "(Ljava/lang/String;Ljava/lang/String;)V" );
jstring jexpl = streamToJString( MPPARM(util->util.mpool) env, expl );
jstring jwords = streamToJString( MPPARM(util->util.mpool) env, words );
(*env)->CallVoidMethod( env, util->jutil, mid, jexpl, jwords );
(*env)->DeleteLocalRef( env, jexpl );
(*env)->DeleteLocalRef( env, jwords );
UTIL_CBK_TAIL();
}
UTIL_CBK_TAIL();
}
static void

View file

@ -100,7 +100,7 @@ public class NetStateCache {
NetworkInfo ni = (NetworkInfo)intent.
getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
Utils.logf( "CommsTransport::onReceive: %s",
Utils.logf( "CommsBroadcastReceiver.onReceive: %s",
ni.getState().toString() );
boolean netAvail;

View file

@ -65,8 +65,6 @@
#include "dragdrpp.h"
#include "dbgutil.h"
#define bEND 0x62454e44
#ifndef MAX_BOARD_ZOOM
/* too big looks bad */
# define MAX_BOARD_ZOOM 4
@ -280,7 +278,6 @@ board_makeFromStream( MPFORMAL XWStreamCtxt* stream, ModelCtxt* model,
board->selInfo = &board->pti[board->selPlayer];
board->trayVisState = (XW_TrayVisState)stream_getBits( stream, 2 );
XP_ASSERT( stream_getU32( stream ) == bEND );
return board;
} /* board_makeFromStream */
@ -340,10 +337,6 @@ board_writeToStream( BoardCtxt* board, XWStreamCtxt* stream )
stream_putBits( stream, PLAYERNUM_NBITS, board->selPlayer );
stream_putBits( stream, 2, board->trayVisState );
#ifdef DEBUG
stream_putU32( stream, bEND );
#endif
} /* board_writeToStream */
void

View file

@ -31,7 +31,6 @@
#include "xwrelay.h"
#include "strutils.h"
#define cEND 0x65454e44
#define HEARTBEAT_NONE 0
#ifndef XWFEATURE_STANDALONE_ONLY
@ -62,10 +61,6 @@ typedef struct MsgQueueElem {
typedef struct AddressRecord {
struct AddressRecord* next;
CommsAddrRec addr;
#ifdef DEBUG
XP_U16 lastACK;
XP_U16 nUniqueBytes;
#endif
MsgID nextMsgID; /* on a per-channel basis */
MsgID lastMsgRcd; /* on a per-channel basis */
/* only used if COMMS_HEARTBEAT set except for serialization (to_stream) */
@ -137,9 +132,6 @@ struct CommsCtxt {
} r;
XP_Bool isServer;
#ifdef DEBUG
XP_U16 nUniqueBytes;
#endif
MPSLOT
};
@ -563,9 +555,6 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
sizeof(comms->r.connName) );
}
#ifdef DEBUG
comms->nUniqueBytes = stream_getU16( stream );
#endif
comms->queueLen = stream_getU8( stream );
nAddrRecs = stream_getU8( stream );
@ -583,11 +572,6 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
rec->r.hostID = stream_getU8( stream );
}
#ifdef DEBUG
rec->lastACK = stream_getU16( stream );
rec->nUniqueBytes = stream_getU16( stream );
#endif
*prevsAddrNext = rec;
prevsAddrNext = &rec->next;
}
@ -614,10 +598,6 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
prevsQueueNext = &msg->next;
}
#ifdef DEBUG
XP_ASSERT( stream_getU32( stream ) == cEND );
#endif
return comms;
} /* comms_makeFromStream */
@ -743,10 +723,6 @@ comms_writeToStream( const CommsCtxt* comms, XWStreamCtxt* stream )
stringToStream( stream, comms->r.connName );
}
#ifdef DEBUG
stream_putU16( stream, comms->nUniqueBytes );
#endif
XP_ASSERT( comms->queueLen <= 255 );
stream_putU8( stream, (XP_U8)comms->queueLen );
@ -764,10 +740,6 @@ comms_writeToStream( const CommsCtxt* comms, XWStreamCtxt* stream )
if ( rec->addr.conType == COMMS_CONN_RELAY ) {
stream_putU8( stream, rec->r.hostID ); /* unneeded unless RELAY */
}
#ifdef DEBUG
stream_putU16( stream, rec->lastACK );
stream_putU16( stream, rec->nUniqueBytes );
#endif
}
for ( msg = comms->msgQueueHead; !!msg; msg = msg->next ) {
@ -778,9 +750,6 @@ comms_writeToStream( const CommsCtxt* comms, XWStreamCtxt* stream )
stream_putBytes( stream, msg->msg, msg->len );
}
#ifdef DEBUG
stream_putU32( stream, cEND );
#endif
} /* comms_writeToStream */
void
@ -906,14 +875,6 @@ makeElemWithID( CommsCtxt* comms, MsgID msgID, AddressRecord* rec,
MsgQueueElem* newMsgElem;
XWStreamCtxt* msgStream;
#ifdef DEBUG
if ( !!rec ) {
rec->nUniqueBytes += streamSize;
} else {
comms->nUniqueBytes += streamSize;
}
#endif
newMsgElem = (MsgQueueElem*)XP_MALLOC( comms->mpool,
sizeof( *newMsgElem ) );
newMsgElem->channelNo = channelNo;
@ -1643,9 +1604,6 @@ validateChannelMessage( CommsCtxt* comms, const CommsAddrRec* addr,
removeFromQueue( comms, channelNo, lastMsgRcd );
if ( msgID == rec->lastMsgRcd + 1 ) {
updateChannelAddress( rec, addr );
#ifdef DEBUG
rec->lastACK = (XP_U16)lastMsgRcd;
#endif
} else {
XP_LOGF( "%s: expected %ld, got %ld", __func__,
rec->lastMsgRcd + 1, msgID );
@ -1919,11 +1877,6 @@ comms_getStats( CommsCtxt* comms, XWStreamCtxt* stream )
stream_catString( stream, buf );
}
XP_SNPRINTF( (XP_UCHAR*)buf, sizeof(buf),
(XP_UCHAR*)"channel-less bytes sent: %d\n",
comms->nUniqueBytes );
stream_catString( stream, buf );
now = util_getCurSeconds( comms->util );
for ( rec = comms->recs; !!rec; rec = rec->next ) {
XP_SNPRINTF( (XP_UCHAR*)buf, sizeof(buf),
@ -1936,19 +1889,10 @@ comms_getStats( CommsCtxt* comms, XWStreamCtxt* stream )
rec->nextMsgID );
stream_catString( stream, buf );
XP_SNPRINTF( (XP_UCHAR*)buf, sizeof(buf),
(XP_UCHAR*)"Unique bytes sent: %d\n",
rec->nUniqueBytes );
stream_catString( stream, buf );
XP_SNPRINTF( (XP_UCHAR*)buf, sizeof(buf),
(XP_UCHAR*)"Last message received: %ld\n",
rec->lastMsgRcd );
stream_catString( stream, buf );
XP_SNPRINTF( (XP_UCHAR*)buf, sizeof(buf),
(XP_UCHAR*)"Last message acknowledged: %d\n",
rec->lastACK );
stream_catString( stream, buf );
}
} /* comms_getStats */
#endif

View file

@ -27,8 +27,6 @@
extern "C" {
#endif
#define eEND 0x63454e44
typedef XP_U8 Engine_rack[MAX_UNIQUE_TILES+1];
#ifndef NUM_SAVED_ENGINE_MOVES
@ -219,16 +217,13 @@ engine_make( MPFORMAL XW_UtilCtxt* util )
void
engine_writeToStream( EngineCtxt* XP_UNUSED(ctxt),
XWStreamCtxt* XP_UNUSED_DBG(stream) )
XWStreamCtxt* XP_UNUSED(stream) )
{
/* nothing to save; see comment below */
#ifdef DEBUG
stream_putU32( stream, eEND );
#endif
} /* engine_writeToStream */
EngineCtxt*
engine_makeFromStream( MPFORMAL XWStreamCtxt* XP_UNUSED_DBG(stream),
engine_makeFromStream( MPFORMAL XWStreamCtxt* XP_UNUSED(stream),
XW_UtilCtxt* util )
{
EngineCtxt* engine = engine_make( MPPARM(mpool) util );
@ -237,8 +232,6 @@ engine_makeFromStream( MPFORMAL XWStreamCtxt* XP_UNUSED_DBG(stream),
move. So if we're willing to have the set of moves found lost across
a save, there's nothing to do! */
XP_ASSERT( stream_getU32( stream ) == eEND );
return engine;
} /* engine_makeFromStream */

View file

@ -33,8 +33,6 @@
extern "C" {
#endif
#define mEND 0x6d454e44
#define MAX_PASSES 2 /* how many times can all players pass? */
/****************************** prototypes ******************************/
@ -153,8 +151,6 @@ model_makeFromStream( MPFORMAL XWStreamCtxt* stream, DictionaryCtxt* dict,
invalidateScore( model, i );
}
XP_ASSERT( stream_getU32( stream ) == mEND );
return model;
} /* model_makeFromStream */
@ -174,10 +170,6 @@ model_writeToStream( ModelCtxt* model, XWStreamCtxt* stream )
for ( i = 0; i < model->nPlayers; ++i ) {
writePlayerCtxt( stream, &model->players[i] );
}
#ifdef DEBUG
stream_putU32( stream, mEND );
#endif
} /* model_writeToStream */
#ifdef TEXT_MODEL

View file

@ -22,8 +22,6 @@
#include "dictnry.h"
#include "xwstream.h"
#define pEND 0x70454e44
// #define BLANKS_FIRST 1
struct PoolContext {
@ -67,9 +65,6 @@ pool_writeToStream( PoolContext* pool, XWStreamCtxt* stream )
stream_putU16( stream, pool->numFaces );
stream_putBytes( stream, pool->lettersLeft,
(XP_U16)(pool->numFaces * sizeof(pool->lettersLeft[0])) );
#ifdef DEBUG
stream_putU32( stream, pEND );
#endif
} /* pool_writeToStream */
PoolContext*
@ -84,8 +79,6 @@ pool_makeFromStream( MPFORMAL XWStreamCtxt* stream )
stream_getBytes( stream, pool->lettersLeft,
(XP_U16)(pool->numFaces * sizeof(pool->lettersLeft[0])) );
XP_ASSERT( stream_getU32( stream ) == pEND );
return pool;
} /* pool_makeFromStream */

View file

@ -41,8 +41,6 @@
extern "C" {
#endif
#define sEND 0x73454e44
#define LOCAL_ADDR NULL
enum {
@ -368,7 +366,6 @@ server_makeFromStream( MPFORMAL XWStreamCtxt* stream, ModelCtxt* model,
if ( version >= STREAM_SAVE_PREVWORDS ) {
server->nv.prevWordsStream = readStreamIf( server, stream );
}
XP_ASSERT( stream_getU32( stream ) == sEND );
return server;
} /* server_makeFromStream */
@ -406,10 +403,6 @@ server_writeToStream( ServerCtxt* server, XWStreamCtxt* stream )
writeStreamIf( stream, server->nv.prevMoveStream );
writeStreamIf( stream, server->nv.prevWordsStream );
#ifdef DEBUG
stream_putU32( stream, sEND );
#endif
} /* server_writeToStream */
static void
@ -872,8 +865,11 @@ showPrevScore( ServerCtxt* server )
util_informMove( util, stream, server->nv.prevWordsStream );
stream_destroy( stream );
stream_destroy( server->nv.prevWordsStream );
server->nv.prevWordsStream = NULL;
if ( !!server->nv.prevWordsStream ) {
stream_destroy( server->nv.prevWordsStream );
server->nv.prevWordsStream = NULL;
}
}
SETSTATE( server, server->nv.stateAfterShow );
} /* showPrevScore */
@ -882,82 +878,85 @@ XP_Bool
server_do( ServerCtxt* server, XP_Bool* moreToDoP )
{
XP_Bool result = XP_TRUE;
XP_Bool moreToDo = XP_FALSE;
if ( server->serverDoing ) {
return XP_FALSE;
}
server->serverDoing = XP_TRUE;
result = XP_FALSE;
} else {
XP_Bool moreToDo = XP_FALSE;
server->serverDoing = XP_TRUE;
switch( server->nv.gameState ) {
case XWSTATE_BEGIN:
if ( server->nv.pendingRegistrations == 0 ) { /* all players on device */
assignTilesToAll( server );
switch( server->nv.gameState ) {
case XWSTATE_BEGIN:
if ( server->nv.pendingRegistrations == 0 ) { /* all players on
device */
assignTilesToAll( server );
SETSTATE( server, XWSTATE_INTURN );
setTurn( server, 0 );
moreToDo = XP_TRUE;
}
break;
case XWSTATE_NEEDSEND_BADWORD_INFO:
XP_ASSERT( server->vol.gi->serverRole == SERVER_ISSERVER );
badWordMoveUndoAndTellUser( server, &server->illegalWordInfo );
#ifndef XWFEATURE_STANDALONE_ONLY
sendBadWordMsgs( server );
#endif
nextTurn( server, PICK_NEXT ); /* sets server->nv.gameState */
//moreToDo = XP_TRUE; /* why? */
break;
#ifndef XWFEATURE_STANDALONE_ONLY
case XWSTATE_RECEIVED_ALL_REG:
server_sendInitialMessage( server );
/* PENDING isn't INTURN_OFFDEVICE possible too? Or just
INTURN? */
SETSTATE( server, XWSTATE_INTURN );
setTurn( server, 0 );
moreToDo = XP_TRUE;
}
break;
break;
case XWSTATE_NEEDSEND_BADWORD_INFO:
XP_ASSERT( server->vol.gi->serverRole == SERVER_ISSERVER );
badWordMoveUndoAndTellUser( server, &server->illegalWordInfo );
#ifndef XWFEATURE_STANDALONE_ONLY
sendBadWordMsgs( server );
#endif
nextTurn( server, PICK_NEXT ); /* sets server->nv.gameState */
//moreToDo = XP_TRUE; /* why? */
break;
#ifndef XWFEATURE_STANDALONE_ONLY
case XWSTATE_RECEIVED_ALL_REG:
server_sendInitialMessage( server );
/* PENDING isn't INTURN_OFFDEVICE possible too? Or just INTURN? */
SETSTATE( server, XWSTATE_INTURN );
setTurn( server, 0 );
moreToDo = XP_TRUE;
break;
case XWSTATE_MOVE_CONFIRM_MUSTSEND:
XP_ASSERT( server->vol.gi->serverRole == SERVER_ISSERVER );
tellMoveWasLegal( server );
nextTurn( server, PICK_NEXT );
break;
case XWSTATE_MOVE_CONFIRM_MUSTSEND:
XP_ASSERT( server->vol.gi->serverRole == SERVER_ISSERVER );
tellMoveWasLegal( server );
nextTurn( server, PICK_NEXT );
break;
#endif /* XWFEATURE_STANDALONE_ONLY */
case XWSTATE_NEEDSEND_ENDGAME:
endGameInternal( server, END_REASON_OUT_OF_TILES );
break;
case XWSTATE_NEEDSEND_ENDGAME:
endGameInternal( server, END_REASON_OUT_OF_TILES );
break;
case XWSTATE_NEED_SHOWSCORE:
showPrevScore( server );
/* state better have changed or we'll infinite loop... */
XP_ASSERT( XWSTATE_NEED_SHOWSCORE != server->nv.gameState );
/* either process turn or end game should come next... */
moreToDo = XWSTATE_NEED_SHOWSCORE != server->nv.gameState;
break;
case XWSTATE_INTURN:
if ( robotMovePending( server ) && !ROBOTWAITING(server) ) {
result = makeRobotMove( server );
/* if robot was interrupted, we need to schedule again */
moreToDo = !result ||
(robotMovePending( server ) && !POSTPONEROBOTMOVE(server));
case XWSTATE_NEED_SHOWSCORE:
showPrevScore( server );
/* state better have changed or we'll infinite loop... */
XP_ASSERT( XWSTATE_NEED_SHOWSCORE != server->nv.gameState );
/* either process turn or end game should come next... */
moreToDo = XWSTATE_NEED_SHOWSCORE != server->nv.gameState;
break;
case XWSTATE_INTURN:
if ( robotMovePending( server ) && !ROBOTWAITING(server) ) {
result = makeRobotMove( server );
/* if robot was interrupted, we need to schedule again */
moreToDo = !result ||
(robotMovePending( server ) && !POSTPONEROBOTMOVE(server));
}
break;
default:
result = XP_FALSE;
break;
} /* switch */
if ( NULL != moreToDoP ) {
*moreToDoP = moreToDo;
} else if ( moreToDo ) {
util_requestTime( server->vol.util );
}
break;
default:
result = XP_FALSE;
break;
server->serverDoing = XP_FALSE;
}
if ( NULL != moreToDoP ) {
*moreToDoP = moreToDo;
} else if ( moreToDo ) {
util_requestTime( server->vol.util );
}
server->serverDoing = XP_FALSE;
return result;
} /* server_do */

View file

@ -1656,11 +1656,14 @@ relay_error_curses( void* XP_UNUSED(closure), XWREASON XP_UNUSED_DBG(relayErr) )
#ifdef USE_GLIBLOOP
static gboolean
handle_stdin( GIOChannel* source, GIOCondition condition, gpointer data )
handle_stdin( GIOChannel* XP_UNUSED_DBG(source), GIOCondition condition,
gpointer data )
{
if ( 0 != (G_IO_IN & condition) ) {
#ifdef DEBUG
gint fd = g_io_channel_unix_get_fd( source );
XP_ASSERT( 0 == fd );
#endif
CursesAppGlobals* globals = (CursesAppGlobals*)data;
int ch = wgetch( globals->mainWin );
remapKey( &ch );