Skip to content

Commit

Permalink
wait on retrying oms connectivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Hong Chen committed Mar 12, 2018
1 parent 6cabf9a commit e01a596
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 32 deletions.
65 changes: 33 additions & 32 deletions app/src/main/java/net/lrstudios/android/pachi/PachiEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,43 +73,44 @@ protected File getEngineFile() {
File file = new File(dir, "pachi");

Context _context = GtpBoardActivity.actionContext;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(_context);
int version = prefs.getInt(PREF_KEY_VERSION, 0);
if (version < EXE_VERSION) {
if (file.exists())
file.delete();
InputStream inputStream = null;
OutputStream outputStream = null;
try {
outputStream = new BufferedOutputStream(new FileOutputStream(file), 4096);
inputStream = new BufferedInputStream(_context.getResources().openRawResource(R.raw.pachi), 4096);
Utils.copyStream(inputStream, outputStream, 4096);

extractRawResToFile(R.raw.libcaffe, dir,"libcaffe.so");
extractRawResToFile(R.raw.golast19, dir,"golast19.prototxt");
extractRawResToFile(R.raw.golast, dir, "golast.trained");

try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(_context);
int version = prefs.getInt(PREF_KEY_VERSION, 0);
if (version < EXE_VERSION) {
if (file.exists())
file.delete();
InputStream inputStream = null;
OutputStream outputStream = null;
try {
//file.setExecutable(true); TODO test this instead of chmod
new ProcessBuilder("chmod", "744", file.getAbsolutePath()).start().waitFor();
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(PREF_KEY_VERSION, EXE_VERSION);
editor.commit();
}
catch (IOException e) {
e.printStackTrace();
}
catch (InterruptedException e) {
outputStream = new BufferedOutputStream(new FileOutputStream(file), 4096);
inputStream = new BufferedInputStream(_context.getResources().openRawResource(R.raw.pachi), 4096);
Utils.copyStream(inputStream, outputStream, 4096);

extractRawResToFile(R.raw.libcaffe, dir, "libcaffe.so");
extractRawResToFile(R.raw.golast19, dir, "golast19.prototxt");
extractRawResToFile(R.raw.golast, dir, "golast.trained");

try {
//file.setExecutable(true); TODO test this instead of chmod
new ProcessBuilder("chmod", "744", file.getAbsolutePath()).start().waitFor();
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(PREF_KEY_VERSION, EXE_VERSION);
editor.commit();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
Utils.closeObject(inputStream);
Utils.closeObject(outputStream);
}
}
catch (IOException e) { // TODO handle file extracting errors
e.printStackTrace();
}
finally {
Utils.closeObject(inputStream);
Utils.closeObject(outputStream);
}
} catch (RuntimeException e){
// fine to continue with the pre-installed engine bits on the cloud node
}

return file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;

import lrstudios.games.ego.lib.GoBoard;
import lrstudios.games.ego.lib.IntentGameInfo;
import lrstudios.games.ego.lib.R;
import lrstudios.games.ego.lib.UpdatePrefsTask;
import lrstudios.util.android.ui.BetterFragmentActivity;

import sapphire.kernel.common.GlobalKernelReferences;
import sapphire.kernel.server.KernelServerImpl;
import sapphire.oms.OMSServer;

/**
* Allows to start a game against a bot.
Expand Down Expand Up @@ -145,6 +149,14 @@ else if (colorPos == 1)
String ipLocal = getWifiIPAddress();

KernelServerImpl.main(new String[]{ipLocal, "22344", omsHost, "22343"});
OMSServer oms = GlobalKernelReferences.nodeServer.oms;
if (oms == null) {
Toast.makeText(
this,
"Cannot connect to OMS. Please check your network connectivity and ensure OMS is available, and try again.",
Toast.LENGTH_LONG).show();
return;
}

intent = new Intent(NewGameActivity.this, GtpBoardActivity.class);
intent.putExtra(GtpBoardActivity.INTENT_GTP_BOT_CLASS, getBotClass());
Expand All @@ -163,6 +175,14 @@ else if (id == R.id.btn_play_continue) {
String ipLocal = getWifiIPAddress();

KernelServerImpl.main(new String[]{ipLocal, "22344", omsHost, "22343"});
OMSServer oms = GlobalKernelReferences.nodeServer.oms;
if (oms == null) {
Toast.makeText(
this,
"Cannot connect to OMS. Please check your network connectivity and ensure OMS is available, and try again.",
Toast.LENGTH_LONG).show();
return;
}

intent = new Intent(NewGameActivity.this, GtpBoardActivity.class);
intent.putExtra(GtpBoardActivity.INTENT_PLAY_RESTORE, true);
Expand Down

0 comments on commit e01a596

Please sign in to comment.