home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / platsdk / inetwork.exe / TAPI-S.cab / 96callnot.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  4.6 KB  |  125 lines

  1. /************************************************************************
  2.  * CallNot (by John W. Gibbs)
  3.  *
  4.  * Copyright (c) 1997 Microsoft Corporation, All Rights Reserved.
  5.  ***********************************************************************/
  6.  
  7. import java.awt.Event;
  8. import com.ms.com.*;
  9. import tapi3.*;
  10.  
  11.  
  12. /////////////////////////////////////////////////////////////////////////
  13. //  CLASS: CallNot
  14. //
  15. //  PURPOSE: Supporting class to JT3Rec
  16. //  DATE:    July 17, 1997
  17. //
  18. //  DESCRIPTION:
  19. //      Implements the ITCallNotification interface which is called
  20. //      by TAPI 3.0 when incoming calls arrive.
  21. //
  22. /////////////////////////////////////////////////////////////////////////
  23.  
  24. class CallNot extends Object
  25.     implements ITCallNotification,  // notification interface
  26.                CALL_EVENT_TYPE,     // CET_xxx constants
  27.                CALL_STATE           // CS_xxx constants
  28. {
  29.     // Reference to main program object.
  30.     private JT3Rec m_App = null;
  31.  
  32.     
  33.     /////////////////////////////////////////////////////////////////////
  34.     // Constructor
  35.     /////////////////////////////////////////////////////////////////////
  36.     public CallNot(JT3Rec app)
  37.     {
  38.         m_App = app;
  39.     }
  40.  
  41.     /////////////////////////////////////////////////////////////////////
  42.     // CallEventNotification
  43.     //
  44.     // The only method in the ITCallNotification interface.  This gets
  45.     // called by TAPI 3.0 when there is a call event to report.
  46.     //
  47.     // It is important that you use the /X:m- switch when importing the
  48.     // TAPI 3.0 typelib to Java using JActiveX.  This will turn off
  49.     // auto-marshalling of variables passed from CallNot to JT3Rec.  If
  50.     // you do not, the program will freeze whenever JT3Rec tries to use
  51.     // a variable given to it by CallNot.
  52.     /////////////////////////////////////////////////////////////////////
  53.     public void CallEventNotification(
  54.                                      ITAddress address,
  55.                                      int eventType,
  56.                                      Object event
  57.                                      )
  58.     {
  59.         // eventType can be CET_CALLMONITOR, CET_CALLOWNER, or
  60.         // CET_CALLSTATEEVENT
  61.         
  62.         switch (eventType)
  63.         {
  64.         case CET_CALLMONITOR:
  65.  
  66.             // CET_CALLMONITOR means that the application is being
  67.             // notified of a new call, and the application has monitor
  68.             // priveleges on that call.  event is the Call object.
  69.             //
  70.             // We should not get any CET_CALLMONITOR notifications in
  71.             // this application, since we only registered for owner in
  72.             // RegisterCallTypes.
  73.  
  74.             break;
  75.             
  76.         case CET_CALLOWNER:
  77.  
  78.             // CET_CALLOWNER means that the application is being notified
  79.             // of a call, and the application has owner privileges on
  80.             // that call.  event is the Call object.
  81.             //
  82.             // Note that we don't answer the call at this point.  The
  83.             // application should wait for a CS_OFFERING CallState
  84.             // message before answering the call.
  85.  
  86.             try {
  87.                 m_App.m_Call = (ITBasicCallControl) event;
  88.                 m_App.SetStatusMessage("Incoming owner call");
  89.             }
  90.             catch (ComException e) {
  91.                 e.printStackTrace();
  92.                 m_App.SetStatusMessage("Incoming call, but failed to get the interface");
  93.             }
  94.             break;
  95.             
  96.         case CET_CALLSTATEEVENT:
  97.  
  98.             // CET_CALLSTATEEVENT is a call state event.  event is an
  99.             // ITCallStateEvent object.
  100.  
  101.             ITCallStateEvent callStateEvent = (ITCallStateEvent) event;
  102.  
  103.             switch (callStateEvent.getState())
  104.             {
  105.             case CS_DISCONNECTED:
  106.                 if (m_App.m_Call != null) {
  107.                     Event evt = new Event(
  108.                                          m_App.ctrls.btnHangup,
  109.                                          Event.ACTION_EVENT,
  110.                                          "Hangup"
  111.                                          );
  112.                     m_App.action(evt, "Hangup");
  113.                 }
  114.                 break;
  115.  
  116.             case CS_OFFERING: // this tells us it's okay to answer
  117.                 m_App.ctrls.btnStop.disable();
  118.                 m_App.ctrls.btnAnswer.enable();
  119.                 m_App.ctrls.btnReject.enable();
  120.                 m_App.SetStatusMessage("Click the Answer or Reject button");
  121.                 break;
  122.             }
  123.         }
  124.     }
  125. }