home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / confcl.exe / CONFCALL.C next >
C/C++ Source or Header  |  1994-08-17  |  10KB  |  359 lines

  1. /****************************************************************************
  2. **    File:    CONFCALL.C
  3. **
  4. **    Desc:    Sample telephony program
  5. **
  6. **        This NetWare Telephony Services program opens a stream,
  7. **        makes a call, conferences in with another extension, and
  8. **        closes the stream.
  9. **
  10. **        This program is written for Borland C 4.0 for Windows 3.1. It
  11. **        is compiled as an EASYWIN program, so that I didn't have to
  12. **        include all the Windows "overhead" code but can just get to
  13. **        the good stuff.
  14. **
  15. **
  16. **        DISCLAIMER
  17. **
  18. **    Novell, Inc. makes no representations or warranties with respect to
  19. **    any NetWare software, and specifically disclaims any express or
  20. **    implied warranties of merchantability, title, or fitness for a
  21. **    particular purpose.
  22. **
  23. **    Distribution of any NetWare software is forbidden without the
  24. **    express written consent of Novell, Inc.  Further, Novell reserves
  25. **    the right to discontinue distribution of any NetWare software.
  26. **
  27. **    Novell is not responsible for lost profits or revenue, loss of use
  28. **    of the software, loss of data, costs of re-creating lost data, the
  29. **    cost of any substitute equipment or program, or claims by any party
  30. **    other than you.  Novell strongly recommends a backup be made before
  31. **    any software is installed.   Technical support for this software
  32. **    may be provided at the discretion of Novell.
  33. **
  34. **    Programmers:
  35. **
  36. **        Ini    Who                        Firm
  37. **        -----------------------------------------------------------------------
  38. **        KVW    Kevin V White                Novell Developer Support.
  39. **
  40. **    History:
  41. **
  42. **        When        Who    What
  43. **        -----------------------------------------------------------------------
  44. **        08-17-94    kvw    First code.
  45. */
  46.  
  47. /****************************************************************************
  48. **    Include headers, macros, function prototypes, etc.
  49. */
  50.  
  51.     /*------------------------------------------------------------------------
  52.     **    ANSI
  53.     */
  54.     #include <stdio.h>
  55.     #include <string.h>
  56.  
  57.     /*------------------------------------------------------------------------
  58.     **    Windows
  59.     */
  60.     #include <windows.h>
  61.  
  62.     /*------------------------------------------------------------------------
  63.     **    Telephony
  64.     */
  65.     #include <acs.h>
  66.     #include <csta.h>
  67.  
  68. /****************************************************************************
  69. **    This function is the entire program, as it is very simple.
  70. **    Prompt user for input, open a stream, make a call, close the stream.
  71. */
  72. void main(void)
  73. {
  74.  
  75.     /*------------------------------------------------------------------
  76.     ** The following are defined for the first call, acsOpenStream
  77.     */
  78.     ACSHandle_t         acsHandle;
  79.     InvokeIDType_t        invokeIDType;
  80.     InvokeID_t        invokeID;
  81.     StreamType_t        streamType;
  82.     ServerID_t        serverID;
  83.     LoginID_t        loginID;
  84.     Passwd_t        passwd;
  85.     AppName_t        applicationName;
  86.     Level_t            acsLevelReq;
  87.     Version_t        apiVer;
  88.     unsigned short        sendQSize;
  89.     unsigned short        sendExtraBufs;
  90.     unsigned short        recvQSize;
  91.     unsigned short        recvExtraBufs;
  92.     PrivateData_t        *privateData;
  93.     RetCode_t        rCode;
  94.  
  95.     /*------------------------------------------------------------------
  96.     ** The following are additional variables necessary for
  97.     ** acsGetEventBlock
  98.     */
  99.     CSTAEvent_t            eventBuffer;
  100.     unsigned short        eventBufferSize;
  101.     unsigned short        numEvents;
  102.  
  103.     /*------------------------------------------------------------------
  104.     ** The following are for the cstaMakeCall
  105.     */
  106.     DeviceID_t            caller,callee,callee2;
  107.     ConnectionID_t        callID;
  108.  
  109.     /*------------------------------------------------------------------
  110.     ** The following are for the second cstaMakeCall
  111.     */
  112.     ConnectionID_t        secondCallID;
  113.  
  114.     /*------------------------------------------------------------------
  115.     ** Miscellaneous variables
  116.     */
  117.     short done=0;
  118.  
  119.  
  120.     /*------------------------------------------------------------------
  121.     ** Setup parameters for call to open stream.  Also, prompt user for
  122.     ** input.
  123.     */
  124.     invokeIDType=LIB_GEN_ID;
  125.     invokeID=0;          /* don't need it, but set to zero anyway */
  126.     streamType=ST_CSTA;     /* want to use csta functions */
  127.  
  128.     strcpy(serverID,"ATT#G3_SWITCH#CSTA#PRV-NMS");
  129.  
  130.     printf("\nEnter your user name:");
  131.     scanf("%s",loginID);
  132.     printf("\nEnter your password:");
  133.     scanf("%s",passwd);
  134.     printf("\nEnter your extension:");
  135.     scanf("%s",caller);
  136.     printf("\nEnter the extension you want to call:");
  137.     scanf("%s",callee);
  138.     printf("\nEnter a third extension, for the conference:");
  139.     scanf("%s",callee2);
  140.  
  141.     strcpy(applicationName,"Simple App");
  142.     acsLevelReq=ACS_LEVEL1;
  143.     strcpy(apiVer,CSTA_API_VERSION);
  144.     sendQSize=0;         /* default size queue*/
  145.     sendExtraBufs=0;     /* use default number */
  146.     recvQSize=0;         /* use default size */
  147.     recvExtraBufs=0;     /* use default number */
  148.     privateData=NULL;     /* no private data */
  149.  
  150.     /*------------------------------------------------------------------
  151.     ** Open the stream with above parameters
  152.     */
  153.     rCode=acsOpenStream(&acsHandle,invokeIDType,invokeID,streamType,
  154.             serverID,loginID,passwd,applicationName,acsLevelReq,
  155.             apiVer,sendQSize,sendExtraBufs,recvQSize,recvExtraBufs,
  156.             privateData);
  157.  
  158.     if (rCode < 0)
  159.     {
  160.         printf("acsOpenStream failure...");
  161.         return;
  162.     }
  163.     else
  164.     {
  165.         printf("acsOpenStream success\n");
  166.         invokeID=rCode;
  167.     }
  168.  
  169.     /*------------------------------------------------------------------
  170.     ** Block until the confirmation has been received that the stream
  171.     ** was successfully opened.  Just because NetWare returned the function
  172.     ** code doesn't mean the stream has been opened yet.
  173.     */
  174.     eventBufferSize=sizeof(CSTAEvent_t);
  175.     rCode=acsGetEventBlock(acsHandle,&eventBuffer,&eventBufferSize,
  176.             privateData,&numEvents);
  177.     if(rCode==ACSPOSITIVE_ACK)
  178.     {
  179.         if(eventBuffer.eventHeader.eventType == ACS_OPEN_STREAM_CONF)
  180.         {
  181.             printf("ACS_OPEN_STREAM_CONF message has been received\n");
  182.         }
  183.         else
  184.         {
  185.             printf("event type is incorrect...");
  186.             return;
  187.         }
  188.     }
  189.     else
  190.     {
  191.         printf("acsGetEventBlock failure...");
  192.         return;
  193.     }
  194.  
  195.     /*------------------------------------------------------------------
  196.     ** Now that the stream has been successfully opened, go ahead and
  197.     ** issue the make call function.
  198.     */
  199.     rCode=cstaMakeCall(acsHandle,invokeID,caller,callee,
  200.     privateData);
  201.  
  202.     /*------------------------------------------------------------------
  203.     ** Now we need to poll for events until a confirmation has been
  204.     ** received that the PBX has been able to make the call.  Note that
  205.     ** if something is invalid, the program will enter an infinite loop,
  206.     ** as this simple program just sits and waits until a confirmation
  207.     ** returns that is successful.
  208.     */
  209.     while (!done)
  210.     {
  211.         rCode=acsGetEventPoll(acsHandle,&eventBuffer,&eventBufferSize,
  212.                 privateData,&numEvents);
  213.  
  214.         if(rCode==ACSPOSITIVE_ACK)
  215.         {
  216.             if(eventBuffer.eventHeader.eventType == CSTA_MAKE_CALL_CONF)
  217.             {
  218.                 printf("CSTA_MAKE_CALL_CONF message has been received\n");
  219.                 callID=eventBuffer.event.cstaConfirmation.u.makeCall.newCall;
  220.                 done=1;
  221.             }
  222.             else
  223.             {
  224.                 printf("event type is incorrect...");
  225.             }
  226.         }
  227.     }
  228.  
  229.     /*------------------------------------------------------------------
  230.     ** Do a cstaHoldCall, which puts the first call on hold, so we can
  231.     ** make the second call.
  232.     */
  233.     printf("press a key when you're ready to put the call on hold...\n");
  234.     getch();
  235.     rCode=cstaHoldCall(acsHandle,invokeID,&callID,FALSE,privateData);
  236.  
  237.     if (rCode<=0)
  238.     {
  239.         printf("cstaHoldCall failed\n");
  240.         return;
  241.     }
  242.  
  243.     /*------------------------------------------------------------------
  244.     ** Now we need to poll for events until a confirmation has been
  245.     ** received that the PBX has been able to put the call on hold.
  246.     */
  247.     done=0;
  248.     while (!done)
  249.     {
  250.         rCode=acsGetEventPoll(acsHandle,&eventBuffer,&eventBufferSize,
  251.                 privateData,&numEvents);
  252.  
  253.         if(rCode==ACSPOSITIVE_ACK)
  254.         {
  255.             if(eventBuffer.eventHeader.eventType == CSTA_HOLD_CALL_CONF)
  256.             {
  257.                 printf("CSTA_HOLD_CALL_CONF message has been received\n");
  258.                 done=1;
  259.             }
  260.             else
  261.             {
  262.                 printf("event type is incorrect...");
  263.             }
  264.         }
  265.     }
  266.  
  267.     /*------------------------------------------------------------------
  268.     ** Now that the first call has been put on hold, we can go ahead and
  269.     ** make the second call.
  270.     */
  271.     printf("press a key when you're ready to make the second call...\n");
  272.     getch();
  273.     rCode=cstaMakeCall(acsHandle,invokeID,caller,callee2,
  274.     privateData);
  275.  
  276.     /*------------------------------------------------------------------
  277.     ** Now we need to poll for events until a confirmation has been
  278.     ** received that the PBX has been able to make the call.
  279.     */
  280.     done=0;
  281.     while (!done)
  282.     {
  283.         rCode=acsGetEventPoll(acsHandle,&eventBuffer,&eventBufferSize,
  284.                 privateData,&numEvents);
  285.  
  286.         if(rCode==ACSPOSITIVE_ACK)
  287.         {
  288.             if(eventBuffer.eventHeader.eventType == CSTA_MAKE_CALL_CONF)
  289.             {
  290.                 printf("CSTA_MAKE_CALL_CONF message has been received\n");
  291.                 secondCallID=eventBuffer.event.cstaConfirmation.u.makeCall.newCall;
  292.                 done=1;
  293.             }
  294.             else
  295.             {
  296.                 printf("event type is incorrect...");
  297.             }
  298.         }
  299.     }
  300.  
  301.     /*------------------------------------------------------------------
  302.     ** Well, now we can conference the two calls together.
  303.     */
  304.     printf("press a key when you're ready to conference the calls...\n");
  305.     getch();
  306.     rCode=cstaConferenceCall(acsHandle,invokeID,&callID,
  307.                         &secondCallID,privateData);
  308.  
  309.     if(rCode<=0)
  310.     {
  311.         printf("cstaConferenceCall() failed\n");
  312.         return;
  313.     }
  314.  
  315.     /*------------------------------------------------------------------
  316.     ** Now we can get the confirmation event to make sure it worked ok.
  317.     */
  318.     done=0;
  319.     while (!done)
  320.     {
  321.         rCode=acsGetEventPoll(acsHandle,&eventBuffer,&eventBufferSize,
  322.                 privateData,&numEvents);
  323.  
  324.         if(rCode==ACSPOSITIVE_ACK)
  325.         {
  326.             if(eventBuffer.eventHeader.eventType == CSTA_CONFERENCE_CALL_CONF)
  327.             {
  328.                 printf("CSTA_CONFERENCE_CALL_CONF message has been received\n");
  329.                 secondCallID=eventBuffer.event.cstaConfirmation.u.makeCall.newCall;
  330.                 done=1;
  331.             }
  332.             else
  333.             {
  334.                 printf("event type is incorrect...");
  335.             }
  336.         }
  337.     }
  338.  
  339.  
  340.     /*------------------------------------------------------------------
  341.     ** All done! Time to close the stream now.
  342.     */
  343.     printf("press a key to close the stream...\n");
  344.     getch();
  345.     rCode=acsCloseStream(acsHandle,invokeID,privateData);
  346.  
  347.     if (rCode < 0)
  348.     {
  349.         printf("acsCloseStream failure...");
  350.         return;
  351.     }
  352.     else
  353.     {
  354.         printf("acsCloseStream success\n");
  355.     }
  356.  
  357.     return;
  358. }
  359.