home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / platsdk / inetwork.exe / TAPI-S.cab / 63CALLNOT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-10  |  4.2 KB  |  143 lines

  1. //////////////////////////////////////////////////////////////////////
  2. // callnot.cpp
  3. //
  4. // Implementation of the ITCallNotification interface.
  5. //
  6. // This is an outgoing interface that is defined by TAPI 3.0.  This
  7. // is basically a callback function that TAPI 3.0 calls to inform
  8. // the application of events related to calls (on a specific address)
  9. //
  10. // Please refer to COM documentation for information on outgoing
  11. // interfaces.
  12. // 
  13. // An application must implement and register this interface in order
  14. // to receive calls and events related to calls
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17.  
  18.  
  19. #include "windows.h"
  20. #include "tapi3.h"
  21. #include "callnot.h"
  22. #include "resource.h"
  23.  
  24. extern ITBasicCallControl * gpCall;
  25. extern HWND ghDlg;
  26.  
  27. void
  28. DoMessage(
  29.           LPWSTR pszMessage
  30.          );
  31.  
  32. void
  33. SetStatusMessage(
  34.                  LPWSTR pszMessage
  35.                 );
  36.  
  37. void
  38. EnableButton(
  39.              int ID
  40.             );
  41. void
  42. DisableButton(
  43.               int ID
  44.              );
  45.  
  46.  
  47. ///////////////////////////////////////////////////////////////////
  48. // CallEventNotification
  49. //
  50. // The only method in the ITCallEventNotification interface.  This gets
  51. // called by TAPI 3.0 when there is a call event to report
  52. //
  53. ///////////////////////////////////////////////////////////////////
  54. HRESULT
  55. STDMETHODCALLTYPE
  56. CCallNotification::CallEventNotification(
  57.                                          ITAddress * pAddress,
  58.                                          CALL_EVENT_TYPE EventType,
  59.                                          IDispatch * pEvent
  60.                                         )
  61. {
  62.     HRESULT hr;
  63.  
  64.     // EventType can be CET_CALLMONITOR, CET_CALLOWNER, or CET_CALLSTATEEVENT
  65.     switch ( EventType )
  66.     {
  67.         case CET_CALLMONITOR:
  68.         {
  69.             // CET_CALLMONITOR means that the application is being notified
  70.             // of a new call, and the application has monitor privileges on
  71.             // that call.  pEvent is the Call object.
  72.  
  73.             // We should not get any CET_CALLMONTOR notifications in
  74.             // this application, since we only registered for owner
  75.             // in RegisterCallTypes
  76.  
  77.             break;
  78.         }
  79.         
  80.         case CET_CALLOWNER:
  81.         {
  82.             // CET_CALLOWNER means that the application is being notified
  83.             // of a call, and the applications has owner privileges on
  84.             // that call.  pEvent is the Call object.
  85.             //
  86.             // Note that we don't answer to call at this point.  The application
  87.             // should wait for a CS_OFFERING CallState message before answering
  88.             // the call.
  89.  
  90.             // pEvent should be the call.  Get the ITBasicCallControl interface
  91.             hr = pEvent->QueryInterface( IID_ITBasicCallControl, (void **)&gpCall );
  92.  
  93.             if (S_OK != hr)
  94.             {
  95.                 DoMessage( L"Incoming call, but failed to get the interface");
  96.                 gpCall->Release();
  97.             }
  98.             else
  99.             {
  100.                 EnableButton( IDC_ANSWER );
  101.                 DisableButton( IDC_DISCONNECT );
  102.                 SetStatusMessage(L"Incoming Owner Call");
  103.             }
  104.             
  105.             break;
  106.         }
  107.         
  108.         case CET_CALLSTATEEVENT:
  109.         {
  110.             // CET_CALLSTATEEVENT is a call state event.  pEvent is
  111.             // an ITCallStateEvent object
  112.  
  113.             CALL_STATE       cs;
  114.             ITCallStateEvent * pCallStateEvent;
  115.  
  116.             // Get the interface
  117.             pEvent->QueryInterface( IID_ITCallStateEvent, (void **)&pCallStateEvent );
  118.  
  119.             // get the CallState that we are being notified of.
  120.             pCallStateEvent->get_State( &cs );
  121.  
  122.             // if it's offering, update our UI
  123.             if (CS_OFFERING == cs)
  124.             {
  125.                 SetStatusMessage(L"Click the Answer button");
  126.             }
  127.             else if (CS_DISCONNECTED == cs)
  128.             {
  129.                 PostMessage(ghDlg, WM_COMMAND, IDC_DISCONNECTED, 0);
  130.             }
  131.  
  132.             // Release the interface
  133.             pCallStateEvent->Release();
  134.  
  135.             break;
  136.         }
  137.     }
  138.  
  139.     
  140.     return S_OK;
  141. }
  142.  
  143.