mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
move TransportProcs into cGlobals to fix gtk crash
This commit is contained in:
parent
47ea296c39
commit
1e447e9d60
6 changed files with 40 additions and 49 deletions
|
@ -52,8 +52,6 @@ struct CursesBoardGlobals {
|
||||||
CursesMenuState* menuState; /* null if we're not using menus */
|
CursesMenuState* menuState; /* null if we're not using menus */
|
||||||
int refCount;
|
int refCount;
|
||||||
|
|
||||||
TransportProcs procs;
|
|
||||||
|
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
XWStreamCtxt* stream; /* how we can reach the server */
|
XWStreamCtxt* stream; /* how we can reach the server */
|
||||||
|
@ -224,7 +222,7 @@ cb_newFor( CursesBoardState* cbState, const NetLaunchInfo* nli,
|
||||||
initCP( cGlobals );
|
initCP( cGlobals );
|
||||||
if ( game_makeFromInvite( &cGlobals->game, NULL_XWE, nli, &selfAddr,
|
if ( game_makeFromInvite( &cGlobals->game, NULL_XWE, nli, &selfAddr,
|
||||||
cGlobals->util, (DrawCtx*)NULL,
|
cGlobals->util, (DrawCtx*)NULL,
|
||||||
&cGlobals->cp, &bGlobals->procs ) ) {
|
&cGlobals->cp, &cGlobals->procs ) ) {
|
||||||
linuxSaveGame( cGlobals );
|
linuxSaveGame( cGlobals );
|
||||||
} else {
|
} else {
|
||||||
XP_ASSERT( 0 );
|
XP_ASSERT( 0 );
|
||||||
|
@ -363,6 +361,30 @@ curses_socket_acceptor( int listener, Acceptor func, CommonGlobals* cGlobals,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
initTProcsCurses( CommonGlobals* cGlobals )
|
||||||
|
{
|
||||||
|
cGlobals->procs.closure = cGlobals;
|
||||||
|
cGlobals->procs.sendMsg = linux_send;
|
||||||
|
#ifdef XWFEATURE_COMMS_INVITE
|
||||||
|
cGlobals->procs.sendInvt = linux_send_invt;
|
||||||
|
#endif
|
||||||
|
#ifdef COMMS_HEARTBEAT
|
||||||
|
cGlobals->procs.reset = linux_reset;
|
||||||
|
#endif
|
||||||
|
#ifdef XWFEATURE_RELAY
|
||||||
|
cGlobals->procs.rstatus = relay_status_curses;
|
||||||
|
cGlobals->procs.rconnd = relay_connd_curses;
|
||||||
|
cGlobals->procs.rerror = relay_error_curses;
|
||||||
|
cGlobals->procs.sendNoConn = relay_sendNoConn_curses;
|
||||||
|
#endif
|
||||||
|
cGlobals->procs.countChanged = curses_countChanged;
|
||||||
|
cGlobals->procs.getFlags = curses_getFlags;
|
||||||
|
# ifdef RELAY_VIA_HTTP
|
||||||
|
cGlobals->procs.requestJoin = relay_requestJoin_curses;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static CursesBoardGlobals*
|
static CursesBoardGlobals*
|
||||||
commonInit( CursesBoardState* cbState, sqlite3_int64 rowid,
|
commonInit( CursesBoardState* cbState, sqlite3_int64 rowid,
|
||||||
const CurGameInfo* gip )
|
const CurGameInfo* gip )
|
||||||
|
@ -386,26 +408,7 @@ commonInit( CursesBoardState* cbState, sqlite3_int64 rowid,
|
||||||
cGlobals->onSaveClosure = bGlobals;
|
cGlobals->onSaveClosure = bGlobals;
|
||||||
cGlobals->addAcceptor = curses_socket_acceptor;
|
cGlobals->addAcceptor = curses_socket_acceptor;
|
||||||
|
|
||||||
bGlobals->procs.closure = cGlobals;
|
initTProcsCurses( cGlobals );
|
||||||
bGlobals->procs.sendMsg = linux_send;
|
|
||||||
#ifdef XWFEATURE_COMMS_INVITE
|
|
||||||
bGlobals->procs.sendInvt = linux_send_invt;
|
|
||||||
#endif
|
|
||||||
#ifdef COMMS_HEARTBEAT
|
|
||||||
bGlobals->procs.reset = linux_reset;
|
|
||||||
#endif
|
|
||||||
#ifdef XWFEATURE_RELAY
|
|
||||||
bGlobals->procs.rstatus = relay_status_curses;
|
|
||||||
bGlobals->procs.rconnd = relay_connd_curses;
|
|
||||||
bGlobals->procs.rerror = relay_error_curses;
|
|
||||||
bGlobals->procs.sendNoConn = relay_sendNoConn_curses;
|
|
||||||
#endif
|
|
||||||
bGlobals->procs.countChanged = curses_countChanged;
|
|
||||||
bGlobals->procs.getFlags = curses_getFlags;
|
|
||||||
# ifdef RELAY_VIA_HTTP
|
|
||||||
bGlobals->procs.requestJoin = relay_requestJoin_curses;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
makeSelfAddress( &cGlobals->selfAddr, params );
|
makeSelfAddress( &cGlobals->selfAddr, params );
|
||||||
|
|
||||||
setOneSecondTimer( cGlobals );
|
setOneSecondTimer( cGlobals );
|
||||||
|
@ -566,7 +569,7 @@ initNoDraw( CursesBoardState* cbState, sqlite3_int64 rowid,
|
||||||
|
|
||||||
initCP( cGlobals );
|
initCP( cGlobals );
|
||||||
|
|
||||||
if ( linuxOpenGame( cGlobals, &result->procs ) ) {
|
if ( linuxOpenGame( cGlobals ) ) {
|
||||||
result = ref( result );
|
result = ref( result );
|
||||||
} else {
|
} else {
|
||||||
disposeBoard( result );
|
disposeBoard( result );
|
||||||
|
|
|
@ -486,6 +486,7 @@ countChanged_gtk( XWEnv XP_UNUSED(xwe), void* closure, XP_U16 newCount )
|
||||||
static void
|
static void
|
||||||
setTransportProcs( TransportProcs* procs, GtkGameGlobals* globals )
|
setTransportProcs( TransportProcs* procs, GtkGameGlobals* globals )
|
||||||
{
|
{
|
||||||
|
XP_ASSERT( !procs->closure );
|
||||||
procs->closure = globals;
|
procs->closure = globals;
|
||||||
procs->sendMsg = linux_send;
|
procs->sendMsg = linux_send;
|
||||||
#ifdef XWFEATURE_COMMS_INVITE
|
#ifdef XWFEATURE_COMMS_INVITE
|
||||||
|
@ -618,10 +619,7 @@ createOrLoadObjects( GtkGameGlobals* globals )
|
||||||
cGlobals->draw = gtkDrawCtxtMake( globals->drawing_area,
|
cGlobals->draw = gtkDrawCtxtMake( globals->drawing_area,
|
||||||
globals );
|
globals );
|
||||||
|
|
||||||
TransportProcs procs;
|
if ( linuxOpenGame( cGlobals ) ) {
|
||||||
setTransportProcs( &procs, globals );
|
|
||||||
|
|
||||||
if ( linuxOpenGame( cGlobals, &procs ) ) {
|
|
||||||
if ( !params->fileName && !!params->dbName ) {
|
if ( !params->fileName && !!params->dbName ) {
|
||||||
XP_UCHAR buf[64];
|
XP_UCHAR buf[64];
|
||||||
snprintf( buf, sizeof(buf), "%s / %lld", params->dbName,
|
snprintf( buf, sizeof(buf), "%s / %lld", params->dbName,
|
||||||
|
@ -843,20 +841,10 @@ new_game_impl( GtkGameGlobals* globals, XP_Bool fireConnDlg )
|
||||||
if ( success ) {
|
if ( success ) {
|
||||||
XP_Bool isClient = gi->serverRole == SERVER_ISCLIENT;
|
XP_Bool isClient = gi->serverRole == SERVER_ISCLIENT;
|
||||||
XP_ASSERT( !isClient ); /* Doesn't make sense! Send invitation. */
|
XP_ASSERT( !isClient ); /* Doesn't make sense! Send invitation. */
|
||||||
TransportProcs procs = {
|
|
||||||
.closure = globals,
|
|
||||||
.sendMsg = linux_send,
|
|
||||||
#ifdef XWFEATURE_COMMS_INVITE
|
|
||||||
.sendInvt = linux_send_invt,
|
|
||||||
#endif
|
|
||||||
#ifdef COMMS_HEARTBEAT
|
|
||||||
.reset = linux_reset,
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
(void)game_reset( MEMPOOL &cGlobals->game, NULL_XWE, gi,
|
(void)game_reset( MEMPOOL &cGlobals->game, NULL_XWE, gi,
|
||||||
&cGlobals->selfAddr, NULL, cGlobals->util,
|
&cGlobals->selfAddr, NULL, cGlobals->util,
|
||||||
&cGlobals->cp, &procs );
|
&cGlobals->cp, &cGlobals->procs );
|
||||||
|
|
||||||
(void)server_do( cGlobals->game.server, NULL_XWE ); /* assign tiles, etc. */
|
(void)server_do( cGlobals->game.server, NULL_XWE ); /* assign tiles, etc. */
|
||||||
board_invalAll( cGlobals->game.board );
|
board_invalAll( cGlobals->game.board );
|
||||||
|
@ -2426,6 +2414,8 @@ initGlobalsNoDraw( GtkGameGlobals* globals, LaunchParams* params,
|
||||||
memset( globals, 0, sizeof(*globals) );
|
memset( globals, 0, sizeof(*globals) );
|
||||||
|
|
||||||
CommonGlobals* cGlobals = &globals->cGlobals;
|
CommonGlobals* cGlobals = &globals->cGlobals;
|
||||||
|
setTransportProcs( &cGlobals->procs, globals );
|
||||||
|
|
||||||
cGlobals->gi = &cGlobals->_gi;
|
cGlobals->gi = &cGlobals->_gi;
|
||||||
if ( !gi ) {
|
if ( !gi ) {
|
||||||
gi = ¶ms->pgi;
|
gi = ¶ms->pgi;
|
||||||
|
@ -2667,9 +2657,6 @@ loadGameNoDraw( GtkGameGlobals* globals, LaunchParams* params,
|
||||||
sqlite3* pDb = params->pDb;
|
sqlite3* pDb = params->pDb;
|
||||||
initGlobalsNoDraw( globals, params, NULL );
|
initGlobalsNoDraw( globals, params, NULL );
|
||||||
|
|
||||||
TransportProcs procs;
|
|
||||||
setTransportProcs( &procs, globals );
|
|
||||||
|
|
||||||
CommonGlobals* cGlobals = &globals->cGlobals;
|
CommonGlobals* cGlobals = &globals->cGlobals;
|
||||||
cGlobals->rowid = rowid;
|
cGlobals->rowid = rowid;
|
||||||
XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(cGlobals->util->mpool)
|
XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(cGlobals->util->mpool)
|
||||||
|
@ -2678,7 +2665,8 @@ loadGameNoDraw( GtkGameGlobals* globals, LaunchParams* params,
|
||||||
if ( loaded ) {
|
if ( loaded ) {
|
||||||
loaded = game_makeFromStream( MEMPOOL NULL_XWE, stream, &cGlobals->game,
|
loaded = game_makeFromStream( MEMPOOL NULL_XWE, stream, &cGlobals->game,
|
||||||
cGlobals->gi,
|
cGlobals->gi,
|
||||||
cGlobals->util, (DrawCtx*)NULL, &cGlobals->cp, &procs );
|
cGlobals->util, (DrawCtx*)NULL,
|
||||||
|
&cGlobals->cp, &cGlobals->procs );
|
||||||
if ( loaded ) {
|
if ( loaded ) {
|
||||||
XP_LOGF( "%s: game loaded", __func__ );
|
XP_LOGF( "%s: game loaded", __func__ );
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
|
|
|
@ -719,10 +719,9 @@ gameFromInvite( GtkAppGlobals* apg, const NetLaunchInfo* nli )
|
||||||
makeSelfAddress( &selfAddr, params );
|
makeSelfAddress( &selfAddr, params );
|
||||||
|
|
||||||
CommonPrefs* cp = &cGlobals->cp;
|
CommonPrefs* cp = &cGlobals->cp;
|
||||||
TransportProcs* procs = NULL;
|
|
||||||
game_makeFromInvite( &cGlobals->game, NULL_XWE, nli,
|
game_makeFromInvite( &cGlobals->game, NULL_XWE, nli,
|
||||||
&selfAddr, cGlobals->util, cGlobals->draw,
|
&selfAddr, cGlobals->util, cGlobals->draw,
|
||||||
cp, procs );
|
cp, &cGlobals->procs );
|
||||||
|
|
||||||
linuxSaveGame( cGlobals );
|
linuxSaveGame( cGlobals );
|
||||||
sqlite3_int64 rowid = cGlobals->rowid;
|
sqlite3_int64 rowid = cGlobals->rowid;
|
||||||
|
|
|
@ -160,7 +160,7 @@ send_msgs_idle( gpointer data )
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs )
|
linuxOpenGame( CommonGlobals* cGlobals )
|
||||||
{
|
{
|
||||||
XWStreamCtxt* stream = NULL;
|
XWStreamCtxt* stream = NULL;
|
||||||
XP_Bool opened = XP_FALSE;
|
XP_Bool opened = XP_FALSE;
|
||||||
|
@ -189,7 +189,7 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs )
|
||||||
opened = game_makeFromStream( MEMPOOL NULL_XWE, stream, &cGlobals->game,
|
opened = game_makeFromStream( MEMPOOL NULL_XWE, stream, &cGlobals->game,
|
||||||
cGlobals->gi,
|
cGlobals->gi,
|
||||||
cGlobals->util, cGlobals->draw,
|
cGlobals->util, cGlobals->draw,
|
||||||
&cGlobals->cp, procs );
|
&cGlobals->cp, &cGlobals->procs );
|
||||||
XP_LOGFF( "loaded gi at %p", &cGlobals->gi );
|
XP_LOGFF( "loaded gi at %p", &cGlobals->gi );
|
||||||
stream_destroy( stream, NULL_XWE );
|
stream_destroy( stream, NULL_XWE );
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs )
|
||||||
}
|
}
|
||||||
game_makeNewGame( MEMPOOL NULL_XWE, &cGlobals->game, cGlobals->gi,
|
game_makeNewGame( MEMPOOL NULL_XWE, &cGlobals->game, cGlobals->gi,
|
||||||
&cGlobals->selfAddr, hostAddr, cGlobals->util,
|
&cGlobals->selfAddr, hostAddr, cGlobals->util,
|
||||||
cGlobals->draw, &cGlobals->cp, procs
|
cGlobals->draw, &cGlobals->cp, &cGlobals->procs
|
||||||
#ifdef SET_GAMESEED
|
#ifdef SET_GAMESEED
|
||||||
, params->gameSeed
|
, params->gameSeed
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -114,7 +114,7 @@ XP_Bool parseSMSParams( LaunchParams* params, gchar** myPhone, XP_U16* myPort );
|
||||||
void makeSelfAddress( CommsAddrRec* selfAddr, const LaunchParams* params );
|
void makeSelfAddress( CommsAddrRec* selfAddr, const LaunchParams* params );
|
||||||
|
|
||||||
unsigned int makeRandomInt();
|
unsigned int makeRandomInt();
|
||||||
bool linuxOpenGame( CommonGlobals* cGlobals, const TransportProcs* procs );
|
bool linuxOpenGame( CommonGlobals* cGlobals );
|
||||||
void tryConnectToServer( CommonGlobals* cGlobals );
|
void tryConnectToServer( CommonGlobals* cGlobals );
|
||||||
void ensureLocalPlayerNames( LaunchParams* params, CurGameInfo* gi );
|
void ensureLocalPlayerNames( LaunchParams* params, CurGameInfo* gi );
|
||||||
void cancelTimers( CommonGlobals* cGlobals );
|
void cancelTimers( CommonGlobals* cGlobals );
|
||||||
|
|
|
@ -224,6 +224,7 @@ typedef void (*OnSaveFunc)( void* closure, sqlite3_int64 rowid,
|
||||||
struct CommonGlobals {
|
struct CommonGlobals {
|
||||||
CurGameInfo _gi;
|
CurGameInfo _gi;
|
||||||
LaunchParams* params;
|
LaunchParams* params;
|
||||||
|
TransportProcs procs;
|
||||||
CommonPrefs cp;
|
CommonPrefs cp;
|
||||||
XW_UtilCtxt* util;
|
XW_UtilCtxt* util;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue