New addr param to checkAndDeliver so address can be passed back to

comms; Add debug-only menus to toggle logging to file and memopad.
This commit is contained in:
ehouse 2006-09-14 01:46:41 +00:00
parent 4f2468c61e
commit ed06a20881
4 changed files with 71 additions and 50 deletions

View file

@ -159,8 +159,9 @@ static void palm_util_addrChange( XW_UtilCtxt* uc, const CommsAddrRec* oldAddr,
const CommsAddrRec* newAddr );
#endif
#ifdef XWFEATURE_BLUETOOTH
static void btDataHandler( PalmAppGlobals* globals, const XP_U8* data,
XP_U16 len );
static void btDataHandler( PalmAppGlobals* globals,
const CommsAddrRec* fromAddr,
const XP_U8* data, XP_U16 len );
#endif
#ifdef XWFEATURE_SEARCHLIMIT
@ -1933,6 +1934,16 @@ initAndStartBoard( PalmAppGlobals* globals, XP_Bool newGame )
} /* initAndStartBoard */
#ifdef DEBUG
static void
toggleBoolFtr( XP_U16 ftr )
{
UInt32 val;
FtrGet( APPID, ftr, &val );
val = !val;
FtrSet( APPID, ftr, val );
XP_WARNF( "Turned %s.", val==0? "OFF" : "ON" );
} /* toggleBoolFtr */
static void
askOnClose( XWStreamCtxt* stream, void* closure )
{
@ -2445,23 +2456,16 @@ mainViewHandleEvent( EventPtr event )
#endif
#ifdef DEBUG
case XW_DEBUGSHOW_PULLDOWN_ID:
globals->gState.showDebugstrs = true;
case XW_LOGFILE_PULLDOWN_ID:
toggleBoolFtr( LOG_FILE_FEATURE );
break;
case XW_DEBUGHIDE_PULLDOWN_ID:
globals->gState.showDebugstrs = false;
board_invalAll( globals->game.board );
draw = true;
case XW_LOGMEMO_PULLDOWN_ID:
toggleBoolFtr( LOG_MEMO_FEATURE );
break;
case XW_DEBUGMEMO_PULLDOWN_ID:
globals->gState.logToMemo = true;
case XW_CLEARLOGS_PULLDOWN_ID:
PalmClearLogs();
break;
case XW_DEBUGSCREEN_PULLDOWN_ID:
globals->gState.logToMemo = false;
break;
# if 0
case XW_RESET_PULLDOWN_ID: {
EventType eventToPost;
@ -3487,10 +3491,11 @@ palm_send( const XP_U8* buf, XP_U16 len,
} /* palm_send */
void
checkAndDeliver( PalmAppGlobals* globals, XWStreamCtxt* instream )
checkAndDeliver( PalmAppGlobals* globals, const CommsAddrRec* addr,
XWStreamCtxt* instream )
{
if ( comms_checkIncomingStream( globals->game.comms,
instream, NULL ) ) {
instream, addr ) ) {
globals->msgReceivedDraw =
server_receiveMessage( globals->game.server, instream );
globals->msgReceivedDraw = true;
@ -3546,13 +3551,14 @@ palm_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi,
#ifdef BEYOND_IR
#ifdef XWFEATURE_BLUETOOTH
static void
btDataHandler( PalmAppGlobals* globals, const XP_U8* data, XP_U16 len )
btDataHandler( PalmAppGlobals* globals, const CommsAddrRec* fromAddr,
const XP_U8* data, XP_U16 len )
{
XWStreamCtxt* instream;
LOG_FUNC();
instream = makeSimpleStream( globals, NULL );
stream_putBytes( instream, data, len );
checkAndDeliver( globals, instream );
checkAndDeliver( globals, fromAddr, instream );
LOG_RETURN_VOID();
}
#endif

View file

@ -127,7 +127,6 @@ typedef struct XWords4PreferenceType {
Boolean showColors;
#ifdef DEBUG
Boolean showDebugstrs;
Boolean logToMemo;
Boolean reserved1;
Boolean reserved2;
#else
@ -336,6 +335,9 @@ enum { dictSelectedEvent = firstUserEvent /* 0x6000 */
enum {
PNOLET_STORE_FEATURE = 1 /* where FtrPtr to pnolet code lives */
, GLOBALS_FEATURE /* for passing globals to form handlers */
, LOG_FILE_FEATURE /* these three for debugging */
, LOG_MEMO_FEATURE
, LOG_SCREEN_FEATURE
#ifdef FEATURE_DUALCHOOSE
, FEATURE_WANTS_68K /* support for (pre-ship) ability to choose
armlet or 68K */
@ -377,7 +379,8 @@ void writeNameToGameRecord( PalmAppGlobals* globals, XP_S16 index,
XP_UCHAR* getResString( PalmAppGlobals* globals, XP_U16 strID );
Boolean palmask( PalmAppGlobals* globals, XP_UCHAR* str, XP_UCHAR* altButton,
XP_S16 titleID );
void checkAndDeliver( PalmAppGlobals* globals, XWStreamCtxt* instream );
void checkAndDeliver( PalmAppGlobals* globals, const CommsAddrRec* addr,
XWStreamCtxt* instream );
#ifdef XW_TARGET_PNO
# define READ_UNALIGNED16(n) read_unaligned16((unsigned char*)(n))

View file

@ -32,6 +32,9 @@
#include "palmmain.h"
#include "comtypes.h"
#define MEMO "MemoDB"
#define LOGFILE "XWLogfile"
/*****************************************************************************
* This is meant to be replaced by an actual beep....
****************************************************************************/
@ -457,7 +460,6 @@ doNothing( EventPtr event )
#endif
#ifdef DEBUG
void
logEvent( eventsEnum eType )
{
@ -659,10 +661,44 @@ logToDB( const char* buf, const char* dbName, XP_U32 dbCreator, XP_U32 dbType )
DmCloseDatabase( ref );
} /* logToDB */
static void
deleteDB( const char* dbName )
{
LocalID dbID;
dbID = DmFindDatabase( CARD_0, dbName );
if ( 0 != dbID ) {
Err err = DmDeleteDatabase( CARD_0, dbID );
XP_ASSERT( errNone == err );
} else {
XP_WARNF( "%s(%s): got back 0", __FUNCTION__, dbName );
}
} /* deleteDB */
void
PalmClearLogs( void )
{
deleteDB( MEMO );
deleteDB( LOGFILE );
}
static void
logToMemo( const char* buf )
{
logToDB( buf, "MemoDB", 'memo', 'DATA' );
UInt32 val = 0L;
Err err = FtrGet( APPID, LOG_MEMO_FEATURE, (UInt32*)&val );
if ( errNone == err && val != 0 ) {
logToDB( buf, MEMO, 'memo', 'DATA' );
}
}
static void
logToFile( const char* buf )
{
UInt32 val = 0L;
Err err = FtrGet( APPID, LOG_FILE_FEATURE, (UInt32*)&val );
if ( errNone == err && val != 0 ) {
logToDB( buf, LOGFILE, 'XWLG', 'TEXT' );
}
}
void
@ -676,6 +712,7 @@ palm_debugf( char* format, ...)
va_end( ap );
logToMemo( buf );
logToFile( buf );
} /* debugf */
/* if -0 isn't passed to compiler it wants to find this!!! */
@ -692,33 +729,7 @@ palm_logf( char* format, ... )
va_end( ap );
logToMemo( buf );
logToDB( buf, "XWLogfile", 'XWLG', 'TEXT' );
logToFile( buf );
} /* palm_logf */
#define ROWSIZE 8
void
palm_logmem( unsigned char* ptr, int nBytes )
{
XP_U16 nRows = (nBytes + ROWSIZE-1) / ROWSIZE;
char buf[(ROWSIZE*3)+5];
char* bp;
unsigned char* end = ptr + nBytes;
XP_U16 i, j;
for ( i = 0; i < nRows; ++i ) {
bp = buf;
bp += StrPrintF( (Char*)buf, "%3x:", i * ROWSIZE );
for ( j = 0; j < ROWSIZE && ptr < end; ++j ) {
char sbuf[6];
StrPrintF( sbuf, "%x ", (XP_U16)*ptr++ );
StrCat( buf, &sbuf[2] );
bp += 3;
}
logToMemo( buf );
}
}
#endif /* DEBUG */

View file

@ -77,6 +77,7 @@ void fitButtonToString( XP_U16 id );
#ifdef DEBUG
void PalmClearLogs( void );
void logEvent( eventsEnum eType );
#else
# define logEvent(e)