Merge remote branch 'origin/android_branch' into android_branch

This commit is contained in:
Eric House 2015-07-11 08:42:19 -07:00
commit b87d258729
7 changed files with 124 additions and 52 deletions

View file

@ -41,46 +41,43 @@ public final class R {
public static final int content_copy__gen=0x7f020002;
public static final int content_discard__gen=0x7f020003;
public static final int content_edit=0x7f020004;
public static final int content_new__gen=0x7f020005;
public static final int content_new_net__gen=0x7f020006;
public static final int content_new_solo__gen=0x7f020007;
public static final int dict__gen=0x7f020008;
public static final int dicticon=0x7f020009;
public static final int down__gen=0x7f02000a;
public static final int downarrow=0x7f02000b;
public static final int download__gen=0x7f02000c;
public static final int email__gen=0x7f02000d;
public static final int expander_ic_maximized=0x7f02000e;
public static final int expander_ic_minimized=0x7f02000f;
public static final int flip=0x7f020010;
public static final int icon48x48=0x7f020011;
public static final int in_arrow=0x7f020012;
public static final int in_arrow_active=0x7f020013;
public static final int multigame__gen=0x7f020014;
public static final int multigame_new__gen=0x7f020015;
public static final int new_group__gen=0x7f020016;
public static final int next_hint=0x7f020017;
public static final int origin=0x7f020018;
public static final int out_arrow=0x7f020019;
public static final int out_arrow_active=0x7f02001a;
public static final int prefs__gen=0x7f02001b;
public static final int prev_hint=0x7f02001c;
public static final int refresh=0x7f02001d;
public static final int relabel__gen=0x7f02001e;
public static final int reset__gen=0x7f02001f;
public static final int rightarrow=0x7f020020;
public static final int save__gen=0x7f020021;
public static final int search__gen=0x7f020022;
public static final int select_all__gen=0x7f020023;
public static final int send__gen=0x7f020024;
public static final int shuffle=0x7f020025;
public static final int sologame__gen=0x7f020026;
public static final int stat_notify_chat=0x7f020027;
public static final int stat_notify_sync=0x7f020028;
public static final int undo=0x7f020029;
public static final int up__gen=0x7f02002a;
public static final int values=0x7f02002b;
public static final int zoom=0x7f02002c;
public static final int content_new_net__gen=0x7f020005;
public static final int content_new_solo__gen=0x7f020006;
public static final int dict__gen=0x7f020007;
public static final int dicticon=0x7f020008;
public static final int down__gen=0x7f020009;
public static final int downarrow=0x7f02000a;
public static final int download__gen=0x7f02000b;
public static final int email__gen=0x7f02000c;
public static final int expander_ic_maximized=0x7f02000d;
public static final int expander_ic_minimized=0x7f02000e;
public static final int flip=0x7f02000f;
public static final int icon48x48=0x7f020010;
public static final int in_arrow=0x7f020011;
public static final int in_arrow_active=0x7f020012;
public static final int multigame__gen=0x7f020013;
public static final int new_group__gen=0x7f020014;
public static final int next_hint=0x7f020015;
public static final int origin=0x7f020016;
public static final int out_arrow=0x7f020017;
public static final int out_arrow_active=0x7f020018;
public static final int prefs__gen=0x7f020019;
public static final int prev_hint=0x7f02001a;
public static final int refresh=0x7f02001b;
public static final int relabel__gen=0x7f02001c;
public static final int reset__gen=0x7f02001d;
public static final int rightarrow=0x7f02001e;
public static final int save__gen=0x7f02001f;
public static final int search__gen=0x7f020020;
public static final int select_all__gen=0x7f020021;
public static final int shuffle=0x7f020022;
public static final int sologame__gen=0x7f020023;
public static final int stat_notify_chat=0x7f020024;
public static final int stat_notify_sync=0x7f020025;
public static final int undo=0x7f020026;
public static final int up__gen=0x7f020027;
public static final int values=0x7f020028;
public static final int zoom=0x7f020029;
}
public static final class id {
public static final int about_xlator=0x7f0a0001;

View file

@ -101,8 +101,15 @@ public class GCMIntentService extends GCMBaseIntentService {
if ( null != value ) {
String title = intent.getStringExtra( "title" );
if ( null != title ) {
String teaser = intent.getStringExtra( "teaser" );
if ( null == teaser ) {
teaser = value;
}
Intent alertIntent = GamesListDelegate
.makeAlertIntent( this, value );
int code = value.hashCode() ^ title.hashCode();
Utils.postNotification( context, null, title, value, code );
Utils.postNotification( context, alertIntent, title,
teaser, code );
}
}
}

View file

@ -204,8 +204,8 @@ public class Utils {
Intents is to send a different second param each time,
though the docs say that param's ignored.
*/
PendingIntent pi =
PendingIntent.getActivity( context, Utils.nextRandomInt(), intent,
PendingIntent pi = null == intent ? null
: PendingIntent.getActivity( context, Utils.nextRandomInt(), intent,
PendingIntent.FLAG_ONE_SHOT );
Notification notification =

View file

@ -44,6 +44,7 @@
static DBMgr* s_instance = NULL;
#define MAX_NUM_PLAYERS 4
#define MAX_WAIT_SECONDS (5*60) // five minutes
static int here_less_seed( const char* seeds, int perDeviceSum,
unsigned short seed );
@ -747,6 +748,34 @@ DBMgr::KillGame( const char* const connName, int hid )
execSql( query );
}
void
DBMgr::WaitDBConn( void )
{
int nSeconds = 0;
int toSleep = 1;
for ( ; ; ) {
PGconn* conn = DBMgr::getThreadConn();
if ( !!conn ) {
ConnStatusType status = PQstatus( conn );
if ( CONNECTION_OK == status ) {
break;
}
}
toSleep *= 2;
if ( toSleep > MAX_WAIT_SECONDS ) {
toSleep = MAX_WAIT_SECONDS;
}
(void)sleep( toSleep );
nSeconds += toSleep;
logf( XW_LOGERROR, "%s: waiting for postgres; %d seconds so far", __func__,
nSeconds );
}
logf( XW_LOGERROR, "%s() done", __func__ );
}
void
DBMgr::ClearCIDs( void )
{
@ -873,6 +902,19 @@ DBMgr::readArray( const char* const connName, const char* column, int arr[] ) /
PQclear( result );
}
// parse something created by comms.c's formatRelayID
DevIDRelay
DBMgr::getDevID( string& relayID )
{
size_t pos = relayID.find_first_of( '/' );
string connName = relayID.substr( 0, pos );
int hid = relayID[pos + 1] - '0';
DevIDRelay result = getDevID( connName.c_str(), hid );
// Not an error. Remove or downlog when confirm working
logf( XW_LOGERROR, "%s(%s) => %d", __func__, relayID.c_str(), result );
return result;
}
DevIDRelay
DBMgr::getDevID( const char* connName, int hid )
{
@ -1330,7 +1372,12 @@ DBMgr::getThreadConn( void )
params.catf( "port = %d ", port );
conn = PQconnectdb( params.c_str() );
if ( CONNECTION_OK == PQstatus( conn ) ) {
pthread_setspecific( m_conn_key, conn );
} else {
PQfinish( conn );
conn = NULL;
}
}
return conn;
}

View file

@ -63,6 +63,8 @@ class DBMgr {
~DBMgr();
void WaitDBConn( void );
void ClearCIDs( void );
void AddNew( const char* cookie, const char* connName, CookieID cid,
@ -146,6 +148,8 @@ class DBMgr {
void RemoveStoredMessage( const int msgID );
void RemoveStoredMessages( vector<int>& ids );
DevIDRelay getDevID( string& relayID );
private:
DBMgr();
bool execSql( const string& query );

View file

@ -14,7 +14,8 @@ def usage():
def sendMsg( devid, msg ):
values = {
'registration_ids': [ devid ],
'data' : { 'title' : 'Msg from Darth2',
'data' : { 'title' : 'Re: CrossWords',
'teaser' : 'Please tap to read in the app',
'msg' : msg,
}
}

View file

@ -1172,6 +1172,7 @@ usage( char* arg0 )
#ifdef DO_HTTP
"\t-w <cport> (localhost port for web interface)\\\n"
#endif
"\t-b (block until postgres connection available)\\\n"
"\t-D (don't become daemon)\\\n"
"\t-F (don't fork and wait to respawn child)\\\n"
"\t-f <conffile> (config file)\\\n"
@ -1779,16 +1780,23 @@ handle_udp_packet( UdpThreadClosure* utc )
break;
}
case XWPDEV_INVITE:
case XWPDEV_INVITE: {
DevIDRelay sender;
DevIDRelay invitee;
string relayID;
if ( getNetLong( &ptr, end, &sender )
&& getNetLong( &ptr, end, &invitee) ) {
&& getNetString( &ptr, end, relayID ) ) {
DevIDRelay invitee;
if ( 0 < relayID.size() ) {
invitee = DBMgr::Get()->getDevID( relayID );
} else if ( !getNetLong( &ptr, end, &invitee ) ) {
break; // failure
}
logf( XW_LOGVERBOSE0, "got invite from %d for %d",
sender, invitee );
post_invite( sender, invitee, ptr, end - ptr );
}
break;
}
case XWPDEV_KEEPALIVE:
case XWPDEV_RQSTMSGS: {
@ -2022,6 +2030,7 @@ main( int argc, char** argv )
const char* maint_str = NULL;
bool doDaemon = true;
bool doFork = true;
bool doBlock = false;
(void)uptime(); /* force capture of start time */
@ -2033,7 +2042,7 @@ main( int argc, char** argv )
first. */
for ( ; ; ) {
int opt = getopt(argc, argv, "h?c:p:M:m:n:f:l:t:s:u:w:"
int opt = getopt(argc, argv, "bh?c:p:M:m:n:f:l:t:s:u:w:"
"DF" );
if ( opt == -1 ) {
@ -2044,6 +2053,9 @@ main( int argc, char** argv )
case 'h':
usage( argv[0] );
exit( 0 );
case 'b':
doBlock = true;
break;
case 'c':
ctrlport = atoi( optarg );
break;
@ -2194,6 +2206,10 @@ main( int argc, char** argv )
}
#endif
if ( doBlock ) {
DBMgr::Get()->WaitDBConn();
}
if ( -1 != udpport ) {
struct sockaddr_in saddr;
g_udpsock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );