glchess: Kill engine processes on new game/exit
This commit is contained in:
parent
f79e366568
commit
fb2a75ef70
2 changed files with 34 additions and 7 deletions
|
@ -35,7 +35,7 @@ public class ChessEngine : Object
|
|||
try
|
||||
{
|
||||
Process.spawn_async_with_pipes (null, argv, null,
|
||||
SpawnFlags.SEARCH_PATH,
|
||||
SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD,
|
||||
null,
|
||||
out pid, out stdin_fd, out stdout_fd, out stderr_fd);
|
||||
}
|
||||
|
@ -45,6 +45,8 @@ public class ChessEngine : Object
|
|||
return false;
|
||||
}
|
||||
|
||||
ChildWatch.add (pid, engine_stopped_cb);
|
||||
|
||||
stdout_channel = new IOChannel.unix_new (stdout_fd);
|
||||
try
|
||||
{
|
||||
|
@ -61,6 +63,11 @@ public class ChessEngine : Object
|
|||
return true;
|
||||
}
|
||||
|
||||
private void engine_stopped_cb (Pid pid, int status)
|
||||
{
|
||||
stopped ();
|
||||
}
|
||||
|
||||
public virtual void start_game ()
|
||||
{
|
||||
}
|
||||
|
@ -79,8 +86,8 @@ public class ChessEngine : Object
|
|||
|
||||
public void stop ()
|
||||
{
|
||||
// FIXME
|
||||
stopped ();
|
||||
if (pid != 0)
|
||||
Posix.kill (pid, Posix.SIGTERM);
|
||||
}
|
||||
|
||||
private bool read_cb (IOChannel source, IOCondition condition)
|
||||
|
|
|
@ -124,6 +124,13 @@ public class Application : Gtk.Application
|
|||
settings_changed_cb (settings, "show-3d");
|
||||
}
|
||||
|
||||
protected override void shutdown ()
|
||||
{
|
||||
base.shutdown ();
|
||||
if (opponent_engine != null)
|
||||
opponent_engine.stop ();
|
||||
}
|
||||
|
||||
public void quit_game ()
|
||||
{
|
||||
if (save_duration_timeout != 0)
|
||||
|
@ -298,7 +305,14 @@ public class Application : Gtk.Application
|
|||
black_level = "normal";
|
||||
|
||||
opponent = null;
|
||||
if (opponent_engine != null)
|
||||
{
|
||||
opponent_engine.stop ();
|
||||
opponent_engine.ready_changed.disconnect (engine_ready_cb);
|
||||
opponent_engine.moved.disconnect (engine_move_cb);
|
||||
opponent_engine.stopped.disconnect (engine_stopped_cb);
|
||||
opponent_engine = null;
|
||||
}
|
||||
if (white_engine != null)
|
||||
{
|
||||
opponent = game.white;
|
||||
|
@ -316,6 +330,7 @@ public class Application : Gtk.Application
|
|||
{
|
||||
opponent_engine.ready_changed.connect (engine_ready_cb);
|
||||
opponent_engine.moved.connect (engine_move_cb);
|
||||
opponent_engine.stopped.connect (engine_stopped_cb);
|
||||
opponent_engine.start ();
|
||||
}
|
||||
|
||||
|
@ -436,6 +451,11 @@ public class Application : Gtk.Application
|
|||
opponent.move (move);
|
||||
}
|
||||
|
||||
private void engine_stopped_cb (ChessEngine engine)
|
||||
{
|
||||
opponent.resign ();
|
||||
}
|
||||
|
||||
private void game_start_cb (ChessGame game)
|
||||
{
|
||||
if (opponent_engine != null)
|
||||
|
|
Loading…
Reference in a new issue