Skip to content

Commit

Permalink
refactor: Getting messages into a better shape
Browse files Browse the repository at this point in the history
  • Loading branch information
gcarreno committed Oct 18, 2023
1 parent ca77ed9 commit a29f351
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
66 changes: 59 additions & 7 deletions src/dispatching/polykerma.dispatching.message.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,43 @@ interface
Classes
, SysUtils
{$ENDIF FPC_DOTTEDUNITS}
, PolyKerma.Dispatching
, PolyKerma.Logging
;

type
{ TMessage }
TMessage = class(TObject)
private
FAttachment: String;
FChannel: String;
FPayload: String;
FText: String;
FAttachement: TObject;

protected
public
constructor Create(const AChannel: String);
constructor Create;
constructor Create(
const AChannel: String);
constructor Create(
const AChannel: String;
const AText: String);
constructor Create(
const AChannel: String;
const AText: String;
const AAttachement: TObject);
destructor Destroy; override;

function Copy: TMessage;

property Channel: String
read FChannel;
property Payload: String
read FPayload
write FPayload;
property Text: String
read FText
write FText;
property Attachment: String
read FAttachment
write FAttachment;
published
end;
TMessageClass = class of TMessage;
Expand All @@ -42,12 +57,46 @@ implementation

{ TMessage }

constructor TMessage.Create(const AChannel: String);
constructor TMessage.Create;
begin
Debug({$I %FILE%}, {$I %LINE%}, 'Message Create');
FChannel:= cChannelNone;
FText:= EmptyStr;
FAttachement:= nil;
end;

constructor TMessage.Create(
const AChannel: String);
begin
Debug({$I %FILE%}, {$I %LINE%}, Format('Message Create: %s', [ AChannel ]));
FChannel:= AChannel;
end;

constructor TMessage.Create(
const AChannel: String;
const AText: String);
begin
Debug({$I %FILE%}, {$I %LINE%}, Format('Message Create: %s, "%s"', [
AChannel,
AText
]));
FChannel:= AChannel;
FText:= AText;
end;

constructor TMessage.Create(
const AChannel: String;
const AText: String;
const AAttachement: TObject);
begin
Debug({$I %FILE%}, {$I %LINE%}, Format('Message Create: %s, "%s"', [
AChannel,
AText
]));
FChannel:= AChannel;
FText:= AText;
end;

destructor TMessage.Destroy;
begin
Debug({$I %FILE%}, {$I %LINE%}, 'Message Destroy');
Expand All @@ -56,8 +105,11 @@ destructor TMessage.Destroy;

function TMessage.Copy: TMessage;
begin
Debug({$I %FILE%}, {$I %LINE%}, 'Message Copy');
Result:= TMessage.Create(Self.Channel);
Result.Payload:= Self.Payload;
Result.FChannel:= Self.FChannel;
Result.FText:= Self.FText;
Result.FAttachement:= Self.FAttachement;
end;

end.
Expand Down
1 change: 1 addition & 0 deletions src/dispatching/polykerma.dispatching.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface
;*)

const
cChannelNone = 'none';
cChannelControllerOut = 'controller.out';
cChannelControllerIn = 'controller.in';
cChannelCommsOut = 'comms.out';
Expand Down

0 comments on commit a29f351

Please sign in to comment.