remove BEYOND_IR, replacing with XWFEATURE_RELAY and

XWFEATURE_BLUETOOTH.  The goal is to be able to build to support
bluetooth only, or relay/ip only, e.g. for a palm bluetooth beta.
Seems to work.
This commit is contained in:
ehouse 2006-10-10 01:34:37 +00:00
parent e63ad30e52
commit ba4f91d9e0
20 changed files with 340 additions and 207 deletions

View file

@ -84,9 +84,9 @@ struct CommsCtxt {
MsgQueueElem* msgQueueTail;
XP_U16 queueLen;
/* The following fields, down to isServer, are only used if BEYOND_IR is
defined, but I'm leaving them in here so apps built both ways can open
each other's saved games files.*/
/* The following fields, down to isServer, are only used if
XWFEATURE_RELAY is defined, but I'm leaving them in here so apps built
both ways can open each other's saved games files.*/
CommsAddrRec addr;
/* Stuff for relays */
@ -130,16 +130,16 @@ static AddressRecord* getRecordFor( CommsCtxt* comms,
static XP_S16 sendMsg( CommsCtxt* comms, MsgQueueElem* elem );
static void addToQueue( CommsCtxt* comms, MsgQueueElem* newMsgElem );
static XP_U16 countAddrRecs( CommsCtxt* comms );
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
static void relayConnect( CommsCtxt* comms );
static void relayDisconnect( CommsCtxt* comms );
static XP_Bool send_via_relay( CommsCtxt* comms, XWRELAY_Cmd cmd,
XWHostID destID, void* data, int dlen );
static XWHostID getDestID( CommsCtxt* comms, XP_PlayerAddr channelNo );
static void setHeartbeatTimer( CommsCtxt* comms );
# ifdef XWFEATURE_BLUETOOTH
#endif
#ifdef XWFEATURE_BLUETOOTH
static void btConnect( CommsCtxt* comms );
# endif
#endif
/****************************************************************************
@ -147,7 +147,8 @@ static void btConnect( CommsCtxt* comms );
****************************************************************************/
CommsCtxt*
comms_make( MPFORMAL XW_UtilCtxt* util, XP_Bool isServer,
XP_U16 nPlayersHere, XP_U16 nPlayersTotal,
XP_U16 XP_UNUSED_RELAY(nPlayersHere),
XP_U16 XP_UNUSED_RELAY(nPlayersTotal),
TransportSend sendproc, void* closure )
{
CommsCtxt* result = (CommsCtxt*)XP_MALLOC( mpool, sizeof(*result) );
@ -160,7 +161,7 @@ comms_make( MPFORMAL XW_UtilCtxt* util, XP_Bool isServer,
result->sendClosure = closure;
result->util = util;
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
result->r.myHostID = isServer? HOST_ID_SERVER: HOST_ID_NONE;
XP_LOGF( "set myHostID to %d", result->r.myHostID );
@ -201,9 +202,10 @@ cleanupAddrRecs( CommsCtxt* comms )
void
comms_reset( CommsCtxt* comms, XP_Bool isServer,
XP_U16 nPlayersHere, XP_U16 nPlayersTotal )
XP_U16 XP_UNUSED_RELAY(nPlayersHere),
XP_U16 XP_UNUSED_RELAY(nPlayersTotal) )
{
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
relayDisconnect( comms );
#endif
@ -215,7 +217,7 @@ comms_reset( CommsCtxt* comms, XP_Bool isServer,
comms->nextChannelNo = 0;
comms->connID = CONN_ID_NONE;
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
comms->r.cookieID = COOKIE_ID_NONE;
comms->r.nPlayersHere = nPlayersHere;
comms->r.nPlayersTotal = nPlayersTotal;
@ -378,17 +380,18 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
void
comms_start( CommsCtxt* comms )
{
#ifdef BEYOND_IR
if ( comms->addr.conType == COMMS_CONN_RELAY ) {
if ( 0 ) {
#ifdef XWFEATURE_RELAY
} else if ( comms->addr.conType == COMMS_CONN_RELAY ) {
comms->r.relayState = COMMS_RELAYSTATE_UNCONNECTED;
relayConnect( comms );
#endif
#ifdef XWFEATURE_BLUETOOTH
} else if ( comms->addr.conType == COMMS_CONN_BT ) {
btConnect( comms );
#endif
}
#endif
}
} /* comms_start */
static void
addrToStream( XWStreamCtxt* stream, CommsAddrRec* addrP )
@ -500,12 +503,12 @@ void
comms_setAddr( CommsCtxt* comms, const CommsAddrRec* addr )
{
XP_ASSERT( comms != NULL );
#ifdef BEYOND_IR
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
util_addrChange( comms->util, &comms->addr, addr );
#endif
XP_MEMCPY( &comms->addr, addr, sizeof(comms->addr) );
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
/* We should now have a cookie so we can connect??? */
if ( addr->conType == COMMS_CONN_RELAY ) {
relayConnect( comms );
@ -513,14 +516,14 @@ comms_setAddr( CommsCtxt* comms, const CommsAddrRec* addr )
#endif
} /* comms_setAddr */
#ifdef BEYOND_IR
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
void
comms_getInitialAddr( CommsAddrRec* addr )
{
/* default values; default is still IR where there's a choice */
#ifdef XWFEATURE_BLUETOOTH
#if defined XWFEATURE_BLUETOOTH
addr->conType = COMMS_CONN_BT; /* for temporary ease in debugging */
#else
#elif defined XWFEATURE_RELAY
addr->conType = COMMS_CONN_RELAY; /* for temporary ease in debugging */
addr->u.ip_relay.ipAddr = 0L; /* force 'em to set it */
addr->u.ip_relay.port = 10999;
@ -706,7 +709,7 @@ sendMsg( CommsCtxt* comms, MsgQueueElem* elem )
channelNo = elem->channelNo;
if ( 0 ) {
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
} else if ( comms_getConType( comms ) == COMMS_CONN_RELAY ) {
if ( comms->r.relayState == COMMS_RELAYSTATE_ALLCONNECTED ) {
XWHostID destID = getDestID( comms, channelNo );
@ -747,7 +750,7 @@ comms_resendAll( CommsCtxt* comms )
return result;
} /* comms_resend */
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
static XP_Bool
relayPreProcess( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID* senderID )
{
@ -861,18 +864,20 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
XWHostID senderID = 0; /* unset; default for non-relay cases */
XP_Bool usingRelay = XP_FALSE;
XP_Bool channelWas0 = XP_FALSE;
XP_Bool done = XP_FALSE;
XP_ASSERT( addr == NULL || comms->addr.conType == addr->conType );
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
/* relayPreProcess returns true if consumes the message. May just eat the
header and leave a regular message to be processed below. */
if ( relayPreProcess( comms, stream, &senderID ) ) {
/* validMessage already false */
} else {
done = relayPreProcess( comms, stream, &senderID );
if ( !done ) {
usingRelay = comms->addr.conType == COMMS_CONN_RELAY;
}
#endif
if ( !done ) {
if ( stream_getSize( stream ) >= sizeof(connID) ) {
connID = stream_getU32( stream );
XP_STATUSF( "read connID of %lx", connID );
@ -969,7 +974,7 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
return validMessage;
} /* comms_checkIncomingStream */
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
static void
p_comms_timerFired( void* closure, XWTimerReason XP_UNUSED_DBG(why) )
{
@ -1114,7 +1119,7 @@ countAddrRecs( CommsCtxt* comms )
return count;
} /* countAddrRecs */
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
static XWHostID
getDestID( CommsCtxt* comms, XP_PlayerAddr channelNo )
{
@ -1234,6 +1239,7 @@ relayConnect( CommsCtxt* comms )
comms->r.connecting = XP_FALSE;
}
} /* relayConnect */
#endif
#ifdef XWFEATURE_BLUETOOTH
static void
@ -1249,10 +1255,10 @@ btConnect( CommsCtxt* comms )
} /* btConnect */
#endif
#ifdef XWFEATURE_RELAY
static void
relayDisconnect( CommsCtxt* comms )
{
#ifdef BEYOND_IR
XP_LOGF( "relayDisconnect called" );
if ( comms->addr.conType == COMMS_CONN_RELAY ) {
if ( comms->r.relayState != COMMS_RELAYSTATE_UNCONNECTED ) {
@ -1261,7 +1267,6 @@ relayDisconnect( CommsCtxt* comms )
NULL, 0 );
}
}
#endif
} /* relayDisconnect */
#endif

View file

@ -75,7 +75,7 @@ typedef XP_U16 XP_PlayerAddr;
typedef enum {
TIMER_PENDOWN = 1, /* ARM doesn't like ids of 0... */
TIMER_TIMERTICK,
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
TIMER_HEARTBEAT,
#endif
@ -166,4 +166,16 @@ typedef struct CommonPrefs {
# define XP_UNUSED_DBG(x) XP_UNUSED(x)
#endif
#ifdef XWFEATURE_RELAY
# define XP_UNUSED_RELAY(x) x
#else
# define XP_UNUSED_RELAY(x) UNUSED__ ## x __attribute__((unused))
#endif
#ifdef XWFEATURE_BLUETOOTH
# define XP_UNUSED_BT(x) x
#else
# define XP_UNUSED_BT(x) UNUSED__ ## x __attribute__((unused))
#endif
#endif

View file

@ -141,7 +141,7 @@ typedef struct UtilVtable {
XP_Bool (*m_util_warnIllegalWord)( XW_UtilCtxt* uc, BadWordInfo* bwi,
XP_U16 turn, XP_Bool turnLost );
#ifdef BEYOND_IR
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
void (*m_util_addrChange)( XW_UtilCtxt* uc, const CommsAddrRec* oldAddr,
const CommsAddrRec* newAddr );
#endif
@ -220,7 +220,7 @@ struct XW_UtilCtxt {
#define util_warnIllegalWord( uc, w, p, b ) \
(uc)->vtable->m_util_warnIllegalWord((uc),(w),(p),(b))
#ifdef BEYOND_IR
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
#define util_addrChange( uc, addro, addrn ) \
(uc)->vtable->m_util_addrChange((uc), (addro), (addrn))
#endif

View file

@ -57,10 +57,11 @@ DEFINES += -DXWFEATURE_SEARCHLIMIT
endif
DEFINES += -DFEATURE_TRAY_EDIT
#DEFINES += -DDRAW_WITH_PRIMITIVES
DEFINES += -DBEYOND_IR
# Bluetooth support
# DEFINES += -DXWFEATURE_IR
DEFINES += -DXWFEATURE_BLUETOOTH
# DEFINES += -DXWFEATURE_RELAY
# Let users pick the tiles going into their trays
#DEFINES += -DFEATURE_TRAY_EDIT

View file

@ -220,6 +220,7 @@ curses_util_engineProgressCallback( XW_UtilCtxt* XP_UNUSED(uc) )
return XP_TRUE;
} /* curses_util_engineProgressCallback */
#ifdef XWFEATURE_RELAY
static void
curses_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why, XP_U16 when,
TimerProc proc, void* closure )
@ -232,6 +233,7 @@ curses_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why, XP_U16 when,
globals->cGlobals.timerClosures[why] = closure;
globals->nextTimer = util_getCurSeconds(uc) + when;
} /* curses_util_setTimer */
#endif
static void
curses_util_requestTime( XW_UtilCtxt* uc )
@ -650,10 +652,10 @@ curses_socket_acceptor( int listener, Acceptor func, CommonGlobals* cGlobals )
}
static int
figureTimeout( CursesAppGlobals* globals )
figureTimeout( CursesAppGlobals* XP_UNUSED_RELAY(globals) )
{
int result = INFINITE_TIMEOUT;
#ifdef XWFEATURE_RELAY
if ( globals->cGlobals.timerProcs[TIMER_HEARTBEAT] != 0 ) {
XP_U32 now = util_getCurSeconds( globals->cGlobals.params->util );
XP_U32 then = globals->nextTimer;
@ -663,7 +665,7 @@ figureTimeout( CursesAppGlobals* globals )
result = (then - now) * 1000;
}
}
#endif
return result;
} /* figureTimeout */
@ -682,9 +684,11 @@ blocking_gotEvent( CursesAppGlobals* globals, int* ch )
numEvents = poll( globals->fdArray, globals->fdCount, timeout );
if ( timeout != INFINITE_TIMEOUT && numEvents == 0 ) {
#ifdef XWFEATURE_RELAY
if ( !globals->cGlobals.params->noHeartbeat ) {
linuxFireTimer( &globals->cGlobals, TIMER_HEARTBEAT );
}
#endif
} else if ( numEvents > 0 ) {
/* stdin first */
@ -722,12 +726,19 @@ blocking_gotEvent( CursesAppGlobals* globals, int* ch )
globals );
} else {
/* It's a normal data socket */
if ( globals->cGlobals.params->conType == COMMS_CONN_RELAY ) {
if ( 0 ) {
#ifdef XWFEATURE_RELAY
} else if ( globals->cGlobals.params->conType
== COMMS_CONN_RELAY ) {
nBytes = linux_relay_receive( &globals->cGlobals, buf,
sizeof(buf) );
} else if ( globals->cGlobals.params->conType == COMMS_CONN_BT ) {
#endif
#ifdef XWFEATURE_BLUETOOTH
} else if ( globals->cGlobals.params->conType
== COMMS_CONN_BT ) {
nBytes = linux_bt_receive( globals->fdArray[fdIndex].fd,
buf, sizeof(buf) );
#endif
} else {
XP_ASSERT( 0 );
}
@ -898,7 +909,9 @@ setupCursesUtilCallbacks( CursesAppGlobals* globals, XW_UtilCtxt* util )
util->vtable->m_util_hiliteCell = curses_util_hiliteCell;
util->vtable->m_util_engineProgressCallback =
curses_util_engineProgressCallback;
#ifdef XWFEATURE_RELAY
util->vtable->m_util_setTimer = curses_util_setTimer;
#endif
util->vtable->m_util_requestTime = curses_util_requestTime;
util->closure = globals;
@ -962,11 +975,12 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
setupCursesUtilCallbacks( &globals, params->util );
#ifdef XWFEATURE_RELAY
if ( params->conType == COMMS_CONN_RELAY ) {
globals.cGlobals.defaultServerName
= params->connInfo.relay.relayName;
}
#endif
cursesListenOnSocket( &globals, 0 ); /* stdin */
piperesult = pipe( globals.timepipe );
@ -987,7 +1001,9 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
if ( globals.cGlobals.game.comms ) {
CommsAddrRec addr;
if ( params->conType == COMMS_CONN_RELAY ) {
if ( 0 ) {
#ifdef XWFEATURE_RELAY
} else if ( params->conType == COMMS_CONN_RELAY ) {
addr.conType = COMMS_CONN_RELAY;
addr.u.ip_relay.ipAddr = 0; /* ??? */
addr.u.ip_relay.port = params->connInfo.relay.defaultSendPort;
@ -995,12 +1011,15 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
sizeof(addr.u.ip_relay.hostName) - 1 );
XP_STRNCPY( addr.u.ip_relay.cookie, params->connInfo.relay.cookie,
sizeof(addr.u.ip_relay.cookie) - 1 );
#endif
#ifdef XWFEATURE_BLUETOOTH
} else if ( params->conType == COMMS_CONN_BT ) {
addr.conType = COMMS_CONN_BT;
XP_ASSERT( sizeof(addr.u.bt.btAddr)
>= sizeof(params->connInfo.bt.hostAddr));
XP_MEMCPY( &addr.u.bt.btAddr, &params->connInfo.bt.hostAddr,
sizeof(params->connInfo.bt.hostAddr) );
#endif
}
comms_setAddr( globals.cGlobals.game.comms, &addr );
}

View file

@ -260,11 +260,13 @@ createOrLoadObjects( GtkAppGlobals* globals )
gameID = (XP_U16)util_getCurSeconds( globals->cGlobals.params->util );
#ifdef XWFEATURE_RELAY
if ( addr.conType == COMMS_CONN_RELAY ) {
XP_ASSERT( !!params->connInfo.relay.relayName );
globals->cGlobals.defaultServerName
= params->connInfo.relay.relayName;
}
#endif
params->gi.gameID = util_getCurSeconds(globals->cGlobals.params->util);
XP_STATUSF( "grabbed gameID: %ld\n", params->gi.gameID );
@ -274,18 +276,23 @@ createOrLoadObjects( GtkAppGlobals* globals )
gameID, &globals->cp, linux_send, globals );
addr.conType = params->conType;
if ( addr.conType == COMMS_CONN_RELAY ) {
if ( 0 ) {
#ifdef XWFEATURE_RELAY
} else if ( addr.conType == COMMS_CONN_RELAY ) {
addr.u.ip_relay.ipAddr = 0;
addr.u.ip_relay.port = params->connInfo.relay.defaultSendPort;
XP_STRNCPY( addr.u.ip_relay.hostName, params->connInfo.relay.relayName,
sizeof(addr.u.ip_relay.hostName) - 1 );
XP_STRNCPY( addr.u.ip_relay.cookie, params->connInfo.relay.cookie,
sizeof(addr.u.ip_relay.cookie) - 1 );
#endif
#ifdef XWFEATURE_BLUETOOTH
} else if ( addr.conType == COMMS_CONN_BT ) {
XP_ASSERT( sizeof(addr.u.bt.btAddr)
>= sizeof(params->connInfo.bt.hostAddr));
XP_MEMCPY( &addr.u.bt.btAddr, &params->connInfo.bt.hostAddr,
sizeof(params->connInfo.bt.hostAddr) );
#endif
}
/* This may trigger network activity */
@ -477,8 +484,9 @@ quit( void* XP_UNUSED(dunno), GtkAppGlobals* globals )
game_dispose( &globals->cGlobals.game ); /* takes care of the dict */
gi_disposePlayerInfo( MEMPOOL &globals->cGlobals.params->gi );
#ifdef XWFEATURE_BLUETOOTH
linux_bt_close( &globals->cGlobals );
#endif
vtmgr_destroy( MEMPOOL globals->cGlobals.params->vtMgr );
mpool_destroy( globals->cGlobals.params->util->mpool );
@ -1124,6 +1132,7 @@ score_timer_func( gpointer data )
return XP_FALSE;
} /* score_timer_func */
#ifdef XWFEATURE_RELAY
static gint
heartbeat_timer_func( gpointer data )
{
@ -1135,9 +1144,11 @@ heartbeat_timer_func( gpointer data )
return (gint)0;
}
#endif
static void
gtk_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why, XP_U16 when,
gtk_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why,
XP_U16 XP_UNUSED_RELAY(when),
TimerProc proc, void* closure )
{
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
@ -1156,8 +1167,10 @@ gtk_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why, XP_U16 when,
(void)gettimeofday( &globals->scoreTv, NULL );
newSrc = g_timeout_add( 1000, score_timer_func, globals );
#ifdef XWFEATURE_RELAY
} else if ( why == TIMER_HEARTBEAT ) {
newSrc = g_timeout_add( 1000 * when, heartbeat_timer_func, globals );
#endif
} else {
XP_ASSERT( 0 );
}
@ -1495,11 +1508,16 @@ newConnectionInput( GIOChannel *source,
ssize_t nRead;
unsigned char buf[512];
if ( globals->cGlobals.params->conType == COMMS_CONN_RELAY ) {
if ( 0 ) {
#ifdef XWFEATURE_RELAY
} else if ( globals->cGlobals.params->conType == COMMS_CONN_RELAY ) {
nRead = linux_relay_receive( &globals->cGlobals,
buf, sizeof(buf) );
#endif
#ifdef XWFEATURE_BLUETOOTH
} else if ( globals->cGlobals.params->conType == COMMS_CONN_BT ) {
nRead = linux_bt_receive( sock, buf, sizeof(buf) );
#endif
} else {
XP_ASSERT( 0 );
}

View file

@ -234,7 +234,9 @@ usage( char* appName, char* msg )
"\t [-S] # slow robot down \n"
"\t [-i] # print game history when game over\n"
"\t [-U] # call 'Undo' after game ends\n"
#ifdef XWFEATURE_RELAY
"\t [-H] # Don't send heartbeats to relay\n"
#endif
"\t [-r name]* # same-process robot\n"
"\t [-n name]* # same-process player (no network used)\n"
"\t [-w pwd]* # passwd for matching local player\n"
@ -251,90 +253,41 @@ usage( char* appName, char* msg )
"\t -d xwd_file # provides tile counts & values\n"
"\t\t # list each player as local or remote\n"
"\t [-N]* # remote client (listen for connection)\n"
#ifdef XWFEATURE_RELAY
"\t [-p relay_port] # relay is at this port\n"
"\t [-a relay_addr] # use relay (via port spec'd above)\n"
"" " (default localhost)\n"
#endif
#ifdef XWFEATURE_BLUETOOTH
"\t [-B n:name|a:00:11:22:33:44:55]\n"
"\t\t\t# connect via bluetooth [param ignored if -s]\n"
#endif
/* "# --------------- OR client-only ----------\n" */
/* "\t [-p client_port] # must != server's port if on same device" */
"\nexample: \n"
"\tserver: ./xwords -d dict.xwd -s -a localhost -p 10999 -r Eric -N\n"
"\tclient: ./xwords -d dict.xwd -a localhost -p 10999 -r Kati\n"
"\tserver: ./xwords -d dict.xwd -s -r Eric -N"
#ifdef XWFEATURE_RELAY
" -a localhost -p 10999"
#endif
#ifdef XWFEATURE_BLUETOOTH
" -B ignored "
#endif
"\n"
"\tclient: ./xwords -d dict.xwd -r Kati"
#ifdef XWFEATURE_RELAY
" -a localhost -p 10999"
#endif
#ifdef XWFEATURE_BLUETOOTH
" -B a:11:22:33:44:55:66 | n:my_treo "
#endif
"\n"
, appName );
fprintf( stderr, "\n(revision: %s)\n", SVN_REV);
exit(1);
}
} /* usage */
static XP_S16
linux_tcp_send( const XP_U8* buf, XP_U16 buflen,
const CommsAddrRec* XP_UNUSED(addrRec),
CommonGlobals* globals )
{
XP_S16 result = 0;
int socket = globals->socket;
if ( socket == -1 ) {
XP_STATUSF( "linux_tcp_send: socket uninitialized" );
socket = linux_init_relay_socket( globals );
if ( socket != -1 ) {
assert( globals->socket == socket );
(*globals->socketChanged)( globals->socketChangedClosure,
-1, socket );
}
}
if ( socket != -1 ) {
XP_U16 netLen = htons( buflen );
errno = 0;
result = send( socket, &netLen, sizeof(netLen), 0 );
if ( result == sizeof(netLen) ) {
result = send( socket, buf, buflen, 0 );
}
if ( result <= 0 ) {
XP_STATUSF( "closing non-functional socket" );
close( socket );
(*globals->socketChanged)( globals->socketChangedClosure,
socket, -1 );
globals->socket = -1;
}
XP_STATUSF( "linux_tcp_send: send returned %d of %d (err=%d)",
result, buflen, errno );
}
return result;
} /* linux_tcp_send */
XP_S16
linux_send( const XP_U8* buf, XP_U16 buflen,
const CommsAddrRec* addrRec,
void* closure )
{
XP_S16 nSent = -1;
CommonGlobals* globals = (CommonGlobals*)closure;
CommsConnType conType;
if ( !!addrRec ) {
conType = addrRec->conType;
} else {
conType = globals->params->conType;
}
if ( conType == COMMS_CONN_RELAY ) {
nSent = linux_tcp_send( buf, buflen, addrRec, globals );
} else if ( conType == COMMS_CONN_BT ) {
XP_Bool isServer = comms_getIsServer( globals->game.comms );
linux_bt_open( globals, isServer );
nSent = linux_bt_send( buf, buflen, addrRec, globals );
} else {
XP_ASSERT(0);
}
return nSent;
} /* linux_send */
int
#ifdef XWFEATURE_RELAY
static int
linux_init_relay_socket( CommonGlobals* cGlobals )
{
struct sockaddr_in to_sock;
@ -379,6 +332,80 @@ linux_init_relay_socket( CommonGlobals* cGlobals )
return sock;
} /* linux_init_relay_socket */
static XP_S16
linux_tcp_send( const XP_U8* buf, XP_U16 buflen,
const CommsAddrRec* XP_UNUSED(addrRec),
CommonGlobals* globals )
{
XP_S16 result = 0;
int socket = globals->socket;
if ( socket == -1 ) {
XP_STATUSF( "linux_tcp_send: socket uninitialized" );
socket = linux_init_relay_socket( globals );
if ( socket != -1 ) {
assert( globals->socket == socket );
(*globals->socketChanged)( globals->socketChangedClosure,
-1, socket );
}
}
if ( socket != -1 ) {
XP_U16 netLen = htons( buflen );
errno = 0;
result = send( socket, &netLen, sizeof(netLen), 0 );
if ( result == sizeof(netLen) ) {
result = send( socket, buf, buflen, 0 );
}
if ( result <= 0 ) {
XP_STATUSF( "closing non-functional socket" );
close( socket );
(*globals->socketChanged)( globals->socketChangedClosure,
socket, -1 );
globals->socket = -1;
}
XP_STATUSF( "linux_tcp_send: send returned %d of %d (err=%d)",
result, buflen, errno );
}
return result;
} /* linux_tcp_send */
#endif
XP_S16
linux_send( const XP_U8* buf, XP_U16 buflen,
const CommsAddrRec* addrRec,
void* closure )
{
XP_S16 nSent = -1;
CommonGlobals* globals = (CommonGlobals*)closure;
CommsConnType conType;
if ( !!addrRec ) {
conType = addrRec->conType;
} else {
conType = globals->params->conType;
}
if ( 0 ) {
#ifdef XWFEATURE_RELAY
} else if ( conType == COMMS_CONN_RELAY ) {
nSent = linux_tcp_send( buf, buflen, addrRec, globals );
#endif
#ifdef XWFEATURE_BLUETOOTH
} else if ( conType == COMMS_CONN_BT ) {
XP_Bool isServer = comms_getIsServer( globals->game.comms );
linux_bt_open( globals, isServer );
nSent = linux_bt_send( buf, buflen, addrRec, globals );
#endif
} else {
XP_ASSERT(0);
}
return nSent;
} /* linux_send */
static void
linux_close_socket( CommonGlobals* cGlobals )
{
@ -591,16 +618,19 @@ linux_util_getUserString( XW_UtilCtxt* XP_UNUSED(uc), XP_U16 code )
}
} /* linux_util_getUserString */
#ifdef BEYOND_IR
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
static void
linux_util_addrChange( XW_UtilCtxt* uc,
linux_util_addrChange( XW_UtilCtxt* XP_UNUSED_BT(uc),
const CommsAddrRec* XP_UNUSED(oldAddr),
const CommsAddrRec* newAddr )
const CommsAddrRec* XP_UNUSED_BT(newAddr) )
{
if ( newAddr->conType == COMMS_CONN_BT ) {
if ( 0 ) {
#ifdef XWFEATURE_BLUETOOTH
} else if ( newAddr->conType == COMMS_CONN_BT ) {
CommonGlobals* cGlobals = (CommonGlobals*)uc->closure;
XP_Bool isServer = comms_getIsServer( cGlobals->game.comms );
linux_bt_open( cGlobals, isServer );
#endif
}
}
#endif
@ -618,6 +648,7 @@ defaultRandomSeed()
} /* defaultRandomSeed */
/* This belongs in linuxbt.c */
#ifdef XWFEATURE_BLUETOOTH
static XP_Bool
nameToBtAddr( const char* name, bdaddr_t* ba )
{
@ -650,6 +681,7 @@ nameToBtAddr( const char* name, bdaddr_t* ba )
}
return success;
} /* nameToBtAddr */
#endif
int
main( int argc, char** argv )
@ -665,7 +697,9 @@ main( int argc, char** argv )
XP_U16 robotCount = 0;
CommsConnType conType = COMMS_CONN_UNUSED;
#ifdef XWFEATURE_BLUETOOTH
const char* btaddr = NULL;
#endif
XP_LOGF( "main started: pid = %d", getpid() );
@ -693,9 +727,11 @@ main( int argc, char** argv )
/* (void)fgetc( stdin ); */
/* defaults */
#ifdef XWFEATURE_RELAY
mainParams.connInfo.relay.defaultListenPort = DEFAULT_LISTEN_PORT;
mainParams.connInfo.relay.defaultSendPort = DEFAULT_SEND_PORT;
mainParams.connInfo.relay.cookie = "COOKIE";
#endif
mainParams.gi.boardSize = 15;
mainParams.quitAfter = XP_FALSE;
mainParams.sleepOnAnchor = XP_FALSE;
@ -727,7 +763,14 @@ main( int argc, char** argv )
#if defined PLATFORM_GTK
"h:"
#endif
"kKf:l:n:Nsd:a:p:e:r:b:qw:Sit:HUmvcC:B:" );
"kKf:l:n:Nsd:e:r:b:qw:Sit:Umvc"
#ifdef XWFEATURE_RELAY
"a:p:C:H"
#endif
#ifdef XWFEATURE_BLUETOOTH
"B:"
#endif
);
switch( opt ) {
case '?':
usage(argv[0], NULL);
@ -735,12 +778,14 @@ main( int argc, char** argv )
case 'c':
mainParams.showRobotScores = XP_TRUE;
break;
#ifdef XWFEATURE_RELAY
case 'C':
XP_ASSERT( conType == COMMS_CONN_UNUSED ||
conType == COMMS_CONN_RELAY );
mainParams.connInfo.relay.cookie = optarg;
conType = COMMS_CONN_RELAY;
break;
#endif
case 'd':
mainParams.gi.dictName = copyString( mainParams.util->mpool,
(XP_UCHAR*)optarg );
@ -821,12 +866,14 @@ main( int argc, char** argv )
case 'b':
mainParams.gi.boardSize = atoi(optarg);
break;
#ifdef XWFEATURE_BLUETOOTH
case 'B':
XP_ASSERT( conType == COMMS_CONN_UNUSED ||
conType == COMMS_CONN_BT );
conType = COMMS_CONN_BT;
btaddr = optarg;
break;
#endif
case 'v':
mainParams.verticalScore = XP_TRUE;
break;
@ -895,7 +942,9 @@ main( int argc, char** argv )
}
}
if ( conType == COMMS_CONN_RELAY ) {
if ( 0 ) {
#ifdef XWFEATURE_RELAY
} else if ( conType == COMMS_CONN_RELAY ) {
mainParams.connInfo.relay.relayName = relayName;
/* convert strings to whatever */
@ -903,6 +952,8 @@ main( int argc, char** argv )
mainParams.connInfo.relay.defaultSendPort =
atoi( sendPortNumString );
}
#endif
#ifdef XWFEATURE_BLUETOOTH
} else if ( conType == COMMS_CONN_BT ) {
bdaddr_t ba;
XP_Bool success;
@ -929,6 +980,7 @@ main( int argc, char** argv )
}
XP_MEMCPY( &mainParams.connInfo.bt.hostAddr, &ba,
sizeof(mainParams.connInfo.bt.hostAddr) );
#endif
}
mainParams.conType = conType;
@ -948,7 +1000,7 @@ main( int argc, char** argv )
linux_util_getCurSeconds;
mainParams.util->vtable->m_util_getUserString =
linux_util_getUserString;
#ifdef BEYOND_IR
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
mainParams.util->vtable->m_util_addrChange = linux_util_addrChange;
#endif

View file

@ -39,7 +39,6 @@ DictionaryCtxt* linux_dictionary_make( MPFORMAL const char* dictFileName );
int initListenerSocket( int port );
XP_S16 linux_send( const XP_U8* buf, XP_U16 buflen,
const CommsAddrRec* addrRec, void* closure );
int linux_init_relay_socket( CommonGlobals* cGlobals );
int linux_relay_receive( CommonGlobals* cGlobals, unsigned char* buf,
int bufSize );

View file

@ -63,15 +63,19 @@ typedef struct LaunchParams {
CommsConnType conType;
union {
#ifdef XWFEATURE_RELAY
struct {
char* relayName;
char* cookie;
short defaultSendPort;
short defaultListenPort;
} relay;
#endif
#ifdef XWFEATURE_BLUETOOTH
struct {
bdaddr_t hostAddr; /* unused if a host */
} bt;
#endif
} connInfo;
union {

View file

@ -114,13 +114,16 @@ MYDEFS_COMMON += -DXWFEATURE_SEARCHLIMIT
# Turn on network play over IP via cellular modem. Very much
# experimental at this point!
# MYDEFS_COMMON += -DBEYOND_IR
# MYDEFS_COMMON += -DXWFEATURE_RELAY
# turn on bluetooth comms option for 68K and ARM -- which won't work yet
# MYDEFS_COMMON += -DXWFEATURE_BLUETOOTH
# BLUETOOTH = -DXWFEATURE_BLUETOOTH
#MYDEFS_COMMON += $(BLUETOOTH)
# Add menu allowing to choose to run 68K or ARM
# ifdef DEBUG
# MYDEFS_COMMON += -DFEATURE_DUALCHOOSE
# endif
# For Danish and perhaps other languages, custom-measure glyph height
# so that overtall letters have a chance of fitting.
@ -144,8 +147,8 @@ endif
MYDEFS_ARM = -D__LITTLE_ENDIAN -DXW_TARGET_PNO $(MYDEFS_COMMON)
MYDEFS_68K = -DPLATFORM_PALM -D__BIG_ENDIAN $(MYDEFS_COMMON) \
-DAPPNAME=\"$(APPNAME)\" \
$(BLUETOOTH)
# -DXWFEATURE_BLUETOOTH
BITMAP_RSRCS = \
$(BITMAPS)/rightarrow.pbitm \

View file

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef BEYOND_IR
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
#include <NetMgr.h>
@ -61,11 +61,13 @@ strFromField( XP_U16 id, XP_UCHAR* buf, XP_U16 max )
static void
ctlsFromState( PalmAppGlobals* XP_UNUSED_BT(globals), ConnsDlgState* state )
{
XP_Bool isNewGame = state->isNewGame;
XP_UCHAR buf[16];
CommsAddrRec* addr = state->addr;
if ( addr->conType == COMMS_CONN_RELAY ) {
if ( 0 ) {
#ifdef XWFEATURE_RELAY
} else if ( addr->conType == COMMS_CONN_RELAY ) {
XP_Bool isNewGame = state->isNewGame;
XP_UCHAR buf[16];
setFieldStr( XW_CONNS_RELAY_FIELD_ID, addr->u.ip_relay.hostName );
setFieldEditable( XW_CONNS_RELAY_FIELD_ID, isNewGame );
@ -75,6 +77,7 @@ ctlsFromState( PalmAppGlobals* XP_UNUSED_BT(globals), ConnsDlgState* state )
setFieldStr( XW_CONNS_COOKIE_FIELD_ID, addr->u.ip_relay.cookie );
setFieldEditable( XW_CONNS_COOKIE_FIELD_ID, isNewGame );
#endif
#ifdef XWFEATURE_BLUETOOTH
} else if ( addr->conType == COMMS_CONN_BT
&& state->serverRole == SERVER_ISCLIENT ) {
@ -93,10 +96,12 @@ static XP_Bool
stateFromCtls( ConnsDlgState* state )
{
XP_Bool ok = XP_TRUE;
XP_UCHAR buf[16];
CommsAddrRec* addr = state->addr;
if ( addr->conType == COMMS_CONN_RELAY ) {
if ( 0 ) {
#ifdef XWFEATURE_RELAY
} else if ( addr->conType == COMMS_CONN_RELAY ) {
XP_UCHAR buf[16];
strFromField( XW_CONNS_RELAY_FIELD_ID, addr->u.ip_relay.hostName,
sizeof(addr->u.ip_relay.hostName) );
@ -105,6 +110,7 @@ stateFromCtls( ConnsDlgState* state )
strFromField( XW_CONNS_COOKIE_FIELD_ID, addr->u.ip_relay.cookie,
sizeof(addr->u.ip_relay.cookie) );
#endif
#ifdef XWFEATURE_BLUETOOTH
} else if ( addr->conType == COMMS_CONN_BT
&& state->serverRole == SERVER_ISCLIENT ) {
@ -125,11 +131,13 @@ updateFormCtls( FormPtr form, ConnsDlgState* state )
{
const XP_U16 relayCtls[] = {
XW_CONNS_RELAY_LABEL_ID ,
#ifdef XWFEATURE_RELAY
XW_CONNS_RELAY_FIELD_ID,
XW_CONNS_PORT_LABEL_ID,
XW_CONNS_PORT_FIELD_ID,
XW_CONNS_COOKIE_LABEL_ID,
XW_CONNS_COOKIE_FIELD_ID,
#endif
0
};
const XP_U16 btGuestCtls[] = {
@ -316,4 +324,4 @@ ConnsFormHandleEvent( EventPtr event )
return result;
} /* ConnsFormHandleEvent */
#endif /* BEYOND_IR */
#endif /* #if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY */

View file

@ -208,7 +208,7 @@ SysUIAppSwitch
FntBaseLine
WinSetScalingMode
WinGetDrawWindow
############ These only needed if BEYOND_IR defined
############ These only needed if XWFEATURE_RELAY defined
NetLibOpen
NetLibSocketOpen
NetLibClose

View file

@ -227,7 +227,7 @@ BEGIN
BUTTON "Cancel" XW_CANCEL_BUTTON_ID RIGHT@PREVLEFT-5 PREVTOP 30 AUTO
END /* FORM XW_PLAYERINFO_FORM */
#ifdef BEYOND_IR
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH || defined XWFEATURE_IR
#define LEFTCOL 4
#define CONNS_FIELD_LEFT 70
#define LOCALIP_TOP 30
@ -242,7 +242,7 @@ BEGIN
POPUPTRIGGER "" ID XW_CONNS_TYPE_TRIGGER_ID
AT (PREVRIGHT+5 PREVTOP 72 12) LEFTANCHOR
LIST
"Bluetooth" "Beaming" "Internet/IP" ID XW_CONNS_TYPE_LIST_ID
"Bluetooth" "Beaming" "Internet" ID XW_CONNS_TYPE_LIST_ID
PREVLEFT PREVTOP 72 12 VISIBLEITEMS 3
NONUSABLE POPUPLIST XW_CONNS_TYPE_TRIGGER_ID XW_CONNS_TYPE_LIST_ID
@ -259,6 +259,7 @@ BEGIN
AUTO AUTO NONUSABLE
/* Relay... */
#ifdef XWFEATURE_RELAY
LABEL "Relay name:" XW_CONNS_RELAY_LABEL_ID
AT ( LEFTCOL+10 LOCALIP_TOP )
FIELD XW_CONNS_RELAY_FIELD_ID CONNS_FIELD_LEFT PREVTOP 70 AUTO \
@ -273,8 +274,12 @@ BEGIN
AT ( LEFTCOL+10 PREVBOTTOM + 2 )
FIELD XW_CONNS_COOKIE_FIELD_ID CONNS_FIELD_LEFT PREVTOP 70 AUTO \
SINGLELINE EDITABLE UNDERLINED MAXCHARS 32
#else
LABEL "Relay feature disabled" XW_CONNS_RELAY_LABEL_ID
AT ( LEFTCOL+10 LOCALIP_TOP )
#endif
BUTTON "Cancel" XW_CONNS_CANCEL_BUTTON_ID 42 PREVBOTTOM+6 AUTO AUTO
BUTTON "Cancel" XW_CONNS_CANCEL_BUTTON_ID 42 75 AUTO AUTO
BUTTON "Ok" XW_CONNS_OK_BUTTON_ID PREVRIGHT+10 PREVTOP AUTO AUTO
END /* XW_CONNS_FORM */
#endif

View file

@ -149,7 +149,7 @@ newGameHandleEvent( EventPtr event )
result = true;
break;
#ifdef BEYOND_IR
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
case connsSettingChgEvent:
XP_ASSERT( globals->isNewGame );
state->connsSettingChanged = XP_TRUE;
@ -573,7 +573,7 @@ changeGadgetHilite( PalmAppGlobals* globals, UInt16 hiliteID )
}
}
#ifdef BEYOND_IR
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
/* Even if it didn't change, pop the connections form. It's only
informational in the non-new-game case; nothing can be changed. */
if ( hiliteID != SERVER_STANDALONE ) {
@ -935,7 +935,7 @@ loadNewGameState( PalmAppGlobals* globals )
globals );
newg_load( state->ngc, gi );
#ifdef BEYOND_IR
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
if ( globals->game.comms ) {
comms_getAddr( globals->game.comms, &state->addr );
} else {

View file

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
#include <TimeMgr.h>

View file

@ -121,7 +121,7 @@ static XWStreamCtxt* palm_util_makeStreamFromAddr( XW_UtilCtxt* uc,
static XP_UCHAR* palm_util_getUserString( XW_UtilCtxt* uc, XP_U16 stringCode );
static XP_Bool palm_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi,
XP_U16 turn, XP_Bool turnLost );
#ifdef BEYOND_IR
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
static void palm_util_addrChange( XW_UtilCtxt* uc, const CommsAddrRec* oldAddr,
const CommsAddrRec* newAddr );
#endif
@ -601,7 +601,7 @@ initUtilFuncs( PalmAppGlobals* globals )
#endif
vtable->m_util_getUserString = palm_util_getUserString;
vtable->m_util_warnIllegalWord = palm_util_warnIllegalWord;
#ifdef BEYOND_IR
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
vtable->m_util_addrChange = palm_util_addrChange;
#endif
#ifdef XWFEATURE_SEARCHLIMIT
@ -1034,7 +1034,7 @@ startApplication( PalmAppGlobals** globalsP )
return XP_FALSE;
}
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
palm_ip_setup( globals );
#endif
@ -1206,10 +1206,8 @@ stopApplication( PalmAppGlobals* globals )
game_dispose( &globals->game );
gi_disposePlayerInfo( MEMPOOL &globals->gameInfo );
#ifdef XWFEATURE_IR
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
palm_ip_close( globals );
#endif
#endif
if ( !!globals->dictList ) {
@ -1257,7 +1255,7 @@ figureWaitTicks( PalmAppGlobals* globals )
XWTimerReason why;
if ( 0 ) {
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
} else if ( ipSocketIsOpen(globals) ) {
/* we'll do our sleeping in NetLibSelect */
result = 0;
@ -1321,7 +1319,7 @@ eventLoop( PalmAppGlobals* globals )
EventType event;
do {
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
if ( !!globals->game.comms
&& (comms_getConType(globals->game.comms) == COMMS_CONN_RELAY) ) {
checkHandleNetEvents( globals );
@ -1393,7 +1391,7 @@ applicationHandleEvent( EventPtr event )
case XW_PREFS_FORM:
handler = PrefsFormHandleEvent;
break;
#ifdef BEYOND_IR
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
case XW_CONNS_FORM:
handler = ConnsFormHandleEvent;
break;
@ -1467,25 +1465,24 @@ timeForTimer( PalmAppGlobals* globals, XWTimerReason* why, XP_U32* when )
static void
showBTState( PalmAppGlobals* globals )
{
char ch[] = { ' ', ' ' };
if ( COMMS_CONN_BT == comms_getConType( globals->game.comms ) ) {
char ch = 'x';
switch( globals->btUIState ) {
case BTUI_NONE:
/* ch = 'x'; */ break;
ch[0] = 'x'; break;
case BTUI_LISTENING:
ch = 'L'; break;
ch[0] = 'L'; break;
case BTUI_CONNECTING:
ch = 'c'; break;
ch[0] = 'c'; break;
case BTUI_CONNECTED:
ch = 'C'; break;
ch[0] = 'C'; break;
case BTUI_SERVING:
ch = 'S'; break;
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, 1, 160-7, 160-27 );
}
/* 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 );
} /* showBTState */
#endif
@ -1823,7 +1820,7 @@ initAndStartBoard( PalmAppGlobals* globals, XP_Bool newGame )
game_reset( MEMPOOL &globals->game, &globals->gameInfo,
&globals->util, newGameID, &globals->gState.cp,
palm_send, globals );
#ifdef BEYOND_IR
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
if ( !!globals->game.comms ) {
comms_setAddr( globals->game.comms,
&globals->newGameState.addr );
@ -3138,7 +3135,7 @@ palm_util_userError( XW_UtilCtxt* uc, UtilErrID id )
strID = STR_CANT_UNDO_TILEASSIGN;
break;
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
case ERR_RELAY_BASE + XWRELAY_ERROR_TIMEOUT:
strID = STR_RELAY_TIMEOUT;
break;
@ -3330,7 +3327,7 @@ palm_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why,
now += PALM_TIMER_DELAY;
} else if ( why == TIMER_TIMERTICK ) {
now += SysTicksPerSecond();
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
} else if ( why == TIMER_HEARTBEAT ) {
now += (secsFromNow * SysTicksPerSecond());
#endif
@ -3399,15 +3396,18 @@ palm_send( const XP_U8* buf, XP_U16 len,
{
PalmAppGlobals* globals = (PalmAppGlobals*)closure;
#ifdef BEYOND_IR
XP_S16 result = 0;
switch( comms_getConType( globals->game.comms ) ) {
#ifdef XWFEATURE_IR
case COMMS_CONN_IR:
result = palm_ir_send( buf, len, globals );
break;
#endif
#ifdef XWFEATURE_RELAY
case COMMS_CONN_RELAY:
result = palm_ip_send( buf, len, addr, globals );
break;
#endif
#ifdef XWFEATURE_BLUETOOTH
case COMMS_CONN_BT:
result = palm_bt_send( buf, len, addr, btDataHandler, globals );
@ -3417,9 +3417,6 @@ palm_send( const XP_U8* buf, XP_U16 len,
XP_ASSERT(0);
}
return result;
#else
return palm_ir_send( buf, len, globals );
#endif
} /* palm_send */
void
@ -3480,7 +3477,6 @@ palm_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi,
return result;
} /* palm_util_warnIllegalWord */
#ifdef BEYOND_IR
#ifdef XWFEATURE_BLUETOOTH
static void
btDataHandler( PalmAppGlobals* globals, const CommsAddrRec* fromAddr,
@ -3495,28 +3491,33 @@ btDataHandler( PalmAppGlobals* globals, const CommsAddrRec* fromAddr,
}
#endif
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
static void
palm_util_addrChange( XW_UtilCtxt* uc, const CommsAddrRec* oldAddr,
const CommsAddrRec* newAddr )
{
PalmAppGlobals* globals = (PalmAppGlobals*)uc->closure;
#ifdef XWFEATURE_BLUETOOTH
# ifdef XWFEATURE_BLUETOOTH
XP_Bool isBT = COMMS_CONN_BT == newAddr->conType;
if ( !isBT ) {
palm_bt_close( globals );
showBTState( globals );
}
#endif
# endif
if ( COMMS_CONN_RELAY == newAddr->conType ) {
if ( 0 ) {
# ifdef XWFEATURE_RELAY
} else if ( COMMS_CONN_RELAY == newAddr->conType ) {
ip_addr_change( globals, oldAddr, newAddr );
#ifdef XWFEATURE_BLUETOOTH
# endif
# ifdef XWFEATURE_BLUETOOTH
} else if ( isBT ) {
palm_bt_init( globals, btDataHandler );
#endif
# endif
}
}
#endif
#endif /* #if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY */
#ifdef XWFEATURE_SEARCHLIMIT
static XP_Bool

View file

@ -30,7 +30,7 @@
#include <List.h>
#include <Form.h>
#include <IrLib.h>
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
# include <NetMgr.h>
#endif
@ -206,7 +206,7 @@ typedef struct PalmNewGameState {
XP_Bool forwardChange;
Connectedness curServerHilite;
#ifdef BEYOND_IR
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
CommsAddrRec addr;
XP_Bool connsSettingChanged;
#endif
@ -214,7 +214,7 @@ typedef struct PalmNewGameState {
typedef struct PalmDictList PalmDictList;
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
typedef struct NetLibStuff {
UInt16 netLibRef;
NetSocketRef socket;
@ -261,7 +261,7 @@ struct PalmAppGlobals {
DmOpenRef gamesDBP;
LocalID gamesDBID;
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
UInt16 exgLibraryRef; /* what library did user choose for sending? */
#endif
@ -316,13 +316,14 @@ struct PalmAppGlobals {
void* timerClosures[NUM_TIMERS_PLUS_ONE];
XP_U32 timerFireAt[NUM_TIMERS_PLUS_ONE];
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
NetLibStuff nlStuff;
XP_U32 heartTimerFireAt;
# ifdef XWFEATURE_BLUETOOTH
#endif
#ifdef XWFEATURE_BLUETOOTH
struct PalmBTStuff* btStuff;
BtUIState btUIState; /* For showing user what's up */
# endif
#endif
#ifdef DEBUG
@ -341,7 +342,7 @@ enum { dictSelectedEvent = firstUserEvent /* 0x6000 */
,loadGameEvent
,prefsChangedEvent
,openSavedGameEvent
#ifdef BEYOND_IR
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
,connsSettingChgEvent
#endif
#ifdef FEATURE_SILK

View file

@ -129,7 +129,7 @@ XP_U8* palm_realloc(XP_U8* in, XP_U16 size);
# define XP_UNUSED_SILK(x) XP_UNUSED(x)
#endif
#ifdef BEYOND_IR
#ifndef XWFEATURE_IR
# define XP_UNUSED_IR(x) x
#else
# define XP_UNUSED_IR(x) XP_UNUSED(x)

View file

@ -328,16 +328,21 @@
#define XW_CONNS_OK_BUTTON_ID 2901
#define XW_CONNS_TYPE_TRIGGER_ID 2902
#define XW_CONNS_TYPE_LIST_ID 2903
#define XW_CONNS_COOKIE_LABEL_ID 2904
#define XW_CONNS_COOKIE_FIELD_ID 2905
#define XW_CONNS_PORT_LABEL_ID 2906
#define XW_CONNS_PORT_FIELD_ID 2907
#define XW_CONNS_RELAY_LABEL_ID 2908
#define XW_CONNS_RELAY_FIELD_ID 2909
#define XW_CONNS_RELAY_LABEL_ID 2904
#ifdef XWFEATURE_RELAY
# define XW_CONNS_COOKIE_FIELD_ID 2905
# define XW_CONNS_COOKIE_LABEL_ID 2906
# define XW_CONNS_PORT_LABEL_ID 2907
# define XW_CONNS_RELAY_FIELD_ID 2908
# define XW_CONNS_PORT_FIELD_ID 2909
#endif
#define XW_CONNS_BT_NOTSUPPORT_LABEL_ID 2910
#define XW_CONNS_BT_HOSTNAME_LABEL_ID 2911
#define XW_CONNS_BT_HOSTFIELD_ID 2912
#define XW_CONNS_BT_BROWSEBUTTON_ID 2913
#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
#endif
/*
* selector for number of tiles during hint

View file

@ -118,7 +118,7 @@ static XWStreamCtxt* ce_util_makeStreamFromAddr( XW_UtilCtxt* uc,
static XP_UCHAR* ce_util_getUserString( XW_UtilCtxt* uc, XP_U16 stringCode );
static XP_Bool ce_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi,
XP_U16 turn, XP_Bool turnLost );
#ifdef BEYOND_IR
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
static void ce_util_addrChange( XW_UtilCtxt* uc, const CommsAddrRec* oldAddr,
const CommsAddrRec* newAddr );
#endif
@ -144,7 +144,7 @@ static XP_Bool ceDoNewGame( CEAppGlobals* globals );
static XP_Bool ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave );
static void updateForColors( CEAppGlobals* globals );
static XWStreamCtxt* make_generic_stream( CEAppGlobals* globals );
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
static void ce_send_on_close( XWStreamCtxt* stream, void* closure );
#endif
static XP_Bool ceSetDictName( const wchar_t* wPath, XP_U16 index, void* ctxt );
@ -366,7 +366,7 @@ ceInitUtilFuncs( CEAppGlobals* globals )
vtable->m_util_makeEmptyDict = ce_util_makeEmptyDict;
vtable->m_util_getUserString = ce_util_getUserString;
vtable->m_util_warnIllegalWord = ce_util_warnIllegalWord;
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
vtable->m_util_addrChange = ce_util_addrChange;
vtable->m_util_makeStreamFromAddr = ce_util_makeStreamFromAddr;
#endif
@ -747,7 +747,7 @@ ceInitAndStartBoard( CEAppGlobals* globals, XP_Bool newGame, CeGamePrefs* gp,
board_invalAll( globals->game.board );
InvalidateRect( globals->hWnd, NULL, TRUE /* erase */ );
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
if ( newGame && globals->gameInfo.serverRole == SERVER_ISCLIENT ) {
XWStreamCtxt* stream;
XP_ASSERT( !!globals->game.comms );
@ -1071,7 +1071,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow)
XP_U16 len;
MPSLOT;
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
{
WORD wVersionRequested;
WSADATA wsaData;
@ -2040,7 +2040,7 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_TIMER:
why = (XWTimerReason)wParam;
if ( why == TIMER_PENDOWN || why == TIMER_TIMERTICK
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
|| why == TIMER_HEARTBEAT
#endif
) {
@ -2237,7 +2237,7 @@ makeTimeStamp( XP_UCHAR* timeStamp, XP_U16 size )
void
wince_debugf(XP_UCHAR* format, ...)
{
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
static HANDLE s_logMutex = NULL;
#endif
XP_UCHAR buf[256];
@ -2255,7 +2255,7 @@ wince_debugf(XP_UCHAR* format, ...)
/* Create logfile if necessary and write to it in ascii. If there are
multiple threads, protect with mutex. */
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
if ( s_logMutex == NULL ) {
s_logMutex = CreateMutex( NULL, FALSE, NULL );
}
@ -2285,7 +2285,7 @@ wince_debugf(XP_UCHAR* format, ...)
nBytes = strlen( buf );
WriteFile( fileH, buf, nBytes, &nWritten, NULL );
CloseHandle( fileH );
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
ReleaseMutex( s_logMutex );
}
#endif
@ -2451,7 +2451,7 @@ ce_util_userError( XW_UtilCtxt* uc, UtilErrID id )
message = "Tile assignment can't be undone.";
break;
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
case ERR_RELAY_BASE + XWRELAY_ERROR_TIMEOUT:
message = "The relay timed you out; usually that means "
"the other players didn't show.";
@ -2657,7 +2657,7 @@ ce_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why, XP_U16 when,
case TIMER_TIMERTICK:
howLong = 1000; /* 1 second */
break;
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
case TIMER_HEARTBEAT:
howLong = when * 1000;
break;
@ -2696,7 +2696,7 @@ ce_util_makeEmptyDict( XW_UtilCtxt* uc )
#endif
} /* ce_util_makeEmptyDict */
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
static XWStreamCtxt*
ce_util_makeStreamFromAddr( XW_UtilCtxt* uc, XP_U16 channelNo )
{
@ -2824,7 +2824,7 @@ ce_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi,
return isOk;
} /* ce_util_warnIllegalWord */
#ifdef BEYOND_IR
#ifdef XWFEATURE_RELAY
static void
ce_util_addrChange( XW_UtilCtxt* XP_UNUSED(uc),
const CommsAddrRec* XP_UNUSED(oldAddr),