use a macro instead of lots of repetitions of the package path to make

it easier to modify.
This commit is contained in:
Eric House 2012-02-13 22:13:23 -08:00
parent 0f8ddadd69
commit 82b232cf74
5 changed files with 56 additions and 31 deletions

View file

@ -22,6 +22,7 @@
#include <time.h> #include <time.h>
#include "andutils.h" #include "andutils.h"
#include "paths.h"
#include "comtypes.h" #include "comtypes.h"
#include "xwstream.h" #include "xwstream.h"
@ -320,7 +321,7 @@ setJAddrRec( JNIEnv* env, jobject jaddr, const CommsAddrRec* addr )
{ {
XP_ASSERT( !!addr ); XP_ASSERT( !!addr );
intToJenumField( env, jaddr, addr->conType, "conType", intToJenumField( env, jaddr, addr->conType, "conType",
"org/eehouse/android/xw4/jni/CommsAddrRec$CommsConnType" ); PKG_PATH("jni/CommsAddrRec$CommsConnType") );
switch ( addr->conType ) { switch ( addr->conType ) {
case COMMS_CONN_NONE: case COMMS_CONN_NONE:
@ -348,9 +349,9 @@ setJAddrRec( JNIEnv* env, jobject jaddr, const CommsAddrRec* addr )
void void
getJAddrRec( JNIEnv* env, CommsAddrRec* addr, jobject jaddr ) getJAddrRec( JNIEnv* env, CommsAddrRec* addr, jobject jaddr )
{ {
addr->conType = jenumFieldToInt( env, jaddr, "conType", addr->conType =
"org/eehouse/android/xw4/jni/" jenumFieldToInt( env, jaddr, "conType",
"CommsAddrRec$CommsConnType" ); PKG_PATH("jni/CommsAddrRec$CommsConnType") );
switch ( addr->conType ) { switch ( addr->conType ) {
case COMMS_CONN_NONE: case COMMS_CONN_NONE:

View file

@ -20,6 +20,7 @@
#include "drawwrapper.h" #include "drawwrapper.h"
#include "andutils.h" #include "andutils.h"
#include "paths.h"
enum { enum {
JCACHE_RECT0 JCACHE_RECT0
@ -75,8 +76,7 @@ makeDSI( AndDraw* draw, int indx, const DrawScoreInfo* dsi )
jobject dsiobj = draw->jCache[indx]; jobject dsiobj = draw->jCache[indx];
if ( !dsiobj ) { if ( !dsiobj ) {
jclass rclass = (*env)->FindClass( env, "org/eehouse/android/" jclass rclass = (*env)->FindClass( env, PKG_PATH("jni/DrawScoreInfo") );
"xw4/jni/DrawScoreInfo");
jmethodID initId = (*env)->GetMethodID( env, rclass, "<init>", "()V" ); jmethodID initId = (*env)->GetMethodID( env, rclass, "<init>", "()V" );
dsiobj = (*env)->NewObject( env, rclass, initId ); dsiobj = (*env)->NewObject( env, rclass, initId );
(*env)->DeleteLocalRef( env, rclass ); (*env)->DeleteLocalRef( env, rclass );
@ -153,8 +153,8 @@ and_draw_measureScoreText( DrawCtx* dctx,
XP_U16* width, XP_U16* height ) XP_U16* width, XP_U16* height )
{ {
DRAW_CBK_HEADER("measureScoreText", DRAW_CBK_HEADER("measureScoreText",
"(Landroid/graphics/Rect;Lorg/eehouse/android/" "(Landroid/graphics/Rect;L"
"xw4/jni/DrawScoreInfo;[I[I)V" ); PKG_PATH("jni/DrawScoreInfo;[I[I)V") );
jobject jrect = makeJRect( draw, JCACHE_RECT0, r ); jobject jrect = makeJRect( draw, JCACHE_RECT0, r );
jobject jdsi = makeDSI( draw, JCACHE_DSI, dsi ); jobject jdsi = makeDSI( draw, JCACHE_DSI, dsi );
@ -192,7 +192,7 @@ and_draw_score_drawPlayer( DrawCtx* dctx,
{ {
DRAW_CBK_HEADER("score_drawPlayer", DRAW_CBK_HEADER("score_drawPlayer",
"(Landroid/graphics/Rect;Landroid/graphics/Rect;" "(Landroid/graphics/Rect;Landroid/graphics/Rect;"
"Lorg/eehouse/android/xw4/jni/DrawScoreInfo;)V" ); "L" PKG_PATH("jni/DrawScoreInfo") ";)V" );
jobject jrinner = makeJRect( draw, JCACHE_RECT0, rInner ); jobject jrinner = makeJRect( draw, JCACHE_RECT0, rInner );
jobject jrouter = makeJRect( draw, JCACHE_RECT1, rOuter ); jobject jrouter = makeJRect( draw, JCACHE_RECT1, rOuter );

View file

@ -0,0 +1,25 @@
/* -*-mode: C; compile-command: "../../scripts/ndkbuild.sh"; -*- */
/*
* Copyright © 2012 by Eric House (xwords@eehouse.org). All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _PATHS_H_
#define _PATHS_H_
#define PKG_PATH(elem) "org/eehouse/android/xw4/" elem
#endif

View file

@ -20,6 +20,7 @@
#include "xportwrapper.h" #include "xportwrapper.h"
#include "andutils.h" #include "andutils.h"
#include "paths.h"
typedef struct _AndTransportProcs { typedef struct _AndTransportProcs {
TransportProcs tp; TransportProcs tp;
@ -34,7 +35,7 @@ makeJAddr( JNIEnv* env, const CommsAddrRec* addr )
jobject jaddr = NULL; jobject jaddr = NULL;
if ( NULL != addr ) { if ( NULL != addr ) {
jclass clazz jclass clazz
= (*env)->FindClass(env, "org/eehouse/android/xw4/jni/CommsAddrRec"); = (*env)->FindClass(env, PKG_PATH("jni/CommsAddrRec") );
XP_ASSERT( !!clazz ); XP_ASSERT( !!clazz );
jmethodID mid = getMethodID( env, clazz, "<init>", "()V" ); jmethodID mid = getMethodID( env, clazz, "<init>", "()V" );
XP_ASSERT( !!mid ); XP_ASSERT( !!mid );
@ -73,7 +74,7 @@ and_xport_send( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addr,
AndTransportProcs* aprocs = (AndTransportProcs*)closure; AndTransportProcs* aprocs = (AndTransportProcs*)closure;
if ( NULL != aprocs->jxport ) { if ( NULL != aprocs->jxport ) {
JNIEnv* env = *aprocs->envp; JNIEnv* env = *aprocs->envp;
const char* sig = "([BLorg/eehouse/android/xw4/jni/CommsAddrRec;)I"; const char* sig = "([BL" PKG_PATH("jni/CommsAddrRec") ";)I";
jmethodID mid = getMethodID( env, aprocs->jxport, "transportSend", sig ); jmethodID mid = getMethodID( env, aprocs->jxport, "transportSend", sig );
jbyteArray jbytes = makeByteArray( env, len, (jbyte*)buf ); jbyteArray jbytes = makeByteArray( env, len, (jbyte*)buf );
@ -98,12 +99,11 @@ and_xport_relayStatus( void* closure, CommsRelayState newState )
AndTransportProcs* aprocs = (AndTransportProcs*)closure; AndTransportProcs* aprocs = (AndTransportProcs*)closure;
if ( NULL != aprocs->jxport ) { if ( NULL != aprocs->jxport ) {
JNIEnv* env = *aprocs->envp; JNIEnv* env = *aprocs->envp;
const char* sig = "(Lorg/eehouse/android/xw4/jni/" const char* sig = "(L" PKG_PATH("jni/TransportProcs$CommsRelayState") ";)V";
"TransportProcs$CommsRelayState;)V";
jmethodID mid = getMethodID( env, aprocs->jxport, "relayStatus", sig ); jmethodID mid = getMethodID( env, aprocs->jxport, "relayStatus", sig );
jobject jenum = intToJEnum( env, newState, "org/eehouse/android/xw4/jni/" jobject jenum = intToJEnum( env, newState,
"TransportProcs$CommsRelayState" ); PKG_PATH("jni/TransportProcs$CommsRelayState") );
(*env)->CallVoidMethod( env, aprocs->jxport, mid, jenum ); (*env)->CallVoidMethod( env, aprocs->jxport, mid, jenum );
(*env)->DeleteLocalRef( env, jenum ); (*env)->DeleteLocalRef( env, jenum );
} }
@ -155,12 +155,12 @@ and_xport_relayError( void* closure, XWREASON relayErr )
if ( NULL != aprocs->jxport ) { if ( NULL != aprocs->jxport ) {
JNIEnv* env = *aprocs->envp; JNIEnv* env = *aprocs->envp;
jmethodID mid; jmethodID mid;
const char* sig = "(Lorg/eehouse/android/xw4/jni/" const char* sig =
"TransportProcs$XWRELAY_ERROR;)V"; "(L" PKG_PATH("jni/TransportProcs$XWRELAY_ERROR") ";)V";
mid = getMethodID( env, aprocs->jxport, "relayErrorProc", sig ); mid = getMethodID( env, aprocs->jxport, "relayErrorProc", sig );
jobject jenum = intToJEnum( env, relayErr, "org/eehouse/android/xw4/jni/" jobject jenum = intToJEnum( env, relayErr,
"TransportProcs$XWRELAY_ERROR" ); PKG_PATH("jni/TransportProcs$XWRELAY_ERROR") );
(*env)->CallVoidMethod( env, aprocs->jxport, mid, jenum ); (*env)->CallVoidMethod( env, aprocs->jxport, mid, jenum );
(*env)->DeleteLocalRef( env, jenum ); (*env)->DeleteLocalRef( env, jenum );

View file

@ -37,6 +37,7 @@
#include "anddict.h" #include "anddict.h"
#include "andutils.h" #include "andutils.h"
#include "jniutlswrapper.h" #include "jniutlswrapper.h"
#include "paths.h"
static CurGameInfo* static CurGameInfo*
makeGI( MPFORMAL JNIEnv* env, jobject j_gi ) makeGI( MPFORMAL JNIEnv* env, jobject j_gi )
@ -65,12 +66,12 @@ makeGI( MPFORMAL JNIEnv* env, jobject j_gi )
gi->allowPickTiles = getBool( env, j_gi, "allowPickTiles" ); gi->allowPickTiles = getBool( env, j_gi, "allowPickTiles" );
gi->allowHintRect = getBool( env, j_gi, "allowHintRect" ); gi->allowHintRect = getBool( env, j_gi, "allowHintRect" );
gi->phoniesAction = jenumFieldToInt( env, j_gi, "phoniesAction", gi->phoniesAction =
"org/eehouse/android/xw4/jni/" jenumFieldToInt( env, j_gi, "phoniesAction",
"CurGameInfo$XWPhoniesChoice"); PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") );
gi->serverRole = gi->serverRole =
jenumFieldToInt( env, j_gi, "serverRole", jenumFieldToInt( env, j_gi, "serverRole",
"org/eehouse/android/xw4/jni/CurGameInfo$DeviceRole"); PKG_PATH("jni/CurGameInfo$DeviceRole"));
getString( env, j_gi, "dictName", buf, VSIZE(buf) ); getString( env, j_gi, "dictName", buf, VSIZE(buf) );
gi->dictName = copyString( mpool, buf ); gi->dictName = copyString( mpool, buf );
@ -78,8 +79,7 @@ makeGI( MPFORMAL JNIEnv* env, jobject j_gi )
XP_ASSERT( gi->nPlayers <= MAX_NUM_PLAYERS ); XP_ASSERT( gi->nPlayers <= MAX_NUM_PLAYERS );
jobject jplayers; jobject jplayers;
if ( getObject( env, j_gi, "players", if ( getObject( env, j_gi, "players", "[L" PKG_PATH("jni/LocalPlayer") ";",
"[Lorg/eehouse/android/xw4/jni/LocalPlayer;",
&jplayers ) ) { &jplayers ) ) {
int ii; int ii;
for ( ii = 0; ii < gi->nPlayers; ++ii ) { for ( ii = 0; ii < gi->nPlayers; ++ii ) {
@ -125,13 +125,13 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
setString( env, jgi, "dictName", gi->dictName ); setString( env, jgi, "dictName", gi->dictName );
intToJenumField( env, jgi, gi->phoniesAction, "phoniesAction", intToJenumField( env, jgi, gi->phoniesAction, "phoniesAction",
"org/eehouse/android/xw4/jni/CurGameInfo$XWPhoniesChoice" ); PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") );
intToJenumField( env, jgi, gi->serverRole, "serverRole", intToJenumField( env, jgi, gi->serverRole, "serverRole",
"org/eehouse/android/xw4/jni/CurGameInfo$DeviceRole" ); PKG_PATH("jni/CurGameInfo$DeviceRole") );
jobject jplayers; jobject jplayers;
if ( getObject( env, jgi, "players", if ( getObject( env, jgi, "players",
"[Lorg/eehouse/android/xw4/jni/LocalPlayer;", "[L" PKG_PATH("jni/LocalPlayer") ";",
&jplayers ) ) { &jplayers ) ) {
int ii; int ii;
for ( ii = 0; ii < gi->nPlayers; ++ii ) { for ( ii = 0; ii < gi->nPlayers; ++ii ) {
@ -1077,8 +1077,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
CommsCtxt* comms = state->game.comms; CommsCtxt* comms = state->game.comms;
comms_getAddr( comms, &addr ); comms_getAddr( comms, &addr );
intToJenumField( env, jsummary, addr.conType, "conType", intToJenumField( env, jsummary, addr.conType, "conType",
"org/eehouse/android/xw4/jni/" PKG_PATH("jni/CommsAddrRec$CommsConnType") );
"CommsAddrRec$CommsConnType" );
if ( COMMS_CONN_RELAY == addr.conType ) { if ( COMMS_CONN_RELAY == addr.conType ) {
XP_UCHAR buf[128]; XP_UCHAR buf[128];
XP_U16 len = VSIZE(buf); XP_U16 len = VSIZE(buf);