mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-15 15:41:24 +01:00
Substitute name of remote host into request for connection
initialization confirmation.
This commit is contained in:
parent
484025a21f
commit
9292e38cab
4 changed files with 38 additions and 17 deletions
|
@ -141,7 +141,7 @@
|
|||
{ "STR_BT_XPORTNAME", "Bluetooth" },
|
||||
{ "STR_BT_NOINIT", "Bluetooth appears to be off. Please turn it "
|
||||
"on if you want Crosswords to use it." },
|
||||
{ "STRS_BT_CONFIRM", "Is Crosswords running on the host device and "
|
||||
{ "STRS_BT_CONFIRM", "Is Crosswords running on %s and "
|
||||
"ready to accept a connection? (If you "
|
||||
"choose \"No\" Crosswords will not try to "
|
||||
"connect until you restart it "
|
||||
|
|
|
@ -165,6 +165,10 @@ static void pbt_killLinks( PalmBTStuff* btStuff );
|
|||
static XP_Bool pbt_checkAddress( PalmBTStuff* btStuff, const CommsAddrRec* addr );
|
||||
static void pbt_setstate( PalmBTStuff* btStuff, PBT_STATE newState,
|
||||
const char* whence );
|
||||
static Err pbt_nameForAddr( PalmBTStuff* btStuff,
|
||||
const BtLibDeviceAddressType* addr,
|
||||
char* const out, XP_U16 outlen );
|
||||
|
||||
#define SET_STATE(b,s) pbt_setstate((b),(s),__func__)
|
||||
#define GET_STATE(b) ((b)->p_connState)
|
||||
|
||||
|
@ -340,22 +344,10 @@ palm_bt_browse_device( PalmAppGlobals* globals, XP_BtAddr* btAddr,
|
|||
Err err = pbd_discover( btStuff, &addr );
|
||||
|
||||
if ( errNone == err ) {
|
||||
UInt8 name[PALM_BT_NAME_LEN];
|
||||
BtLibFriendlyNameType nameType = {
|
||||
.name = name,
|
||||
.nameLength = sizeof(name)
|
||||
};
|
||||
|
||||
XP_MEMCPY( btAddr, &addr, sizeof(addr) );
|
||||
LOG_HEX( &btAddr, sizeof(btAddr), __func__ );
|
||||
|
||||
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 );
|
||||
XP_MEMCPY( out, nameType.name, nameType.nameLength );
|
||||
err = pbt_nameForAddr( btStuff, &addr, out, len );
|
||||
}
|
||||
success = errNone == err;
|
||||
}
|
||||
|
@ -404,6 +396,28 @@ palm_bt_getStats( PalmAppGlobals* globals, XWStreamCtxt* stream )
|
|||
}
|
||||
#endif
|
||||
|
||||
static Err
|
||||
pbt_nameForAddr( PalmBTStuff* btStuff, const BtLibDeviceAddressType* addr,
|
||||
char* const out, XP_U16 outlen )
|
||||
{
|
||||
Err err;
|
||||
UInt8 name[PALM_BT_NAME_LEN];
|
||||
BtLibFriendlyNameType nameType = {
|
||||
.name = name,
|
||||
.nameLength = sizeof(name)
|
||||
};
|
||||
|
||||
CALL_ERR( err, BtLibGetRemoteDeviceName, btStuff->btLibRefNum,
|
||||
(BtLibDeviceAddressType*)addr, &nameType,
|
||||
btLibCachedThenRemote );
|
||||
XP_ASSERT( errNone == err ); /* deal with btLibErrPending */
|
||||
XP_LOGF( "%s: got name %s", __func__, nameType.name );
|
||||
|
||||
XP_ASSERT( outlen >= nameType.nameLength );
|
||||
XP_MEMCPY( out, nameType.name, nameType.nameLength );
|
||||
return err;
|
||||
}
|
||||
|
||||
static XP_U16
|
||||
pbt_peekQueue( const PBT_queue* queue, const XP_U8** bufp )
|
||||
{
|
||||
|
@ -686,7 +700,11 @@ pbt_do_work( PalmBTStuff* btStuff, BtCbEvtProc proc )
|
|||
|
||||
case PBT_ACT_CONNECT_ACL:
|
||||
if ( GET_STATE(btStuff) == PBTST_NONE ) {
|
||||
UInt8 name[PALM_BT_NAME_LEN];
|
||||
(void)pbt_nameForAddr( btStuff, &btStuff->otherAddr,
|
||||
name, sizeof(name) );
|
||||
info.evt = BTCBEVT_CONFIRM;
|
||||
info.u.confirm.hostName = name;
|
||||
info.u.confirm.confirmed = XP_TRUE;
|
||||
(*proc)( btStuff->globals, &info );
|
||||
if ( !info.u.confirm.confirmed ) {
|
||||
|
|
|
@ -58,6 +58,7 @@ typedef struct BtCbEvtInfo {
|
|||
BtCbEvt evt;
|
||||
union {
|
||||
struct {
|
||||
const char* hostName;
|
||||
XP_Bool confirmed;
|
||||
} confirm;
|
||||
struct {
|
||||
|
|
|
@ -1618,11 +1618,13 @@ btEvtHandler( PalmAppGlobals* globals, BtCbEvtInfo* evt )
|
|||
if ( globals->suspendBT ) {
|
||||
evt->u.confirm.confirmed = XP_FALSE;
|
||||
} else if ( globals->gameInfo.confirmBTConnect ) {
|
||||
const XP_UCHAR* str;
|
||||
const XP_UCHAR* fmt;
|
||||
char buf[256]; /* fmt is 182+ bytes in English */
|
||||
XP_ASSERT( !!globals->game.comms &&
|
||||
!comms_getIsServer(globals->game.comms) );
|
||||
str = getResString( globals, STRS_BT_CONFIRM );
|
||||
evt->u.confirm.confirmed = palmask( globals, str, NULL, -1 );
|
||||
fmt = getResString( globals, STRS_BT_CONFIRM );
|
||||
XP_SNPRINTF( buf, sizeof(buf), fmt, evt->u.confirm.hostName );
|
||||
evt->u.confirm.confirmed = palmask( globals, buf, NULL, -1 );
|
||||
globals->suspendBT = !evt->u.confirm.confirmed;
|
||||
} else {
|
||||
evt->u.confirm.confirmed = XP_TRUE;
|
||||
|
|
Loading…
Reference in a new issue