When bt init fails, put up alert; check for failure after and don't

crash; erase bt status area even when no comms in order to erase after
turning bt off; in connect dlg, use a trigger rather than field and
button for host name.
This commit is contained in:
ehouse 2006-10-15 16:14:42 +00:00
parent be5e857600
commit 1aa6d81177
7 changed files with 86 additions and 84 deletions

View file

@ -43,21 +43,10 @@ typedef struct ConnsDlgState {
XP_Bool isNewGame;
CommsAddrRec* addr;
XP_BtAddr btAddr; /* since there's no field, save it here */
XP_BtAddrStr tmp;
char btName[32];
} ConnsDlgState;
static void
strFromField( XP_U16 id, XP_UCHAR* buf, XP_U16 max )
{
FieldPtr field = getActiveObjectPtr( id );
XP_UCHAR* str = FldGetTextPtr( field );
XP_U16 len = FldGetTextLength( field );
if ( len > max-1 ) {
len = max - 1;
}
XP_MEMCPY( buf, str, len );
buf[len] = '\0';
} /* strFromField */
static void
ctlsFromState( PalmAppGlobals* XP_UNUSED_BT(globals), ConnsDlgState* state )
{
@ -81,12 +70,12 @@ ctlsFromState( PalmAppGlobals* XP_UNUSED_BT(globals), ConnsDlgState* state )
#ifdef XWFEATURE_BLUETOOTH
} else if ( addr->conType == COMMS_CONN_BT
&& state->serverRole == SERVER_ISCLIENT ) {
ControlPtr ctrl = getActiveObjectPtr( XW_CONNS_BT_HOSTTRIGGER_ID );
if ( '\0' == addr->u.bt.hostName[0] ) {
XP_BtAddrStr tmp;
palm_bt_addrString( globals, &addr->u.bt.btAddr, &tmp );
setFieldStr( XW_CONNS_BT_HOSTFIELD_ID, tmp.chars );
palm_bt_addrString( globals, &addr->u.bt.btAddr, &state->tmp );
CtlSetLabel( ctrl, state->tmp.chars );
} else {
setFieldStr( XW_CONNS_BT_HOSTFIELD_ID, addr->u.bt.hostName );
CtlSetLabel( ctrl, addr->u.bt.hostName );
}
#endif
}
@ -114,9 +103,9 @@ stateFromCtls( ConnsDlgState* state )
#ifdef XWFEATURE_BLUETOOTH
} else if ( addr->conType == COMMS_CONN_BT
&& state->serverRole == SERVER_ISCLIENT ) {
strFromField( XW_CONNS_BT_HOSTFIELD_ID, addr->u.bt.hostName,
sizeof(addr->u.bt.hostName) );
/* Not exactly from a control... */
XP_MEMCPY( addr->u.bt.hostName, state->btName,
sizeof(addr->u.bt.hostName) );
XP_MEMCPY( &addr->u.bt.btAddr, &state->btAddr,
sizeof(addr->u.bt.btAddr) );
LOG_HEX( &addr->u.bt.btAddr, sizeof(addr->u.bt.btAddr), __FUNCTION__ );
@ -143,8 +132,7 @@ updateFormCtls( FormPtr form, ConnsDlgState* state )
const XP_U16 btGuestCtls[] = {
#ifdef XWFEATURE_BLUETOOTH
XW_CONNS_BT_HOSTNAME_LABEL_ID,
XW_CONNS_BT_HOSTFIELD_ID,
XW_CONNS_BT_BROWSEBUTTON_ID,
XW_CONNS_BT_HOSTTRIGGER_ID,
#else
XW_CONNS_BT_NOTSUPPORT_LABEL_ID,
#endif
@ -219,10 +207,11 @@ selToConType( XP_U16 sel )
static void
browseForDeviceName( PalmAppGlobals* globals, ConnsDlgState* state )
{
char buf[32];
XP_BtAddr btAddr;
if ( palm_bt_browse_device( globals, &btAddr, buf, sizeof( buf ) ) ) {
setFieldStr( XW_CONNS_BT_HOSTFIELD_ID, buf );
if ( palm_bt_browse_device( globals, &btAddr,
state->btName, sizeof( state->btName ) ) ) {
CtlSetLabel( getActiveObjectPtr( XW_CONNS_BT_HOSTTRIGGER_ID ),
state->btName );
XP_MEMCPY( &state->btAddr, &btAddr, sizeof(state->btAddr) );
LOG_HEX( &state->btAddr, sizeof(state->btAddr), __FUNCTION__ );
}
@ -282,7 +271,7 @@ ConnsFormHandleEvent( EventPtr event )
switch ( event->data.ctlSelect.controlID ) {
#ifdef XWFEATURE_BLUETOOTH
case XW_CONNS_BT_BROWSEBUTTON_ID:
case XW_CONNS_BT_HOSTTRIGGER_ID:
browseForDeviceName( globals, state );
break;
#endif

View file

@ -131,6 +131,12 @@
"connection." },
{ "STR_RELAY_GENERIC", "Relay error: something's wrong." },
#endif
#ifdef XWFEATURE_BLUETOOTH
{ "STR_BT_NOINIT", "Unable to initialize Bluetooth. "
"Is it enabled?" },
#endif
{ "STR_ABOUT_CONTENT",
#if 1
"THANKS FOR LOOKING at this alpha version of "

View file

@ -253,11 +253,9 @@ BEGIN
AT ( LEFTCOL+10 LOCALIP_TOP ) NONUSABLE
#ifdef XWFEATURE_BLUETOOTH
LABEL "Host name:" XW_CONNS_BT_HOSTNAME_LABEL_ID
AT ( PREVLEFT PREVTOP ) NONUSABLE
FIELD XW_CONNS_BT_HOSTFIELD_ID CONNS_FIELD_LEFT PREVTOP 70 AUTO \
SINGLELINE EDITABLE UNDERLINED MAXCHARS 32 NONUSABLE
BUTTON "Browse" XW_CONNS_BT_BROWSEBUTTON_ID LEFTCOL+10 PREVBOTTOM+5
AUTO AUTO NONUSABLE
AT ( PREVLEFT PREVTOP+3 ) NONUSABLE
SELECTORTRIGGER "Find host..." XW_CONNS_BT_HOSTTRIGGER_ID \
AT (CONNS_FIELD_LEFT PREVTOP 70 AUTO) NONUSABLE LEFTANCHOR
#endif
/* Relay... */

View file

@ -158,9 +158,10 @@ static const char* proleToString( PBT_PicoRole r );
static void libMgmtCallback( BtLibManagementEventType* mEvent, UInt32 refCon );
static void l2SocketCallback( BtLibSocketEventType* sEvent, UInt32 refCon );
Err
XP_Bool
palm_bt_init( PalmAppGlobals* globals, DataCb cb )
{
XP_Bool inited;
PalmBTStuff* btStuff;
LOG_FUNC();
@ -173,15 +174,18 @@ palm_bt_init( PalmAppGlobals* globals, DataCb cb )
pbt_reset( btStuff );
}
if ( comms_getIsServer( globals->game.comms ) ) {
pbt_setup_master( btStuff );
} else if ( btStuff->picoRole == PBT_MASTER ) {
pbt_takedown_master( btStuff );
}
inited = !!btStuff;
if ( inited ) {
if ( comms_getIsServer( globals->game.comms ) ) {
pbt_setup_master( btStuff );
} else if ( btStuff->picoRole == PBT_MASTER ) {
pbt_takedown_master( btStuff );
}
btStuff->cb = cb;
LOG_RETURN_VOID();
return errNone;
btStuff->cb = cb;
}
LOG_RETURNF( "%d", (XP_U16)inited );
return inited;
} /* palm_bt_init */
void
@ -405,36 +409,38 @@ palm_bt_send( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addr,
XP_LOGF( "%s(len=%d)", __FUNCTION__, len);
btStuff = pbt_checkInit( globals );
if ( !btStuff->cb ) {
btStuff->cb = cb;
} else {
XP_ASSERT( cb == btStuff->cb );
}
if ( !addr ) {
comms_getAddr( globals->game.comms, &remoteAddr );
addr = &remoteAddr;
}
XP_ASSERT( !!addr );
picoRole = btStuff->picoRole;
XP_LOGF( "%s: role=%s", __FUNCTION__, proleToString(picoRole) );
if ( picoRole == PBT_UNINIT ) {
XP_Bool amMaster = comms_getIsServer( globals->game.comms );
picoRole = amMaster? PBT_MASTER : PBT_SLAVE;
}
pbt_checkAddress( btStuff, addr );
if ( !!btStuff ) {
if ( picoRole == PBT_MASTER ) {
pbt_setup_master( btStuff );
if ( !btStuff->cb ) {
btStuff->cb = cb;
} else {
pbt_setup_slave( btStuff, addr );
XP_ASSERT( cb == btStuff->cb );
}
nSent = pbt_enque( &btStuff->vol.out, buf, len );
pbt_send_pending( btStuff );
if ( !addr ) {
comms_getAddr( globals->game.comms, &remoteAddr );
addr = &remoteAddr;
}
XP_ASSERT( !!addr );
picoRole = btStuff->picoRole;
XP_LOGF( "%s: role=%s", __FUNCTION__, proleToString(picoRole) );
if ( picoRole == PBT_UNINIT ) {
XP_Bool amMaster = comms_getIsServer( globals->game.comms );
picoRole = amMaster? PBT_MASTER : PBT_SLAVE;
}
pbt_checkAddress( btStuff, addr );
if ( !!btStuff ) {
if ( picoRole == PBT_MASTER ) {
pbt_setup_master( btStuff );
} else {
pbt_setup_slave( btStuff, addr );
}
nSent = pbt_enque( &btStuff->vol.out, buf, len );
pbt_send_pending( btStuff );
}
}
LOG_RETURNF( "%d", nSent );
return nSent;

View file

@ -48,7 +48,7 @@ typedef void (*DataCb)( PalmAppGlobals* globals,
const CommsAddrRec* fromAddr,
const XP_U8* data, XP_U16 len );
Err palm_bt_init( PalmAppGlobals* globals, DataCb cb );
XP_Bool palm_bt_init( PalmAppGlobals* globals, DataCb cb );
void palm_bt_close( PalmAppGlobals* globals );
void palm_bt_addrString( PalmAppGlobals* globals, XP_BtAddr* btAddr,

View file

@ -1470,26 +1470,28 @@ timeForTimer( PalmAppGlobals* globals, XWTimerReason* why, XP_U32* when )
static void
showBTState( PalmAppGlobals* globals )
{
char ch[] = { ' ', ' ' };
CommsCtxt* comms = globals->game.comms;
if ( (comms != NULL)
&& COMMS_CONN_BT == comms_getConType( globals->game.comms ) ) {
switch( globals->btUIState ) {
case BTUI_NONE:
ch[0] = 'x'; break;
case BTUI_LISTENING:
ch[0] = 'L'; break;
case BTUI_CONNECTING:
ch[0] = 'c'; break;
case BTUI_CONNECTED:
ch[0] = 'C'; break;
case BTUI_SERVING:
ch[0] = 'S'; break;
char ch[] = { ' ', ' ' };
if ( comms != NULL ) {
if ( COMMS_CONN_BT == comms_getConType( globals->game.comms ) ) {
switch( globals->btUIState ) {
case BTUI_NONE:
ch[0] = 'x'; break;
case BTUI_LISTENING:
ch[0] = 'L'; break;
case BTUI_CONNECTING:
ch[0] = 'c'; break;
case BTUI_CONNECTED:
ch[0] = 'C'; break;
case BTUI_SERVING:
ch[0] = 'S'; break;
}
}
}
/* Looks ok on T650, bad on lowres. Need to replace with gadget or icon
or something long before ship. */
WinDrawChars( ch, 2, 160-7, 160-27 );
WinDrawChars( ch, sizeof(ch), 160-7, 160-27 );
} /* showBTState */
#endif
@ -3520,7 +3522,9 @@ palm_util_addrChange( XW_UtilCtxt* uc, const CommsAddrRec* oldAddr,
# endif
# ifdef XWFEATURE_BLUETOOTH
} else if ( isBT ) {
palm_bt_init( globals, btDataHandler );
if ( !palm_bt_init( globals, btDataHandler ) ) {
userErrorFromStrId( globals, STR_BT_NOINIT );
}
# endif
}
}

View file

@ -340,8 +340,7 @@
#define XW_CONNS_BT_NOTSUPPORT_LABEL_ID 2910
#ifdef XWFEATURE_BLUETOOTH
# define XW_CONNS_BT_HOSTNAME_LABEL_ID 2911
# define XW_CONNS_BT_HOSTFIELD_ID 2912
# define XW_CONNS_BT_BROWSEBUTTON_ID 2913
# define XW_CONNS_BT_HOSTTRIGGER_ID 2912
#endif
/*