Improve error handling

Add coreMessage, die to EmuThread, propagate msgboxf to coreMessage
This commit is contained in:
Stefanos Kornilios Mitsis Poiitidis 2014-11-10 05:28:45 +01:00
parent ff4f5c21a8
commit d1aa96d3e1
2 changed files with 77 additions and 59 deletions

View File

@ -23,7 +23,7 @@ extern "C"
{
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_config(JNIEnv *env,jobject obj,jstring dirName) __attribute__((visibility("default")));
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_init(JNIEnv *env,jobject obj,jstring fileName) __attribute__((visibility("default")));
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_run(JNIEnv *env,jobject obj,jobject track) __attribute__((visibility("default")));
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_run(JNIEnv *env,jobject obj,jobject emu_thread) __attribute__((visibility("default")));
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_stop(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_send(JNIEnv *env,jobject obj,jint id, jint v) __attribute__((visibility("default")));
@ -212,18 +212,6 @@ static void *ThreadHandler(void *UserData)
// Platform-specific NullDC functions
//
int msgboxf(const wchar* Text,unsigned int Type,...)
{
wchar S[2048];
va_list Args;
va_start(Args,Type);
vsprintf(S,Text,Args);
va_end(Args);
puts(S);
return(MBX_OK);
}
void UpdateInputState(u32 Port)
{
@ -296,7 +284,9 @@ JNIEnv* jenv; //we are abusing the f*** out of this poor guy
//stuff for audio
jshortArray jsamples;
jmethodID writemid;
jobject track;
jmethodID coreMessageMid;
jmethodID dieMid;
jobject emu;
//stuff for microphone
jobject sipemu;
jmethodID getmicdata;
@ -306,21 +296,40 @@ jbyteArray jpix = NULL;
jmethodID updatevmuscreen;
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_run(JNIEnv *env,jobject obj,jobject trk)
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_run(JNIEnv *env,jobject obj,jobject emu_thread)
{
install_prof_handler(0);
jenv=env;
track=trk;
emu=emu_thread;
jsamples=env->NewShortArray(SAMPLE_COUNT*2);
writemid=env->GetMethodID(env->GetObjectClass(track),"WriteBuffer","([SI)I");
//showMessageMid=env->GetMethodID(env->GetObjectClass(track),"WriteBuffer","([SI)I");
//dieMid=env->GetMethodID(env->GetObjectClass(track),"Die","([SI)I");
writemid=env->GetMethodID(env->GetObjectClass(emu),"WriteBuffer","([SI)I");
coreMessageMid=env->GetMethodID(env->GetObjectClass(emu),"coreMessage","([B)V");
dieMid=env->GetMethodID(env->GetObjectClass(emu),"Die","()V");
dc_run();
}
int msgboxf(const wchar* Text,unsigned int Type,...)
{
wchar S[2048];
va_list Args;
va_start(Args,Type);
vsprintf(S,Text,Args);
va_end(Args);
int byteCount = strlen(S);
jbyteArray bytes = jenv->NewByteArray(byteCount);
jenv->SetByteArrayRegion(bytes, 0, byteCount, (jbyte*)S);
//puts(S);
jenv->CallVoidMethod(emu,coreMessageMid,bytes);
return(MBX_OK);
}
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setupMic(JNIEnv *env,jobject obj,jobject sip)
{
sipemu = env->NewGlobalRef(sip);
@ -475,12 +484,12 @@ u32 os_Push(void* frame, u32 amt, bool wait)
verify(amt==SAMPLE_COUNT);
//yeah, do some audio piping magic here !
jenv->SetShortArrayRegion(jsamples,0,amt*2,(jshort*)frame);
return jenv->CallIntMethod(track,writemid,jsamples,wait);
return jenv->CallIntMethod(emu,writemid,jsamples,wait);
}
bool os_IsAudioBuffered()
{
return jenv->CallIntMethod(track,writemid,jsamples,-1)==0;
return jenv->CallIntMethod(emu,writemid,jsamples,-1)==0;
}
int get_mic_data(u8* buffer)

View File

@ -3,12 +3,16 @@ package com.reicast.emulator.emu;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Paint;
@ -149,7 +153,7 @@ public class GL2JNIView extends GLSurfaceView
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
ethd = new EmuThread(!Config.nosound);
ethd = new EmuThread((Activity) getContext(), !Config.nosound);
touchVibrationEnabled = prefs.getBoolean(Config.pref_touchvibe, true);
vibrationDuration = prefs.getInt(Config.pref_vibrationDuration, 20);
@ -620,13 +624,15 @@ public class GL2JNIView extends GLSurfaceView
class EmuThread extends Thread
{
Activity activity;
AudioTrack Player;
long pos; //write position
long size; //size in frames
private boolean sound;
public EmuThread(boolean sound) {
public EmuThread(Activity activity, boolean sound) {
this.sound = sound;
this.activity = activity;
}
@Override public void run()
@ -680,44 +686,47 @@ public class GL2JNIView extends GLSurfaceView
return 1;
}
}
void coreMessage(byte[] msg) {
showMessage(new String(msg, Charset.forName("UTF-8")));
}
void showMessage(final String msg) {
activity.runOnUiThread(new Runnable() {
public void run() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("Ooops");
// set dialog message
alertDialogBuilder
.setMessage(msg)
.setCancelable(false)
.setPositiveButton("Okay...",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
//MainActivity.this.finish();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
}
void showMessage(String msg) {
/*
activity.runOnUiThread(new Runnable() {
public void run() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("Ooops");
// set dialog message
alertDialogBuilder
.setMessage(msg)
.setCancelable(false)
.setPositiveButton("Okay...",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
*/
}
void die() {
showMessage("Something went wrong and reicast crashed.\nPlease report this on the reicast forums.");
activity.finish();
}
void die() {
showMessage("Something went very bad. Please report this on the reicast forums.");
onStop();
}
public void onStop() {