expect array of message bodies rather than just one

This commit is contained in:
Eric House 2013-05-22 06:45:34 -07:00
parent 120748416b
commit 2e30ccd4c6
2 changed files with 26 additions and 12 deletions

View file

@ -25,6 +25,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import com.google.android.gcm.GCMBaseIntentService; import com.google.android.gcm.GCMBaseIntentService;
import com.google.android.gcm.GCMRegistrar; import com.google.android.gcm.GCMRegistrar;
import org.json.JSONArray;
public class GCMIntentService extends GCMBaseIntentService { public class GCMIntentService extends GCMBaseIntentService {
@ -63,11 +64,20 @@ public class GCMIntentService extends GCMBaseIntentService {
RelayReceiver.RestartTimer( context, true ); RelayReceiver.RestartTimer( context, true );
} }
value = intent.getStringExtra( "msg64" ); value = intent.getStringExtra( "msgs64" );
if ( null != value ) { if ( null != value ) {
String connname = intent.getStringExtra( "connname" ); String connname = intent.getStringExtra( "connname" );
if ( null != connname ) { if ( null != connname ) {
RelayService.processMsg( context, connname, value ); try {
JSONArray msgs64 = new JSONArray( value );
String[] strs64 = new String[msgs64.length()];
for ( int ii = 0; ii < strs64.length; ++ii ) {
strs64[ii] = msgs64.optString(ii);
}
RelayService.processMsgs( context, connname, strs64 );
} catch (org.json.JSONException jse ) {
DbgUtils.loge( jse );
}
} }
} }

View file

@ -40,16 +40,15 @@ public class RelayService extends Service {
private static final int MAX_BUF = MAX_SEND - 2; private static final int MAX_BUF = MAX_SEND - 2;
private static final String CMD_STR = "CMD"; private static final String CMD_STR = "CMD";
private static final int PROCESS_MSG = 1; private static final int PROCESS_MSGS = 1;
private static final String MSG = "MSG"; private static final String MSGS = "MSGS";
private static final String RELAY_ID = "RELAY_ID"; private static final String RELAY_ID = "RELAY_ID";
public static void processMsg( Context context, String relayId, public static void processMsgs( Context context, String relayId,
String msg64 ) String[] msgs64 )
{ {
byte[] msg = XwJNI.base64Decode( msg64 ); Intent intent = getIntentTo( context, PROCESS_MSGS )
Intent intent = getIntentTo( context, PROCESS_MSG ) .putExtra( MSGS, msgs64 )
.putExtra( MSG, msg )
.putExtra( RELAY_ID, relayId ); .putExtra( RELAY_ID, relayId );
context.startService( intent ); context.startService( intent );
} }
@ -86,13 +85,18 @@ public class RelayService extends Service {
{ {
int cmd = intent.getIntExtra( CMD_STR, -1 ); int cmd = intent.getIntExtra( CMD_STR, -1 );
switch( cmd ) { switch( cmd ) {
case PROCESS_MSG: case PROCESS_MSGS:
String[] relayIDs = new String[1]; String[] relayIDs = new String[1];
relayIDs[0] = intent.getStringExtra( RELAY_ID ); relayIDs[0] = intent.getStringExtra( RELAY_ID );
long[] rowIDs = DBUtils.getRowIDsFor( this, relayIDs[0] ); long[] rowIDs = DBUtils.getRowIDsFor( this, relayIDs[0] );
if ( 0 < rowIDs.length ) { if ( 0 < rowIDs.length ) {
byte[][][] msgs = new byte[1][1][1]; String[] msgs64 = intent.getStringArrayExtra( MSGS );
msgs[0][0] = intent.getByteArrayExtra( MSG ); int count = msgs64.length;
byte[][][] msgs = new byte[1][count][];
for ( int ii = 0; ii < count; ++ii ) {
msgs[0][ii] = XwJNI.base64Decode( msgs64[ii] );
}
process( msgs, rowIDs, relayIDs ); process( msgs, rowIDs, relayIDs );
} }
break; break;