mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-03 23:04:08 +01:00
call new web api to ack mqtt messages
This is toward debugging. Not sure it'll be use to add functionality yet.
This commit is contained in:
parent
356280565a
commit
daf5894d79
6 changed files with 79 additions and 5 deletions
|
@ -483,6 +483,27 @@ public class MQTTUtils extends Thread implements IMqttActionListener, MqttCallba
|
|||
addToSendQueue( context, topic[0], packet );
|
||||
}
|
||||
|
||||
public static void ackMessage( Context context, int gameID,
|
||||
String senderDevID, byte[] payload )
|
||||
{
|
||||
String sum = Utils.getMD5SumFor( payload );
|
||||
JSONObject params = new JSONObject();
|
||||
try {
|
||||
params.put( "sum", sum );
|
||||
params.put( "gid", gameID );
|
||||
// params.put( "from", senderDevID );
|
||||
// params.put( "to", XwJNI.dvc_getMQTTDevID( null ) );
|
||||
|
||||
HttpsURLConnection conn
|
||||
= NetUtils.makeHttpsMQTTConn( context, "ack" );
|
||||
String resStr = NetUtils.runConn( conn, params, true );
|
||||
Log.d( TAG, "runConn(ack) => %s", resStr );
|
||||
} catch ( JSONException je ) {
|
||||
Log.e( TAG, "ackMessage() ex: %s", je );
|
||||
}
|
||||
}
|
||||
|
||||
// MqttCallbackExtended
|
||||
@Override
|
||||
public void connectComplete(boolean reconnect, String serverURI)
|
||||
{
|
||||
|
@ -498,7 +519,7 @@ public class MQTTUtils extends Thread implements IMqttActionListener, MqttCallba
|
|||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived( String topic, MqttMessage message) throws Exception
|
||||
public void messageArrived( String topic, MqttMessage message ) throws Exception
|
||||
{
|
||||
Log.d( TAG, "%H.messageArrived(topic=%s)", this, topic );
|
||||
Assert.assertTrueNR( topic.equals(mTopic) );
|
||||
|
@ -533,6 +554,7 @@ public class MQTTUtils extends Thread implements IMqttActionListener, MqttCallba
|
|||
}
|
||||
}
|
||||
|
||||
// IMqttActionListener
|
||||
@Override
|
||||
public void onSuccess( IMqttToken asyncActionToken )
|
||||
{
|
||||
|
|
|
@ -372,4 +372,9 @@ public class DUtilCtxt {
|
|||
Assert.assertTrueNR( from.contains( CommsAddrRec.CommsConnType.COMMS_CONN_MQTT ) );
|
||||
MQTTUtils.handleGameGone( m_context, from, gameID );
|
||||
}
|
||||
|
||||
public void ackMQTTMsg( int gameID, String senderID, byte[] msg )
|
||||
{
|
||||
MQTTUtils.ackMessage( m_context, gameID, senderID, msg );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "LocalizedStrIncludes.h"
|
||||
#include "dbgutil.h"
|
||||
#include "nli.h"
|
||||
#include "strutils.h"
|
||||
|
||||
#define MAX_QUANTITY_STRS 4
|
||||
|
||||
|
@ -919,6 +920,23 @@ and_dutil_onGameGoneReceived( XW_DUtilCtxt* duc, XWEnv xwe, XP_U32 gameID,
|
|||
DUTIL_CBK_TAIL();
|
||||
}
|
||||
|
||||
static void
|
||||
and_dutil_ackMQTTMsg( XW_DUtilCtxt* duc, XWEnv xwe, XP_U32 gameID,
|
||||
const MQTTDevID* senderID, const XP_U8* msg, XP_U16 len )
|
||||
{
|
||||
DUTIL_CBK_HEADER( "ackMQTTMsg", "(ILjava/lang/String;[B)V" );
|
||||
|
||||
XP_UCHAR tmp[32];
|
||||
formatMQTTDevID( senderID, tmp, VSIZE(tmp) );
|
||||
jstring jdevid = (*env)->NewStringUTF( env, tmp );
|
||||
jbyteArray jmsg = makeByteArray( env, len, (const jbyte*)msg );
|
||||
|
||||
(*env)->CallVoidMethod( env, dutil->jdutil, mid, gameID, jdevid, jmsg );
|
||||
|
||||
deleteLocalRefs( env, jdevid, jmsg, DELETE_NO_REF );
|
||||
DUTIL_CBK_TAIL();
|
||||
}
|
||||
|
||||
XW_UtilCtxt*
|
||||
makeUtil( MPFORMAL JNIEnv* env,
|
||||
#ifdef MAP_THREAD_TO_ENV
|
||||
|
@ -1073,6 +1091,7 @@ makeDUtil( MPFORMAL JNIEnv* env,
|
|||
SET_DPROC(onInviteReceived);
|
||||
SET_DPROC(onMessageReceived);
|
||||
SET_DPROC(onGameGoneReceived);
|
||||
SET_DPROC(ackMQTTMsg);
|
||||
|
||||
#undef SET_DPROC
|
||||
|
||||
|
|
|
@ -223,9 +223,14 @@ dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_U8* buf, XP_U16 le
|
|||
XP_LOGFF( "read proto %d, expected %d; dropping packet",
|
||||
proto, PROTO_1 );
|
||||
} else {
|
||||
MQTTDevID myID;
|
||||
stream_getBytes( stream, &myID, sizeof(myID) );
|
||||
myID = be64toh( myID );
|
||||
MQTTDevID senderID;
|
||||
stream_getBytes( stream, &senderID, sizeof(senderID) );
|
||||
senderID = be64toh( senderID );
|
||||
#ifdef DEBUG
|
||||
XP_UCHAR tmp[32];
|
||||
formatMQTTDevID( &senderID, tmp, VSIZE(tmp) );
|
||||
XP_LOGFF( "senderID: %s", tmp );
|
||||
#endif
|
||||
|
||||
MQTTCmd cmd;
|
||||
XP_U32 gameID = 0;
|
||||
|
@ -233,6 +238,9 @@ dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_U8* buf, XP_U16 le
|
|||
gameID = stream_getU32( stream );
|
||||
cmd = stream_getU8( stream );
|
||||
|
||||
/* Need to ack even if discarded/malformed */
|
||||
dutil_ackMQTTMsg( dutil, xwe, gameID, &senderID, buf, len );
|
||||
|
||||
switch ( cmd ) {
|
||||
case CMD_INVITE: {
|
||||
NetLaunchInfo nli = {0};
|
||||
|
@ -245,7 +253,7 @@ dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_U8* buf, XP_U16 le
|
|||
case CMD_MSG: {
|
||||
CommsAddrRec from = {0};
|
||||
addr_addType( &from, COMMS_CONN_MQTT );
|
||||
from.u.mqtt.devID = myID;
|
||||
from.u.mqtt.devID = senderID;
|
||||
if ( CMD_MSG == cmd ) {
|
||||
dutil_onMessageReceived( dutil, xwe, gameID, &from, stream );
|
||||
} else if ( CMD_DEVGONE == cmd ) {
|
||||
|
|
|
@ -91,6 +91,9 @@ typedef struct _DUtilVtable {
|
|||
const CommsAddrRec* from, XWStreamCtxt* stream );
|
||||
void (*m_dutil_onGameGoneReceived)( XW_DUtilCtxt* duc, XWEnv xwe, XP_U32 gameID,
|
||||
const CommsAddrRec* from );
|
||||
|
||||
void (*m_dutil_ackMQTTMsg)( XW_DUtilCtxt* duc, XWEnv xwe, XP_U32 gameID,
|
||||
const MQTTDevID* senderID, const XP_U8* msg, XP_U16 len );
|
||||
} DUtilVtable;
|
||||
|
||||
struct XW_DUtilCtxt {
|
||||
|
@ -160,4 +163,7 @@ void dutil_super_init( MPFORMAL XW_DUtilCtxt* dutil );
|
|||
#define dutil_onGameGoneReceived(duc, xwe, gameID, from) \
|
||||
(duc)->vtable.m_dutil_onGameGoneReceived((duc),(xwe),(gameID),(from))
|
||||
|
||||
#define dutil_ackMQTTMsg( duc, xwe, gameID, senderID, msg, len ) \
|
||||
(duc)->vtable.m_dutil_ackMQTTMsg((duc), (xwe), (gameID), (senderID), (msg), (len) )
|
||||
|
||||
#endif
|
||||
|
|
|
@ -130,6 +130,19 @@ linux_dutil_onGameGoneReceived( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe),
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dutil_ackMQTTMsg( XW_DUtilCtxt* duc, XWEnv xwe, XP_U32 gameID,
|
||||
const MQTTDevID* senderID, const XP_U8* msg, XP_U16 len )
|
||||
{
|
||||
XP_USE(duc);
|
||||
XP_USE(xwe);
|
||||
XP_USE(gameID);
|
||||
XP_USE(senderID);
|
||||
XP_USE(msg);
|
||||
XP_USE(len);
|
||||
XP_LOGFF( "doing nothing" );
|
||||
}
|
||||
|
||||
XW_DUtilCtxt*
|
||||
linux_dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
||||
{
|
||||
|
@ -168,6 +181,7 @@ linux_dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
|||
SET_PROC(onInviteReceived);
|
||||
SET_PROC(onMessageReceived);
|
||||
SET_PROC(onGameGoneReceived);
|
||||
SET_PROC(ackMQTTMsg);
|
||||
|
||||
# undef SET_PROC
|
||||
|
||||
|
|
Loading…
Reference in a new issue