Ignore:
Timestamp:
Nov 1, 2011, 10:32:54 AM (13 years ago)
Author:
george
Message:
  • Added: New class TPinConcentrator as special case of TCommHub. Concentrator send data received from Main pin to all registred pins and send all data received from registred pins to main pin.
  • Modified: Pins of TCommHub are now implemented as descendand of TObjectList rather then methods of TCommHub.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • PinConnection/UCommHub.pas

    r288 r289  
    99
    1010type
     11  TCommHub = class;
     12
     13  { TPinList }
     14
     15  TPinList = class(TObjectList)
     16    Hub: TCommHub;
     17    function Add(AObject: TObject): Integer;
     18    function AddNew: TCommPin;
     19    function Extract(Item: TObject): TObject;
     20    procedure Insert(Index: Integer; AObject: TObject);
     21  end;
    1122
    1223  { TCommHub }
     
    1526  private
    1627    FActive: Boolean;
    17     FPins: TObjectList;
    18     function GetPin(Index: Integer): TCommPin;
     28    FPins: TPinList;
    1929    procedure Receive(Sender: TCommPin; Stream: TStream);
    2030    procedure SetStatus(Sender: TCommPin; Status: Integer);
     
    2232    constructor Create;
    2333    destructor Destroy; override;
    24     function Add(Pin: TCommPin): Integer;
    25     function Extract(Pin: TCommPin): TCommPin;
    26     function Remove(Pin: TCommPin): Integer;
    27     function IndexOf(Pin: TCommPin): Integer;
    28     Procedure Insert(Index: Integer; Pin: TCommPin);
    29     function First: TCommPin;
    30     Function Last: TCommPin;
    31     function AddNew: TCommPin;
    32     property Pins[Index: Integer]: TCommPin read GetPin;
     34    property Pins: TPinList read FPins write FPins;
    3335    property Active: Boolean read FActive write FActive;
    3436  end;
     
    3638implementation
    3739
     40{ TPinList }
     41
     42function TPinList.Add(AObject: TObject): Integer;
     43begin
     44  Result := inherited Add(AObject);
     45  TCommPin(AObject).OnReceive := Hub.Receive;
     46  TCommPin(AObject).OnSetSatus := Hub.SetStatus;
     47end;
     48
     49function TPinList.AddNew: TCommPin;
     50begin
     51  Result := TCommPin(Items[Add(TCommPin.Create)]);
     52end;
     53
     54function TPinList.Extract(Item: TObject): TObject;
     55begin
     56  TCommPin(Item).OnReceive := nil;
     57  TCommPin(Item).OnSetSatus := nil;
     58  Result := inherited Extract(Item);
     59end;
     60
     61procedure TPinList.Insert(Index: Integer; AObject: TObject);
     62begin
     63  inherited Insert(Index, AObject);
     64  TCommPin(AObject).OnReceive := Hub.Receive;
     65  TCommPin(AObject).OnSetSatus := Hub.SetStatus;
     66end;
     67
    3868{ TCommHub }
    39 
    40 function TCommHub.GetPin(Index: Integer): TCommPin;
    41 begin
    42   Result := TCommPin(FPins[Index]);
    43 end;
    4469
    4570procedure TCommHub.Receive(Sender: TCommPin; Stream: TStream);
     
    6994constructor TCommHub.Create;
    7095begin
    71   FPins := TObjectList.Create;
     96  FPins := TPinList.Create;
     97  FPins.Hub := Self;
    7298end;
    7399
    74100destructor TCommHub.Destroy;
    75101begin
     102  Active := False;
    76103  FPins.Free;
    77104  inherited Destroy;
    78105end;
    79106
    80 function TCommHub.Add(Pin: TCommPin): Integer;
    81 begin
    82   Pin.OnReceive := Receive;
    83   Pin.OnSetSatus := SetStatus;
    84   Result := FPins.Add(Pin);
    85 end;
    86 
    87 function TCommHub.Extract(Pin: TCommPin): TCommPin;
    88 begin
    89   Pin.OnReceive := nil;
    90   Pin.OnSetSatus := nil;
    91   Result := TCommPin(FPins.Extract(Pin));
    92 end;
    93 
    94 function TCommHub.Remove(Pin: TCommPin): Integer;
    95 begin
    96   Result := FPins.Remove(Pin);
    97 end;
    98 
    99 function TCommHub.IndexOf(Pin: TCommPin): Integer;
    100 begin
    101   Result := FPins.IndexOf(Pin);
    102 end;
    103 
    104 procedure TCommHub.Insert(Index: Integer; Pin: TCommPin);
    105 begin
    106   Pin.OnReceive := Receive;
    107   Pin.OnSetSatus := SetStatus;
    108   FPins.Insert(Index, Pin);
    109 end;
    110 
    111 function TCommHub.First: TCommPin;
    112 begin
    113   Result := TCommPin(FPins.First);
    114 end;
    115 
    116 function TCommHub.Last: TCommPin;
    117 begin
    118   Result := TCommPin(FPins.Last);
    119 end;
    120 
    121 function TCommHub.AddNew: TCommPin;
    122 begin
    123   Result := TCommPin.Create;
    124   Result.OnReceive := Receive;
    125   Result.OnSetSatus := SetStatus;
    126   FPins.Add(Result);
    127 end;
    128 
    129107end.
    130108
Note: See TracChangeset for help on using the changeset viewer.