| Class TTapiTerminal (unit TapiTerm) |
TComponent
| Constructors |
constructor Create( AOwner: TComponent );--------------------------------------------------------------------------------------------- ********************************************************************************************** TERMINAL PART ********************************************************************************************** ---------------------------------------------------------------------------------------------} (******************************************************************************) // TTapiTerminal PUBLIC METHODS (
| Functions |
destructor Destroy;
procedure DropCall;
procedure GetDialingConfig;
procedure MakeCall;
function WriteCommData( pDataToWrite: PChar; dwSizeofDataToWrite: Word ): Boolean;
procedure CloseReadThread;TTapiTerminal.
procedure CloseWriteThread;
procedure ReceiveData( Buffer: PChar; BufferLength: Word );
procedure RequestHangup;
procedure CommWndProc( var msg: TMessage );
procedure DirectConnect(fCommPort : pChar);
procedure DoConnect;
function GetReceiveDataEvent: TReceiveDataEvent;
function GetRequestHangupEvent: TNotifyEvent;
procedure SetCommsLogFileName( LogFileName: string );
procedure SetReceiveDataEvent( AReceiveDataEvent: TReceiveDataEvent );
procedure SetRequestHangupEvent( ARequestHangupEvent: TNotifyEvent );
function StartComm(hNewCommFile: THandle): Boolean;
procedure StopComm;| Properties |
property DeviceID : Longint
property PhoneNumber : string| Events |
event OnReceiveData : TReceiveDataEvent
event OnRequestHangup : TNotifyEvent| Variables |
APIVer : Longint;
call : THCall;
CallParams : TlineCallParams;
FBaudRate : DWORD;
FByteSize : Byte;
FCommPort : string;
FCommsLogFileName : string;
fDeviceID : Longint;
FHWnd : THandle;
FOnReceiveData : TReceiveDataEvent;
FOnRequestHangup : TNotifyEvent;
FParity : TParity;
fPhoneNUmber : string;
FStopBits : TStopBits;
hCloseEvent : THandle;
hCommFile : THandle;
line : THLine;
lineApp : THLineApp;
LineHandle : Longint;
lReturn : Longint;
lVarString : LPVarString;
nDevs : Longint;
ReadCreated : Boolean;
ReadThread : TReadThread;
tapiVersion : Longint;
ThreadError : Boolean;
WriteCreated : Boolean;
WriteThread : TWriteThread;| Constructors |
constructor Create( AOwner: TComponent );Public declarations
--------------------------------------------------------------------------------------------- ********************************************************************************************** TERMINAL PART ********************************************************************************************** ---------------------------------------------------------------------------------------------} (******************************************************************************) // TTapiTerminal PUBLIC METHODS (
| Functions |
destructor Destroy;Check for version (copied from a TAPI sample)
procedure DropCall;We have a direct connection;
procedure GetDialingConfig;---- Free the memory help by lpVarString
procedure MakeCall;case
function WriteCommData( pDataToWrite: PChar; dwSizeofDataToWrite: Word ): Boolean;TTapiTerminal.StopComm} // // FUNCTION: WriteCommData(PChar, Word) // // PURPOSE: Send a String to the Write Thread to be written to the Comm. // // PARAMETERS: // pszStringToWrite - String to Write to Comm port. // nSizeofStringToWrite - length of pszStringToWrite. // // RETURN VALUE: // Returns TRUE if the PostMessage is successful. // Returns FALSE if PostMessage fails or Write thread doesn't exist. // // COMMENTS: // // This is a wrapper function so that other modules don't care that // Comm writing is done via PostMessage to a Write thread. Note that // using PostMessage speeds up response to the UI (very little delay to // 'write' a string) and provides a natural buffer if the comm is slow // (ie: the messages just pile up in the message queue). // // Note that it is assumed that pszStringToWrite is allocated with // LocalAlloc, and that if WriteCommData succeeds, its the job of the // Write thread to LocalFree it. If WriteCommData fails, then its // the job of the calling function to free the string. // //
procedure CloseReadThread;Protected declarations
TTapiTerminal.WriteCommData} (******************************************************************************) // TTapiTerminal PROTECTED METHODS (******************************************************************************) // // FUNCTION: CloseReadThread // // PURPOSE: Close the Read Thread. // // PARAMETERS: // none // // RETURN VALUE: // none // // COMMENTS: // // Closes the Read thread by signaling the CloseEvent. // Purges any outstanding reads on the comm port. // // Note that terminating a thread leaks memory. // Besides the normal leak incurred, there is an event object // that doesn't get closed. This isn't worth worrying about // since it shouldn't happen anyway. // //
procedure CloseWriteThread;TTapiTerminal.CloseReadThread} // // FUNCTION: CloseWriteThread // // PURPOSE: Closes the Write Thread. // // PARAMETERS: // none // // RETURN VALUE: // none // // COMMENTS: // // Closes the write thread by signaling the CloseEvent. // Purges any outstanding writes on the comm port. // // Note that terminating a thread leaks memory. // Besides the normal leak incurred, there is an event object // that doesn't get closed. This isn't worth worrying about // since it shouldn't happen anyway. // //
procedure ReceiveData( Buffer: PChar; BufferLength: Word );TTapiTerminal.CloseWriteThread
procedure RequestHangup;
procedure CommWndProc( var msg: TMessage );
procedure DirectConnect(fCommPort : pChar);< 0 then MessageDlg('Error: Could not drop the call.', mtError, [mbok], 0);
procedure DoConnect;FILE_ATTRIBUTE_NORMAL+
function GetReceiveDataEvent: TReceiveDataEvent;
function GetRequestHangupEvent: TNotifyEvent;
procedure SetCommsLogFileName( LogFileName: string );*****************************************************************************) // TTapiTerminal PRIVATE METHODS (
procedure SetReceiveDataEvent( AReceiveDataEvent: TReceiveDataEvent );
procedure SetRequestHangupEvent( ARequestHangupEvent: TNotifyEvent );
function StartComm(hNewCommFile: THandle): Boolean;FUNCTION: StartComm // PURPOSE: Starts communications over the comm port. // PARAMETERS: hNewCommFile - This is the COMM File handle to communicate with. This handle is obtained from TAPI. // RETURN VALUE: TRUE if able to setup the communications. // COMMENTS: // StartComm makes sure there isn't communication in progress already, creates a Comm file, and creates the read and write threads. It also configures the hNewCommFile for the appropriate COMM settings. // If StartComm fails for any reason, it's up to the calling application to close the Comm file handle. // //
procedure StopComm;TTapiTerminal.StartComm} // // FUNCTION: StopComm // // PURPOSE: Stop and end all communication threads. // // PARAMETERS: // none // // RETURN VALUE: // none // // COMMENTS: // // Tries to gracefully signal all communication threads to // close, but terminates them if it has to. // //
| Properties |
property DeviceID : Longint
property PhoneNumber : stringPublished declarations
| Events |
event OnReceiveData : TReceiveDataEvent
event OnRequestHangup : TNotifyEvent| Variables |
APIVer : Longint;
call : THCall;
CallParams : TlineCallParams;
FBaudRate : DWORD;
FByteSize : Byte;
FCommPort : string;
FCommsLogFileName : string;
fDeviceID : Longint;
FHWnd : THandle;
FOnReceiveData : TReceiveDataEvent;
FOnRequestHangup : TNotifyEvent;
FParity : TParity;
fPhoneNUmber : string;
FStopBits : TStopBits;
hCloseEvent : THandle;
hCommFile : THandle;
line : THLine;
lineApp : THLineApp;
LineHandle : Longint;
lReturn : Longint;
lVarString : LPVarString;
nDevs : Longint;
ReadCreated : Boolean;
ReadThread : TReadThread;Private declarations
tapiVersion : Longint;
ThreadError : Boolean;
WriteCreated : Boolean;
WriteThread : TWriteThread;