source: trunk/Packages/Kernel/Kernel.Core.pas

Last change on this file was 61, checked in by chronos, 8 months ago
  • Modified: Kernel API class definition improvement.
File size: 4.3 KB
Line 
1unit Kernel.Core;
2
3interface
4
5uses
6 Classes, SysUtils, Kernel.List, Kernel.FileSystem, Kernel.Memory,
7 Kernel.Screen, Kernel.Device, Kernel.App, Kernel.Scheduler, Kernel.Api,
8 Kernel.Graphics, Generics.Collections, Kernel.IPC;
9
10type
11 { TDrive }
12
13 TDrive = class(TNamedObject)
14 FileSystem: TFileSystem;
15 constructor Create;
16 destructor Destroy; override;
17 end;
18
19// TTimer = class
20// Period: TDateTime;
21// end;
22
23 { TKernel }
24
25 TKernel = class
26 private
27 Api: TSystemApi;
28 procedure InitVideo;
29 function KernelApiExecute(Command: TApiCommand; Data: Pointer): Pointer;
30 public
31 Apps: TNamedObjects<TApp>;
32 Drives: TNamedObjects<TDrive>;
33 Scheduler: TScheduler;
34 SchedulerClass: TSchedulerClass;
35 FileSystemClass: TFileSystemClass;
36 Devices: TNamedObjects<TDevice>;
37 Screens: TObjectList<TScreen>;
38 Desktop: TDesktop;
39 procedure AppExecute(AFile: TFile);
40 procedure Init;
41 procedure Run;
42 procedure Terminate;
43 constructor Create;
44 destructor Destroy; override;
45 end;
46
47
48implementation
49
50uses
51 Kernel.KernelAPI;
52
53{ TDrive }
54
55constructor TDrive.Create;
56begin
57end;
58
59destructor TDrive.Destroy;
60begin
61 FreeAndNil(FileSystem);
62 inherited;
63end;
64
65{ TKernel }
66
67procedure TKernel.InitVideo;
68var
69 NewScreen: TScreen;
70 VideoDevice: TDeviceVideo;
71 VideoMode: TVideoMode;
72 Modes: TVideoModes;
73begin
74 VideoDevice := TDeviceVideo(Devices.FindByName('Video0'));
75 if Assigned(VideoDevice) then begin
76 NewScreen := TScreen.Create;
77 Modes := TVideoModes.Create;
78 VideoDevice.GetSupportedModes(Modes);
79 if Modes.Count > 0 then begin
80 VideoMode := TVideoMode(Modes.Last);
81 VideoDevice.VideoMode := VideoMode;
82 NewScreen.Size := VideoMode.Size;
83 NewScreen.ColorFormat := VideoMode.ColorFormat;
84 NewScreen.Device := VideoDevice;
85 NewScreen.Canvas := TScreenCanvas.Create;
86 TScreenCanvas(NewScreen.Canvas).Screen := NewScreen;
87 Screens.Add(NewScreen);
88 Desktop.ParentCanvas := Screens.First.Canvas;
89 end;
90 Modes.Free;
91 end;
92end;
93
94function TKernel.KernelApiExecute(Command: TApiCommand;
95 Data: Pointer): Pointer;
96begin
97 Result := Api.Call(Command, Data);
98end;
99
100procedure TKernel.AppExecute(AFile: TFile);
101var
102 App: TApp;
103begin
104 App := TApp(Apps.FindByName(AFile.Name));
105 if Assigned(App) then begin
106 App.API.KernelApiCallback := KernelApiExecute;
107 Scheduler.AddTask(App.Name, App.Run);
108 end else raise Exception.Create('Application ''' + AFile.Name + ''' no found');
109end;
110
111procedure TKernel.Init;
112var
113 NewDrive: TDrive;
114 NewFile: TFile;
115begin
116 Scheduler.Free;
117 Scheduler := SchedulerClass.Create;
118
119 NewDrive := TDrive.Create;
120 NewDrive.Name := 'System';
121 NewDrive.FileSystem := FileSystemClass.Create;
122 Drives.Add(NewDrive);
123
124 NewFile := TFile.Create;
125 NewFile.Name := 'Clock';
126 NewDrive.FileSystem.TopDirectory.Items.Add(NewFile);
127
128 NewFile := TFile.Create;
129 NewFile.Name := 'Clock2';
130 NewDrive.FileSystem.TopDirectory.Items.Add(NewFile);
131 InitVideo;
132end;
133
134procedure TKernel.Run;
135var
136 SystemDrive: TDrive;
137 SystemFileSystem: TFileSystem;
138 AppFile: TFile;
139begin
140 Init;
141 SystemDrive := TDrive(Drives.FindByName('System'));
142 if Assigned(SystemDrive) then begin
143 SystemFileSystem := SystemDrive.FileSystem;
144 AppFile := TFile(SystemFileSystem.TopDirectory.Items.FindByName('Clock'));
145 if Assigned(AppFile) then AppExecute(AppFile)
146 else raise Exception.Create('Cannot start first application');
147 AppFile := TFile(SystemFileSystem.TopDirectory.Items.FindByName('Clock2'));
148 if Assigned(AppFile) then AppExecute(AppFile)
149 else raise Exception.Create('Cannot start first application');
150 Scheduler.Start;
151 end else raise Exception.Create('Missing System drive');
152end;
153
154procedure TKernel.Terminate;
155begin
156 if Scheduler.Running then Scheduler.Stop;
157end;
158
159constructor TKernel.Create;
160begin
161 Devices := TNamedObjects<TDevice>.Create;
162 Drives := TNamedObjects<TDrive>.Create;
163 Apps := TNamedObjects<TApp>.Create;
164 Scheduler := TScheduler.Create;
165 Screens := TObjectList<TScreen>.Create;
166 Api := TKernelApi.Create;
167 TKernelApi(Api).Kernel := Self;
168 Desktop := TDesktop.Create;
169end;
170
171destructor TKernel.Destroy;
172begin
173 Terminate;
174 FreeAndNil(Desktop);
175 FreeAndNil(Api);
176 FreeAndNil(Screens);
177 FreeAndNil(Scheduler);
178 FreeAndNil(Apps);
179 FreeAndNil(Drives);
180 FreeAndNil(Devices);
181 inherited;
182end;
183
184end.
185
Note: See TracBrowser for help on using the repository browser.