|
OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
|
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. | |
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.
|
inline |
Initializes a new instance of the FileTransferReceiver class.
| maximumFileSize | Largest total file size to accept, in bytes. Defaults to DefaultMaximumFileSize. |
| ArgumentOutOfRangeException | The maximum file size is not positive. |
Definition at line 52 of file FileTransferReceiver.cs.
References DefaultMaximumFileSize.
|
inline |
Accepts one file transfer fragment and produces the status reply to send back to the ACU.
| fragment | The incoming osdp_FILETRANSFER payload. |
| ArgumentNullException | The 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.
|
inline |
Returns a copy of the assembled file.
| InvalidOperationException | The transfer has not completed. |
Definition at line 179 of file FileTransferReceiver.cs.
References IsComplete.
|
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().
|
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().
|
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.
|
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().
|
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().
|
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.
|
get |
Gets the number of contiguous bytes received so far.
Definition at line 87 of file FileTransferReceiver.cs.
|
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.
|
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.
|
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.