Indy 9
|
TIdCommandHandler = class(TCollectionItem)
TIdCommandHandler implements an OnCommand event handler that receives a TIdCommandEvent event type representing the unique command to be executed. TIdCommandHandler implements the virtual Check method that handles creation of TIdCommand object instances, signalling of event notifications for the associated command object, as well as preparation of reply and response values for the associated threaded peer connection.
TIdCommandHandler is an optional feature for use with TIdTCPServer and descendant classes. TIdCommandHandler can be used when TIdTCPServer.CommandHandlersEnabled indicates that command handlers are desired, and the server has valid TIdCommandHandler instances assigned in the CommandHandlers collection. Under any other circumstance, TIdTCPServer reverts to the default behavior implemented using the TIdTCPServer.OnExecute event handler.
property CmdDelimiter: Char;
The default value for CmdDelimiter is ' ' (Decimal 32), as assigned in Create.
property Command: string;
property Data: TObject;
Note: It is the responsibility of the application to cast Data to the class instance required, or an exception will be raised.
Data is not initialized in the Create constructor, nor is it released in the Destroy destructor. The application must assume all responsibility for maintaining Data when assigned.
property Disconnect: boolean;
property Enabled: boolean;
The default value for Enabled is IdEnabledDefault, as assigned in the Create constructor.
property Name: string;
property ParamDelimiter: Char;
The default value for ParamDelimiter is the SPACE character (Decimal 32) as assigned in Create.
property ParseParams: Boolean;
The default value for ParseParams is IdParseParamsDefault.
property ReplyExceptionCode: Integer;
Note: An exception that occurs in Check can result in the OnException event handler for the server context being executed. Check examines the ReplyExceptionCode on the server to insure that either condition is detected.
property ReplyNormal: TIdRFCReply;
ReplyNormal is used in the Check method prior to invoking execution of the command object of the command handler.
property Response: TStrings;
Response is sent to the peer connection in the current thread of execution using the TIdTCPConnection.WriteRFCStrings method.
property Tag: integer;
TIdNNTPServer uses the Tag property to identify the index position of the NNTPCommand assigned to the TIdCommandHandler.
function Check(const AData: string; AThread: TIdPeerThread): boolean; virtual;
Check creates a TIdCommand object instance used to represent the command handled by the command handler, and sets property values including the CommandHandler that created the object and the peer thread used for data and response messages.
Check parses parameter values into the TIdCOmmand object when ParseParams is True.
Check assigns the values in ReplyNormal as the default reply for the TIdCommand associated with the command handler.
Check signals the OnCommand event handler to allow execution of actions for the command.
If an exception occurs, Check updates the Reply from the command object to contain the value in ReplyExceptionCode and exception message text. Exception messages are then written to the peer thread connection.
When the command object completes execution, values in Reply and Response are sent to the peer thread connection. If Disconnect is True, the peer thread connection is closed prior to exiting from the method.
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
function GetNamePath: string; override;
function NameIs(ACommand: string): Boolean;
property OnCommand: TIdCommandEvent;