Process.Update for synchronization
This commit is contained in:
@@ -3,7 +3,8 @@ unit Myc.Trade.DataPoint;
|
||||
interface
|
||||
|
||||
uses
|
||||
System.TimeSpan;
|
||||
System.TimeSpan,
|
||||
Myc.Core.Notifier;
|
||||
|
||||
type
|
||||
// A data record for an Ask/Bid price pair.
|
||||
@@ -31,11 +32,34 @@ type
|
||||
|
||||
IMycProcessor<T> = interface
|
||||
function ProcessData(const Value: T): Boolean;
|
||||
procedure Update;
|
||||
end;
|
||||
|
||||
TMycProcessor<T> = class abstract(TInterfacedObject, IMycProcessor<T>)
|
||||
protected
|
||||
function ProcessData(const Value: T): Boolean; virtual; abstract;
|
||||
procedure Update; virtual;
|
||||
end;
|
||||
|
||||
TTag = Pointer;
|
||||
|
||||
IMycDataProvider<T> = interface
|
||||
function Link(const Receiver: IMycProcessor<T>): TTag;
|
||||
procedure Unlink(Tag: TTag);
|
||||
end;
|
||||
|
||||
TMycDataProvider<T> = class abstract(TContainedObject, IMycDataProvider<T>)
|
||||
private
|
||||
FListeners: TMycNotifyList<IMycProcessor<T>>;
|
||||
public
|
||||
constructor Create(const Controller: IInterface);
|
||||
destructor Destroy; override;
|
||||
// Notifies all linked processors.
|
||||
procedure Notify(const Func: TMycNotifyList<IMycProcessor<T>>.TNotifyProc);
|
||||
// Link a Processor
|
||||
function Link(const Processor: IMycProcessor<T>): TTag;
|
||||
// Unlink a linked strategy
|
||||
procedure Unlink(Tag: TTag);
|
||||
end;
|
||||
|
||||
TMycGenericProcessor<T> = class(TMycProcessor<T>)
|
||||
@@ -43,6 +67,7 @@ type
|
||||
TProc = reference to function(const Value: T): Boolean;
|
||||
private
|
||||
FProc: TProc;
|
||||
protected
|
||||
function ProcessData(const Value: T): Boolean; override;
|
||||
public
|
||||
constructor Create(const AProc: TProc);
|
||||
@@ -54,6 +79,7 @@ type
|
||||
private
|
||||
FProc: TProc;
|
||||
function ProcessData(const Value: T): Boolean;
|
||||
procedure Update;
|
||||
public
|
||||
constructor Create(const Controller: IInterface; const AProc: TProc);
|
||||
end;
|
||||
@@ -441,4 +467,58 @@ begin
|
||||
Result := FProc(Value);
|
||||
end;
|
||||
|
||||
procedure TMycContainedProcessor<T>.Update;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
{ TMycDataProvider<S, T> }
|
||||
|
||||
constructor TMycDataProvider<T>.Create(const Controller: IInterface);
|
||||
begin
|
||||
inherited Create(Controller);
|
||||
end;
|
||||
|
||||
destructor TMycDataProvider<T>.Destroy;
|
||||
begin
|
||||
FListeners.Finalize;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TMycDataProvider<T>.Notify(const Func: TMycNotifyList<IMycProcessor<T>>.TNotifyProc);
|
||||
begin
|
||||
FListeners.Lock;
|
||||
try
|
||||
FListeners.Notify(Func);
|
||||
finally
|
||||
FListeners.Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TMycDataProvider<T>.Link(const Processor: IMycProcessor<T>): TTag;
|
||||
begin
|
||||
// Add the Processor to the notification list
|
||||
FListeners.Lock;
|
||||
try
|
||||
Result := FListeners.Advise(Processor);
|
||||
finally
|
||||
FListeners.Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMycDataProvider<T>.Unlink(Tag: TTag);
|
||||
begin
|
||||
FListeners.Lock;
|
||||
try
|
||||
FListeners.Unadvise(Tag);
|
||||
finally
|
||||
FListeners.Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMycProcessor<T>.Update;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user