Changeset 5 for os/trunk/System


Ignore:
Timestamp:
Jun 2, 2013, 2:34:55 PM (12 years ago)
Author:
chronos
Message:
  • Added: Implemented sample desktop manager as simple application.
Location:
os/trunk
Files:
1 added
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • os/trunk

    • Property svn:ignore
      •  

        old new  
        11Win32
        22*.~dsk
         3__history
  • os/trunk/System

    • Property svn:ignore set to
      __history
  • os/trunk/System/LDOS.Kernel.pas

    r3 r5  
    1 unit Xvcl.Kernel;
     1unit LDOS.Kernel;
    22
    33interface
     
    1717    Priority: Integer;
    1818    State: TProcessState;
     19    TimerExpire: TDateTime;
     20    Application: TApplication;
    1921    procedure Execute; virtual;
     22    procedure Terminate; virtual;
     23  end;
     24
     25  TTimer = class
     26  end;
     27
     28  TScheduler = class
     29    Kernel: TKernel;
     30    procedure Reschedule;
     31    constructor Create;
     32    destructor Destroy; override;
    2033  end;
    2134
     
    3346
    3447  TScreen = class(TComponent)
     48  private
     49  public
     50    Kernel: TKernel;
    3551    Canvas: TScreenCanvas;
    3652    Size: TPoint;
    3753    Forms: TList<TForm>;
    3854    VideoDevice: TVideoDevice;
     55    procedure HandleResize;
    3956    procedure Paint;
    4057    procedure FocusForm(Form: TForm);
     
    5774  end;
    5875
    59   TScheduler = class
    60     Kernel: TKernel;
    61     procedure Reschedule;
    62   end;
    63 
    6476  TKernel = class
    6577  private
    6678    FOnAfterDriverInit: TNotifyEvent;
    6779    FOnTick: TNotifyEvent;
     80    procedure HandleTaskList;
    6881  public
     82    Timers: TList<TTimer>;
    6983    Processes: TList<TProcess>;
    7084    Drivers: TList<TDriver>;
     
    7892    procedure PowerOff;
    7993    procedure Reboot;
     94    function GetProcessId: Integer;
     95    procedure RunApplication(App: TApplication);
    8096    constructor Create;
    8197    destructor Destroy; override;
     
    99115
    100116  for App in StartOnBoot do
    101     App.Run;
     117    RunApplication(App);
    102118
    103119  repeat
     
    113129begin
    114130  Processes := TList<TProcess>.Create;
     131  Timers := TList<TTimer>.Create;
    115132  Drivers := TList<TDriver>.Create;
    116133  Screen := TScreen.Create;
     134  Screen.Kernel := Self;
    117135  StartOnBoot := TList<TApplication>.Create;
    118136  Scheduler := TScheduler.Create;
     137  Scheduler.Kernel := Self;
    119138  Keyboard := TKeyboard.Create;
    120139  Keyboard.Kernel := Self;
     
    132151  Drivers.Destroy;
    133152  Processes.Destroy;
    134   inherited;
    135 end;
    136 
     153  Timers.Destroy;
     154  inherited;
     155end;
     156
     157
     158function TKernel.GetProcessId: Integer;
     159var
     160  I: Integer;
     161begin
     162  Result := 1;
     163  for I := 0 to Processes.Count - 1 do
     164    if Processes[I].Id > Result then Result := Processes[I].Id + 1;
     165end;
    137166
    138167procedure TKernel.PowerOff;
     
    144173begin
    145174
     175end;
     176
     177procedure TKernel.RunApplication(App: TApplication);
     178var
     179  NewProcess: TProcess;
     180  I: Integer;
     181begin
     182  NewProcess := TProcess.Create;
     183  NewProcess.Application := App;
     184  NewProcess.Id := GetProcessId;
     185  Processes.Add(NewProcess);
     186  App.Run;
     187  NewProcess.Name := App.Caption;
     188  HandleTaskList;
     189end;
     190
     191procedure TKernel.HandleTaskList;
     192var
     193  Form: TForm;
     194  NewMessage: TMessageTaskList;
     195  Process: TProcess;
     196begin
     197  NewMessage := TMessageTaskList.Create;
     198  try
     199    for Form in Screen.Forms do
     200      Form.HandleMessage(NewMessage);
     201    for Process in Processes do
     202      Process.Application.HandleMessage(NewMessage);
     203  finally
     204    NewMessage.Destroy;
     205  end;
    146206end;
    147207
     
    176236end;
    177237
     238procedure TScreen.HandleResize;
     239var
     240  Form: TForm;
     241  NewMessage: TMessageResize;
     242  Process: TProcess;
     243begin
     244  NewMessage := TMessageResize.Create;
     245  try
     246    for Form in Kernel.Screen.Forms do
     247      Form.HandleMessage(NewMessage);
     248    for Process in Kernel.Processes do
     249      Process.Application.HandleMessage(NewMessage);
     250  finally
     251    NewMessage.Destroy;
     252  end;
     253end;
     254
    178255procedure TScreen.Paint;
    179256var
     
    199276{ TScheduler }
    200277
     278constructor TScheduler.Create;
     279begin
     280  inherited;
     281end;
     282
     283destructor TScheduler.Destroy;
     284begin
     285
     286  inherited;
     287end;
     288
    201289procedure TScheduler.Reschedule;
    202290begin
     
    218306
    219307procedure TProcess.Execute;
     308begin
     309
     310end;
     311
     312procedure TProcess.Terminate;
    220313begin
    221314
Note: See TracChangeset for help on using the changeset viewer.