mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-01 19:57:11 +01:00
snapshot: registering from linux works
This commit is contained in:
parent
a43d51edf7
commit
7200833d27
6 changed files with 83 additions and 8 deletions
|
@ -28,6 +28,16 @@
|
||||||
#include "nli.h"
|
#include "nli.h"
|
||||||
#include "dbgutil.h"
|
#include "dbgutil.h"
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
# define MAGIC_INITED 0x8283413F
|
||||||
|
# define ASSERT_MAGIC() XP_ASSERT(dutil->magic == MAGIC_INITED)
|
||||||
|
#else
|
||||||
|
# define ASSERT_MAGIC()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define LAST_REG_KEY FULL_KEY("device_last_reg")
|
||||||
|
#define REG_INTERVAL_SECS 60 /* for now. :-) */
|
||||||
|
|
||||||
static XWStreamCtxt*
|
static XWStreamCtxt*
|
||||||
mkStream( XW_DUtilCtxt* dutil )
|
mkStream( XW_DUtilCtxt* dutil )
|
||||||
{
|
{
|
||||||
|
@ -584,3 +594,55 @@ dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic,
|
||||||
}
|
}
|
||||||
LOG_RETURN_VOID();
|
LOG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
registerIf( XW_DUtilCtxt* dutil, XWEnv xwe )
|
||||||
|
{
|
||||||
|
XP_U32 prevNow;
|
||||||
|
XP_U32 len = sizeof(prevNow);
|
||||||
|
const XP_UCHAR* keys[] = { LAST_REG_KEY, NULL };
|
||||||
|
dutil_loadPtr( dutil, xwe, keys, &prevNow, &len );
|
||||||
|
|
||||||
|
XP_U32 now = dutil_getCurSeconds( dutil, xwe );
|
||||||
|
if ( prevNow + REG_INTERVAL_SECS < now ) {
|
||||||
|
XP_LOGFF( "been long enough; trying to register" );
|
||||||
|
cJSON* params = cJSON_CreateObject();
|
||||||
|
|
||||||
|
MQTTDevID myID;
|
||||||
|
dvc_getMQTTDevID( dutil, xwe, &myID );
|
||||||
|
XP_UCHAR tmp[32];
|
||||||
|
formatMQTTDevID( &myID, tmp, VSIZE(tmp) );
|
||||||
|
cJSON_AddStringToObject( params, "devid", tmp );
|
||||||
|
|
||||||
|
cJSON_AddStringToObject( params, "gitrev", GITREV_SHORT );
|
||||||
|
cJSON_AddStringToObject( params, "os", "Linux" );
|
||||||
|
/* // PENDING remove me in favor of SDK_INT */
|
||||||
|
cJSON_AddStringToObject( params, "vers", "DEBUG" );
|
||||||
|
/* params.put( "versI", Build.VERSION.SDK_INT ); */
|
||||||
|
/* params.put( "vrntCode", BuildConfig.VARIANT_CODE ); */
|
||||||
|
/* params.put( "vrntName", BuildConfig.VARIANT_NAME ); */
|
||||||
|
#ifdef DEBUG
|
||||||
|
cJSON_AddBoolToObject( params, "dbg", XP_TRUE );
|
||||||
|
#endif
|
||||||
|
char* loc = getenv("LANG");
|
||||||
|
cJSON_AddStringToObject( params, "loc", loc );
|
||||||
|
/* params.put( "tmpKey", getTmpKey(mContext) ); */
|
||||||
|
/* params.put( "frstV", Utils.getFirstVersion( mContext ) ); */
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject( params, "myNow", now );
|
||||||
|
|
||||||
|
dutil_sendViaWeb( dutil, xwe, "register", params );
|
||||||
|
cJSON_Delete( params );
|
||||||
|
|
||||||
|
// dutil_storePtr( dutil, xwe, keys, &now, sizeof(now) );
|
||||||
|
}
|
||||||
|
} /* registerIf */
|
||||||
|
|
||||||
|
void
|
||||||
|
dvc_init( XW_DUtilCtxt* dutil, XWEnv xwe )
|
||||||
|
{
|
||||||
|
LOG_FUNC();
|
||||||
|
XP_ASSERT( 00 == dutil->magic );
|
||||||
|
dutil->magic = MAGIC_INITED;
|
||||||
|
registerIf( dutil, xwe );
|
||||||
|
}
|
||||||
|
|
|
@ -59,4 +59,8 @@ void dvc_makeMQTTNoSuchGames( XW_DUtilCtxt* dutil, XWEnv xwe,
|
||||||
XP_U32 gameID );
|
XP_U32 gameID );
|
||||||
void dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic,
|
void dvc_parseMQTTPacket( XW_DUtilCtxt* dutil, XWEnv xwe, const XP_UCHAR* topic,
|
||||||
const XP_U8* buf, XP_U16 len );
|
const XP_U8* buf, XP_U16 len );
|
||||||
|
|
||||||
|
/* All platforms need to call this shortly after setting up their XW_DUtilCtxt */
|
||||||
|
void dvc_init( XW_DUtilCtxt* dutil, XWEnv xwe );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -115,6 +115,9 @@ struct XW_DUtilCtxt {
|
||||||
pthread_mutex_t kpMutex;
|
pthread_mutex_t kpMutex;
|
||||||
#endif
|
#endif
|
||||||
VTableMgr* vtMgr;
|
VTableMgr* vtMgr;
|
||||||
|
#ifdef DEBUG
|
||||||
|
XP_U32 magic;
|
||||||
|
#endif
|
||||||
MPSLOT
|
MPSLOT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ CFLAGS += -g $(GPROFFLAG) -Wall -Wunused-parameter -Wcast-align -Werror -O0
|
||||||
#CFLAGS += -Os -Werror -Wunused
|
#CFLAGS += -Os -Werror -Wunused
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
CFLAGS += -DGITREV_SHORT="\"$(shell git rev-parse --short HEAD)\""
|
||||||
|
|
||||||
# Getting ready for gtk 3.x
|
# Getting ready for gtk 3.x
|
||||||
CFLAGS += -DGTK_DISABLE_SINGLE_INCLUDES
|
CFLAGS += -DGTK_DISABLE_SINGLE_INCLUDES
|
||||||
CFLAGS += -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED
|
CFLAGS += -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
#include "dutil.h"
|
#include "dutil.h"
|
||||||
|
#include "device.h"
|
||||||
#include "mempool.h"
|
#include "mempool.h"
|
||||||
#include "knownplyr.h"
|
#include "knownplyr.h"
|
||||||
#include "lindutil.h"
|
#include "lindutil.h"
|
||||||
|
@ -96,7 +97,7 @@ linux_dutil_notifyPause( XW_DUtilCtxt* XP_UNUSED(duc), XWEnv XP_UNUSED(xwe),
|
||||||
const XP_UCHAR* XP_UNUSED_DBG(name),
|
const XP_UCHAR* XP_UNUSED_DBG(name),
|
||||||
const XP_UCHAR* XP_UNUSED_DBG(msg) )
|
const XP_UCHAR* XP_UNUSED_DBG(msg) )
|
||||||
{
|
{
|
||||||
XP_LOGF( "%s(id=%d, turn=%d, name=%s, typ=%d, %s)", __func__, gameID, pauser,
|
XP_LOGFF( "(id=%d, turn=%d, name=%s, typ=%d, %s)", gameID, pauser,
|
||||||
name, pauseTyp, msg );
|
name, pauseTyp, msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ linux_dutil_onDupTimerChanged( XW_DUtilCtxt* XP_UNUSED(duc), XWEnv XP_UNUSED(xwe
|
||||||
XP_U32 XP_UNUSED_DBG(oldVal),
|
XP_U32 XP_UNUSED_DBG(oldVal),
|
||||||
XP_U32 XP_UNUSED_DBG(newVal) )
|
XP_U32 XP_UNUSED_DBG(newVal) )
|
||||||
{
|
{
|
||||||
XP_LOGF( "%s(id=%d, oldVal=%d, newVal=%d)", __func__, gameID, oldVal, newVal );
|
XP_LOGFF( "(id=%d, oldVal=%d, newVal=%d)", gameID, oldVal, newVal );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -238,6 +239,7 @@ sendViaThreadProc( void* arg )
|
||||||
snprintf( url, sizeof(url), "%s://%s/xw4/api/v1/%s", proto,
|
snprintf( url, sizeof(url), "%s://%s/xw4/api/v1/%s", proto,
|
||||||
params->connInfo.mqtt.hostName, svdp->api );
|
params->connInfo.mqtt.hostName, svdp->api );
|
||||||
curl_easy_setopt( curl, CURLOPT_URL, url );
|
curl_easy_setopt( curl, CURLOPT_URL, url );
|
||||||
|
XP_LOGFF( "url: %s", url );
|
||||||
|
|
||||||
curl_easy_setopt( curl, CURLOPT_POSTFIELDS, svdp->pstr );
|
curl_easy_setopt( curl, CURLOPT_POSTFIELDS, svdp->pstr );
|
||||||
curl_easy_setopt( curl, CURLOPT_POSTFIELDSIZE, -1L );
|
curl_easy_setopt( curl, CURLOPT_POSTFIELDSIZE, -1L );
|
||||||
|
@ -449,7 +451,7 @@ linux_dutil_getUserString( XW_DUtilCtxt* XP_UNUSED(uc),
|
||||||
return "%s: %d points\n";
|
return "%s: %d points\n";
|
||||||
|
|
||||||
default:
|
default:
|
||||||
XP_LOGF( "%s(code=%d)", __func__, code );
|
XP_LOGFF( "(code=%d)", code );
|
||||||
return (XP_UCHAR*)"unknown code";
|
return (XP_UCHAR*)"unknown code";
|
||||||
}
|
}
|
||||||
} /* linux_dutil_getUserString */
|
} /* linux_dutil_getUserString */
|
||||||
|
@ -510,7 +512,7 @@ linux_dutil_loadPtr( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe),
|
||||||
*lenp = 0; /* doesn't exist */
|
*lenp = 0; /* doesn't exist */
|
||||||
}
|
}
|
||||||
|
|
||||||
XP_LOGF( "%s(key=%s) => len: %d", __func__, keys[0], *lenp );
|
XP_LOGFF( "(key=%s) => len: %d", keys[0], *lenp );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -536,7 +538,7 @@ linux_dutil_phoneNumbersSame( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe),
|
||||||
LOG_FUNC();
|
LOG_FUNC();
|
||||||
XP_USE( duc );
|
XP_USE( duc );
|
||||||
XP_Bool result = 0 == strcmp( p1, p2 );
|
XP_Bool result = 0 == strcmp( p1, p2 );
|
||||||
XP_LOGF( "%s(%s, %s) => %d", __func__, p1, p2, result );
|
XP_LOGFF( "(%s, %s) => %d", p1, p2, result );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -558,12 +560,12 @@ linux_dutil_deviceRegistered( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe), DevIDType
|
||||||
LaunchParams* params = (LaunchParams*)duc->closure;
|
LaunchParams* params = (LaunchParams*)duc->closure;
|
||||||
switch( typ ) {
|
switch( typ ) {
|
||||||
case ID_TYPE_NONE: /* error case */
|
case ID_TYPE_NONE: /* error case */
|
||||||
XP_LOGF( "%s: id rejected", __func__ );
|
XP_LOGFF( "id rejected" );
|
||||||
params->lDevID = NULL;
|
params->lDevID = NULL;
|
||||||
break;
|
break;
|
||||||
case ID_TYPE_RELAY:
|
case ID_TYPE_RELAY:
|
||||||
if ( !!params->pDb && 0 < strlen( idRelay ) ) {
|
if ( !!params->pDb && 0 < strlen( idRelay ) ) {
|
||||||
XP_LOGF( "%s: new id: %s", __func__, idRelay );
|
XP_LOGFF( "new id: %s", idRelay );
|
||||||
gdb_store( params->pDb, KEY_RDEVID, idRelay );
|
gdb_store( params->pDb, KEY_RDEVID, idRelay );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -3372,6 +3372,8 @@ main( int argc, char** argv )
|
||||||
XP_ASSERT( !!mainParams.dbName );
|
XP_ASSERT( !!mainParams.dbName );
|
||||||
mainParams.pDb = gdb_open( mainParams.dbName );
|
mainParams.pDb = gdb_open( mainParams.dbName );
|
||||||
|
|
||||||
|
dvc_init( mainParams.dutil, NULL_XWE );
|
||||||
|
|
||||||
if ( mainParams.useCurses ) {
|
if ( mainParams.useCurses ) {
|
||||||
/* if ( mainParams.needsNewGame ) { */
|
/* if ( mainParams.needsNewGame ) { */
|
||||||
/* /\* curses doesn't have newgame dialog *\/ */
|
/* /\* curses doesn't have newgame dialog *\/ */
|
||||||
|
|
Loading…
Add table
Reference in a new issue