Changeset 4
- Timestamp:
- Nov 23, 2014, 12:56:33 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Apps/UClock.pas
r3 r4 6 6 7 7 uses 8 Classes, SysUtils, UA PI, dateutils;8 Classes, SysUtils, UApp, dateutils; 9 9 10 10 type … … 23 23 procedure TAppClock.Run; 24 24 begin 25 while Truedo begin25 while not Terminated do begin 26 26 API.WriteText('test'); 27 27 API.Sleep(OneSecond); -
trunk/ChronOS.lpi
r3 r4 33 33 </Item1> 34 34 </RequiredPackages> 35 <Units Count=" 9">35 <Units Count="12"> 36 36 <Unit0> 37 37 <Filename Value="ChronOS.lpr"/> … … 81 81 <UnitName Value="UList"/> 82 82 </Unit8> 83 <Unit9> 84 <Filename Value="UApp.pas"/> 85 <IsPartOfProject Value="True"/> 86 <UnitName Value="UApp"/> 87 </Unit9> 88 <Unit10> 89 <Filename Value="UThreadEx.pas"/> 90 <IsPartOfProject Value="True"/> 91 <UnitName Value="UThreadEx"/> 92 </Unit10> 93 <Unit11> 94 <Filename Value="UMemory.pas"/> 95 <IsPartOfProject Value="True"/> 96 <UnitName Value="UMemory"/> 97 </Unit11> 83 98 </Units> 84 99 </ProjectOptions> -
trunk/ChronOS.lpr
r3 r4 11 11 Interfaces, // this includes the LCL widgetset 12 12 Forms, UFormMain, UKernel, UFileSystem, UClock, UMemoryManager, UAPI, 13 UPlatformBase, UList ;13 UPlatformBase, UList, UApp, UThreadEx, UMemory; 14 14 15 15 {$R *.res} -
trunk/Platform/Base/UPlatformBase.pas
r3 r4 6 6 7 7 uses 8 Classes, SysUtils, UFileSystem, UKernel ;8 Classes, SysUtils, UFileSystem, UKernel, syncobjs, UThreadEx, UMemory; 9 9 10 10 type 11 11 { TCustomThread } 12 12 13 TCustomThread = class(TThread )13 TCustomThread = class(TThreadEx) 14 14 Task: TTask; 15 15 procedure Execute; override; … … 32 32 33 33 TBaseScheduler = class(TScheduler) 34 function AddTask(Name: string; EntryPoint: T Event): TTask; override;34 function AddTask(Name: string; EntryPoint: TBasicEvent): TTask; override; 35 35 constructor Create; override; 36 destructor Destroy; override; 36 37 procedure Start; override; 38 procedure Stop; override; 39 end; 40 41 TReceiveEvent = procedure(Data: TMemory) of object; 42 43 { TBaseSerialDevice } 44 45 TBaseSerialDevice = class(TDevice) 46 private 47 Lock: TCriticalSection; 48 FOnReceiveData: TReceiveEvent; 49 public 50 constructor Create; override; 51 destructor Destroy; override; 52 procedure Service(Index: Integer; DataIn, DataOut: TMemory); override; 53 property OnReceiveData: TReceiveEvent read FOnReceiveData write FOnReceiveData; 37 54 end; 38 55 39 56 implementation 57 58 { TBaseSerialDevice } 59 60 constructor TBaseSerialDevice.Create; 61 begin 62 inherited Create; 63 ClassName := 'Serial'; 64 Lock := TCriticalSection.Create; 65 end; 66 67 destructor TBaseSerialDevice.Destroy; 68 begin 69 Lock.Free; 70 inherited Destroy; 71 end; 72 73 procedure TBaseSerialDevice.Service(Index: Integer; DataIn, DataOut: TMemory); 74 begin 75 inherited Service(Index, DataIn, DataOut); 76 if Index = 0 then begin 77 Lock.Acquire; 78 if Assigned(FOnReceiveData) then 79 FOnReceiveData(DataIn); 80 Lock.Release; 81 end else raise Exception.Create('Unsupported service ' + IntToStr(Index) + ' for driver ''' + Name + ''''); 82 end; 40 83 41 84 { TBaseTask } … … 63 106 { TBaseScheduler } 64 107 65 function TBaseScheduler.AddTask(Name: string; EntryPoint: T Event): TTask;108 function TBaseScheduler.AddTask(Name: string; EntryPoint: TBasicEvent): TTask; 66 109 var 67 110 Task: TBaseTask; … … 77 120 end; 78 121 122 destructor TBaseScheduler.Destroy; 123 begin 124 inherited Destroy; 125 end; 126 79 127 procedure TBaseScheduler.Start; 80 128 var … … 86 134 end; 87 135 136 procedure TBaseScheduler.Stop; 137 begin 138 inherited Start; 139 end; 140 88 141 end. 89 142 -
trunk/UAPI.pas
r3 r4 6 6 7 7 uses 8 Classes, SysUtils, UList ;8 Classes, SysUtils, UList, UKernel, DateUtils, UMemory; 9 9 10 10 type … … 13 13 14 14 TAPI = class 15 Kernel: TKernel; 15 16 procedure WriteText(Text: string); 16 17 procedure Sleep(Time: TDateTime); 17 18 end; 18 19 19 { TApp }20 21 TApp = class(TNamedObject)22 API: TAPI;23 constructor Create; virtual;24 destructor Destroy; override;25 procedure Run; virtual;26 end;27 20 28 21 implementation … … 31 24 32 25 procedure TAPI.WriteText(Text: string); 26 var 27 Device: TDevice; 28 DataIn: TMemory; 33 29 begin 34 30 Device := TDevice(Kernel.Devices.FindByName('Serial0')); 31 if Assigned(Device) then begin 32 DataIn := TMemory.Create; 33 DataIn.Size := Length(Text); 34 Move(Text[1], DataIn.Data^, DataIn.Size); 35 Device.Service(0, DataIn, nil); 36 DataIn.Free; 37 end else raise Exception.Create('Device Serial0 not found'); 35 38 end; 36 39 37 40 procedure TAPI.Sleep(Time: TDateTime); 38 41 begin 39 42 SysUtils.Sleep(Trunc(Time / OneMillisecond)); 40 43 end; 41 44 42 { TApp }43 44 constructor TApp.Create;45 begin46 inherited Create;47 API := TAPI.Create;48 end;49 50 destructor TApp.Destroy;51 begin52 API.Free;53 inherited Destroy;54 end;55 56 procedure TApp.Run;57 begin58 59 end;60 45 61 46 end. -
trunk/UFormMain.lfm
r3 r4 5 5 Width = 932 6 6 Caption = 'Form1' 7 ClientHeight = 687 8 ClientWidth = 932 7 9 OnCreate = FormCreate 8 10 OnDestroy = FormDestroy 9 11 OnShow = FormShow 10 12 LCLVersion = '1.3' 13 object Memo1: TMemo 14 Left = 16 15 Height = 658 16 Top = 8 17 Width = 904 18 TabOrder = 0 19 end 11 20 end -
trunk/UFormMain.pas
r3 r4 6 6 7 7 uses 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, UKernel; 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 UKernel, UMemory; 9 10 10 11 type … … 13 14 14 15 TForm1 = class(TForm) 16 Memo1: TMemo; 15 17 procedure FormCreate(Sender: TObject); 16 18 procedure FormDestroy(Sender: TObject); 17 19 procedure FormShow(Sender: TObject); 18 20 private 19 { private declarations } 21 SerialText: string; 22 procedure SerialDeviceReceiveDataSync; 23 procedure SerialDeviceReceiveData(Data: TMemory); 20 24 public 21 25 Kernel: TKernel; … … 28 32 29 33 uses 30 UList, UA PI, UClock, UPlatformBase;34 UList, UApp, UAPI, UClock, UPlatformBase, UThreadEx; 31 35 32 36 {$R *.lfm} … … 37 41 var 38 42 NewApp: TApp; 43 SerialDevice: TBaseSerialDevice; 39 44 begin 40 45 Kernel := TKernel.Create; 41 46 Kernel.SchedulerClass := TBaseScheduler; 42 47 Kernel.FileSystemClass := TBaseFileSystem; 43 48 SerialDevice := TBaseSerialDevice.Create; 49 SerialDevice.Name := 'Serial0'; 50 SerialDevice.OnReceiveData := SerialDeviceReceiveData; 51 Kernel.Devices.Add(SerialDevice); 44 52 NewApp := TAppClock.Create; 45 53 Kernel.Apps.Add(NewApp); … … 56 64 end; 57 65 66 procedure TForm1.SerialDeviceReceiveDataSync; 67 begin 68 Memo1.Lines.AddText(SerialText); 69 end; 70 71 procedure TForm1.SerialDeviceReceiveData(Data: TMemory); 72 begin 73 SetLength(SerialText, Data.Size); 74 Move(Data.Data^, SerialText[1], Data.Size); 75 TThreadEx.Synchronize(TThreadEx.CurrentThread, SerialDeviceReceiveDataSync); 76 end; 77 58 78 end. 59 79 -
trunk/UKernel.pas
r3 r4 6 6 7 7 uses 8 Classes, SysUtils, UList, Contnrs, UFileSystem, U API;8 Classes, SysUtils, UList, Contnrs, UFileSystem, UMemory; 9 9 10 10 type 11 T Event = procedure of object;11 TBasicEvent = procedure of object; 12 12 13 13 TTaskState = (tsStopped, tsRunning, tsSuspended); … … 18 18 Name: string; 19 19 State: TTaskState; 20 EntryPoint: T Event;20 EntryPoint: TBasicEvent; 21 21 constructor Create; virtual; 22 22 end; … … 31 31 Running: Boolean; 32 32 procedure Start; virtual; 33 procedure Stop; 34 function AddTask(Name: string; EntryPoint: T Event): TTask; virtual;33 procedure Stop; virtual; 34 function AddTask(Name: string; EntryPoint: TBasicEvent): TTask; virtual; 35 35 constructor Create; virtual; 36 36 destructor Destroy; override; … … 43 43 end; 44 44 45 { TDevice } 46 47 TDevice = class(TNamedObject) 48 ClassName: string; 49 constructor Create; virtual; 50 procedure Service(Index: Integer; DataIn, DataOut: TMemory); virtual; 51 end; 52 45 53 { TKernel } 46 54 … … 51 59 SchedulerClass: TSchedulerClass; 52 60 FileSystemClass: TFileSystemClass; 61 Devices: TNamedObjectList; // TList<TDevice> 53 62 procedure AppExecute(AFile: TFile); 54 63 procedure Init; … … 59 68 60 69 implementation 70 71 uses 72 UApp; 73 74 { TDevice } 75 76 constructor TDevice.Create; 77 begin 78 inherited Create; 79 end; 80 81 procedure TDevice.Service(Index: Integer; DataIn, DataOut: TMemory); 82 begin 83 84 end; 61 85 62 86 { TTask } … … 79 103 end; 80 104 81 function TScheduler.AddTask(Name: string; EntryPoint: T Event): TTask;105 function TScheduler.AddTask(Name: string; EntryPoint: TBasicEvent): TTask; 82 106 var 83 107 NewTask: TTask; … … 111 135 App := TApp(Apps.FindByName(AFile.Name)); 112 136 if Assigned(App) then begin 137 App.API.Kernel := Self; 113 138 Scheduler.AddTask(App.Name, App.Run); 114 139 end else raise Exception.Create('Application ''' + AFile.Name + ''' no found'); … … 152 177 constructor TKernel.Create; 153 178 begin 179 Devices := TNamedObjectList.Create; 154 180 Drives := TNamedObjectList.Create; 155 181 Apps := TNamedObjectList.Create; … … 162 188 Apps.Free; 163 189 Drives.Free; 190 Devices.Free; 164 191 inherited Destroy; 165 192 end; -
trunk/UList.pas
r2 r4 9 9 10 10 type 11 12 { TNamedObject } 13 11 14 TNamedObject = class 12 15 Name: string;
Note:
See TracChangeset
for help on using the changeset viewer.