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

View file

@ -20,6 +20,7 @@
#include "drawwrapper.h"
#include "andutils.h"
#include "paths.h"
enum {
JCACHE_RECT0
@ -75,8 +76,7 @@ makeDSI( AndDraw* draw, int indx, const DrawScoreInfo* dsi )
jobject dsiobj = draw->jCache[indx];
if ( !dsiobj ) {
jclass rclass = (*env)->FindClass( env, "org/eehouse/android/"
"xw4/jni/DrawScoreInfo");
jclass rclass = (*env)->FindClass( env, PKG_PATH("jni/DrawScoreInfo") );
jmethodID initId = (*env)->GetMethodID( env, rclass, "<init>", "()V" );
dsiobj = (*env)->NewObject( env, rclass, initId );
(*env)->DeleteLocalRef( env, rclass );
@ -153,8 +153,8 @@ and_draw_measureScoreText( DrawCtx* dctx,
XP_U16* width, XP_U16* height )
{
DRAW_CBK_HEADER("measureScoreText",
"(Landroid/graphics/Rect;Lorg/eehouse/android/"
"xw4/jni/DrawScoreInfo;[I[I)V" );
"(Landroid/graphics/Rect;L"
PKG_PATH("jni/DrawScoreInfo;[I[I)V") );
jobject jrect = makeJRect( draw, JCACHE_RECT0, r );
jobject jdsi = makeDSI( draw, JCACHE_DSI, dsi );
@ -192,7 +192,7 @@ and_draw_score_drawPlayer( DrawCtx* dctx,
{
DRAW_CBK_HEADER("score_drawPlayer",
"(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 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 "andutils.h"
#include "paths.h"
typedef struct _AndTransportProcs {
TransportProcs tp;
@ -34,7 +35,7 @@ makeJAddr( JNIEnv* env, const CommsAddrRec* addr )
jobject jaddr = NULL;
if ( NULL != addr ) {
jclass clazz
= (*env)->FindClass(env, "org/eehouse/android/xw4/jni/CommsAddrRec");
= (*env)->FindClass(env, PKG_PATH("jni/CommsAddrRec") );
XP_ASSERT( !!clazz );
jmethodID mid = getMethodID( env, clazz, "<init>", "()V" );
XP_ASSERT( !!mid );
@ -73,7 +74,7 @@ and_xport_send( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addr,
AndTransportProcs* aprocs = (AndTransportProcs*)closure;
if ( NULL != aprocs->jxport ) {
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 );
jbyteArray jbytes = makeByteArray( env, len, (jbyte*)buf );
@ -98,12 +99,11 @@ and_xport_relayStatus( void* closure, CommsRelayState newState )
AndTransportProcs* aprocs = (AndTransportProcs*)closure;
if ( NULL != aprocs->jxport ) {
JNIEnv* env = *aprocs->envp;
const char* sig = "(Lorg/eehouse/android/xw4/jni/"
"TransportProcs$CommsRelayState;)V";
const char* sig = "(L" PKG_PATH("jni/TransportProcs$CommsRelayState") ";)V";
jmethodID mid = getMethodID( env, aprocs->jxport, "relayStatus", sig );
jobject jenum = intToJEnum( env, newState, "org/eehouse/android/xw4/jni/"
"TransportProcs$CommsRelayState" );
jobject jenum = intToJEnum( env, newState,
PKG_PATH("jni/TransportProcs$CommsRelayState") );
(*env)->CallVoidMethod( env, aprocs->jxport, mid, jenum );
(*env)->DeleteLocalRef( env, jenum );
}
@ -155,12 +155,12 @@ and_xport_relayError( void* closure, XWREASON relayErr )
if ( NULL != aprocs->jxport ) {
JNIEnv* env = *aprocs->envp;
jmethodID mid;
const char* sig = "(Lorg/eehouse/android/xw4/jni/"
"TransportProcs$XWRELAY_ERROR;)V";
const char* sig =
"(L" PKG_PATH("jni/TransportProcs$XWRELAY_ERROR") ";)V";
mid = getMethodID( env, aprocs->jxport, "relayErrorProc", sig );
jobject jenum = intToJEnum( env, relayErr, "org/eehouse/android/xw4/jni/"
"TransportProcs$XWRELAY_ERROR" );
jobject jenum = intToJEnum( env, relayErr,
PKG_PATH("jni/TransportProcs$XWRELAY_ERROR") );
(*env)->CallVoidMethod( env, aprocs->jxport, mid, jenum );
(*env)->DeleteLocalRef( env, jenum );

View file

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