|
| 1 | +------------------------------------------------------------------------------ |
| 2 | +-- Language Server Protocol -- |
| 3 | +-- -- |
| 4 | +-- Copyright (C) 2024, AdaCore -- |
| 5 | +-- -- |
| 6 | +-- This is free software; you can redistribute it and/or modify it under -- |
| 7 | +-- terms of the GNU General Public License as published by the Free Soft- -- |
| 8 | +-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 9 | +-- sion. This software is distributed in the hope that it will be useful, -- |
| 10 | +-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- |
| 11 | +-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -- |
| 12 | +-- License for more details. You should have received a copy of the GNU -- |
| 13 | +-- General Public License distributed with this software; see file -- |
| 14 | +-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy -- |
| 15 | +-- of the license. -- |
| 16 | +------------------------------------------------------------------------------ |
| 17 | + |
| 18 | +with Ada.Containers.Hashed_Maps; |
| 19 | +with Ada.Tags; |
| 20 | + |
| 21 | +with LSP.Client_Message_Receivers; |
| 22 | +with LSP.Server_Message_Handlers; |
| 23 | +with LSP.Server_Messages; |
| 24 | + |
| 25 | +package LSP.Job_Schedulers is |
| 26 | + pragma Preelaborate; |
| 27 | + |
| 28 | + type Job_Scheduler is tagged limited private; |
| 29 | + |
| 30 | + procedure Register_Handler |
| 31 | + (Self : in out Job_Scheduler'Class; |
| 32 | + Tag : Ada.Tags.Tag; |
| 33 | + Handler : LSP.Server_Message_Handlers.Server_Message_Handler_Access); |
| 34 | + -- Register server message handler per message tag. |
| 35 | + |
| 36 | + function Has_Jobs (Self : Job_Scheduler'Class) return Boolean; |
| 37 | + -- Return true if there are any jobs in the queue. |
| 38 | + |
| 39 | + procedure Create_Job |
| 40 | + (Self : in out Job_Scheduler'Class; |
| 41 | + Message : in out LSP.Server_Messages.Server_Message_Access); |
| 42 | + -- Create a job to process a server message. The scheduler takes ownership |
| 43 | + -- of the message and will return it to the server when the job is done. |
| 44 | + |
| 45 | + procedure Process_High_Priority_Job |
| 46 | + (Self : in out Job_Scheduler'Class; |
| 47 | + Client : |
| 48 | + in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class; |
| 49 | + Waste : out LSP.Server_Messages.Server_Message_Access); |
| 50 | + -- Execute jobs with highest priority (Immediate, Fence). |
| 51 | + -- When a job is done the routine returns (in Waste) the message to be |
| 52 | + -- deallocated by the server. The Client is used to send messages during |
| 53 | + -- the execution of the job. |
| 54 | + |
| 55 | + procedure Process_Job |
| 56 | + (Self : in out Job_Scheduler'Class; |
| 57 | + Client : |
| 58 | + in out LSP.Client_Message_Receivers.Client_Message_Receiver'Class; |
| 59 | + Waste : out LSP.Server_Messages.Server_Message_Access) is null; |
| 60 | + -- Execute jobs with ordinal priority (Low, High). |
| 61 | + -- When a job is done the routine returns (in Waste) the message to be |
| 62 | + -- deallocated by the server. The Client is used to send messages during |
| 63 | + -- the execution of the job. |
| 64 | + |
| 65 | +private |
| 66 | + |
| 67 | + function Hash (Tag : Ada.Tags.Tag) return Ada.Containers.Hash_Type; |
| 68 | + |
| 69 | + package Handler_Maps is new Ada.Containers.Hashed_Maps |
| 70 | + (Ada.Tags.Tag, |
| 71 | + LSP.Server_Message_Handlers.Server_Message_Handler_Access, |
| 72 | + Hash, |
| 73 | + Ada.Tags."=", |
| 74 | + LSP.Server_Message_Handlers."="); |
| 75 | + |
| 76 | + type Job_Scheduler is tagged limited record |
| 77 | + Message : LSP.Server_Messages.Server_Message_Access; |
| 78 | + -- Last added message |
| 79 | + Handlers : Handler_Maps.Map; |
| 80 | + end record; |
| 81 | + |
| 82 | +end LSP.Job_Schedulers; |
0 commit comments