Changeset 4 for trunk/Platform
- Timestamp:
- Nov 23, 2014, 12:56:33 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.