📄 simpletapi.h
字号:
#if !defined _SIMPLE_TAPI_H
#define _SIMPLE_TAPI_H
//
// SimpleTapi.h
//
// Source code from:
//
// Serial Communications: A C++ Developer's Guide, 2nd
// Edition by Mark Nelson, IDG Books, 1999
//
// Please see the book for information on usage.
//
// This file contains the complete declaration of
// the SimpleTapi class. SimpleTapi wraps up a limited
// subset of TAPI 1.4, using the SDK only for its modem
// control and call setup capabilities. This class
// contains several pure virtual functions that are needed
// for notification. Before you can use SimpleTapi, you will
// need to create a derived class that implements those
// functions. A simple example used in the book is
// MySimpleTapi, used in the Chapter 15 example.
//
#include <string>
#include <vector>
using namespace std;
//
// TAPI 1.4 contains everything we need to do first party
// call control, which means setting up and tearing down
// calls on our local modem.
//
#define TAPI_CURRENT_VERSION 0x00010004
#include <tapi.h>
#include "ConStream.h"
#include "resource.h"
//
// This little baby class is used to hold the definitions
// of modems in the m_Devices vector in SimpleTapi. Each
// modem has a text name and a device ID. By creating this
// little structure I can easily hold them in the vector.
//
struct TapiDevice {
int m_iDeviceNumber;
string m_sName;
};
class SimpleTapi {
public :
SimpleTapi();
virtual ~SimpleTapi();
//
// Informational
//
bool IsOpen(){ return m_hLine != 0; }
bool CallActive(){ return m_hCall != 0; }
int GetDeviceCount()
{
return m_Devices.size();
}
string GetDeviceName( int i )
{
return m_Devices[ i ].m_sName;
}
//
// Configuration/setup
//
void ConfigureDevice( int index );
void ConfigureCall( int index, const string &number );
//
// The four big calls used for call progress
//
int OpenLine( int index ); //synchronous
int CloseLine(); //synchronous
void MakeCall( const string &number ); //asynchronous
void DropCall(); //asynchronous
//
// Access the com port
//
HANDLE GetPortHandle();
//
// Debug
//
static ConStream m_Trace;
protected :
void HandleMakeCallResult( DWORD result );
void HandleDropResult( DWORD result );
void HandleAnswerResult( DWORD result );
//
// All of the data members are protected, and should
// only be used internally.
//
protected :
vector< TapiDevice > m_Devices;
HLINEAPP m_hLineApp;
HCALL m_hCall;
bool m_bCallHandleValid;
HLINE m_hLine;
LONG m_lCallState;
DWORD m_dwPendingReplyCode;
string m_sNumber;
enum {
NOTHING,
HANDLE_MAKE_CALL_RESULT,
HANDLE_DROP_RESULT,
HANDLE_ANSWER_RESULT
} m_ReplyAction;
int m_iDeviceId;
//
// Two general purpose functions for translating codes
// into human readable strings.
//
protected :
static string TranslateTapiError( LONG code );
static string TranslateCallState( LONG state );
//
// The static callback function is where all TAPI
// asyncrhonous message processing takes place. That
// means it is responsible for determining when calls
// are initiated, completed, and dropped.
//
private :
static void PASCAL Callback( DWORD hDevice,
DWORD dwMsg,
DWORD dwCallbackInstace,
DWORD dwParam1,
DWORD dwParam2,
DWORD dwParam3 );
//
// The remaining functions in the definition are all
// pure virtual, which means they must be defined in
// a derive class before a SimpleTapi object can be
// instantiated. Nearly all of them are concerned with
// notification messages being sent to the owner of the
// SimpleTapi object.
//
protected :
//
// The two asynchronous functions return results via
// a event handler.
//
virtual void MakeCallResult( bool result ) = 0;
virtual void DropCallResult( bool result ) = 0;
//
// Two events that happen asynchronously are the making
// and breaking of calls. We always signal these via
// the IdleEvent()and ConnectedEvent() function calls
//
virtual void ConnectedEvent() = 0;
virtual void DisconnectedEvent() = 0;
//
// The NotifyCallStateChange() function call is
// lets you track the state of a call with annoyingly
// fine precision.
//
virtual void NotifyCallStateChange( long new_state ) = 0;
//
//
virtual void Error( const char *msg, LONG code ) = 0;
//
// GetWindow() isn't a notification function, but it
// provides a way for us to tell SimpleTapi what the
// handle is of the window that will be the parent of
// the configure line/call dialogs.
//
virtual HWND GetWindow() = 0;
};
#endif //#if !defined _SIMPLE_TAPI_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -