cleanup; replace a bunch of EvtAddEventToQueue calls with

postEmptyEvent; pass transport type with incoming packets so they can
be rejected if not on expected channel (to stop IR, which is always
on, from injecting into a BT game); do BT work and fire timers even
when menu is down; don't let robot run until after board is drawn for
the first time; on startup, don't let robot run until after board is
drawn once.  Up version to b3.
This commit is contained in:
ehouse 2007-12-09 01:59:15 +00:00
parent c72d0fec65
commit 63ccaed46e
15 changed files with 78 additions and 82 deletions

View file

@ -307,7 +307,6 @@ addrFromStream( CommsAddrRec* addrP, XWStreamCtxt* stream )
switch( addr.conType ) {
case COMMS_CONN_NONE:
/* XP_ASSERT( 0 ); */
break;
case COMMS_CONN_BT:
stringFromStreamHere( stream, addr.u.bt.hostName,
@ -481,12 +480,9 @@ addrToStream( XWStreamCtxt* stream, const CommsAddrRec* addrP )
stream_putU8( stream, addr.conType );
switch( addr.conType ) {
#ifdef DEBUG
case COMMS_CONN_NONE:
case LAST_____FOO:
/* XP_ASSERT( 0 ); */
/* nothing to write */
break;
#endif
case COMMS_CONN_BT:
stringToStream( stream, addr.u.bt.hostName );
/* sizeof(.bits) below defeats ARM's padding. */
@ -618,6 +614,7 @@ comms_getInitialAddr( CommsAddrRec* addr )
CommsConnType
comms_getConType( const CommsCtxt* comms )
{
XP_ASSERT( !!comms ); /* or: return COMMS_CONN_NONE */
return comms->addr.conType;
} /* comms_getConType */

View file

@ -33,13 +33,11 @@ typedef XP_U32 MsgID; /* this is too big!!! PENDING */
typedef XP_U8 XWHostID;
typedef enum {
COMMS_CONN_NONE, /* I want errors on uninited case */
COMMS_CONN_IR,
COMMS_CONN_IP_DIRECT,
COMMS_CONN_RELAY,
COMMS_CONN_BT,
LAST_____FOO
COMMS_CONN_NONE /* I want errors on uninited case */
,COMMS_CONN_IR
,COMMS_CONN_IP_DIRECT
,COMMS_CONN_RELAY
,COMMS_CONN_BT
} CommsConnType;
/* WHAT SHOULD THIS BE? Copied from Whiteboard.... PENDING */

View file

@ -336,9 +336,8 @@ ConnsFormHandleEvent( EventPtr event )
if ( !state->isNewGame ) {
/* do nothing; same as cancel */
} else {
EventType eventToPost = { .eType = connsSettingChgEvent };
stateFromCtls( state );
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( connsSettingChgEvent );
}
/* FALLTHRU */
case XW_CONNS_CANCEL_BUTTON_ID:

View file

@ -297,7 +297,7 @@ BEGIN
#ifdef XWFEATURE_BLUETOOTH
LABEL "Host name:" XW_CONNS_BT_HOSTNAME_LABEL_ID
AT ( LEFTCOL LOCALIP_TOP ) NONUSABLE
AT ( LEFTCOL LOCALIP_TOP+5 ) NONUSABLE
SELECTORTRIGGER "Find host..." XW_CONNS_BT_HOSTTRIGGER_ID \
AT (CONNS_FIELD_LEFT PREVTOP 70 AUTO) NONUSABLE LEFTANCHOR
#endif

View file

@ -83,7 +83,6 @@ Boolean
newGameHandleEvent( EventPtr event )
{
Boolean result = false;
EventType eventToPost; /* used only with OK button */
PalmAppGlobals* globals;
FormPtr form;
CurGameInfo* gi;
@ -219,15 +218,13 @@ newGameHandleEvent( EventPtr event )
needs to arrive before the newGame event so any changes will
be incorporated. */
if ( state->forwardChange ) {
eventToPost.eType = prefsChangedEvent;
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( prefsChangedEvent );
state->forwardChange = false;
}
updatePlayerInfo( globals );
if ( globals->isNewGame ) {
eventToPost.eType = newGameOkEvent;
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( newGameOkEvent );
globals->postponeDraw = true;
}
@ -238,8 +235,7 @@ newGameHandleEvent( EventPtr event )
case XW_CANCEL_BUTTON_ID:
unloadNewGameState( globals );
eventToPost.eType = newGameCancelEvent;
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( newGameCancelEvent );
FrmReturnToForm( 0 );
break;

View file

@ -23,6 +23,7 @@
#include "xptypes.h"
#include "palmbt.h"
#include "strutils.h"
#include "palmutil.h"
# include <BtLib.h>
# include <BtLibTypes.h>
@ -148,7 +149,7 @@ static const BtLibSdpUuidType XWORDS_UUID = {
static PalmBTStuff* pbt_checkInit( PalmAppGlobals* globals,
XP_Bool* userCancelled );
static Err bpd_discover( PalmBTStuff* btStuff, BtLibDeviceAddressType* addr );
static Err pbd_discover( PalmBTStuff* btStuff, BtLibDeviceAddressType* addr );
static void pbt_setup_slave( PalmBTStuff* btStuff, const CommsAddrRec* addr );
static void pbt_takedown_slave( PalmBTStuff* btStuff );
static void pbt_setup_master( PalmBTStuff* btStuff );
@ -337,7 +338,7 @@ palm_bt_browse_device( PalmAppGlobals* globals, XP_BtAddr* btAddr,
btStuff = pbt_checkInit( globals, NULL );
if ( NULL != btStuff ) {
BtLibDeviceAddressType addr;
Err err = bpd_discover( btStuff, &addr );
Err err = pbd_discover( btStuff, &addr );
if ( errNone == err ) {
UInt8 name[PALM_BT_NAME_LEN];
@ -351,6 +352,7 @@ palm_bt_browse_device( PalmAppGlobals* globals, XP_BtAddr* btAddr,
CALL_ERR( err, BtLibGetRemoteDeviceName, btStuff->btLibRefNum,
&addr, &nameType, btLibCachedThenRemote );
XP_ASSERT( errNone == err ); /* deal with btLibErrPending */
XP_LOGF( "%s: got name %s", __func__, nameType.name );
XP_ASSERT( len >= nameType.nameLength );
@ -736,7 +738,7 @@ pbt_do_work( PalmBTStuff* btStuff, BtCbEvtProc proc )
break;
case PBT_ACT_CONNECT_DATA:
/* XP_ASSERT( btStuff->picoRole == PBT_SLAVE ); */
XP_ASSERT( btStuff->picoRole == PBT_SLAVE );
if ( GET_STATE(btStuff) == PBTST_SDP_QUERIED ) {
pbt_close_datasocket( btStuff );
CALL_ERR( err, BtLibSocketCreate, btLibRefNum,
@ -805,9 +807,7 @@ pbt_do_work( PalmBTStuff* btStuff, BtCbEvtProc proc )
static void
pbt_postpone( PalmBTStuff* btStuff, PBT_ACTION act )
{
EventType eventToPost;
eventToPost.eType = noopEvent;
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( noopEvent );
XP_LOGF( "%s(%s)", __func__, actToStr(act) );
@ -951,7 +951,7 @@ waitACL( PalmBTStuff* btStuff )
}
static Err
bpd_discover( PalmBTStuff* btStuff, BtLibDeviceAddressType* addr )
pbd_discover( PalmBTStuff* btStuff, BtLibDeviceAddressType* addr )
{
Err err;
const BtLibClassOfDeviceType deviceFilter
@ -963,7 +963,7 @@ bpd_discover( PalmBTStuff* btStuff, BtLibDeviceAddressType* addr )
"Crosswords host", (BtLibClassOfDeviceType*)&deviceFilter, 1,
addr, false, false );
return err;
} /* bpd_discover */
} /* pbd_discover */
static void
pbt_setup_slave( PalmBTStuff* btStuff, const CommsAddrRec* addr )

View file

@ -371,7 +371,7 @@ checkHandleNetEvents( PalmAppGlobals* globals )
XWStreamCtxt* instream = packetToStream( globals );
if ( !!instream ) {
checkAndDeliver( globals, NULL, instream );
checkAndDeliver( globals, NULL, instream, COMMS_CONN_RELAY );
}
}
}

View file

@ -93,7 +93,7 @@ palm_ir_receiveMove( PalmAppGlobals* globals, ExgSocketPtr socket )
(void)ExgDisconnect( socket, err );
if ( nBytesReceived == 0 ) { /* successful loop exit */
checkAndDeliver( globals, NULL, instream );
checkAndDeliver( globals, NULL, instream, COMMS_CONN_IR );
}
}
} /* palm_ir_receiveMove */

View file

@ -873,10 +873,6 @@ getResString( PalmAppGlobals* globals, XP_U16 strID )
static Err
volChangeEventProc( SysNotifyParamType* XP_UNUSED_SILK(notifyParamsP) )
{
#ifndef REALLY_HANDLE_MEDIA
EventType eventToPost;
#endif
#if 0
if ( notifyParamsP->notifyType == sysNotifyVolumeUnmountedEvent ) {
@ -894,8 +890,7 @@ volChangeEventProc( SysNotifyParamType* XP_UNUSED_SILK(notifyParamsP) )
#ifdef FEATURE_SILK
if ( notifyParamsP->notifyType == sysNotifyDisplayChangeEvent ) {
eventToPost.eType = doResizeWinEvent;
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( doResizeWinEvent );
return errNone;
}
#endif
@ -903,8 +898,7 @@ volChangeEventProc( SysNotifyParamType* XP_UNUSED_SILK(notifyParamsP) )
datastructures when it's relaunched. This is a hack but I like
it. :-) */
#ifndef REALLY_HANDLE_MEDIA
eventToPost.eType = appStopEvent;
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( appStopEvent );
#endif
return errNone;
@ -1105,6 +1099,10 @@ startApplication( PalmAppGlobals** globalsP )
} else {
XP_LOGF( "no sysFileCBtLib via FtrGet: OS too old?" );
}
/* Make the UI elements easier to test */
if ( globals->runningOnPOSE ) {
globals->hasBTLib = XP_TRUE;
}
# endif
#endif
@ -1190,10 +1188,7 @@ startApplication( PalmAppGlobals** globalsP )
if ( prefsFound && loadCurrentGame( globals, globals->gState.curGameIndex,
&globals->game, &globals->gameInfo) ) {
EventType eventToPost;
eventToPost.eType = loadGameEvent;
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( loadGameEvent );
globals->isFirstLaunch = false;
} else {
DictListEntry* dlep;
@ -1629,7 +1624,8 @@ btEvtHandler( PalmAppGlobals* globals, const BtCbEvtInfo* evt )
XWStreamCtxt* instream;
instream = makeSimpleStream( globals, NULL );
stream_putBytes( instream, evt->u.data.data, evt->u.data.len );
checkAndDeliver( globals, evt->u.data.fromAddr, instream );
checkAndDeliver( globals, evt->u.data.fromAddr,
instream, COMMS_CONN_BT );
} else {
/* If we're no longer using BT (meaning somebody loaded a new game
that doesn't use it), close it down. We don't want to do it as
@ -1637,9 +1633,7 @@ btEvtHandler( PalmAppGlobals* globals, const BtCbEvtInfo* evt )
BT and the new game will probably use the same connection. But if
we get here, a non-bt game's been loaded and we should shut
down.*/
EventType eventToPost;
eventToPost.eType = closeBtLibEvent;
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( closeBtLibEvent );
}
break;
case BTCBEVT_HOSTFAIL: {
@ -1670,20 +1664,22 @@ handleNilEvent( PalmAppGlobals* globals )
XP_U32 when;
XWTimerReason why;
if ( globals->menuIsDown ) {
/* do nothing */
} else if ( globals->hintPending ) {
handled = handleHintRequest( globals );
} else if ( timeForTimer( globals, &why, &when )
&& (when <= TimGetTicks()) ) {
palmFireTimer( globals, why );
if ( 0 ) {
#ifdef XWFEATURE_BLUETOOTH
} else if ( (handled = (!globals->suspendBT)
&& palm_bt_doWork( globals, btEvtHandler,
&globals->btUIState ) ),
showConnState( globals ), handled ) {
&globals->btUIState ) )
,showConnState( globals )
,handled ) {
/* nothing to do */
#endif
} else if ( timeForTimer( globals, &why, &when )
&& (when <= TimGetTicks()) ) {
palmFireTimer( globals, why );
} else if ( globals->menuIsDown ) {
/* do nothing */
} else if ( globals->hintPending ) {
handled = handleHintRequest( globals );
} else if ( globals->timeRequested ) {
globals->timeRequested = false;
if ( globals->msgReceivedDraw ) {
@ -2047,9 +2043,11 @@ initAndStartBoard( PalmAppGlobals* globals, XP_Bool newGame )
comms_start( globals->game.comms );
}
/* do this before drawing the board. If it assigns tiles, for example,
that'll make a difference on the screen. */
(void)server_do( globals->game.server );
/* Used to call server_do here, but if it's a robot's turn it'll run
without drawing the board first. This allows work to get done almost
as quickly. If the board starts flashing on launch this is why;
server_do might need to take a bool param skip-robot */
palm_util_requestTime( &globals->util );
board_invalAll( globals->game.board );
board_draw( globals->game.board );
@ -2546,9 +2544,7 @@ mainViewHandleEvent( EventPtr event )
quit. It's easier than dealing with everything that can go wrong
in this state. */
if ( globals->isFirstLaunch ) {
EventType eventToPost;
eventToPost.eType = appStopEvent;
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( appStopEvent );
}
globals->isNewGame = false;
break;
@ -2900,9 +2896,7 @@ mainViewHandleEvent( EventPtr event )
break;
# if 0
case XW_RESET_PULLDOWN_ID: {
EventType eventToPost;
eventToPost.eType = appStopEvent;
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( appStopEvent );
}
globals->resetGame = true;
@ -3844,7 +3838,6 @@ palm_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why,
{
PalmAppGlobals* globals = (PalmAppGlobals*)uc->closure;
XP_U32 now = TimGetTicks();
EventType eventToPost;
if ( why == TIMER_PENDOWN ) {
now += PALM_TIMER_DELAY;
@ -3869,8 +3862,7 @@ palm_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why,
/* Post an event to force us back out of EvtGetEvent. Required if this
* is called from inside some BT callback. */
eventToPost.eType = noopEvent;
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( noopEvent );
} /* palm_util_setTimer */
static void
@ -3992,15 +3984,21 @@ palm_reset( void* closure )
void
checkAndDeliver( PalmAppGlobals* globals, const CommsAddrRec* addr,
XWStreamCtxt* instream )
XWStreamCtxt* instream, CommsConnType conType )
{
if ( comms_checkIncomingStream( globals->game.comms,
instream, addr ) ) {
(void)server_receiveMessage( globals->game.server, instream );
globals->msgReceivedDraw = true;
/* For now we'll just drop incoming packets on transports not the same as
the current game's. We *could* however alert the user, or even
volunteer to switch e.g. from BT to IR as two passengers board a
plane. That'd require significant changes. */
CommsCtxt* comms = globals->game.comms;
if ( !!comms && (conType == comms_getConType( comms )) ) {
if ( comms_checkIncomingStream( comms, instream, addr ) ) {
(void)server_receiveMessage( globals->game.server, instream );
globals->msgReceivedDraw = true;
}
palm_util_requestTime( &globals->util );
}
stream_destroy( instream );
palm_util_requestTime( &globals->util );
} /* checkAndDeliver */
static const XP_UCHAR*

View file

@ -428,7 +428,7 @@ const XP_UCHAR* getResString( PalmAppGlobals* globals, XP_U16 strID );
XP_Bool palmask( PalmAppGlobals* globals, const XP_UCHAR* str,
const XP_UCHAR* altButton, XP_S16 titleID );
void checkAndDeliver( PalmAppGlobals* globals, const CommsAddrRec* addr,
XWStreamCtxt* instream );
XWStreamCtxt* instream, CommsConnType conType );
#ifdef XW_TARGET_PNO
# define READ_UNALIGNED16(n) read_unaligned16((unsigned char*)(n))

View file

@ -48,7 +48,6 @@ savedGamesHandleEvent( EventPtr event )
Boolean result;
PalmAppGlobals* globals;
SavedGamesState* state;
EventType eventToPost;
XP_S16 newGameIndex;
Int16* curGameIndexP;
char* newName;
@ -153,7 +152,7 @@ savedGamesHandleEvent( EventPtr event )
case XW_SAVEDGAMES_OPEN_BUTTON: /* open the selected db if not already
open. */
if ( *curGameIndexP != state->displayGameIndex ) {
eventToPost.eType = openSavedGameEvent;
EventType eventToPost = { .eType = openSavedGameEvent };
((OpenSavedGameData*)&eventToPost.data.generic)->newGameIndex
= state->displayGameIndex;
EvtAddEventToQueue( &eventToPost );

View file

@ -108,6 +108,14 @@ setFieldEditable( UInt16 objectID, Boolean editable )
}
} /* setFieldEditable */
void
postEmptyEvent( eventsEnum typ )
{
EventType eventToPost;
eventToPost.eType = typ;
EvtAddEventToQueue( &eventToPost );
} /* postEmptyEvent */
void
disOrEnable( FormPtr form, UInt16 id, Boolean enable )
{

View file

@ -60,6 +60,8 @@ void getFieldStr( XP_U16 id, XP_UCHAR* buf, XP_U16 max );
#endif
void setFieldEditable( UInt16 objectID, Boolean editable );
void postEmptyEvent( eventsEnum typ );
/* list item stuff */
void initListData( MPFORMAL ListData* ld, XP_U16 nItems );
void addListTextItem( MPFORMAL ListData* ld, const XP_UCHAR* txt );

View file

@ -42,7 +42,6 @@ PrefsFormHandleEvent( EventPtr event )
PalmAppGlobals* globals;
PrefsDlgState* state;
FormPtr form;
EventType eventToPost;
Int16 chosen;
XP_S16 selGadget;
@ -145,8 +144,7 @@ PrefsFormHandleEvent( EventPtr event )
case XW_PREFS_OK_BUTTON_ID:
controlsToLocalPrefs( state );
eventToPost.eType = prefsChangedEvent;
EvtAddEventToQueue( &eventToPost );
postEmptyEvent( connsSettingChgEvent );
globals->postponeDraw = true;
case XW_PREFS_CANCEL_BUTTON_ID:

View file

@ -433,8 +433,9 @@
/* versioning stuff */
#ifdef XWFEATURE_BLUETOOTH
# define XW_PALM_VERSION_STRING "4.3b2"
# define XW_PALM_VERSION_STRING "4.3b3"
#else
/* There's a separate branch for 2.4 releases now. */
# define XW_PALM_VERSION_STRING "4.2.1"
#endif
#define CUR_PREFS_VERS 0x0405