Changeset 12


Ignore:
Timestamp:
Sep 6, 2017, 6:47:49 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Separate API command to be kernel and user space. Execute API command through single callback function.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Apps/UClock.pas

    r11 r12  
    3636  Message := TIPCMessage.Create;
    3737  WindowId := API.WindowCreate;
    38   API.WindowSetAttr(300, 200, True);
     38  API.WindowSetAttr(Point(300, 200), True);
    3939  while not Task.Terminated do begin
    4040    API.WriteText('test');
     
    6565  Message := TIPCMessage.Create;
    6666  WindowId := API.WindowCreate;
    67   API.WindowSetAttr(300, 200, True);
     67  API.WindowSetAttr(Point(300, 200), True);
    6868  while not Task.Terminated do begin
    6969    API.WriteText('test2');
  • trunk/ChronOS.lpi

    r9 r12  
    22<CONFIG>
    33  <ProjectOptions>
    4     <Version Value="9"/>
     4    <Version Value="10"/>
    55    <General>
    66      <SessionStorage Value="InProjectDir"/>
     
    151151    </Linking>
    152152    <Other>
     153      <CompilerMessages>
     154        <IgnoredMessages idx5024="True"/>
     155      </CompilerMessages>
    153156      <CustomOptions Value="-dDEBUG"/>
    154157    </Other>
  • trunk/Packages/Kernel/UAPI.pas

    r9 r12  
    1010
    1111type
    12 
    13   { TAPI }
    14 
    15   TAPI = class
     12  TApiCommand = (acNone, acWriteText, acDrawText, acDrawLine, acDrawRect, acSleep,
     13    acReadMessage, acWindowCreate, acWindowSetAttr);
     14
     15  TDrawTextParams = record
     16    P: TPoint;
     17    Text: string;
     18    Color: TColor;
     19  end;
     20
     21  TDrawLineParams = record
     22    P1: TPoint;
     23    P2: TPoint;
     24    Color: TColor;
     25  end;
     26
     27  TWindowSetAttrParams = record
     28    Size: TPoint;
     29    Visible: Boolean;
     30  end;
     31
     32  TDrawRectParams = record
     33    Rect: TRect;
     34    Color: TColor;
     35  end;
     36
     37  { TKernelApi }
     38
     39  TKernelApi = class
    1640    Kernel: TObject; //TKernel;
     41    function Call(Command: TApiCommand; Data: Pointer): Pointer;
    1742    procedure WriteText(Text: string);
    1843    procedure DrawText(P: TPoint; Text: string; Color: TColor);
     
    2247    procedure ReadMessage(Message: TIPCMessage);
    2348    function WindowCreate: Integer;
    24     procedure WindowSetAttr(SizeX, SizeY: Integer; Visible: Boolean);
     49    procedure WindowSetAttr(Size: TPoint; Visible: Boolean);
     50  end;
     51
     52  TApiCall = function (Command: TApiCommand; Data: Pointer): Pointer of object;
     53
     54  { TUserApi }
     55
     56  TUserApi = class
     57    KernelApiCallback: TApiCall;
     58    function Call(Command: TApiCommand; Data: Pointer): Pointer;
     59    procedure WriteText(Text: string);
     60    procedure DrawText(P: TPoint; Text: string; Color: TColor);
     61    procedure DrawLine(P1, P2: TPoint; Color: TColor);
     62    procedure DrawRect(Rect: TRect; Color: TColor);
     63    procedure Sleep(Time: TDateTime);
     64    procedure ReadMessage(Message: TIPCMessage);
     65    function WindowCreate: Integer;
     66    procedure WindowSetAttr(Size: TPoint; Visible: Boolean);
    2567  end;
    2668
     
    3173  UKernel;
    3274
    33 { TAPI }
    34 
    35 procedure TAPI.WriteText(Text: string);
     75{ TUserApi }
     76
     77function TUserApi.Call(Command: TApiCommand; Data: Pointer
     78  ): Pointer;
     79begin
     80  Result := KernelApiCallback(Command, Data);
     81end;
     82
     83procedure TUserApi.WriteText(Text: string);
     84begin
     85  Call(acWriteText, Pointer(Text));
     86end;
     87
     88procedure TUserApi.DrawText(P: TPoint; Text: string; Color: TColor);
     89var
     90  Params: TDrawTextParams;
     91begin
     92  Params.P := P;
     93  Params.Text := Text;
     94  Params.Color := Color;
     95  Call(acDrawText, @Params);
     96end;
     97
     98procedure TUserApi.DrawLine(P1, P2: TPoint; Color: TColor);
     99var
     100  Params: TDrawLineParams;
     101begin
     102  Params.P1 := P1;
     103  Params.P2 := P2;
     104  Params.Color := Color;
     105  Call(acDrawLine, @Params);
     106end;
     107
     108procedure TUserApi.DrawRect(Rect: TRect; Color: TColor);
     109var
     110  Params: TDrawRectParams;
     111begin
     112  Params.Rect := Rect;
     113  Params.Color := Color;
     114  Call(acDrawRect, @Params);
     115end;
     116
     117procedure TUserApi.Sleep(Time: TDateTime);
     118begin
     119  Call(acSleep, @Time);
     120end;
     121
     122procedure TUserApi.ReadMessage(Message: TIPCMessage);
     123begin
     124  Call(acReadMessage, Message);
     125end;
     126
     127function TUserApi.WindowCreate: Integer;
     128begin
     129  Call(acWindowCreate, nil);
     130end;
     131
     132procedure TUserApi.WindowSetAttr(Size: TPoint; Visible: Boolean);
     133var
     134  Params: TWindowSetAttrParams;
     135begin
     136  Params.Size := Size;
     137  Params.Visible := Visible;
     138  Call(acWindowSetAttr, @Params);
     139end;
     140
     141{ TKernelApi }
     142
     143function TKernelApi.Call(Command: TApiCommand; Data: Pointer
     144  ): Pointer;
     145begin
     146  case Command of
     147    acDrawLine: DrawLine(TDrawLineParams(Data^).P1, TDrawLineParams(Data^).P2,
     148      TDrawLineParams(Data^).Color);
     149    acDrawRect: DrawRect(TDrawRectParams(Data^).Rect, TDrawRectParams(Data^).Color);
     150    acDrawText: DrawText(TDrawTextParams(Data^).P, TDrawTextParams(Data^).Text,
     151      TDrawTextParams(Data^).Color);
     152    acSleep: Sleep(TDateTime(Data^));
     153    acWindowCreate: Result := Pointer(WindowCreate);
     154    acWindowSetAttr: WindowSetAttr(TWindowSetAttrParams(Data^).Size,
     155      TWindowSetAttrParams(Data^).Visible);
     156    acWriteText: WriteText(string(Data));
     157    acReadMessage: ReadMessage(Data);
     158  end;
     159end;
     160
     161procedure TKernelApi.WriteText(Text: string);
    36162var
    37163  Device: TDeviceSerial;
     
    43169end;
    44170
    45 procedure TAPI.DrawText(P: TPoint; Text: string; Color: TColor);
     171procedure TKernelApi.DrawText(P: TPoint; Text: string; Color: TColor);
    46172var
    47173  Screen: TScreen;
     
    51177end;
    52178
    53 procedure TAPI.DrawLine(P1, P2: TPoint; Color: TColor);
     179procedure TKernelApi.DrawLine(P1, P2: TPoint; Color: TColor);
    54180var
    55181  Screen: TScreen;
     
    59185end;
    60186
    61 procedure TAPI.DrawRect(Rect: TRect; Color: TColor);
     187procedure TKernelApi.DrawRect(Rect: TRect; Color: TColor);
    62188var
    63189  Screen: TScreen;
     
    67193end;
    68194
    69 procedure TAPI.Sleep(Time: TDateTime);
     195procedure TKernelApi.Sleep(Time: TDateTime);
    70196var
    71197  Task: TTask;
     
    75201end;
    76202
    77 procedure TAPI.ReadMessage(Message: TIPCMessage);
     203procedure TKernelApi.ReadMessage(Message: TIPCMessage);
    78204var
    79205  Task: TTask;
     
    83209end;
    84210
    85 function TAPI.WindowCreate: Integer;
    86 begin
    87 
    88 end;
    89 
    90 procedure TAPI.WindowSetAttr(SizeX, SizeY: Integer; Visible: Boolean);
     211function TKernelApi.WindowCreate: Integer;
     212begin
     213
     214end;
     215
     216procedure TKernelApi.WindowSetAttr(Size: TPoint; Visible: Boolean);
    91217begin
    92218
  • trunk/Packages/Kernel/UApp.pas

    r9 r12  
    1212
    1313  TApp = class(TNamedObject)
    14     API: TAPI;
     14    API: TUserApi;
    1515    Terminated: Boolean;
    1616    constructor Create; virtual;
     
    2727begin
    2828  inherited Create;
    29   API := TAPI.Create;
     29  API := TUserApi.Create;
    3030end;
    3131
  • trunk/Packages/Kernel/UKernel.pas

    r10 r12  
    77uses
    88  Classes, Math, SysUtils, UList, Contnrs, UFileSystem, UMemory, UScreen, UDevice,
    9   fgl, UApp, UScheduler;
     9  fgl, UApp, UScheduler, UApi;
    1010
    1111type
     
    2626  TKernel = class
    2727  private
     28    Api: TKernelApi;
    2829    procedure InitVideo;
     30    function KernelApiExecute(Command: TApiCommand; Data: Pointer): Pointer;
    2931  public
    3032    Apps: TNamedObjectList<TApp>;
     
    8890end;
    8991
     92function TKernel.KernelApiExecute(Command: TApiCommand;
     93  Data: Pointer): Pointer;
     94begin
     95  Result := Api.Call(Command, Data);
     96end;
     97
    9098procedure TKernel.AppExecute(AFile: TFile);
    9199var
     
    94102  App := TApp(Apps.FindByName(AFile.Name));
    95103  if Assigned(App) then begin
    96     App.API.Kernel := Self;
     104    App.API.KernelApiCallback := KernelApiExecute;
    97105    Scheduler.AddTask(App.Name, App.Run);
    98106  end else raise Exception.Create('Application ''' + AFile.Name + ''' no found');
     
    119127  NewFile.Name := 'Clock2';
    120128  NewDrive.FileSystem.TopDirectory.Items.Add(NewFile);
    121 InitVideo;
     129  InitVideo;
    122130end;
    123131
     
    149157  Scheduler := TScheduler.Create;
    150158  Screens := TFPGObjectList<TScreen>.Create;
     159  Api := TKernelApi.Create;
     160  Api.Kernel := Self;
    151161end;
    152162
    153163destructor TKernel.Destroy;
    154164begin
    155   Screens.Free;
    156   Scheduler.Free;
    157   Apps.Free;
    158   Drives.Free;
    159   Devices.Free;
     165  FreeAndNil(Api);
     166  FreeAndNil(Screens);
     167  FreeAndNil(Scheduler);
     168  FreeAndNil(Apps);
     169  FreeAndNil(Drives);
     170  FreeAndNil(Devices);
    160171  inherited Destroy;
    161172end;
Note: See TracChangeset for help on using the changeset viewer.