Closing BT lib from datahandler (since don't want to close on game

close in case next game will use); erase BT status icon when not BT
game; plug leak of dict name.
This commit is contained in:
ehouse 2007-03-18 23:57:30 +00:00
parent dfc2d679e0
commit 03433901fc
2 changed files with 75 additions and 56 deletions

View file

@ -559,13 +559,13 @@ reportMissingDict( PalmAppGlobals* globals, XP_UCHAR* name )
} }
} /* reportMissingDict */ } /* reportMissingDict */
static Boolean static XP_Bool
loadCurrentGame( PalmAppGlobals* globals, XP_U16 gIndex, loadCurrentGame( PalmAppGlobals* globals, XP_U16 gIndex,
XWGame* game, CurGameInfo* ginfo ) XWGame* game, CurGameInfo* ginfo )
{ {
XP_Bool hasDict; XP_Bool hasDict;
XWStreamCtxt* recStream; XWStreamCtxt* recStream;
Boolean success = false; XP_Bool success = XP_FALSE;
DictionaryCtxt* dict; DictionaryCtxt* dict;
recStream = gameRecordToStream( globals, gIndex ); recStream = gameRecordToStream( globals, gIndex );
@ -581,19 +581,19 @@ loadCurrentGame( PalmAppGlobals* globals, XP_U16 gIndex,
hasDict = stream_getU8( recStream ); hasDict = stream_getU8( recStream );
if ( hasDict ) { if ( hasDict ) {
XP_UCHAR* name = stringFromStream( globals->mpool, recStream ); XP_UCHAR name[33];
stringFromStreamHere( recStream, name, sizeof(name) );
dict = palm_dictionary_make( MPPARM(globals->mpool) globals, dict = palm_dictionary_make( MPPARM(globals->mpool) globals,
name, globals->dictList ); name, globals->dictList );
success = dict != NULL; success = dict != NULL;
if ( !success ) { if ( !success ) {
reportMissingDict( globals, name ); reportMissingDict( globals, name );
XP_FREE( globals->mpool, name );
beep(); beep();
} }
} else { } else {
dict = NULL; dict = NULL;
success = true; success = XP_TRUE;
} }
if ( success ) { if ( success ) {
@ -1567,38 +1567,41 @@ timeForTimer( PalmAppGlobals* globals, XWTimerReason* why, XP_U32* when )
#ifdef XWFEATURE_BLUETOOTH #ifdef XWFEATURE_BLUETOOTH
static void static void
showBTState( PalmAppGlobals* globals ) showConnState( PalmAppGlobals* globals )
{ {
CommsCtxt* comms = globals->game.comms; CommsCtxt* comms = globals->game.comms;
if ( (comms != NULL) Int16 resID = 0;
&& (COMMS_CONN_BT == comms_getConType( globals->game.comms )) ) { if ( !!comms ) {
Int16 resID = 0; if ( (COMMS_CONN_BT == comms_getConType( comms )) ) {
switch( globals->btUIState ) {
switch( globals->btUIState ) { case BTUI_NONE:
case BTUI_NONE: resID = BTSTATUS_NONE_RES_ID; break;
resID = BTSTATUS_NONE_RES_ID; break; case BTUI_LISTENING:
case BTUI_LISTENING: resID = BTSTATUS_LISTENING_RES_ID; break;
resID = BTSTATUS_LISTENING_RES_ID; break; case BTUI_CONNECTING:
case BTUI_CONNECTING: resID = BTSTATUS_SEEKING_RES_ID; break;
resID = BTSTATUS_SEEKING_RES_ID; break; case BTUI_CONNECTED:
case BTUI_CONNECTED: case BTUI_SERVING:
case BTUI_SERVING: resID = BTSTATUS_CONNECTED_RES_ID; break;
resID = BTSTATUS_CONNECTED_RES_ID; break;
}
if ( globals->lastBTStatusRes != resID ) {
RectangleType bounds;
getObjectBounds( XW_BTSTATUS_GADGET_ID, &bounds );
if ( resID != 0 ) {
draw_drawBitmapAt( globals->draw, resID,
bounds.topLeft.x, bounds.topLeft.y );
} else {
WinEraseRectangle( &bounds, 0 );
} }
globals->lastBTStatusRes = resID; } /* else might want IP conn status too.... */
}
} }
} /* showBTState */ if ( globals->lastBTStatusRes != resID ) {
RectangleType bounds;
getObjectBounds( XW_BTSTATUS_GADGET_ID, &bounds );
if ( resID != 0 ) {
draw_drawBitmapAt( globals->draw, resID,
bounds.topLeft.x, bounds.topLeft.y );
} else {
if ( globals->useHiRes ) {
bounds.extent.x = (1 + bounds.extent.x) >> 1;
bounds.extent.y = (1 + bounds.extent.y) >> 1;
}
WinEraseRectangle( &bounds, 0 );
}
globals->lastBTStatusRes = resID;
}
} /* showConnState */
#endif #endif
static Boolean static Boolean
@ -1617,7 +1620,7 @@ handleNilEvent( PalmAppGlobals* globals )
palmFireTimer( globals, why ); palmFireTimer( globals, why );
#ifdef XWFEATURE_BLUETOOTH #ifdef XWFEATURE_BLUETOOTH
} else if ( palm_bt_doWork( globals, &globals->btUIState ) ) { } else if ( palm_bt_doWork( globals, &globals->btUIState ) ) {
showBTState( globals ); showConnState( globals );
#endif #endif
} else if ( globals->timeRequested ) { } else if ( globals->timeRequested ) {
globals->timeRequested = false; globals->timeRequested = false;
@ -1631,10 +1634,6 @@ handleNilEvent( PalmAppGlobals* globals )
handled = false; handled = false;
} }
#ifdef XWFEATURE_BLUETOOTH /* don't check this in */
showBTState( globals );
#endif
return handled; return handled;
} /* handleNilEvent */ } /* handleNilEvent */
@ -1945,8 +1944,7 @@ initAndStartBoard( PalmAppGlobals* globals, XP_Bool newGame )
if ( !dict ) { if ( !dict ) {
XP_ASSERT( !!newDictName ); XP_ASSERT( !!newDictName );
dict = palm_dictionary_make( MPPARM(globals->mpool) globals, dict = palm_dictionary_make( MPPARM(globals->mpool) globals,
copyString( globals->mpool, newDictName ), newDictName, globals->dictList );
globals->dictList );
XP_ASSERT( !!dict ); XP_ASSERT( !!dict );
model_setDictionary( globals->game.model, dict ); model_setDictionary( globals->game.model, dict );
} }
@ -1971,7 +1969,6 @@ initAndStartBoard( PalmAppGlobals* globals, XP_Bool newGame )
(void)positionBoard( globals ); (void)positionBoard( globals );
#ifdef XWFEATURE_IR #ifdef XWFEATURE_IR
if ( newGame && globals->gameInfo.serverRole == SERVER_ISCLIENT ) { if ( newGame && globals->gameInfo.serverRole == SERVER_ISCLIENT ) {
XWStreamCtxt* stream; XWStreamCtxt* stream;
XP_ASSERT( !!globals->game.comms ); XP_ASSERT( !!globals->game.comms );
@ -1991,6 +1988,8 @@ initAndStartBoard( PalmAppGlobals* globals, XP_Bool newGame )
board_invalAll( globals->game.board ); board_invalAll( globals->game.board );
board_draw( globals->game.board ); board_draw( globals->game.board );
showConnState( globals );
globals->isNewGame = false; globals->isNewGame = false;
} /* initAndStartBoard */ } /* initAndStartBoard */
@ -2114,16 +2113,15 @@ tryLoadSavedGame( PalmAppGlobals* globals, XP_U16 newIndex )
XP_MEMSET( &tmpGInfo, 0, sizeof(tmpGInfo) ); XP_MEMSET( &tmpGInfo, 0, sizeof(tmpGInfo) );
loaded = loadCurrentGame( globals, newIndex, &tmpGame, &tmpGInfo ); loaded = loadCurrentGame( globals, newIndex, &tmpGame, &tmpGInfo );
/* Nuke the one we don't want */
game_dispose( loaded? &globals->game : &tmpGame );
gi_disposePlayerInfo( MEMPOOL (loaded? &globals->gameInfo : &tmpGInfo) );
if ( loaded ) { if ( loaded ) {
game_dispose( &globals->game ); XP_MEMCPY( &globals->game, &tmpGame, sizeof(globals->game) );
gi_disposePlayerInfo( MEMPOOL &globals->gameInfo );
globals->game = tmpGame;
/* we leaking dictName here? PENDING(ehouse) */
XP_MEMCPY( &globals->gameInfo, &tmpGInfo, sizeof(globals->gameInfo) ); XP_MEMCPY( &globals->gameInfo, &tmpGInfo, sizeof(globals->gameInfo) );
globals->gState.curGameIndex = newIndex; globals->gState.curGameIndex = newIndex;
} else {
game_dispose( &tmpGame );
gi_disposePlayerInfo( MEMPOOL &tmpGInfo );
} }
return loaded; return loaded;
@ -2511,6 +2509,12 @@ mainViewHandleEvent( EventPtr event )
XP_ASSERT( !!globals->game.board ); XP_ASSERT( !!globals->game.board );
break; break;
#ifdef XWFEATURE_BLUETOOTH
case closeBtLibEvent:
palm_bt_close( globals );
break;
#endif
#ifdef FEATURE_SILK #ifdef FEATURE_SILK
case doResizeWinEvent: case doResizeWinEvent:
getSizes( globals ); getSizes( globals );
@ -3832,8 +3836,10 @@ palm_send( const XP_U8* buf, XP_U16 len,
const CommsAddrRec* addr, void* closure ) const CommsAddrRec* addr, void* closure )
{ {
PalmAppGlobals* globals = (PalmAppGlobals*)closure; PalmAppGlobals* globals = (PalmAppGlobals*)closure;
XP_S16 result = 0; XP_S16 result = 0;
XP_ASSERT( !!globals->game.comms );
switch( comms_getConType( globals->game.comms ) ) { switch( comms_getConType( globals->game.comms ) ) {
#ifdef XWFEATURE_IR #ifdef XWFEATURE_IR
case COMMS_CONN_IR: case COMMS_CONN_IR:
@ -3924,12 +3930,22 @@ static void
btDataHandler( PalmAppGlobals* globals, const CommsAddrRec* fromAddr, btDataHandler( PalmAppGlobals* globals, const CommsAddrRec* fromAddr,
const XP_U8* data, XP_U16 len ) const XP_U8* data, XP_U16 len )
{ {
XWStreamCtxt* instream; if ( COMMS_CONN_BT == comms_getConType( globals->game.comms ) ) {
LOG_FUNC(); XWStreamCtxt* instream;
instream = makeSimpleStream( globals, NULL ); instream = makeSimpleStream( globals, NULL );
stream_putBytes( instream, data, len ); stream_putBytes( instream, data, len );
checkAndDeliver( globals, fromAddr, instream ); checkAndDeliver( globals, fromAddr, instream );
LOG_RETURN_VOID(); } 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
part of unloading the old game since it's expensive to stop/start
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 );
}
} /* btDataHandler */ } /* btDataHandler */
static void static void
@ -3953,7 +3969,7 @@ palm_util_addrChange( XW_UtilCtxt* uc, const CommsAddrRec* oldAddr,
if ( !isBT ) { if ( !isBT ) {
XP_ASSERT( !!globals->mainForm ); XP_ASSERT( !!globals->mainForm );
palm_bt_close( globals ); palm_bt_close( globals );
showBTState( globals ); showConnState( globals );
} }
# endif # endif

View file

@ -354,6 +354,9 @@ enum { dictSelectedEvent = firstUserEvent /* 0x6000 */
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY #if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
,connsSettingChgEvent ,connsSettingChgEvent
#endif #endif
#if defined XWFEATURE_BLUETOOTH
,closeBtLibEvent
#endif
#ifdef FEATURE_SILK #ifdef FEATURE_SILK
,doResizeWinEvent ,doResizeWinEvent
#endif #endif