home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_06 / 1006047a < prev    next >
Text File  |  1991-11-07  |  1KB  |  58 lines

  1. LISTING TWO
  2.  
  3. #include    "channel.hpp"
  4.  
  5. // initialize the channel
  6. void CHANNEL::prep(int line)
  7. {
  8.     lineno = line;
  9.  
  10.     // enable events for this line: change in loop
  11.     // current, ring detected, off-hook or on-hook
  12.     // completed.  Answer after 1 ring.
  13.     setcst(lineno, C_LC | C_RING | C_OFFH | C_ONH, 1);
  14.  
  15.     // initial state is wait for ring
  16.     begin_func = &CHANNEL::wait_for_ring;      
  17.     end_func   = &CHANNEL::wait_complete;    
  18.  
  19.     begin_state();
  20. }
  21.  
  22. // play the message back to the user
  23. int CHANNEL::play()
  24. {
  25.     printf("Playing %s on %d\n", msgname, lineno);
  26.     clrrwb(&rwb);    // clear the read/write block
  27.  
  28.     char fname[13];
  29.     sprintf(fname, "%s%s", msgname, SPEECH_EXT);
  30.  
  31.     // open the handle to be played back, should 
  32.     // check against -1 return in production code
  33.     rwb.filehndl = open(fname, O_RDONLY | O_BINARY);
  34.  
  35.     // instruct card to cause event if keypad is 
  36.     // pressed or loop signal detected
  37.     rwb.maxdtmf  = 1;
  38.     rwb.loopsig  = 1;
  39.  
  40.     return(xplayf(lineno, PM_NORM, &rwb));
  41. }
  42.  
  43. // execute the state begin function
  44. int CHANNEL::begin_state()
  45. {
  46.     INTPROC fp = this->begin_func;
  47.     return (this->*fp)();
  48. }
  49.  
  50. // execute the state end function
  51. void CHANNEL::cmplt_state(int evtcode)
  52. {
  53.     VOIDPROC fp = this->end_func;
  54.     (this->*fp)(evtcode);
  55. }
  56.  
  57.  
  58.