TimeoutCounter

1. Overview

The TimeoutCounter module provides interactive timeout enforcement for BastionGuard Backup. It starts a counter thread that can terminate a named process or exit the application when an interactive operation exceeds its allowed time.

The implementation is written in Vala and uses GLib/GIO together with the application utility namespaces required by the file.


2. Dependencies and Integration

The module imports:

  • TeeJee.Logging
  • TeeJee.FileSystem
  • TeeJee.Misc

3. Declared Types

3.1 TimeoutCounter

public class TimeoutCounter : GLib.Object

This class encapsulates the state and operations described by this source file.


4. State, Properties, Constants, and Signals

Public and protected state

  • public bool active – Whether the timeout counter is currently running.
  • public string process_to_kill – Runtime state used by the module.
  • public const int DEFAULT_SECONDS_TO_WAIT – Compile-time constant used by this module.
  • public int seconds_to_wait – Maximum wait duration in seconds.
  • public bool exit_app – Boolean state controlling or reporting exit app.

5. Public API and Operational Methods

5.1 kill_process_on_timeout()

public void kill_process_on_timeout( string process_to_kill, int seconds_to_wait = DEFAULT_SECONDS_TO_WAIT, bool exit_app = false)

Implements the kill process on timeout operation for this module.

  • Uses asynchronous callbacks, child watches, or worker-thread behavior.
  • Catches runtime errors locally and reports them through the logging layer or return value.

5.2 exit_on_timeout()

public void exit_on_timeout(int seconds_to_wait = DEFAULT_SECONDS_TO_WAIT)

Implements the exit on timeout operation for this module.

  • Uses asynchronous callbacks, child watches, or worker-thread behavior.
  • Catches runtime errors locally and reports them through the logging layer or return value.

5.3 stop()

public void stop()

Stops or closes the active operation and releases related runtime state.

5.4 start_counter_thread()

public void start_counter_thread()

Starts a worker thread that counts down, optionally kills a named process, and can terminate the application when the timeout expires.

  • Contains a polling loop with an explicit sleep interval.

6. Operational Flow

  1. Apply the requested operation and update runtime or persistent state.
  2. Finalize the operation and release files, mounts, child processes, widgets, or cached state.

7. Error Handling and Diagnostics

  • GLib and filesystem exceptions are caught locally in the operations that can fail.
  • The TeeJee logging layer records errors, debug state, generated commands, and operational messages.

8. Runtime and Security Considerations

  • Concurrency: callbacks and worker state must remain synchronized with object destruction and GTK main-loop ownership.
  • Polling: synchronous wait loops can delay shutdown or block the caller when the underlying operation does not complete.
  • Shared state: static caches and global switches are shared by all callers and are not automatically thread-isolated.

9. Licensing

The source is distributed under the GNU General Public License version 2 or any later version.

The source header identifies:

Copyright 2012-2018 Tony George <teejeetech@gmail.com>