5
* Copyright 2016 Tony George <teejeetech@gmail.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27
using TeeJee.FileSystem;
30
public class TimeoutCounter : GLib.Object {
32
public bool active = false;
33
public string process_to_kill = "";
34
public int seconds_to_wait = 30;
35
public bool exit_app = false;
37
public void kill_process_on_timeout(
38
string process_to_kill, int seconds_to_wait = 20, bool exit_app = false){
40
this.process_to_kill = process_to_kill;
41
this.seconds_to_wait = seconds_to_wait;
42
this.exit_app = exit_app;
46
Thread.create<void> (start_counter_thread, true);
49
log_error (e.message);
53
public void exit_on_timeout(int seconds_to_wait = 20){
54
this.process_to_kill = "";
55
this.seconds_to_wait = seconds_to_wait;
60
Thread.create<void> (start_counter_thread, true);
63
log_error (e.message);
71
public void start_counter_thread(){
74
while (active && (secs < seconds_to_wait)){
75
Thread.usleep((ulong) GLib.TimeSpan.MILLISECOND * 1000);
83
if (process_to_kill.length > 0){
84
Posix.system("killall " + process_to_kill);
85
stderr.printf("\n[timeout] Killed process" + ": %s\n".printf(process_to_kill));
89
stderr.printf("\n[timeout] Exit application\n");