mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-03 23:04:08 +01:00
Add a bit more logging; do a better job of changing roles. Now can switch
roles with a new game and communication starts without a restart of the app.
This commit is contained in:
parent
f6c0ea92e0
commit
b8107cbd6e
1 changed files with 53 additions and 15 deletions
|
@ -142,6 +142,7 @@ static const char* mgmtEvtToStr( BtLibManagementEventEnum event );
|
||||||
static const char* actToStr(PBT_ACTION act);
|
static const char* actToStr(PBT_ACTION act);
|
||||||
static const char* stateToStr(PBT_STATE st);
|
static const char* stateToStr(PBT_STATE st);
|
||||||
static const char* connEnumToStr( BtLibAccessibleModeEnum mode );
|
static const char* connEnumToStr( BtLibAccessibleModeEnum mode );
|
||||||
|
static const char* proleToString( PBT_PicoRole r );
|
||||||
|
|
||||||
#else
|
#else
|
||||||
# define btErrToStr( err ) ""
|
# define btErrToStr( err ) ""
|
||||||
|
@ -150,6 +151,7 @@ static const char* connEnumToStr( BtLibAccessibleModeEnum mode );
|
||||||
# define actToStr(act) ""
|
# define actToStr(act) ""
|
||||||
# define stateToStr(st) ""
|
# define stateToStr(st) ""
|
||||||
# define connEnumToStr(mode) ""
|
# define connEnumToStr(mode) ""
|
||||||
|
# define proleToString(r) ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* callbacks */
|
/* callbacks */
|
||||||
|
@ -161,14 +163,24 @@ palm_bt_init( PalmAppGlobals* globals, DataCb cb )
|
||||||
{
|
{
|
||||||
PalmBTStuff* btStuff;
|
PalmBTStuff* btStuff;
|
||||||
|
|
||||||
|
LOG_FUNC();
|
||||||
|
|
||||||
btStuff = globals->btStuff;
|
btStuff = globals->btStuff;
|
||||||
if ( !btStuff ) {
|
if ( !btStuff ) {
|
||||||
btStuff = pbt_checkInit( globals );
|
btStuff = pbt_checkInit( globals );
|
||||||
|
/* Should I start master/slave setup here? If not, how? */
|
||||||
} else {
|
} else {
|
||||||
pbt_reset( btStuff );
|
pbt_reset( btStuff );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( comms_getIsServer( globals->game.comms ) ) {
|
||||||
|
pbt_setup_master( btStuff );
|
||||||
|
} else if ( btStuff->picoRole == PBT_MASTER ) {
|
||||||
|
pbt_takedown_master( btStuff );
|
||||||
|
}
|
||||||
|
|
||||||
btStuff->cb = cb;
|
btStuff->cb = cb;
|
||||||
|
LOG_RETURN_VOID();
|
||||||
return errNone;
|
return errNone;
|
||||||
} /* palm_bt_init */
|
} /* palm_bt_init */
|
||||||
|
|
||||||
|
@ -265,6 +277,8 @@ palm_bt_browse_device( PalmAppGlobals* globals, XP_BtAddr* btAddr,
|
||||||
XP_Bool success = XP_FALSE;
|
XP_Bool success = XP_FALSE;
|
||||||
PalmBTStuff* btStuff;
|
PalmBTStuff* btStuff;
|
||||||
|
|
||||||
|
LOG_FUNC();
|
||||||
|
|
||||||
btStuff = pbt_checkInit( globals );
|
btStuff = pbt_checkInit( globals );
|
||||||
if ( NULL != btStuff ) {
|
if ( NULL != btStuff ) {
|
||||||
BtLibDeviceAddressType addr;
|
BtLibDeviceAddressType addr;
|
||||||
|
@ -293,6 +307,7 @@ palm_bt_browse_device( PalmAppGlobals* globals, XP_BtAddr* btAddr,
|
||||||
}
|
}
|
||||||
success = errNone == err;
|
success = errNone == err;
|
||||||
}
|
}
|
||||||
|
LOG_RETURNF( "%d", (XP_U16)success );
|
||||||
return success;
|
return success;
|
||||||
} /* palm_bt_browse_device */
|
} /* palm_bt_browse_device */
|
||||||
|
|
||||||
|
@ -369,7 +384,7 @@ pbt_send_pending( PalmBTStuff* btStuff )
|
||||||
const XP_U8* buf;
|
const XP_U8* buf;
|
||||||
XP_U16 len = pbt_peekQueue( &btStuff->vol.out, &buf );
|
XP_U16 len = pbt_peekQueue( &btStuff->vol.out, &buf );
|
||||||
|
|
||||||
if ( len > 0 ) {
|
if ( SOCK_INVAL != btStuff->dataSocket && len > 0 ) {
|
||||||
CALL_ERR( err, BtLibSocketSend, btStuff->btLibRefNum,
|
CALL_ERR( err, BtLibSocketSend, btStuff->btLibRefNum,
|
||||||
btStuff->dataSocket, (char*)buf, len );
|
btStuff->dataSocket, (char*)buf, len );
|
||||||
if ( btLibErrPending == err ) {
|
if ( btLibErrPending == err ) {
|
||||||
|
@ -403,6 +418,7 @@ palm_bt_send( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addr,
|
||||||
XP_ASSERT( !!addr );
|
XP_ASSERT( !!addr );
|
||||||
|
|
||||||
picoRole = btStuff->picoRole;
|
picoRole = btStuff->picoRole;
|
||||||
|
XP_LOGF( "%s: role=%s", __FUNCTION__, proleToString(picoRole) );
|
||||||
if ( picoRole == PBT_UNINIT ) {
|
if ( picoRole == PBT_UNINIT ) {
|
||||||
XP_Bool amMaster = comms_getIsServer( globals->game.comms );
|
XP_Bool amMaster = comms_getIsServer( globals->game.comms );
|
||||||
picoRole = amMaster? PBT_MASTER : PBT_SLAVE;
|
picoRole = amMaster? PBT_MASTER : PBT_SLAVE;
|
||||||
|
@ -493,6 +509,7 @@ pbt_takedown_master( PalmBTStuff* btStuff )
|
||||||
|
|
||||||
btStuff->picoRole = PBT_UNINIT;
|
btStuff->picoRole = PBT_UNINIT;
|
||||||
SET_STATE( btStuff, PBTST_NONE );
|
SET_STATE( btStuff, PBTST_NONE );
|
||||||
|
LOG_RETURN_VOID();
|
||||||
} /* pbt_takedown_master */
|
} /* pbt_takedown_master */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -634,6 +651,7 @@ pbt_reset( PalmBTStuff* btStuff )
|
||||||
{
|
{
|
||||||
LOG_FUNC();
|
LOG_FUNC();
|
||||||
XP_MEMSET( &btStuff->vol, 0, sizeof(btStuff->vol) );
|
XP_MEMSET( &btStuff->vol, 0, sizeof(btStuff->vol) );
|
||||||
|
LOG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Err
|
static Err
|
||||||
|
@ -754,6 +772,7 @@ pbt_checkAddress( PalmBTStuff* btStuff, const CommsAddrRec* addr )
|
||||||
XP_MEMCPY( &btStuff->otherAddr, &addr->u.bt.btAddr,
|
XP_MEMCPY( &btStuff->otherAddr, &addr->u.bt.btAddr,
|
||||||
sizeof(btStuff->otherAddr) );
|
sizeof(btStuff->otherAddr) );
|
||||||
}
|
}
|
||||||
|
LOG_RETURN_VOID();
|
||||||
} /* pbt_checkAddress */
|
} /* pbt_checkAddress */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -890,6 +909,11 @@ libMgmtCallback( BtLibManagementEventType* mEvent, UInt32 refCon )
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case btLibManagementEventACLDisconnect:
|
case btLibManagementEventACLDisconnect:
|
||||||
|
if ( mEvent->status == btLibMeStatusLocalTerminated ) {
|
||||||
|
/* We caused this, probably switching roles. Perhaps we've already
|
||||||
|
done what's needed, e.g. opened socket to listen */
|
||||||
|
} else {
|
||||||
|
XP_ASSERT( mEvent->status == btLibMeStatusUserTerminated );/* fired */
|
||||||
/* This is getting called from inside the BtLibLinkDisconnect call!!!! */
|
/* This is getting called from inside the BtLibLinkDisconnect call!!!! */
|
||||||
XP_ASSERT( 0 == XP_MEMCMP( &mEvent->eventData.bdAddr,
|
XP_ASSERT( 0 == XP_MEMCMP( &mEvent->eventData.bdAddr,
|
||||||
&btStuff->otherAddr,
|
&btStuff->otherAddr,
|
||||||
|
@ -904,6 +928,7 @@ libMgmtCallback( BtLibManagementEventType* mEvent, UInt32 refCon )
|
||||||
if ( PBT_SLAVE == btStuff->picoRole ) {
|
if ( PBT_SLAVE == btStuff->picoRole ) {
|
||||||
pbt_postpone( btStuff, PBT_ACT_CONNECT_ACL );
|
pbt_postpone( btStuff, PBT_ACT_CONNECT_ACL );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -1127,6 +1152,19 @@ btErrToStr( Err err )
|
||||||
}
|
}
|
||||||
} /* btErrToStr */
|
} /* btErrToStr */
|
||||||
|
|
||||||
|
static const char*
|
||||||
|
proleToString( PBT_PicoRole r )
|
||||||
|
{
|
||||||
|
switch ( r ) {
|
||||||
|
CASESTR(PBT_UNINIT);
|
||||||
|
CASESTR(PBT_MASTER);
|
||||||
|
CASESTR(PBT_SLAVE);
|
||||||
|
default:
|
||||||
|
XP_ASSERT(0);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
palm_bt_log( const char* btfunc, const char* func, Err err )
|
palm_bt_log( const char* btfunc, const char* func, Err err )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue