Skip to content
API Documentation
BastionGuard™
TimeoutCounter Class Reference
Inheritance diagram for TimeoutCounter:

Public Member Functions

void kill_process_on_timeout (string process_to_kill, int seconds_to_wait=DEFAULT_SECONDS_TO_WAIT, bool exit_app=false)
void exit_on_timeout (int seconds_to_wait=DEFAULT_SECONDS_TO_WAIT)
void stop ()
void start_counter_thread ()

Public Attributes

bool active = false
string process_to_kill = ""
int seconds_to_wait = 60
bool exit_app = false

Static Public Attributes

const int DEFAULT_SECONDS_TO_WAIT = 60

Detailed Description

Definition at line 30 of file TimeoutCounter.vala.

Member Function Documentation

◆ exit_on_timeout()

void TimeoutCounter.exit_on_timeout ( int seconds_to_wait = DEFAULT_SECONDS_TO_WAIT)
inline

Definition at line 54 of file TimeoutCounter.vala.

54 {
55 this.process_to_kill = "";
56 this.seconds_to_wait = seconds_to_wait;
57 this.exit_app = true;
58
59 try {
60 active = true;
61 new Thread<void>.try ("timeout-counter", () => {start_counter_thread();});
62 }
63 catch (Error e) {
64 log_error (e.message);
65 }
66 }
void start_counter_thread()
void log_error(string message, bool highlight=false, bool is_warning=false)

References active, DEFAULT_SECONDS_TO_WAIT, Error, TeeJee.Logging.log_error(), seconds_to_wait, and start_counter_thread().

◆ kill_process_on_timeout()

void TimeoutCounter.kill_process_on_timeout ( string process_to_kill,
int seconds_to_wait = DEFAULT_SECONDS_TO_WAIT,
bool exit_app = false )
inline

Definition at line 38 of file TimeoutCounter.vala.

39 {
40
41 this.process_to_kill = process_to_kill;
42 this.seconds_to_wait = seconds_to_wait;
43 this.exit_app = exit_app;
44
45 try {
46 active = true;
47 new Thread<void>.try ("timeout-counter",() => { start_counter_thread();});
48 }
49 catch (Error e) {
50 log_error (e.message);
51 }
52 }

References active, DEFAULT_SECONDS_TO_WAIT, Error, exit_app, TeeJee.Logging.log_error(), process_to_kill, seconds_to_wait, and start_counter_thread().

◆ start_counter_thread()

void TimeoutCounter.start_counter_thread ( )
inline

Definition at line 72 of file TimeoutCounter.vala.

72 {
73 int secs = 0;
74
75 while (active && (secs < seconds_to_wait)){
76 Thread.usleep((ulong) GLib.TimeSpan.MILLISECOND * 1000);
77 secs += 1;
78 }
79
80 if (active){
81 active = false;
82 stdout.printf("\n");
83
84 if (process_to_kill.length > 0){
85 Posix.system("killall " + process_to_kill);
86 log_debug("[timeout] Killed process" + ": %s".printf(process_to_kill));
87 }
88
89 if (exit_app){
90 log_debug("[timeout] Exit application");
91 exit(0);
92 }
93 }
94 }
void exit(int exit_code)
void log_debug(string message)

References active, exit(), exit_app, TeeJee.Logging.log_debug(), process_to_kill, and seconds_to_wait.

Referenced by exit_on_timeout(), and kill_process_on_timeout().

◆ stop()

void TimeoutCounter.stop ( )
inline

Definition at line 68 of file TimeoutCounter.vala.

68 {
69 active = false;
70 }

References active.

Member Data Documentation

◆ active

bool TimeoutCounter.active = false

◆ DEFAULT_SECONDS_TO_WAIT

const int TimeoutCounter.DEFAULT_SECONDS_TO_WAIT = 60
static

Definition at line 34 of file TimeoutCounter.vala.

Referenced by exit_on_timeout(), and kill_process_on_timeout().

◆ exit_app

bool TimeoutCounter.exit_app = false

Definition at line 36 of file TimeoutCounter.vala.

Referenced by kill_process_on_timeout(), and start_counter_thread().

◆ process_to_kill

string TimeoutCounter.process_to_kill = ""

Definition at line 33 of file TimeoutCounter.vala.

Referenced by kill_process_on_timeout(), and start_counter_thread().

◆ seconds_to_wait

int TimeoutCounter.seconds_to_wait = 60

The documentation for this class was generated from the following file: