mysticbbs/mdl/m_protocol_base.pas

143 lines
3.6 KiB
ObjectPascal
Raw Normal View History

// ====================================================================
// Mystic BBS Software Copyright 1997-2013 By James Coyle
// ====================================================================
//
// This file is part of Mystic BBS.
//
// Mystic BBS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Mystic BBS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Mystic BBS. If not, see <http://www.gnu.org/licenses/>.
//
// ====================================================================
2012-08-08 10:52:49 -07:00
Unit m_Protocol_Base;
{$I M_OPS.PAS}
Interface
Uses
m_DateTime,
m_Input,
2012-08-11 11:58:12 -07:00
m_io_Base,
2012-08-08 10:52:49 -07:00
m_Protocol_Queue;
Type
RecProtocolStatus = Record
Protocol : String[15];
Sender : Boolean;
FilePath : String;
FileName : String;
FileSize : Int64;
Position : Int64;
BlockSize : Word;
Errors : Word;
StartTime : LongInt;
StartPos : Int64;
LastMessage : String[80];
End;
TProtocolStatusProc = Procedure (Starting, Ending: Boolean; Status: RecProtocolStatus);
TProtocolAbortProc = Function : Boolean;
TProtocolBase = Class
Status : RecProtocolStatus;
StatusProc : TProtocolStatusProc;
AbortProc : TProtocolAbortProc;
2012-08-11 11:58:12 -07:00
Client : TIOBase;
2012-08-08 10:52:49 -07:00
Queue : TProtocolQueue;
EndTransfer : Boolean;
Connected : Boolean;
2012-08-11 09:50:14 -07:00
StatusCheck : Word;
StatusTimer : LongInt;
2012-08-08 10:52:49 -07:00
ReceivePath : String;
2012-08-11 11:58:12 -07:00
Constructor Create (Var C: TIOBase; Var Q: TProtocolQueue); Virtual;
2012-08-08 10:52:49 -07:00
Destructor Destroy; Override;
Function AbortTransfer : Boolean;
Procedure StatusUpdate (Starting, Ending: Boolean);
Function ReadByteTimeOut (hSec: LongInt) : SmallInt;
2012-08-11 09:50:14 -07:00
Procedure QueueReceive; Virtual;
Procedure QueueSend; Virtual;
2012-08-08 10:52:49 -07:00
End;
Implementation
Function NoAbortProc : Boolean;
Begin
Result := False;
End;
2012-08-11 11:58:12 -07:00
Constructor TProtocolBase.Create (Var C: TIOBase; Var Q: TProtocolQueue);
2012-08-08 10:52:49 -07:00
Begin
Client := C;
Queue := Q;
EndTransfer := False;
Connected := True;
ReceivePath := '';
StatusProc := NIL;
AbortProc := @NoAbortProc;
2012-08-11 09:50:14 -07:00
StatusCheck := 100;
StatusTimer := 0;
2012-08-08 10:52:49 -07:00
FillChar(Status, SizeOf(Status), 0);
End;
Destructor TProtocolBase.Destroy;
Begin
Inherited Destroy;
End;
Procedure TProtocolBase.StatusUpdate (Starting, Ending: Boolean);
Begin
If Assigned(StatusProc) Then
StatusProc(Starting, Ending, Status);
End;
Function TProtocolBase.ReadByteTimeOut (hSec: LongInt) : SmallInt;
Var
Res : Byte;
Begin
Result := -1;
If Client.DataWaiting Then Begin
2012-08-11 09:50:14 -07:00
Connected := Client.ReadBuf(Res, 1) >= 0;
2012-08-08 10:52:49 -07:00
Result := Res;
End Else
2012-08-11 09:50:14 -07:00
Case Client.WaitForData(hSec * 10) of
2012-08-08 10:52:49 -07:00
-1 : Connected := False;
0 : ;
Else
Client.ReadBuf(Res, 1);
Result := Res;
End;
End;
Function TProtocolBase.AbortTransfer : Boolean;
Begin
If Not EndTransfer Then
EndTransfer := (Not Connected) or AbortProc;
AbortTransfer := EndTransfer;
End;
2012-08-11 09:50:14 -07:00
Procedure TProtocolBase.QueueReceive;
Begin
End;
Procedure TProtocolBase.QueueSend;
Begin
End;
2012-08-08 10:52:49 -07:00
End.