CALLNOT.CPP

////////////////////////////////////////////////////////////////////// 
// callnot.cpp
//
// Implementation of the ITCallNotification interface.
//
// This is an outgoing interface that is defined by TAPI 3.0. This
// is basically a callback function that TAPI 3.0 calls to inform
// the application of events related to calls (on a specific address)
//
// Please refer to COM documentation for information on outgoing
// interfaces.
//
// An application must implement and register this interface in order
// to receive calls and events related to calls
//
//////////////////////////////////////////////////////////////////////


#include "windows.h"
#include "tapi3.h"
#include "callnot.h"
#include "resource.h"

extern ITBasicCallControl * gpCall;
extern HWND ghDlg;

void
DoMessage(
LPWSTR pszMessage
);

void
SetStatusMessage(
LPWSTR pszMessage
);

void
EnableButton(
int ID
);
void
DisableButton(
int ID
);


///////////////////////////////////////////////////////////////////
// CallEventNotification
//
// The only method in the ITCallEventNotification interface. This gets
// called by TAPI 3.0 when there is a call event to report
//
///////////////////////////////////////////////////////////////////
HRESULT
STDMETHODCALLTYPE
CCallNotification::CallEventNotification(
ITAddress * pAddress,
CALL_EVENT_TYPE EventType,
IDispatch * pEvent
)
{
HRESULT hr;

// EventType can be CET_CALLMONITOR, CET_CALLOWNER, or CET_CALLSTATEEVENT
switch ( EventType )
{
case CET_CALLMONITOR:
{
// CET_CALLMONITOR means that the application is being notified
// of a new call, and the application has monitor privileges on
// that call. pEvent is the Call object.

// We should not get any CET_CALLMONTOR notifications in
// this application, since we only registered for owner
// in RegisterCallTypes

break;
}

case CET_CALLOWNER:
{
// CET_CALLOWNER means that the application is being notified
// of a call, and the applications has owner privileges on
// that call. pEvent is the Call object.
//
// Note that we don't answer to call at this point. The application
// should wait for a CS_OFFERING CallState message before answering
// the call.

// pEvent should be the call. Get the ITBasicCallControl interface
hr = pEvent->QueryInterface( IID_ITBasicCallControl, (void **)&gpCall );

if (S_OK != hr)
{
DoMessage( L"Incoming call, but failed to get the interface");
gpCall->Release();
}
else
{
EnableButton( IDC_ANSWER );
DisableButton( IDC_DISCONNECT );
SetStatusMessage(L"Incoming Owner Call");
}

break;
}

case CET_CALLSTATEEVENT:
{
// CET_CALLSTATEEVENT is a call state event. pEvent is
// an ITCallStateEvent object

CALL_STATE cs;
ITCallStateEvent * pCallStateEvent;

// Get the interface
pEvent->QueryInterface( IID_ITCallStateEvent, (void **)&pCallStateEvent );

// get the CallState that we are being notified of.
pCallStateEvent->get_State( &cs );

// if it's offering, update our UI
if (CS_OFFERING == cs)
{
SetStatusMessage(L"Click the Answer button");
}
else if (CS_DISCONNECTED == cs)
{
PostMessage(ghDlg, WM_COMMAND, IDC_DISCONNECTED, 0);
}

// Release the interface
pCallStateEvent->Release();

break;
}
}


return S_OK;
}