private static int PLUGIN_TIMEOUT = 5;
private PluginLoader plugin_loader;
- private SignalHandler signal_handler;
private ContextManager context_manager;
private ArrayList <RootDeviceFactory> factories;
private ArrayList <RootDevice> root_devices;
private MainLoop main_loop;
private int exit_code;
- public bool restart;
+ public bool need_restart;
private Main () throws GLib.Error {
Environment.set_application_name (_(BuildConfig.PACKAGE_NAME));
this.plugin_loader.plugin_available.connect (this.on_plugin_loaded);
- this.signal_handler = SignalHandler.get_default ();
- this.signal_handler.exit.connect (this.application_exit_cb);
- this.signal_handler.restart.connect (this.application_restart_cb);
+ SignalHandler.setup (this);
}
public void exit (int exit_code) {
this.exit_code = exit_code;
this.main_loop.quit ();
+
+ SignalHandler.cleanup ();
+ }
+
+ public void restart () {
+ this.need_restart = true;
+
+ this.exit (0);
}
private int run () {
return this.exit_code;
}
- private void application_restart_cb () {
- this.restart = true;
-
- this.exit (0);
- }
-
- private void application_exit_cb () {
- this.exit (0);
- }
-
private void on_plugin_loaded (PluginLoader plugin_loader,
Plugin plugin) {
var iterator = this.factories.iterator ();
int exit_code = main.run ();
- if (main.restart) {
+ if (main.need_restart) {
Posix.execvp (original_args[0], original_args);
}
* Handles Posix signals.
*/
public class Rygel.SignalHandler : GLib.Object {
- private static SignalHandler handler;
+ private static Main main = null;
+ private static sigaction_t action;
- public signal void exit ();
- public signal void restart ();
+ public static void setup (Main _main) {
+ main = _main;
- private sigaction_t action;
+ action = sigaction_t ();
- public static SignalHandler get_default () {
- if (handler == null) {
- handler = new SignalHandler ();
- }
+ action.sa_handler = signal_handler;
- return handler;
+ /* Hook the handler for SIGTERM */
+ sigaction (SIGINT, action, null);
+ sigaction (SIGHUP, action, null);
}
- private SignalHandler () {
- this.action = sigaction_t ();
-
- this.action.sa_handler = this.signal_handler;
-
- /* Hook the handler for SIGTERM */
- sigaction (SIGINT, this.action, null);
- sigaction (SIGHUP, this.action, null);
+ public static void cleanup () {
+ main = null;
}
private static void signal_handler (int signum) {
if (signum == SIGHUP) {
- handler.restart ();
+ main.restart ();
} else {
- handler.exit ();
+ main.exit (0);
}
}
}