Changeset 3
- Timestamp:
- Nov 22, 2014, 11:50:49 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Apps/UClock.pas
r2 r3 6 6 7 7 uses 8 Classes, SysUtils, UAPI ;8 Classes, SysUtils, UAPI, dateutils; 9 9 10 10 type … … 23 23 procedure TAppClock.Run; 24 24 begin 25 25 while True do begin 26 API.WriteText('test'); 27 API.Sleep(OneSecond); 28 end; 26 29 end; 27 30 -
trunk/ChronOS.lpi
r2 r3 109 109 <StackChecks Value="True"/> 110 110 </Checks> 111 <VerifyObjMethodCallValidity Value="True"/>112 111 </CodeGeneration> 113 112 <Linking> -
trunk/ChronOS.lpr
r2 r3 4 4 5 5 uses 6 {$IFDEF UNIX}{$IFDEF UseCThreads} 6 {$IFDEF UNIX} 7 //{$IFDEF UseCThreads} 7 8 cthreads, 8 {$ENDIF}{$ENDIF} 9 //{$ENDIF} 10 {$ENDIF} 9 11 Interfaces, // this includes the LCL widgetset 10 12 Forms, UFormMain, UKernel, UFileSystem, UClock, UMemoryManager, UAPI, 11 UPlatformBase, UList;13 UPlatformBase, UList; 12 14 13 15 {$R *.res} -
trunk/Platform/Base/UPlatformBase.pas
r2 r3 6 6 7 7 uses 8 Classes, SysUtils, UFileSystem ;8 Classes, SysUtils, UFileSystem, UKernel; 9 9 10 10 type 11 { TCustomThread } 12 13 TCustomThread = class(TThread) 14 Task: TTask; 15 procedure Execute; override; 16 end; 17 18 { TBaseTask } 19 20 TBaseTask = class(TTask) 21 Thread: TCustomThread; 22 constructor Create; override; 23 destructor Destroy; override; 24 end; 25 26 11 27 TBaseFileSystem = class(TFileSystem) 12 28 13 29 end; 14 30 31 { TBaseScheduler } 32 33 TBaseScheduler = class(TScheduler) 34 function AddTask(Name: string; EntryPoint: TEvent): TTask; override; 35 constructor Create; override; 36 procedure Start; override; 37 end; 38 15 39 implementation 40 41 { TBaseTask } 42 43 constructor TBaseTask.Create; 44 begin 45 inherited; 46 Thread := TCustomThread.Create(True); 47 Thread.Task := Self; 48 end; 49 50 destructor TBaseTask.Destroy; 51 begin 52 Thread.Free; 53 inherited Destroy; 54 end; 55 56 { TCustomThread } 57 58 procedure TCustomThread.Execute; 59 begin 60 Task.EntryPoint; 61 end; 62 63 { TBaseScheduler } 64 65 function TBaseScheduler.AddTask(Name: string; EntryPoint: TEvent): TTask; 66 var 67 Task: TBaseTask; 68 begin 69 Task := TBaseTask(inherited AddTask(Name, EntryPoint)); 70 if Running then Task.Thread.Start; 71 end; 72 73 constructor TBaseScheduler.Create; 74 begin 75 inherited Create; 76 TaskClass := TBaseTask; 77 end; 78 79 procedure TBaseScheduler.Start; 80 var 81 I: Integer; 82 begin 83 inherited Start; 84 for I := 0 to Tasks.Count - 1 do 85 TBaseTask(Tasks[I]).Thread.Start; 86 end; 16 87 17 88 end. -
trunk/UAPI.pas
r2 r3 14 14 TAPI = class 15 15 procedure WriteText(Text: string); 16 procedure Sleep(Time: TDateTime); 16 17 end; 17 18 … … 30 31 31 32 procedure TAPI.WriteText(Text: string); 33 begin 34 35 end; 36 37 procedure TAPI.Sleep(Time: TDateTime); 32 38 begin 33 39 -
trunk/UFileSystem.pas
r2 r3 33 33 end; 34 34 35 TFileSystemClass = class of TFileSystem; 36 35 37 implementation 36 38 -
trunk/UFormMain.lfm
r2 r3 1 1 object Form1: TForm1 2 Left = 8193 Height = 2404 Top = 4295 Width = 3202 Left = 565 3 Height = 687 4 Top = 259 5 Width = 932 6 6 Caption = 'Form1' 7 7 OnCreate = FormCreate -
trunk/UFormMain.pas
r2 r3 28 28 29 29 uses 30 UList, UAPI, UClock ;30 UList, UAPI, UClock, UPlatformBase; 31 31 32 32 {$R *.lfm} … … 39 39 begin 40 40 Kernel := TKernel.Create; 41 Kernel.SchedulerClass := TBaseScheduler; 42 Kernel.FileSystemClass := TBaseFileSystem; 41 43 42 44 NewApp := TAppClock.Create; -
trunk/UKernel.pas
r2 r3 9 9 10 10 type 11 TEvent = procedure of object; 11 12 12 13 TTaskState = (tsStopped, tsRunning, tsSuspended); 13 14 14 TTask = class 15 { TTask } 16 17 TTask = class(TNamedObject) 15 18 Name: string; 16 19 State: TTaskState; 20 EntryPoint: TEvent; 21 constructor Create; virtual; 17 22 end; 18 23 19 TTask s = class(TObjectList)24 TTaskClass = class of TTask; 20 25 26 { TScheduler } 27 28 TScheduler = class 29 TaskClass: TTaskClass; 30 Tasks: TNamedObjectList; // TList<TTask> 31 Running: Boolean; 32 procedure Start; virtual; 33 procedure Stop; 34 function AddTask(Name: string; EntryPoint: TEvent): TTask; virtual; 35 constructor Create; virtual; 36 destructor Destroy; override; 21 37 end; 22 38 23 TScheduler = class 24 Tasks: TTasks; 25 end; 39 TSchedulerClass = class of TScheduler; 26 40 27 41 TDrive = class(TNamedObject) … … 34 48 Apps: TNamedObjectList; // TList<TApp> 35 49 Drives: TNamedObjectList; // TList<TDrive> 36 procedure Execute(AFile: TFile); 50 Scheduler: TScheduler; 51 SchedulerClass: TSchedulerClass; 52 FileSystemClass: TFileSystemClass; 53 procedure AppExecute(AFile: TFile); 37 54 procedure Init; 38 55 procedure Run; … … 43 60 implementation 44 61 45 uses 46 UPlatformBase; 62 { TTask } 63 64 constructor TTask.Create; 65 begin 66 67 end; 68 69 { TScheduler } 70 71 procedure TScheduler.Start; 72 begin 73 Running := True; 74 end; 75 76 procedure TScheduler.Stop; 77 begin 78 Running := False; 79 end; 80 81 function TScheduler.AddTask(Name: string; EntryPoint: TEvent): TTask; 82 var 83 NewTask: TTask; 84 begin 85 NewTask := TaskClass.Create; 86 NewTask.Name := Name; 87 NewTask.EntryPoint := EntryPoint; 88 Tasks.Add(NewTask); 89 Result := NewTask; 90 end; 91 92 constructor TScheduler.Create; 93 begin 94 TaskClass := TTask; 95 Tasks := TNamedObjectList.Create; 96 end; 97 98 destructor TScheduler.Destroy; 99 begin 100 if Running then Stop; 101 Tasks.Free; 102 inherited Destroy; 103 end; 47 104 48 105 { TKernel } 49 106 50 procedure TKernel. Execute(AFile: TFile);107 procedure TKernel.AppExecute(AFile: TFile); 51 108 var 52 109 App: TApp; 53 110 begin 54 111 App := TApp(Apps.FindByName(AFile.Name)); 55 if Assigned(App) then App.Run 56 else raise Exception.Create('Application ''' + AFile.Name + ''' no found'); 112 if Assigned(App) then begin 113 Scheduler.AddTask(App.Name, App.Run); 114 end else raise Exception.Create('Application ''' + AFile.Name + ''' no found'); 57 115 end; 58 116 … … 62 120 NewFile: TFile; 63 121 begin 122 Scheduler.Free; 123 Scheduler := SchedulerClass.Create; 124 64 125 NewDrive := TDrive.Create; 65 126 NewDrive.Name := 'System'; 66 NewDrive.FileSystem := TBaseFileSystem.Create;127 NewDrive.FileSystem := FileSystemClass.Create; 67 128 Drives.Add(NewDrive); 68 129 … … 83 144 SystemFileSystem := SystemDrive.FileSystem; 84 145 AppFile := TFile(SystemFileSystem.TopDirectory.Items.FindByName('Clock')); 85 if Assigned(AppFile) then Execute(AppFile)146 if Assigned(AppFile) then AppExecute(AppFile) 86 147 else raise Exception.Create('Cannot start first application'); 148 Scheduler.Start; 87 149 end else raise Exception.Create('Missing System drive'); 88 150 end; … … 92 154 Drives := TNamedObjectList.Create; 93 155 Apps := TNamedObjectList.Create; 156 Scheduler := TScheduler.Create; 94 157 end; 95 158 96 159 destructor TKernel.Destroy; 97 160 begin 161 Scheduler.Free; 98 162 Apps.Free; 99 163 Drives.Free;
Note:
See TracChangeset
for help on using the changeset viewer.