text
stringlengths 0
234
|
|---|
-- ------------------------------
|
-- Set the current registry (for unit testing mostly).
|
-- ------------------------------
|
procedure Set_Context (Context : in Servlet.Core.Servlet_Registry_Access) is
|
C : Request_Context;
|
begin
|
C.Application := Context;
|
C.Request := null;
|
C.Response := null;
|
Set_Context (C);
|
end Set_Context;
|
-- ------------------------------
|
-- Set the current registry. This is called by <b>Service</b> once the
|
-- registry is identified from the URI.
|
-- ------------------------------
|
procedure Set_Context (Context : in Request_Context) is
|
begin
|
Task_Context.Set_Value (Context);
|
end Set_Context;
|
-- ------------------------------
|
-- Give access to the current request and response object to the `Process`
|
-- procedure. If there is no current request for the thread, do nothing.
|
-- ------------------------------
|
procedure Update_Context (Process : not null access
|
procedure (Request : in out Requests.Request'Class;
|
Response : in out Responses.Response'Class)) is
|
Ctx : constant Request_Context := Task_Context.Value;
|
begin
|
Process (Ctx.Request.all, Ctx.Response.all);
|
end Update_Context;
|
-- ------------------------------
|
-- Register the application to serve requests
|
-- ------------------------------
|
procedure Register_Application (Server : in out Container;
|
URI : in String;
|
Context : in Core.Servlet_Registry_Access) is
|
Count : constant Natural := Server.Nb_Bindings;
|
Apps : constant Binding_Array_Access := new Binding_Array (1 .. Count + 1);
|
Old : Binding_Array_Access := Server.Applications;
|
begin
|
Log.Info ("Register application {0}", URI);
|
if Old /= null then
|
Apps (1 .. Count) := Server.Applications (1 .. Count);
|
end if;
|
Apps (Count + 1) := new Binding '(Len => URI'Length, Context => Context, Base_URI => URI);
|
-- Inform the servlet registry about the base URI.
|
Context.Register_Application (URI);
|
-- Start the application if the container is started.
|
if Server.Is_Started and then Context.Get_Status = Core.Ready then
|
Context.Start;
|
end if;
|
-- Update the binding.
|
Server.Applications := Apps;
|
Server.Nb_Bindings := Count + 1;
|
if Old /= null then
|
Free (Old);
|
end if;
|
end Register_Application;
|
-- ------------------------------
|
-- Remove the application
|
-- ------------------------------
|
procedure Remove_Application (Server : in out Container;
|
Context : in Core.Servlet_Registry_Access) is
|
use type Servlet.Core.Servlet_Registry_Access;
|
Count : constant Natural := Server.Nb_Bindings;
|
Old : Binding_Array_Access := Server.Applications;
|
Apps : Binding_Array_Access;
|
begin
|
for I in 1 .. Count loop
|
if Old (I).Context = Context then
|
Log.Info ("Removed application {0}", Old (I).Base_URI);
|
Free (Old (I));
|
if I < Count then
|
Old (I) := Old (Count);
|
end if;
|
if Count > 1 then
|
Apps := new Binding_Array (1 .. Count - 1);
|
Apps.all := Old (1 .. Count - 1);
|
else
|
Apps := null;
|
end if;
|
Server.Applications := Apps;
|
Server.Nb_Bindings := Count - 1;
|
Free (Old);
|
return;
|
end if;
|
end loop;
|
end Remove_Application;
|
-- ------------------------------
|
-- Start the applications that have been registered.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.