mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
If BT is off, ask user to turn it on only once. If cancels, warn that
it must be turned on, and don't attempt to turn it on again. This prevents BTLib from repeatedly asking for permission to turn BT on.
This commit is contained in:
parent
2f52acd5e6
commit
9a86b69527
5 changed files with 59 additions and 22 deletions
|
@ -129,8 +129,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef XWFEATURE_BLUETOOTH
|
#ifdef XWFEATURE_BLUETOOTH
|
||||||
{ "STR_BT_NOINIT", "Unable to initialize Bluetooth. "
|
{ "STR_BT_NOINIT", "Bluetooth appears to be off. Please turn it "
|
||||||
"Is it enabled?" },
|
"on if you want Crosswords to use it." },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ "STR_ABOUT_CONTENT",
|
{ "STR_ABOUT_CONTENT",
|
||||||
|
|
|
@ -53,7 +53,7 @@ typedef enum {
|
||||||
, PBTST_L2C_CONNECTED /* slave */
|
, PBTST_L2C_CONNECTED /* slave */
|
||||||
} PBT_STATE;
|
} PBT_STATE;
|
||||||
|
|
||||||
#define PBT_MAX_ACTS 6 /* four wasn't enough */
|
#define PBT_MAX_ACTS 8 /* six wasn't enough */
|
||||||
#define HASWORK(s) ((s)->queueCur != (s)->queueNext)
|
#define HASWORK(s) ((s)->queueCur != (s)->queueNext)
|
||||||
#define MAX_PACKETS 4
|
#define MAX_PACKETS 4
|
||||||
|
|
||||||
|
@ -125,7 +125,8 @@ static const BtLibSdpUuidType XWORDS_UUID = {
|
||||||
{ 0x83, 0xe0, 0x87, 0xae, 0x4e, 0x18, 0x46, 0xbe,
|
{ 0x83, 0xe0, 0x87, 0xae, 0x4e, 0x18, 0x46, 0xbe,
|
||||||
0x83, 0xe0, 0x7b, 0x3d, 0xe6, 0xa1, 0xc3, 0x3b } };
|
0x83, 0xe0, 0x7b, 0x3d, 0xe6, 0xa1, 0xc3, 0x3b } };
|
||||||
|
|
||||||
static PalmBTStuff* pbt_checkInit( PalmAppGlobals* globals );
|
static PalmBTStuff* pbt_checkInit( PalmAppGlobals* globals,
|
||||||
|
XP_Bool* userCancelled );
|
||||||
static Err bpd_discover( PalmBTStuff* btStuff, BtLibDeviceAddressType* addr );
|
static Err bpd_discover( PalmBTStuff* btStuff, BtLibDeviceAddressType* addr );
|
||||||
static void pbt_setup_slave( PalmBTStuff* btStuff, const CommsAddrRec* addr );
|
static void pbt_setup_slave( PalmBTStuff* btStuff, const CommsAddrRec* addr );
|
||||||
static void pbt_takedown_slave( PalmBTStuff* btStuff );
|
static void pbt_takedown_slave( PalmBTStuff* btStuff );
|
||||||
|
@ -168,7 +169,7 @@ static void libMgmtCallback( BtLibManagementEventType* mEvent, UInt32 refCon );
|
||||||
static void l2SocketCallback( BtLibSocketEventType* sEvent, UInt32 refCon );
|
static void l2SocketCallback( BtLibSocketEventType* sEvent, UInt32 refCon );
|
||||||
|
|
||||||
XP_Bool
|
XP_Bool
|
||||||
palm_bt_init( PalmAppGlobals* globals, DataCb dataCb )
|
palm_bt_init( PalmAppGlobals* globals, DataCb dataCb, XP_Bool* userCancelled )
|
||||||
{
|
{
|
||||||
XP_Bool inited;
|
XP_Bool inited;
|
||||||
PalmBTStuff* btStuff;
|
PalmBTStuff* btStuff;
|
||||||
|
@ -177,7 +178,7 @@ palm_bt_init( PalmAppGlobals* globals, DataCb dataCb )
|
||||||
|
|
||||||
btStuff = globals->btStuff;
|
btStuff = globals->btStuff;
|
||||||
if ( !btStuff ) {
|
if ( !btStuff ) {
|
||||||
btStuff = pbt_checkInit( globals );
|
btStuff = pbt_checkInit( globals, userCancelled );
|
||||||
/* Should I start master/slave setup here? If not, how? */
|
/* Should I start master/slave setup here? If not, how? */
|
||||||
} else {
|
} else {
|
||||||
pbt_reset( btStuff );
|
pbt_reset( btStuff );
|
||||||
|
@ -277,7 +278,7 @@ void
|
||||||
palm_bt_addrString( PalmAppGlobals* globals, XP_BtAddr* btAddr,
|
palm_bt_addrString( PalmAppGlobals* globals, XP_BtAddr* btAddr,
|
||||||
XP_BtAddrStr* str )
|
XP_BtAddrStr* str )
|
||||||
{
|
{
|
||||||
PalmBTStuff* btStuff = pbt_checkInit( globals );
|
PalmBTStuff* btStuff = pbt_checkInit( globals, NULL );
|
||||||
str->chars[0] = '\0';
|
str->chars[0] = '\0';
|
||||||
if ( !!btStuff ) {
|
if ( !!btStuff ) {
|
||||||
Err err;
|
Err err;
|
||||||
|
@ -298,7 +299,7 @@ palm_bt_browse_device( PalmAppGlobals* globals, XP_BtAddr* btAddr,
|
||||||
|
|
||||||
LOG_FUNC();
|
LOG_FUNC();
|
||||||
|
|
||||||
btStuff = pbt_checkInit( globals );
|
btStuff = pbt_checkInit( globals, NULL );
|
||||||
if ( NULL != btStuff ) {
|
if ( NULL != btStuff ) {
|
||||||
BtLibDeviceAddressType addr;
|
BtLibDeviceAddressType addr;
|
||||||
Err err = bpd_discover( btStuff, &addr );
|
Err err = bpd_discover( btStuff, &addr );
|
||||||
|
@ -420,7 +421,8 @@ pbt_send_pending( PalmBTStuff* btStuff )
|
||||||
|
|
||||||
XP_S16
|
XP_S16
|
||||||
palm_bt_send( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addr,
|
palm_bt_send( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addr,
|
||||||
DataCb dataCb, OnConnCb connCb, PalmAppGlobals* globals )
|
DataCb dataCb, OnConnCb connCb, PalmAppGlobals* globals,
|
||||||
|
XP_Bool* userCancelled )
|
||||||
{
|
{
|
||||||
XP_S16 nSent = -1;
|
XP_S16 nSent = -1;
|
||||||
PalmBTStuff* btStuff;
|
PalmBTStuff* btStuff;
|
||||||
|
@ -428,7 +430,7 @@ palm_bt_send( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addr,
|
||||||
PBT_PicoRole picoRole;
|
PBT_PicoRole picoRole;
|
||||||
XP_LOGF( "%s(len=%d)", __FUNCTION__, len);
|
XP_LOGF( "%s(len=%d)", __FUNCTION__, len);
|
||||||
|
|
||||||
btStuff = pbt_checkInit( globals );
|
btStuff = pbt_checkInit( globals, userCancelled );
|
||||||
if ( !!btStuff ) {
|
if ( !!btStuff ) {
|
||||||
if ( !btStuff->dataCb ) {
|
if ( !btStuff->dataCb ) {
|
||||||
btStuff->dataCb = dataCb;
|
btStuff->dataCb = dataCb;
|
||||||
|
@ -807,9 +809,10 @@ pbt_takedown_slave( PalmBTStuff* btStuff )
|
||||||
}
|
}
|
||||||
|
|
||||||
static PalmBTStuff*
|
static PalmBTStuff*
|
||||||
pbt_checkInit( PalmAppGlobals* globals )
|
pbt_checkInit( PalmAppGlobals* globals, XP_Bool* userCancelledP )
|
||||||
{
|
{
|
||||||
PalmBTStuff* btStuff = globals->btStuff;
|
PalmBTStuff* btStuff = globals->btStuff;
|
||||||
|
XP_Bool userCancelled = XP_FALSE;
|
||||||
if ( !btStuff ) {
|
if ( !btStuff ) {
|
||||||
Err err;
|
Err err;
|
||||||
XP_U16 btLibRefNum;
|
XP_U16 btLibRefNum;
|
||||||
|
@ -818,6 +821,8 @@ pbt_checkInit( PalmAppGlobals* globals )
|
||||||
if ( errNone == err ) {
|
if ( errNone == err ) {
|
||||||
CALL_ERR( err, BtLibOpen, btLibRefNum, false );
|
CALL_ERR( err, BtLibOpen, btLibRefNum, false );
|
||||||
|
|
||||||
|
userCancelled = err == btLibErrBluetoothOff;
|
||||||
|
|
||||||
/* BT is probably off if this fails */
|
/* BT is probably off if this fails */
|
||||||
if ( errNone == err ) {
|
if ( errNone == err ) {
|
||||||
btStuff = XP_MALLOC( globals->mpool, sizeof(*btStuff) );
|
btStuff = XP_MALLOC( globals->mpool, sizeof(*btStuff) );
|
||||||
|
@ -836,6 +841,11 @@ pbt_checkInit( PalmAppGlobals* globals )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !!userCancelledP ) {
|
||||||
|
*userCancelledP = userCancelled;
|
||||||
|
}
|
||||||
|
|
||||||
return btStuff;
|
return btStuff;
|
||||||
} /* pbt_checkInit */
|
} /* pbt_checkInit */
|
||||||
|
|
||||||
|
@ -1084,8 +1094,15 @@ connEnumToStr( BtLibAccessibleModeEnum mode )
|
||||||
CASESTR(btLibNotAccessible);
|
CASESTR(btLibNotAccessible);
|
||||||
CASESTR(btLibConnectableOnly);
|
CASESTR(btLibConnectableOnly);
|
||||||
CASESTR(btLibDiscoverableAndConnectable);
|
CASESTR(btLibDiscoverableAndConnectable);
|
||||||
|
case 0x0006:
|
||||||
|
/* I've seen this on 68K even. Seems to happen when the other
|
||||||
|
device changes roles (temporarily). */
|
||||||
|
return "undoc_06";
|
||||||
|
case 0x00F8: /* seen on ARM only */
|
||||||
|
return "undoc_F8";
|
||||||
default:
|
default:
|
||||||
XP_ASSERT(0);
|
XP_ASSERT(0);
|
||||||
|
XP_LOGF( "%s: got 0x%x", __func__, mode );
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,14 +50,16 @@ typedef void (*DataCb)( PalmAppGlobals* globals,
|
||||||
typedef void (*OnConnCb)( PalmAppGlobals* globals );
|
typedef void (*OnConnCb)( PalmAppGlobals* globals );
|
||||||
|
|
||||||
|
|
||||||
XP_Bool palm_bt_init( PalmAppGlobals* globals, DataCb dataCb );
|
XP_Bool palm_bt_init( PalmAppGlobals* globals, DataCb dataCb,
|
||||||
|
XP_Bool* userCancelled );
|
||||||
void palm_bt_close( PalmAppGlobals* globals );
|
void palm_bt_close( PalmAppGlobals* globals );
|
||||||
|
|
||||||
void palm_bt_addrString( PalmAppGlobals* globals, XP_BtAddr* btAddr,
|
void palm_bt_addrString( PalmAppGlobals* globals, XP_BtAddr* btAddr,
|
||||||
XP_BtAddrStr* str );
|
XP_BtAddrStr* str );
|
||||||
|
|
||||||
XP_S16 palm_bt_send( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addr,
|
XP_S16 palm_bt_send( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addr,
|
||||||
DataCb cb, OnConnCb connCb, PalmAppGlobals* globals );
|
DataCb cb, OnConnCb connCb, PalmAppGlobals* globals,
|
||||||
|
XP_Bool* userCancelled );
|
||||||
|
|
||||||
XP_Bool palm_bt_browse_device( PalmAppGlobals* globals, XP_BtAddr* btAddr,
|
XP_Bool palm_bt_browse_device( PalmAppGlobals* globals, XP_BtAddr* btAddr,
|
||||||
XP_UCHAR* out,XP_U16 len );
|
XP_UCHAR* out,XP_U16 len );
|
||||||
|
|
|
@ -1619,8 +1619,9 @@ handleNilEvent( PalmAppGlobals* globals )
|
||||||
&& (when <= TimGetTicks()) ) {
|
&& (when <= TimGetTicks()) ) {
|
||||||
palmFireTimer( globals, why );
|
palmFireTimer( globals, why );
|
||||||
#ifdef XWFEATURE_BLUETOOTH
|
#ifdef XWFEATURE_BLUETOOTH
|
||||||
} else if ( palm_bt_doWork( globals, &globals->btUIState ) ) {
|
} else if ( (handled = palm_bt_doWork( globals, &globals->btUIState ) ),
|
||||||
showConnState( globals );
|
showConnState( globals ), handled ) {
|
||||||
|
/* nothing to do */
|
||||||
#endif
|
#endif
|
||||||
} else if ( globals->timeRequested ) {
|
} else if ( globals->timeRequested ) {
|
||||||
globals->timeRequested = false;
|
globals->timeRequested = false;
|
||||||
|
@ -3828,6 +3829,16 @@ palm_send_on_close( XWStreamCtxt* stream, void* closure )
|
||||||
comms_send( globals->game.comms, stream );
|
comms_send( globals->game.comms, stream );
|
||||||
} /* palm_send_on_close */
|
} /* palm_send_on_close */
|
||||||
|
|
||||||
|
#ifdef XWFEATURE_BLUETOOTH
|
||||||
|
static void
|
||||||
|
handleUserBTCancel( PalmAppGlobals* globals )
|
||||||
|
{
|
||||||
|
XP_ASSERT( !globals->userCancelledBT );
|
||||||
|
globals->userCancelledBT = XP_TRUE;
|
||||||
|
userErrorFromStrId( globals, STR_BT_NOINIT );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static XP_S16
|
static XP_S16
|
||||||
palm_send( const XP_U8* buf, XP_U16 len,
|
palm_send( const XP_U8* buf, XP_U16 len,
|
||||||
const CommsAddrRec* addr, void* closure )
|
const CommsAddrRec* addr, void* closure )
|
||||||
|
@ -3850,11 +3861,12 @@ palm_send( const XP_U8* buf, XP_U16 len,
|
||||||
#endif
|
#endif
|
||||||
#ifdef XWFEATURE_BLUETOOTH
|
#ifdef XWFEATURE_BLUETOOTH
|
||||||
case COMMS_CONN_BT:
|
case COMMS_CONN_BT:
|
||||||
if ( !!globals->mainForm ) {
|
if ( !!globals->mainForm && !globals->userCancelledBT ) {
|
||||||
|
XP_Bool userCancelled;
|
||||||
result = palm_bt_send( buf, len, addr, btDataHandler,
|
result = palm_bt_send( buf, len, addr, btDataHandler,
|
||||||
btConnHandler, globals );
|
btConnHandler, globals, &userCancelled );
|
||||||
if ( result < 0 ) {
|
if ( userCancelled ) {
|
||||||
userErrorFromStrId( globals, STR_BT_NOINIT );
|
handleUserBTCancel( globals );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -3976,10 +3988,13 @@ palm_util_addrChange( XW_UtilCtxt* uc, const CommsAddrRec* oldAddr,
|
||||||
ip_addr_change( globals, oldAddr, newAddr );
|
ip_addr_change( globals, oldAddr, newAddr );
|
||||||
# endif
|
# endif
|
||||||
# ifdef XWFEATURE_BLUETOOTH
|
# ifdef XWFEATURE_BLUETOOTH
|
||||||
} else if ( isBT ) {
|
} else if ( isBT && !globals->userCancelledBT ) {
|
||||||
|
XP_Bool userCancelled;
|
||||||
XP_ASSERT( !!globals->mainForm );
|
XP_ASSERT( !!globals->mainForm );
|
||||||
if ( !palm_bt_init( globals, btDataHandler ) ) {
|
if ( !palm_bt_init( globals, btDataHandler, &userCancelled ) ) {
|
||||||
userErrorFromStrId( globals, STR_BT_NOINIT );
|
if ( userCancelled ) {
|
||||||
|
handleUserBTCancel( globals );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,6 +274,9 @@ struct PalmAppGlobals {
|
||||||
Boolean menuIsDown;
|
Boolean menuIsDown;
|
||||||
XP_Bool newGameIsNew;
|
XP_Bool newGameIsNew;
|
||||||
XP_Bool runningOnPOSE; /* Needed for NetLibSelect */
|
XP_Bool runningOnPOSE; /* Needed for NetLibSelect */
|
||||||
|
#ifdef XWFEATURE_BLUETOOTH
|
||||||
|
XP_Bool userCancelledBT;
|
||||||
|
#endif
|
||||||
|
|
||||||
GraphicsAbility able;
|
GraphicsAbility able;
|
||||||
XP_U16 prevScroll; /* for scrolling in 'ask' dialog */
|
XP_U16 prevScroll; /* for scrolling in 'ask' dialog */
|
||||||
|
|
Loading…
Reference in a new issue