]> Devoid-pointer.net GitWeb - Nine-Q.git/commitdiff
- Add logging system
authorMichal Malý <madcatxster@devoid-pointer.net>
Sun, 21 Dec 2014 02:27:38 +0000 (03:27 +0100)
committerMichal Malý <madcatxster@devoid-pointer.net>
Sun, 21 Dec 2014 02:27:38 +0000 (03:27 +0100)
- Gracefully exit on SIGINT

src/formatting_helpers.adb
src/global_types.ads
src/launcher.adb [new file with mode: 0644]
src/launcher.ads [new file with mode: 0644]
src/nine_q.adb

index 76c807438174d6340308496c83f8a1f603d5b951..182619df7adb05e4bd2e479bebb3897fdb6f40b4 100644 (file)
@@ -1,6 +1,5 @@
 with Ada.Numerics.Generic_Elementary_Functions;
 with Ada.Strings.Fixed;
-with Ada.Strings.Unbounded;
 --with Ada.Text_IO;
 
 package body Formatting_Helpers is
@@ -100,7 +99,6 @@ package body Formatting_Helpers is
 
   procedure Prepend_Zeros_To_Text(Num: in FH_Float; Decimals: in FH_Float; Text: in out UB_Text) is
     package FHEF is new Ada.Numerics.Generic_Elementary_Functions(FH_Float);
-    use Ada.Strings.Unbounded;
     use FHEF;
 
     Log_Dec: constant FH_Float := Log(Base => 10.0, X => Decimals);
index d80f381b887d533b7e202be0b8b4340e606fbdee..67e93e8228a77e4e5e66cb38b310db0f3adbd8fb 100644 (file)
@@ -4,7 +4,7 @@ with Ada.Strings.Unbounded;
 package Global_Types is
 
   type Problem_ID is new Ada.Containers.Count_Type;
-  type RetCode is (OK, E_NOTFOUND, E_UNKW, E_INVAL, E_NOMEM, E_NULLPTR); 
+  type RetCode is (OK, E_NOTFOUND, E_UNKW, E_INVAL, E_NOMEM, E_NULLPTR, E_FAIL); 
   type Unique_ID is new Ada.Containers.Count_Type;
   subtype HTML_Code is Ada.Strings.Unbounded.Unbounded_String;
   subtype UB_Text is Ada.Strings.Unbounded.Unbounded_String;
diff --git a/src/launcher.adb b/src/launcher.adb
new file mode 100644 (file)
index 0000000..61be8a7
--- /dev/null
@@ -0,0 +1,46 @@
+with Ada.Text_IO;
+with AWS.Config.Ini;
+
+with Global_Types;
+with Handlers;
+with Logging_System;
+
+use Global_Types;
+
+package body Launcher is
+
+  procedure Launch is
+    RC: RetCode;
+  begin
+    RC := Logging_System.Initialize;
+    if RC /= OK then
+      Ada.Text_IO.Put_Line("Nine-Q will not start without a log file");
+      return;
+    end if;
+
+    AWS.Config.Ini.Read(Server_Config, "nine_q_config.ini");
+
+    AWS.Server.Start(Web_Server => Web_Server,
+                    Dispatcher => Handlers.Get_Dispatchers,
+                    Config => Server_Config);
+
+    Ada.Text_IO.Put_Line("Nine-Q server started");
+    Logging_System.Log("Nine-Q server started", Logging_System.DEBUG);
+
+    AWS.Server.Wait(AWS.Server.No_Server);
+    Logging_System.Log("Nine-Q server shut down", Logging_System.DEBUG);
+    Ada.Text_IO.Put_Line("Nine-Q server shut down");
+
+    Logging_System.Close;
+  end Launch;
+
+  protected body Signal_Handlers is
+
+    procedure Shutdown_On_Signal is
+    begin
+      AWS.Server.Shutdown(Web_Server);
+    end Shutdown_On_Signal;
+
+  end Signal_Handlers;
+
+end Launcher;
diff --git a/src/launcher.ads b/src/launcher.ads
new file mode 100644 (file)
index 0000000..896f5e0
--- /dev/null
@@ -0,0 +1,23 @@
+with Ada.Interrupts;
+with Ada.Interrupts.Names;
+with AWS.Config;
+with AWS.Server;
+
+package Launcher is
+  pragma Unreserve_All_Interrupts;
+
+  procedure Launch;
+
+private
+  Server_Config: AWS.Config.Object;
+  Web_Server: AWS.Server.HTTP;
+
+  protected Signal_Handlers is
+    procedure Shutdown_On_Signal;
+
+    pragma Attach_Handler(Shutdown_On_Signal, Ada.Interrupts.Names.SIGINT);
+  end Signal_Handlers;
+
+end Launcher;
+
+
index 004df6747a57e19275ef50c35861542353b14759..37e070e1e34203fe5e6c9f36ff36bb6da5b4c716 100644 (file)
@@ -1,20 +1,6 @@
-with AWS.Config;
-with AWS.Config.Ini;
-with AWS.Server;
-
-with Handlers;
+with Launcher;
 
 procedure Nine_Q is
-  Server_Config: AWS.Config.Object;
-  Web_Server: AWS.Server.HTTP;
 begin
-  AWS.Config.Ini.Read(Server_Config, "nine_q_config.ini");
-
-  AWS.Server.Start(Web_Server => Web_Server,
-                  Dispatcher => Handlers.Get_Dispatchers,
-                  Config => Server_Config);
-
-  AWS.Server.Wait(AWS.Server.Forever);
-  AWS.Server.Shutdown(Web_Server);
-
+  Launcher.Launch;
 end Nine_Q;