class TRingHandler
{
public:
TRingHandler (const TTelephoneLineHandle*);
virtual ~TRingHandler ();
virtual void HandleRing(const TTelephoneRingNotification&);
private:
TTelephoneLineHandle* fLineHandle;
TTelephoneCallHandle* fCallHandle;
TMemberFunctionConnection fConnection;
};
// Implement TRingHandler.
TRingHandler::TRingHandler(const TTelephoneLineHandle* lineHandle)
: fLineHandle(lineHandle)
{
fConnection.SetReceiver(this, (NotificationMemberFunction)
&TRingHandler::HandleRing);
fConnection.AdoptInterest(fLineHandle->CreateRingInterest());
fConnection.Connect();
}
TRingHandler::~TRingHandler()
{
delete fCallHandle;
delete fLineHandle;
}
TRingHandler::HandleRing(const TNotification& ringNotification)
{
// If the phone system supports calling party ID, before the
// call is connected you can ask who is calling
TStandardText callingParty;
((const TTelephoneRingNotification&)
theNotification).GetIncomingNumber(callingParty);
// Answer the call
fCallHandle = fLineHandle->CreateAndAnswerCall();
}