OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
OSDP.Net.FileTransferReceiver Class Reference

Reassembles a file sent by an ACU through a sequence of osdp_FILETRANSFER commands and produces the osdp_FTSTAT reply that each fragment requires. More...

Public Member Functions

 FileTransferReceiver (int maximumFileSize=DefaultMaximumFileSize)
 Initializes a new instance of the FileTransferReceiver class.
FileTransferStatus AcceptFragment (FileTransferFragment fragment)
 Accepts one file transfer fragment and produces the status reply to send back to the ACU.
byte[] GetFile ()
 Returns a copy of the assembled file.
void Reset ()
 Discards any transfer in progress and returns the receiver to its initial state.

Static Public Attributes

const int DefaultMaximumFileSize = 16 * 1024 * 1024
 Largest file accepted when the caller does not specify a limit.

Properties

bool IsTransferInProgress [get]
 Gets a value indicating whether a transfer has been started and has not yet been reset.
bool IsComplete [get]
 Gets a value indicating whether every byte of the current transfer has been received.
byte FileType [get]
 Gets the file transfer type declared by the ACU, or zero when no transfer is in progress.
int TotalSize [get]
 Gets the total size of the file being transferred, or zero when no transfer is in progress.
int ReceivedSize [get]
 Gets the number of contiguous bytes received so far.
FileTransferStatus.ControlFlags Action = FileTransferStatus.ControlFlags.None [get, set]
 Gets or sets the control flags reported to the ACU with every status reply.
ushort RequestedDelay [get, set]
 Gets or sets the delay in milliseconds the ACU is asked to wait before sending the next osdp_FILETRANSFER command.
ushort UpdateMessageMaximum [get, set]
 Gets or sets the alternate maximum fragment size reported to the ACU.

Detailed Description

Reassembles a file sent by an ACU through a sequence of osdp_FILETRANSFER commands and produces the osdp_FTSTAT reply that each fragment requires.

A PD implementation calls AcceptFragment from its Device.HandleFileTransfer override and returns the result. The receiver validates each fragment against OSDP v2.2.2 subclauses 6.26 and 7.25, copies its data into a buffer sized from the total size declared by the ACU, and reports FileTransferStatus.StatusDetail.OkToProceed until the final byte arrives, at which point it reports FileTransferStatus.StatusDetail.FileContentsProcessed and exposes the assembled file through GetFile.

Fragments are written at the offset the ACU declares, so a retransmitted or overlapping fragment is absorbed without corrupting the file. A fragment that would leave a gap is rejected, because the spec requires offsets to be monotonically increasing and the PD has no way to request a resend.

This class is not thread safe. A Device processes commands one at a time on a single connection loop, so a receiver owned by one device needs no external locking.

Definition at line 31 of file FileTransferReceiver.cs.

Constructor & Destructor Documentation

◆ FileTransferReceiver()

OSDP.Net.FileTransferReceiver.FileTransferReceiver ( int maximumFileSize = DefaultMaximumFileSize)
inline

Initializes a new instance of the FileTransferReceiver class.

Parameters
maximumFileSizeLargest total file size to accept, in bytes. Defaults to DefaultMaximumFileSize.
Exceptions
ArgumentOutOfRangeExceptionThe maximum file size is not positive.

Definition at line 52 of file FileTransferReceiver.cs.

References DefaultMaximumFileSize.

Member Function Documentation

◆ AcceptFragment()

FileTransferStatus OSDP.Net.FileTransferReceiver.AcceptFragment ( FileTransferFragment fragment)
inline

Accepts one file transfer fragment and produces the status reply to send back to the ACU.

Parameters
fragmentThe incoming osdp_FILETRANSFER payload.
Returns
The osdp_FTSTAT reply for this fragment: a negative FileTransferStatus.StatusDetail aborts the transfer at the ACU, FileTransferStatus.StatusDetail.OkToProceed asks for the next fragment, and FileTransferStatus.StatusDetail.FileContentsProcessed reports the file complete.
Exceptions
ArgumentNullExceptionThe fragment is null.

Definition at line 118 of file FileTransferReceiver.cs.

References FileType, OSDP.Net.Model.CommandData.FileTransferFragment.Fragment, IsComplete, Reset(), and OSDP.Net.Model.CommandData.FileTransferFragment.Type.

◆ GetFile()

byte[] OSDP.Net.FileTransferReceiver.GetFile ( )
inline

Returns a copy of the assembled file.

Returns
The complete file contents.
Exceptions
InvalidOperationExceptionThe transfer has not completed.

Definition at line 179 of file FileTransferReceiver.cs.

References IsComplete.

◆ Reset()

void OSDP.Net.FileTransferReceiver.Reset ( )
inline

Discards any transfer in progress and returns the receiver to its initial state.

Definition at line 193 of file FileTransferReceiver.cs.

References FileType.

Referenced by AcceptFragment().

Member Data Documentation

◆ DefaultMaximumFileSize

const int OSDP.Net.FileTransferReceiver.DefaultMaximumFileSize = 16 * 1024 * 1024
static

Largest file accepted when the caller does not specify a limit.

A transfer declaring a total size beyond the limit is rejected before any buffer is allocated, so a malformed or hostile header cannot exhaust memory.

Definition at line 38 of file FileTransferReceiver.cs.

Referenced by FileTransferReceiver().

Property Documentation

◆ Action

FileTransferStatus.ControlFlags OSDP.Net.FileTransferReceiver.Action = FileTransferStatus.ControlFlags.None
getset

Gets or sets the control flags reported to the ACU with every status reply.

See OSDP v2.2.2 Table 68.

Definition at line 93 of file FileTransferReceiver.cs.

◆ FileType

byte OSDP.Net.FileTransferReceiver.FileType
get

Gets the file transfer type declared by the ACU, or zero when no transfer is in progress.

See OSDP v2.2.2 Table 34.

Definition at line 77 of file FileTransferReceiver.cs.

Referenced by AcceptFragment(), and Reset().

◆ IsComplete

bool OSDP.Net.FileTransferReceiver.IsComplete
get

Gets a value indicating whether every byte of the current transfer has been received.

Definition at line 71 of file FileTransferReceiver.cs.

Referenced by AcceptFragment(), and GetFile().

◆ IsTransferInProgress

bool OSDP.Net.FileTransferReceiver.IsTransferInProgress
get

Gets a value indicating whether a transfer has been started and has not yet been reset.

Definition at line 66 of file FileTransferReceiver.cs.

◆ ReceivedSize

int OSDP.Net.FileTransferReceiver.ReceivedSize
get

Gets the number of contiguous bytes received so far.

Definition at line 87 of file FileTransferReceiver.cs.

◆ RequestedDelay

ushort OSDP.Net.FileTransferReceiver.RequestedDelay
getset

Gets or sets the delay in milliseconds the ACU is asked to wait before sending the next osdp_FILETRANSFER command.

Zero requests no delay.

Definition at line 99 of file FileTransferReceiver.cs.

◆ TotalSize

int OSDP.Net.FileTransferReceiver.TotalSize
get

Gets the total size of the file being transferred, or zero when no transfer is in progress.

Definition at line 82 of file FileTransferReceiver.cs.

◆ UpdateMessageMaximum

ushort OSDP.Net.FileTransferReceiver.UpdateMessageMaximum
getset

Gets or sets the alternate maximum fragment size reported to the ACU.

Zero requests no change, leaving the ACU on the size it derived from osdp_PDCAP.

Definition at line 105 of file FileTransferReceiver.cs.


The documentation for this class was generated from the following file: