with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Strings.Fixed;
-with Ada.Strings.Unbounded;
--with Ada.Text_IO;
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);
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;
--- /dev/null
+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;
--- /dev/null
+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;
+
+
-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;