mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
Merge branch 'android_invite' of ssh://xwords.git.sourceforge.net/gitroot/xwords/xwords into android_invite
This commit is contained in:
commit
ba4d898de1
5 changed files with 34 additions and 13 deletions
|
@ -175,7 +175,10 @@ CidLock::Relinquish( CidInfo* claim, bool drop )
|
||||||
m_infos.erase( iter );
|
m_infos.erase( iter );
|
||||||
delete claim;
|
delete claim;
|
||||||
} else {
|
} else {
|
||||||
claim->SetSockets( claim->GetRef()->GetSockets() ); /* cache these */
|
CookieRef* ref = claim->GetRef();
|
||||||
|
if ( NULL != ref ) {
|
||||||
|
claim->SetSockets( ref->GetSockets() ); /* cache these */
|
||||||
|
}
|
||||||
claim->SetOwner( 0 );
|
claim->SetOwner( 0 );
|
||||||
}
|
}
|
||||||
PRINT_CLAIMED();
|
PRINT_CLAIMED();
|
||||||
|
|
|
@ -402,13 +402,15 @@ CRefMgr::PrintSocketInfo( int socket, string& out )
|
||||||
}
|
}
|
||||||
|
|
||||||
CidInfo*
|
CidInfo*
|
||||||
CRefMgr::getCookieRef( CookieID cid )
|
CRefMgr::getCookieRef( CookieID cid, bool failOk )
|
||||||
{
|
{
|
||||||
CidInfo* cinfo = NULL;
|
CidInfo* cinfo = NULL;
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
cinfo = m_cidlock->Claim( cid );
|
cinfo = m_cidlock->Claim( cid );
|
||||||
if ( NULL != cinfo->GetRef() ) {
|
if ( NULL != cinfo->GetRef() ) {
|
||||||
break;
|
break;
|
||||||
|
} else if ( failOk ) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
m_cidlock->Relinquish( cinfo, true );
|
m_cidlock->Relinquish( cinfo, true );
|
||||||
}
|
}
|
||||||
|
@ -655,13 +657,16 @@ SafeCref::SafeCref( CookieID cid, bool failOk )
|
||||||
: m_cinfo( NULL )
|
: m_cinfo( NULL )
|
||||||
, m_mgr( CRefMgr::Get() )
|
, m_mgr( CRefMgr::Get() )
|
||||||
, m_isValid( false )
|
, m_isValid( false )
|
||||||
|
, m_locked( false )
|
||||||
{
|
{
|
||||||
CidInfo* cinfo = m_mgr->getCookieRef( cid );
|
CidInfo* cinfo = m_mgr->getCookieRef( cid, failOk );
|
||||||
if ( cinfo != NULL ) { /* known cookie? */
|
if ( cinfo != NULL ) { /* known cookie? */
|
||||||
CookieRef* cref = cinfo->GetRef();
|
CookieRef* cref = cinfo->GetRef();
|
||||||
|
if ( NULL != cref ) {
|
||||||
assert( cinfo->GetCid() == cref->GetCid() );
|
assert( cinfo->GetCid() == cref->GetCid() );
|
||||||
m_locked = cref->Lock();
|
m_locked = cref->Lock();
|
||||||
m_isValid = m_locked && cid == cref->GetCid();
|
m_isValid = m_locked && cid == cref->GetCid();
|
||||||
|
}
|
||||||
m_cinfo = cinfo;
|
m_cinfo = cinfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -684,7 +689,7 @@ SafeCref::SafeCref( int socket )
|
||||||
SafeCref::~SafeCref()
|
SafeCref::~SafeCref()
|
||||||
{
|
{
|
||||||
if ( m_cinfo != NULL ) {
|
if ( m_cinfo != NULL ) {
|
||||||
bool recycle = false;
|
bool recycle = true;
|
||||||
if ( m_locked ) {
|
if ( m_locked ) {
|
||||||
CookieRef* cref = m_cinfo->GetRef();
|
CookieRef* cref = m_cinfo->GetRef();
|
||||||
assert( m_cinfo->GetCid() == cref->GetCid() );
|
assert( m_cinfo->GetCid() == cref->GetCid() );
|
||||||
|
|
|
@ -131,7 +131,7 @@ class CRefMgr {
|
||||||
|
|
||||||
CidInfo* getMakeCookieRef( const char* const connName, bool* isDead );
|
CidInfo* getMakeCookieRef( const char* const connName, bool* isDead );
|
||||||
|
|
||||||
CidInfo* getCookieRef( CookieID cid );
|
CidInfo* getCookieRef( CookieID cid, bool failOk = false );
|
||||||
CidInfo* getCookieRef( int socket );
|
CidInfo* getCookieRef( int socket );
|
||||||
bool checkCookieRef_locked( CookieRef* cref );
|
bool checkCookieRef_locked( CookieRef* cref );
|
||||||
CidInfo* getCookieRef_impl( CookieID cid );
|
CidInfo* getCookieRef_impl( CookieID cid );
|
||||||
|
|
|
@ -289,9 +289,10 @@ DBMgr::RmDeviceByHid( const char* connName, HostID hid )
|
||||||
return execSql( query );
|
return execSql( query );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
HostID
|
||||||
DBMgr::RmDeviceBySeed( const char* const connName, unsigned short seed )
|
DBMgr::HIDForSeed( const char* const connName, unsigned short seed )
|
||||||
{
|
{
|
||||||
|
HostID hid = HOST_ID_NONE;
|
||||||
char seeds[128] = {0};
|
char seeds[128] = {0};
|
||||||
const char* fmt = "SELECT seeds FROM " GAMES_TABLE
|
const char* fmt = "SELECT seeds FROM " GAMES_TABLE
|
||||||
" WHERE connName = '%s'"
|
" WHERE connName = '%s'"
|
||||||
|
@ -316,7 +317,7 @@ DBMgr::RmDeviceBySeed( const char* const connName, unsigned short seed )
|
||||||
} else {
|
} else {
|
||||||
int asint = atoi( tok );
|
int asint = atoi( tok );
|
||||||
if ( asint == seed ) {
|
if ( asint == seed ) {
|
||||||
RmDeviceByHid( connName, ii + 1 );
|
hid = ii + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -324,6 +325,17 @@ DBMgr::RmDeviceBySeed( const char* const connName, unsigned short seed )
|
||||||
} else {
|
} else {
|
||||||
assert(0); /* but don't ship with this!!!! */
|
assert(0); /* but don't ship with this!!!! */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return hid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DBMgr::RmDeviceBySeed( const char* const connName, unsigned short seed )
|
||||||
|
{
|
||||||
|
HostID hid = HIDForSeed( connName, seed );
|
||||||
|
if ( hid != HOST_ID_NONE ) {
|
||||||
|
RmDeviceByHid( connName, hid );
|
||||||
|
}
|
||||||
} /* RmDeviceSeed */
|
} /* RmDeviceSeed */
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -639,8 +651,8 @@ formatParams( char* paramValues[], int nParams, const char* fmt, char* buf,
|
||||||
static int
|
static int
|
||||||
here_less_seed( const char* seeds, int sumPerDevice, unsigned short seed )
|
here_less_seed( const char* seeds, int sumPerDevice, unsigned short seed )
|
||||||
{
|
{
|
||||||
logf( XW_LOGINFO, "%s: find %x in \"%s\", sub from \"%d\"", __func__,
|
logf( XW_LOGINFO, "%s: find %x(%d) in \"%s\", sub from \"%d\"", __func__,
|
||||||
seed, seeds, sumPerDevice );
|
seed, seed, seeds, sumPerDevice );
|
||||||
return sumPerDevice - 1; /* FIXME */
|
return sumPerDevice - 1; /* FIXME */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ class DBMgr {
|
||||||
HostID AddDevice( const char* const connName, HostID curID,
|
HostID AddDevice( const char* const connName, HostID curID,
|
||||||
int nToAdd, unsigned short seed, bool unAckd );
|
int nToAdd, unsigned short seed, bool unAckd );
|
||||||
void NoteAckd( const char* const connName, HostID id );
|
void NoteAckd( const char* const connName, HostID id );
|
||||||
|
HostID HIDForSeed( const char* const connName, unsigned short seed );
|
||||||
bool RmDeviceByHid( const char* const connName, HostID id );
|
bool RmDeviceByHid( const char* const connName, HostID id );
|
||||||
void RmDeviceBySeed( const char* const connName, unsigned short seed );
|
void RmDeviceBySeed( const char* const connName, unsigned short seed );
|
||||||
bool HaveDevice( const char* const connName, HostID id, int seed );
|
bool HaveDevice( const char* const connName, HostID id, int seed );
|
||||||
|
|
Loading…
Reference in a new issue