Changeset 6


Ignore:
Timestamp:
Nov 23, 2014, 11:17:11 PM (10 years ago)
Author:
chronos
Message:
  • Added: Preparation for support for IPC messaging.
Location:
trunk
Files:
6 added
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Apps/UClock.pas

    r5 r6  
    2222
    2323procedure TAppClock.Run(Task: TTask);
     24var
     25  Message: TIPCMessage;
    2426begin
     27  Message := TIPCMessage.Create;
    2528  while not Task.Terminated do begin
    2629    API.WriteText('test');
    2730    API.Sleep(OneSecond);
     31    //API.ReadMessage(Message);
    2832  end;
     33  Message.Free;
    2934end;
    3035
  • trunk/ChronOS.lpi

    r5 r6  
    7171      </Item1>
    7272    </RequiredPackages>
    73     <Units Count="12">
     73    <Units Count="14">
    7474      <Unit0>
    7575        <Filename Value="ChronOS.lpr"/>
     
    7777      </Unit0>
    7878      <Unit1>
    79         <Filename Value="UFormMain.pas"/>
    80         <IsPartOfProject Value="True"/>
    81         <ComponentName Value="Form1"/>
     79        <Filename Value="Forms/UFormMain.pas"/>
     80        <IsPartOfProject Value="True"/>
     81        <ComponentName Value="FormMain"/>
    8282        <HasResources Value="True"/>
    8383        <ResourceBaseClass Value="Form"/>
     
    134134        <UnitName Value="UMemory"/>
    135135      </Unit11>
     136      <Unit12>
     137        <Filename Value="Forms/UFormTerminal.pas"/>
     138        <IsPartOfProject Value="True"/>
     139        <ComponentName Value="FormTerminal"/>
     140        <ResourceBaseClass Value="Form"/>
     141        <UnitName Value="UFormTerminal"/>
     142      </Unit12>
     143      <Unit13>
     144        <Filename Value="UClasses.pas"/>
     145        <IsPartOfProject Value="True"/>
     146        <UnitName Value="UClasses"/>
     147      </Unit13>
    136148    </Units>
    137149  </ProjectOptions>
     
    143155    <SearchPaths>
    144156      <IncludeFiles Value="$(ProjOutDir)"/>
    145       <OtherUnitFiles Value="Apps;Platform/Base"/>
     157      <OtherUnitFiles Value="Apps;Platform/Base;Forms"/>
    146158      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
    147159    </SearchPaths>
  • trunk/ChronOS.lpr

    r5 r6  
    1111  Interfaces, // this includes the LCL widgetset
    1212  Forms, SysUtils, UFormMain, UKernel, UFileSystem, UClock, UMemoryManager, UAPI,
    13   UPlatformBase, UList, UApp, UThreadEx, UMemory;
     13  UPlatformBase, UList, UApp, UThreadEx, UMemory, UFormTerminal, UClasses;
    1414
    1515{$R *.res}
     
    2929  RequireDerivedFormResource := True;
    3030  Application.Initialize;
    31   Application.CreateForm(TForm1, Form1);
     31  Application.CreateForm(TFormMain, FormMain);
     32  Application.CreateForm(TFormTerminal, FormTerminal);
    3233  Application.Run;
    3334end.
  • trunk/Platform/Base/UPlatformBase.pas

    r5 r6  
    66
    77uses
    8   Classes, SysUtils, UFileSystem, UKernel, syncobjs, UThreadEx, UMemory;
     8  Classes, SysUtils, UFileSystem, UKernel, syncobjs, UThreadEx, UMemory,
     9  DateUtils;
    910
    1011type
     
    3233
    3334  TBaseScheduler = class(TScheduler)
     35    procedure SwitchNext; override;
     36    function GetCurrentTask: TTask; override;
    3437    function AddTask(Name: string; EntryPoint: TTaskEvent): TTask; override;
    3538    constructor Create; override;
     
    106109{ TBaseScheduler }
    107110
     111procedure TBaseScheduler.SwitchNext;
     112var
     113  Task: TTask;
     114  Duration: TDateTime;
     115begin
     116  Task := GetCurrentTask;
     117  if Task.State = tsWaiting then begin
     118    if Task.WaitReason = wrSleep then begin
     119      Duration := (Task.WakeUpTime - Now) / OneMillisecond;
     120      if Duration > 0 then SysUtils.Sleep(Trunc(Duration));
     121    end;
     122  end;
     123end;
     124
     125function TBaseScheduler.GetCurrentTask: TTask;
     126var
     127  I: Integer;
     128begin
     129  I := 0;
     130  while (I < Tasks.Count) and (TBaseTask(Tasks[I]).Thread.ThreadID <> ThreadID) do
     131    Inc(I);
     132  if I < Tasks.Count then Result := TBaseTask(Tasks[I])
     133    else Result := nil;
     134end;
     135
    108136function TBaseScheduler.AddTask(Name: string; EntryPoint: TTaskEvent): TTask;
    109137var
  • trunk/UAPI.pas

    r4 r6  
    1616    procedure WriteText(Text: string);
    1717    procedure Sleep(Time: TDateTime);
     18    procedure ReadMessage(Message: TIPCMessage);
    1819  end;
    1920
     
    3940
    4041procedure TAPI.Sleep(Time: TDateTime);
     42var
     43  Task: TTask;
    4144begin
    42   SysUtils.Sleep(Trunc(Time / OneMillisecond));
     45  Task := Kernel.Scheduler.GetCurrentTask;
     46  Task.Sleep(Time);
     47end;
     48
     49procedure TAPI.ReadMessage(Message: TIPCMessage);
     50var
     51  Task: TTask;
     52begin
     53  Task := Kernel.Scheduler.GetCurrentTask;
     54  while Task.Messages.Count = 0 do Task.WaitForMessage;
    4355end;
    4456
  • trunk/UKernel.pas

    r5 r6  
    1010type
    1111  TTask = class;
     12  TScheduler = class;
    1213
    1314  TTaskEvent = procedure(Task: TTask) of object;
    1415
    15   TTaskState = (tsStopped, tsRunning, tsSuspended);
     16  TTaskState = (tsStopped, tsRunning, tsSuspended, tsWaiting);
     17
     18  TIPCMessage = class
     19    Name: string;
     20    Action: string;
     21
     22  end;
     23
     24  TWaitReason = (wrSleep, wrMessage);
    1625
    1726  { TTask }
    1827
    1928  TTask = class(TNamedObject)
    20     Name: string;
     29    Scheduler: TScheduler;
    2130    State: TTaskState;
     31    WaitReason: TWaitReason;
     32    WakeUpTime: TDateTime;
    2233    Terminated: Boolean;
    2334    EntryPoint: TTaskEvent;
     35    Messages: TObjectQueue; // TQueue<TIPMessage>
     36    procedure WaitForMessage;
     37    procedure Sleep(Duration: TDateTime);
    2438    constructor Create; virtual;
     39    destructor Destroy; override;
    2540  end;
    2641
     
    3348    Tasks: TNamedObjectList; // TList<TTask>
    3449    Running: Boolean;
     50    function GetCurrentTask: TTask; virtual;
    3551    procedure Start; virtual;
    3652    procedure Stop; virtual;
    3753    function AddTask(Name: string; EntryPoint: TTaskEvent): TTask; virtual;
     54    procedure SwitchNext; virtual;
    3855    constructor Create; virtual;
    3956    destructor Destroy; override;
     
    5673    constructor Create; virtual;
    5774    procedure Service(Index: Integer; DataIn, DataOut: TMemory); virtual;
     75  end;
     76
     77  TTimer = class
     78    Period: TDateTime;
     79  end;
     80
     81  TScreen = class
     82    Size: TPoint;
     83    DPI: Integer;
    5884  end;
    5985
     
    6793    FileSystemClass: TFileSystemClass;
    6894    Devices: TNamedObjectList; // TList<TDevice>
     95    Screens: TObjectList; // TList<TScreen>
    6996    procedure AppExecute(AFile: TFile);
    7097    procedure Init;
     
    106133{ TTask }
    107134
     135procedure TTask.WaitForMessage;
     136begin
     137  WaitReason := wrMessage;
     138  State := tsWaiting;
     139  Scheduler.SwitchNext;
     140end;
     141
     142procedure TTask.Sleep(Duration: TDateTime);
     143begin
     144  WakeUpTime := Now + Duration;
     145  State := tsWaiting;
     146  WaitReason := wrSleep;
     147  Scheduler.SwitchNext;
     148end;
     149
    108150constructor TTask.Create;
    109151begin
    110 
     152  Messages := TObjectQueue.Create;
     153end;
     154
     155destructor TTask.Destroy;
     156begin
     157  Messages.Free;
     158  inherited Destroy;
    111159end;
    112160
    113161{ TScheduler }
    114162
     163function TScheduler.GetCurrentTask: TTask;
     164begin
     165  Result := nil;
     166end;
     167
    115168procedure TScheduler.Start;
    116169begin
     
    128181begin
    129182  NewTask := TaskClass.Create;
     183  NewTask.Scheduler := Self;
    130184  NewTask.Name := Name;
    131185  NewTask.EntryPoint := EntryPoint;
    132186  Tasks.Add(NewTask);
    133187  Result := NewTask;
     188end;
     189
     190procedure TScheduler.SwitchNext;
     191begin
     192
    134193end;
    135194
     
    201260  Apps := TNamedObjectList.Create;
    202261  Scheduler := TScheduler.Create;
     262  Screens := TObjectList.Create;
    203263end;
    204264
    205265destructor TKernel.Destroy;
    206266begin
     267  Screens.Free;
    207268  Scheduler.Free;
    208269  Apps.Free;
Note: See TracChangeset for help on using the changeset viewer.