home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / kvfon2.exe / PHONEDLG.H < prev    next >
C/C++ Source or Header  |  1994-11-16  |  16KB  |  528 lines

  1. /****************************************************************************
  2. **    File:    PHONEDLG.H
  3. **
  4. **    Desc:    Include files for the dialpad program.
  5. **
  6. **    This file is an include file for the dialpad program.  It contains the
  7. **    dialog source code for the dial pad, along with all of its functionality.
  8. **
  9. **    It is written for OWL 2.0 with Borland C++ 4.x.  To compile this program,
  10. **    create a project in BC4.x, similar to the .IDE project file included.
  11. **
  12. **        DISCLAIMER
  13. **
  14. **    Novell, Inc. makes no representations or warranties with respect to
  15. **    any NetWare software, and specifically disclaims any express or
  16. **    implied warranties of merchantability, title, or fitness for a
  17. **    particular purpose.
  18. **
  19. **    You may use this sample code in your own programs.
  20. **
  21. **    Distribution of any NetWare software is forbidden without the
  22. **    express written consent of Novell, Inc.  Further, Novell reserves
  23. **    the right to discontinue distribution of any NetWare software.
  24. **
  25. **    Novell is not responsible for lost profits or revenue, loss of use
  26. **    of the software, loss of data, costs of re-creating lost data, the
  27. **    cost of any substitute equipment or program, or claims by any party
  28. **    other than you.  Novell strongly recommends a backup be made before
  29. **    any software is installed.   Technical support for this software
  30. **    may be provided at the discretion of Novell.
  31. **
  32. **    Programmers:
  33. **
  34. **        Ini    Who                        Firm
  35. **        -----------------------------------------------------------------------
  36. **        KVW    Kevin V White        Novell Developer Support.
  37. **
  38. **    History:
  39. **
  40. **        When        Who    What
  41. **        -----------------------------------------------------------------------
  42. **        11-2        KVW    First code release
  43. **        11-16        KVW     Added conference, transfer, hold, hangup connection
  44. */
  45.  
  46. /****************************************************************************
  47. **    This is the dial pad dialog's class.
  48. */
  49. class TPhoneDlg:public TDialog
  50. {
  51.     public:
  52.         char numToDial[30];
  53.         short entryIndex;
  54.         DeviceID_t callerExt;
  55.         ACSHandle_t globalACSHandle;
  56.         CSTAEvent_t eventBuffer;
  57.         unsigned short eventBufferSize;
  58.         unsigned short numEvents;
  59.         DeviceID_t callee;
  60.         ConnectionID_t callID;
  61.         RetCode_t    rCode;
  62.         InvokeID_t    invokeID;
  63.  
  64.         TEdit *numberEntryWindow;
  65.  
  66.         TPhoneDlg(TWindow *parent,TResId resId,ACSHandle_t *acsHandle,
  67.             DeviceID_t *userExt);
  68.         void SetupWindow();
  69.         void CleanupWindow();
  70.         void CmDial1();
  71.         void CmDial2();
  72.         void CmDial3();
  73.         void CmDial4();
  74.         void CmDial5();
  75.         void CmDial6();
  76.         void CmDial7();
  77.         void CmDial8();
  78.         void CmDial9();
  79.         void CmDial0();
  80.         void CmDialNumber();
  81.         void CmHangupCall();
  82.         void CmHangupConn();
  83.         void CmHold();
  84.         void CmUnhold();
  85.         void CmHelp();
  86.         void CmClearEntry();
  87.         void CmConference();
  88.         void CmTransfer();
  89.  
  90.     DECLARE_RESPONSE_TABLE(TPhoneDlg);
  91. };
  92.  
  93. /****************************************************************************
  94. **    this is how OWL adds message handling to the windows message loop
  95. */
  96. DEFINE_RESPONSE_TABLE1(TPhoneDlg,TDialog)
  97.     EV_COMMAND(IDC_1,CmDial1),
  98.     EV_COMMAND(IDC_2,CmDial2),
  99.     EV_COMMAND(IDC_3,CmDial3),
  100.     EV_COMMAND(IDC_4,CmDial4),
  101.     EV_COMMAND(IDC_5,CmDial5),
  102.     EV_COMMAND(IDC_6,CmDial6),
  103.     EV_COMMAND(IDC_7,CmDial7),
  104.     EV_COMMAND(IDC_8,CmDial8),
  105.     EV_COMMAND(IDC_9,CmDial9),
  106.     EV_COMMAND(IDC_10,CmDial0),
  107.     EV_COMMAND(IDC_DIAL,CmDialNumber),
  108.     EV_COMMAND(IDC_HANGUPCALL,CmHangupCall),
  109.     EV_COMMAND(IDC_HANGUPCONN,CmHangupConn),
  110.     EV_COMMAND(IDC_HOLD,CmHold),
  111.     EV_COMMAND(IDC_UNHOLD,CmUnhold),
  112.     EV_COMMAND(IDC_HELP,CmHelp),
  113.     EV_COMMAND(IDC_CLEARENTRY,CmClearEntry),
  114.     EV_COMMAND(IDC_CONFERENCE,CmConference),
  115.     EV_COMMAND(IDC_TRANSFER,CmTransfer),
  116. END_RESPONSE_TABLE;
  117.  
  118. /****************************************************************************
  119. **    constructor for the dial pad dialog
  120. */
  121. TPhoneDlg::TPhoneDlg(TWindow *parent,TResId resId,ACSHandle_t *acsHandle,
  122.     DeviceID_t *userExt)
  123.     :TDialog(parent,resId),TWindow(parent)
  124. {
  125.     /*------------------------------------------------------------------------
  126.     **    callerExt is the user's extension
  127.     ** numToDial is a string built from the number the user dials
  128.     **    entryIndex is the position in the array for the next digit dialed
  129.     ** globalACSHandle is the acshandle we receive in the constructor
  130.     */
  131.     strcpy(callerExt,*userExt);
  132.     numToDial[0]=0;
  133.     entryIndex=0;
  134.     strcpy(callerExt,*userExt);
  135.     globalACSHandle=*acsHandle;
  136.     eventBufferSize=sizeof(CSTAEvent_t);
  137. }
  138.  
  139. /****************************************************************************
  140. ** SetupWindow is called when the dialog window is created
  141. */
  142. void TPhoneDlg::SetupWindow()
  143. {
  144.     /*------------------------------------------------------------------------
  145.     ** first, call the parent's SetupWindow
  146.     */
  147.     TDialog::SetupWindow();
  148.  
  149.     /*------------------------------------------------------------------------
  150.     ** create an alias to the text box in the dialog, as the alias will be
  151.     ** easier to enter text into and retrieve text from than the dialog
  152.     */
  153.     numberEntryWindow=new TEdit(this,IDC_NUMDISPLAY,30);
  154.     numberEntryWindow->Create();
  155. }
  156.  
  157. /****************************************************************************
  158. **    CleanupWindow is called when the window is destroyed.  We just use it to
  159. ** free the memory allocated to our TEdit alias in SetupWindow, then call
  160. **    the parent's CleanupWindow
  161. */
  162. void TPhoneDlg::CleanupWindow()
  163. {
  164.     delete numberEntryWindow;
  165.  
  166.     TDialog::CleanupWindow();
  167. }
  168.  
  169. /****************************************************************************
  170. **    these functinos are used when the user presses one of the buttons corres-
  171. **    ponding to the digits on the phone dial pad.  In each one, we want to store
  172. **    the digit the user enters, increment the index into the character array,
  173. **    and then redisplay the string in the text window.
  174. */
  175.  
  176. void TPhoneDlg::CmDial1()
  177. {
  178.     if(entryIndex<28)
  179.     {
  180.         numToDial[entryIndex++]='1';
  181.         numToDial[entryIndex]=0;
  182.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  183.     }
  184. }
  185.  
  186. void TPhoneDlg::CmDial2()
  187. {
  188.     if(entryIndex<28)
  189.     {
  190.         numToDial[entryIndex++]='2';
  191.         numToDial[entryIndex]=0;
  192.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  193.     }
  194. }
  195.  
  196. void TPhoneDlg::CmDial3()
  197. {
  198.     if(entryIndex<28)
  199.     {
  200.         numToDial[entryIndex++]='3';
  201.         numToDial[entryIndex]=0;
  202.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  203.     }
  204. }
  205.  
  206. void TPhoneDlg::CmDial4()
  207. {
  208.     if(entryIndex<28)
  209.     {
  210.         numToDial[entryIndex++]='4';
  211.         numToDial[entryIndex]=0;
  212.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  213.     }
  214. }
  215.  
  216. void TPhoneDlg::CmDial5()
  217. {
  218.     if(entryIndex<28)
  219.     {
  220.         numToDial[entryIndex++]='5';
  221.         numToDial[entryIndex]=0;
  222.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  223.     }
  224. }
  225.  
  226. void TPhoneDlg::CmDial6()
  227. {
  228.     if(entryIndex<28)
  229.     {
  230.         numToDial[entryIndex++]='6';
  231.         numToDial[entryIndex]=0;
  232.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  233.     }
  234. }
  235.  
  236. void TPhoneDlg::CmDial7()
  237. {
  238.     if(entryIndex<28)
  239.     {
  240.         numToDial[entryIndex++]='7';
  241.         numToDial[entryIndex]=0;
  242.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  243.     }
  244. }
  245.  
  246. void TPhoneDlg::CmDial8()
  247. {
  248.     if(entryIndex<28)
  249.     {
  250.         numToDial[entryIndex++]='8';
  251.         numToDial[entryIndex]=0;
  252.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  253.     }
  254. }
  255.  
  256. void TPhoneDlg::CmDial9()
  257. {
  258.     if(entryIndex<28)
  259.     {
  260.         numToDial[entryIndex++]='9';
  261.         numToDial[entryIndex]=0;
  262.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  263.     }
  264. }
  265.  
  266. void TPhoneDlg::CmDial0()
  267. {
  268.     if(entryIndex<28)
  269.     {
  270.         numToDial[entryIndex++]='0';
  271.         numToDial[entryIndex]=0;
  272.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  273.     }
  274. }
  275.  
  276. /****************************************************************************
  277. **    Here we dial the number the user has entered.
  278. */
  279. void TPhoneDlg::CmDialNumber()
  280. {
  281.     BOOL done=FALSE;
  282.  
  283.     /*------------------------------------------------------------------------
  284.     **    has the user actually pressed the digits to make a number to dial?
  285.     */
  286.     if(numToDial[0]!=0)
  287.     {
  288.         /*---------------------------------------------------------------------
  289.         **    get the number dialed, and make the call.
  290.         */
  291.         strcpy(callee,numToDial);
  292.         rCode=cstaMakeCall(globalACSHandle,invokeID,&callerExt,&callee,NULL);
  293.         /*---------------------------------------------------------------------
  294.         **    if MakeCall was successful, it will return the invokeID (above 0)
  295.         */
  296.         if(rCode>0)
  297.         {
  298.             /*------------------------------------------------------------------
  299.             **    We enter a poll loop, waiting for our event to confirm the makecall
  300.             */
  301.             while(!done)
  302.             {
  303.                 /*---------------------------------------------------------------
  304.                 **    first, very important, set the event buffer size to pass to
  305.                 ** getEventPoll.  If we don't reset it each time, it may be too
  306.                 ** small to get our event, and we will never get our make call
  307.                 ** confirmation event
  308.                 */
  309.                 eventBufferSize=sizeof(CSTAEvent_t);
  310.                 /*---------------------------------------------------------------
  311.                 **    get the event, and check its type
  312.                 */
  313.                 rCode=acsGetEventPoll(globalACSHandle,&eventBuffer,&eventBufferSize,
  314.                     NULL,&numEvents);
  315.                 if(rCode==ACSPOSITIVE_ACK)
  316.                 {
  317.                     if(eventBuffer.eventHeader.eventType==CSTA_MAKE_CALL_CONF)
  318.                     {
  319.                         /*---------------------------------------------------------
  320.                         **    if it's the right event type, the callID is stored in
  321.                         ** the confirmation event structure, which we will need to
  322.                         ** store so that the user can hangup on the call later.  Then,
  323.                         **    we'll enable the appropriate buttons.
  324.                         */
  325.                         callID=eventBuffer.event.cstaConfirmation.u.makeCall.newCall;
  326.                         ::EnableWindow(GetDlgItem(IDC_HANGUPCALL),1);
  327.                         ::EnableWindow(GetDlgItem(IDC_HANGUPCONN),1);
  328.                         ::EnableWindow(GetDlgItem(IDC_CONFERENCE),1);
  329.                         ::EnableWindow(GetDlgItem(IDC_TRANSFER),1);
  330.                         ::EnableWindow(GetDlgItem(IDC_HOLD),1);
  331.                         done=TRUE;
  332.                     }
  333.                 }
  334.                 else if(rCode==ACSERR_NOMESSAGE)
  335.                 {
  336.                     done=FALSE;
  337.                 }
  338.                 else
  339.                 {
  340.                     /*------------------------------------------------------------
  341.                     ** we can't get the event that the call was made successfully,
  342.                     **    so disable the appropriate buttons.
  343.                     */
  344.                     ::EnableWindow(GetDlgItem(IDC_HANGUPCONN),0);
  345.                     ::EnableWindow(GetDlgItem(IDC_CONFERENCE),0);
  346.                     ::EnableWindow(GetDlgItem(IDC_HANGUPCALL),0);
  347.                     ::EnableWindow(GetDlgItem(IDC_TRANSFER),0);
  348.                     ::EnableWindow(GetDlgItem(IDC_HOLD),0);
  349.                     done=TRUE;
  350.                 }
  351.             }
  352.         }
  353.         else
  354.         {
  355.             MessageBox("Unable to make call","TS Error!");
  356.         }
  357.     }
  358.  
  359. }
  360.  
  361. /****************************************************************************
  362. **    the user wants to hangup on a call.  Note that this will only work on a
  363. **    call that the user created, as we have to have a valid callID.  If that
  364. ** call was already cleared, well, we won't know about it, and will try to
  365. ** hang up on it anyway.  That won't gpf or anything, but it would be a nice
  366. ** enhancement to monitor the device, and clear the hangup button if the call
  367. ** happens to be cleared by the user, and not through this program.
  368. */
  369. void TPhoneDlg::CmHangupCall()
  370. {
  371.     /*------------------------------------------------------------------------
  372.     **    try to hangup on the call. we don't bother confirming that it worked,
  373.     ** as we don't really care.  We get an event, but don't check it's type.
  374.     **    As we're only getting solicited events, this should be fine.  One way
  375.     **    or the other, we're going to disable appropriate buttons afterwards.
  376.     */
  377.     rCode=cstaClearCall(globalACSHandle,invokeID,&callID,NULL);
  378.     if(rCode>0)
  379.     {
  380.         ::EnableWindow(GetDlgItem(IDC_HANGUPCALL),0);
  381.         ::EnableWindow(GetDlgItem(IDC_HANGUPCONN),0);
  382.         ::EnableWindow(GetDlgItem(IDC_CONFERENCE),0);
  383.         ::EnableWindow(GetDlgItem(IDC_HOLD),0);
  384.         ::EnableWindow(GetDlgItem(IDC_UNHOLD),0);
  385.         ::EnableWindow(GetDlgItem(IDC_TRANSFER),0);
  386.     }
  387.     eventBufferSize=sizeof(CSTAEvent_t);
  388.     rCode=acsGetEventBlock(globalACSHandle,&eventBuffer,&eventBufferSize,
  389.         NULL,&numEvents);
  390. }
  391.  
  392. void TPhoneDlg::CmHangupConn()
  393. {
  394.     /*------------------------------------------------------------------------
  395.     **    try to hangup the connection. we don't bother confirming that it worked,
  396.     ** as we don't really care.  We get an event, but don't check it's type.
  397.     **    As we're only getting solicited events, this should be fine.  One way
  398.     **    or the other, we're going to disable appropriate buttons afterwards.
  399.     */
  400.     rCode=cstaClearConnection(globalACSHandle,invokeID,&callID,NULL);
  401.     if(rCode>0)
  402.     {
  403.         ::EnableWindow(GetDlgItem(IDC_HANGUPCALL),0);
  404.         ::EnableWindow(GetDlgItem(IDC_HANGUPCONN),0);
  405.         ::EnableWindow(GetDlgItem(IDC_CONFERENCE),0);
  406.         ::EnableWindow(GetDlgItem(IDC_HOLD),0);
  407.         ::EnableWindow(GetDlgItem(IDC_UNHOLD),0);
  408.         ::EnableWindow(GetDlgItem(IDC_TRANSFER),0);
  409.     }
  410.     eventBufferSize=sizeof(CSTAEvent_t);
  411.     rCode=acsGetEventBlock(globalACSHandle,&eventBuffer,&eventBufferSize,
  412.         NULL,&numEvents);
  413. }
  414.  
  415. /*************************************************************************
  416. **    The user wants to put the call on hold
  417. */
  418. void TPhoneDlg::CmHold()
  419. {
  420.     /*---------------------------------------------------------------------
  421.     **    put the call on hold
  422.     */
  423.     rCode=cstaHoldCall(globalACSHandle,invokeID,&callID,FALSE,NULL);
  424.     if(rCode<=0)
  425.     {
  426.         return;
  427.     }
  428.     /*---------------------------------------------------------------------
  429.     **    get an event
  430.     */
  431.     eventBufferSize=sizeof(CSTAEvent_t);
  432.     rCode=acsGetEventBlock(globalACSHandle,&eventBuffer,&eventBufferSize,NULL,
  433.         &numEvents);
  434.     if(rCode==ACSPOSITIVE_ACK)
  435.     {
  436.         /*------------------------------------------------------------------
  437.         **    set or disable appropriate buttons
  438.         */
  439.         ::EnableWindow(GetDlgItem(IDC_UNHOLD),1);
  440.         ::EnableWindow(GetDlgItem(IDC_HOLD),0);
  441.         ::EnableWindow(GetDlgItem(IDC_CONFERENCE),0);
  442.         ::EnableWindow(GetDlgItem(IDC_TRANSFER),0);
  443.     }
  444.     return;
  445. }
  446.  
  447. /*************************************************************************
  448. **    pick the call up from on hold
  449. */
  450. void TPhoneDlg::CmUnhold()
  451. {
  452.     /*---------------------------------------------------------------------
  453.     **    pick up the call
  454.     */
  455.     rCode=cstaRetrieveCall(globalACSHandle,invokeID,&callID,NULL);
  456.     if(rCode<=0)
  457.     {
  458.         return;
  459.     }
  460.     /*---------------------------------------------------------------------
  461.     **    get an event
  462.     */
  463.     eventBufferSize=sizeof(CSTAEvent_t);
  464.     rCode=acsGetEventBlock(globalACSHandle,&eventBuffer,&eventBufferSize,NULL,
  465.         &numEvents);
  466.     if(rCode==ACSPOSITIVE_ACK)
  467.     {
  468.         /*------------------------------------------------------------------
  469.         **    enable and disable appropriate buttons
  470.         */
  471.         ::EnableWindow(GetDlgItem(IDC_HOLD),1);
  472.         ::EnableWindow(GetDlgItem(IDC_UNHOLD),0);
  473.         ::EnableWindow(GetDlgItem(IDC_TRANSFER),1);
  474.         ::EnableWindow(GetDlgItem(IDC_CONFERENCE),1);
  475.     }
  476.     return;
  477. }
  478.  
  479. /****************************************************************************
  480. **    the user presed help.  Display help as a simple dialog with text.  If this
  481. **    were a more complex program, it would be nice to have a normal windows
  482. ** help file to use.
  483. */
  484. void TPhoneDlg::CmHelp()
  485. {
  486.     MessageBox(
  487.     "KVPhone is used as a dialpad for your phone with "
  488.     "NetWare Telephony Services.\n\n"
  489.     "Use the mouse to dial a number, then select Dial. \n\n"
  490.     "When on a phone conversation that you have created, you may press:\n"
  491.     "-Hangup Call to clear the call\n "
  492.     "-Hangup Conn to clear just your connectiona\n"
  493.     "-Conference to conference in another extension\n"
  494.     "-Transfer to transfer to another extionsion\n"
  495.     "-Hold to put the call on hold\n"
  496.     "-UnHold picks a call up from on hold\n"
  497.     "-Clear to clear the number display box to enter a new number."
  498.     ,"KVPhone Help");
  499. }
  500.  
  501. /****************************************************************************
  502. **    this is called to clear the number and start entering a new number to dial
  503. */
  504. void TPhoneDlg::CmClearEntry()
  505. {
  506.     numToDial[0]=0;
  507.     entryIndex=0;
  508.     SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  509. }
  510.  
  511. /*************************************************************************
  512. **    call the conference dialog to conference the call
  513. */
  514. void TPhoneDlg::CmConference()
  515. {
  516.     TConfDlg *confDlg=new TConfDlg(this,5,&globalACSHandle,&callerExt,&callID);
  517.     confDlg->Execute();
  518. }
  519.  
  520. /*************************************************************************
  521. **    call the transfer dialog to transfer the call to another extionsion
  522. */
  523. void TPhoneDlg::CmTransfer()
  524. {
  525.     TXferDlg *xferDlg=new TXferDlg(this,1,&globalACSHandle,&callerExt,&callID);
  526.     xferDlg->Execute();
  527. }
  528.