⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adtapi.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      LineCallState_Proceeding :
        begin
          TapiStatus(False, False, Device, Line_CallState, P1, P2, P3);
        end;

      LineCallState_Ringback :
        begin
          TapiStatus(False, False, Device, Line_CallState, P1, P2, P3);
        end;

      LineCallState_Busy :
        begin
          TapiLogging(ltapiBusy);
          TapiStatus(False, False, Device, Line_CallState, P1, P2, P3);
          HangupCall(False);
        end;

      LineCallState_Idle :
        begin
          TapiStatus(False, False, Device, Line_CallState, P1, P2, P3);
          HangupCall(False);
        end;

      LineCallState_SpecialInfo :
        begin
          TapiStatus(False, False, Device, Line_CallState, P1, P2, P3);
          HangupCall(False);
        end;

      LineCallState_Disconnected :
        begin
          FFailCode := P2;                                             
          TapiStatus(False, False, Device, Line_CallState, P1, P2, P3);
          if P2 = LineDisconnectMode_Busy then
            TapiLogging(ltapiBusy);
          HangupCall(False);
        end;

      LineCallState_Offering :
        begin
          { Update the CallInfo record }
          UpdateCallInfo(Device);

          if not Assigned(FCallInfo) then
            raise ETapiUnexpected.Create(ecTapiUnexpected, True);

          {$IFDEF TapiDebug}
          WriteLn(Dbg, 'Offering MediaModes: ', HexL(FCallInfo^.MediaMode));
          {$ENDIF}

          {Got an incoming call, check line media, exit if not ours}
          if (FCallInfo^.MediaMode and OurMediaModes[FEnableVoice]) = 0 then
            Exit;

          {Note the call handle}
          CallHandle := Device;

          {Start showing status}
          TapiStatus(True, False, Device, Line_CallState, P1, P2, P3);

          {Accept the call}
          WaitForReply(tuLineAccept(CallHandle, nil, 0));
          TapiLogging(ltapiAccept);
        end;

      LineCallState_Accepted :
        begin
          TapiStatus(False, False, Device, Line_CallState, P1, P2, P3);
        end;

      LineCallState_Connected :
        begin
          { Duplicate connect message }
          if Connected then Exit;

          { Update the CallInfo record }
          UpdateCallInfo(Device);

          { Say we're connected }
          Connected := True;

          { We don't need retries anymore }
          if Assigned(DialTimer) then begin
            DialTimer.Free;
            DialTimer := nil;
          end;
          RetryPending := False;

          if FEnableVoice then
            {Start monitoring for DTMF tones if in voice mode}
            MonitorDTMF(CallHandle, LINEDIGITMODE_DTMF)
          else
            {Port was just opened, grab the Cid and pass to comport}
            OpenTapiPort;


          {Show last status}
          TapiStatus(False, True, Device, Line_CallState, P1, P2, P3);

          {Generate the TAPI connect event}
          {TapiConnect;}
          PostMessage(FHandle, apw_TapiEventMessage, etTapiConnect, 0);
          TapiLogging(ltapiConnect);
        end;
        
        LineCallState_OnHold :                                           {!!.06}
          begin                                                          {!!.06}
            TapiStatus(False, False, Device, Line_CallState, P1, P2, P3);{!!.06}
          end;                                                           {!!.06}
      else
        { it's a LINE_CALLSTATE message that we don't handle, pass it along }
        TapiStatus(False, False, Device, Line_CallState, P1, P2, P3);    {!!.04}
    end;
  end;

  procedure TApdCustomTapiDevice.DoLineClose(Device, P1, P2, P3 : LongInt);
  begin
    LineHandle := 0;
    CallHandle := 0;

    {$IFDEF TapiDebug}
    WriteLn(Dbg, 'Line forcibly closed by Tapi');
    {$ENDIF}

    HangupCall(True);
  end;

  procedure TApdCustomTapiDevice.DoLineDevState(Device, P1, P2, P3 : LongInt);
  begin
    case P1 of
      LineDevState_Ringing : begin                                     
          {Show status}                             
          TapiStatus(False, False, Device, Line_LineDevState, P1, P2, P3);
          if (P3 >= FAnsRings) then begin
            {Answer the call}
            WaitForReply(tuLineAnswer(CallHandle, nil, 0));
            TapiLogging(ltapiAnswer);
          end;
        end;

      LineDevState_OutOfService :
        begin
          HangupCall(True);
          {$IFDEF TapiDebug}
          WriteLn(Dbg, 'Selected Line Out of Service');
          {$ENDIF}
        end;

      LineDevState_Disconnected :
        begin
          HangupCall(True);
          {$IFDEF TapiDebug}
          WriteLn(Dbg, 'Line Disconnected');
          {$ENDIF}
        end;

      LineDevState_Maintenance :
        begin
          HangupCall(True);
          {$IFDEF TapiDebug}
          WriteLn(Dbg, 'Line down for maintenance');
          {$ENDIF}
        end;

      else if (P1 = LineDevState_Reinit) then begin
        case P2 of
          { Hard reinit -- must shutdown }
          0 :
            begin
              {$IFDEF TapiDebug}
              WriteLn(Dbg, 'Hard Reinit: shutting down Tapi');
              {$ENDIF}
              StopTapi;
            end;

          { Soft reinit -- shutdown not required }
          Line_Create :
            begin
              {$IFDEF TapiDebug}
              WriteLn(Dbg, 'Soft Reinit: Line_Create');
              {$ENDIF}
              DoLineCreate(Device, P3, 0, 0);
            end;

          { Soft reinit -- shutdown not required }
          Line_LineDevState :
            begin
              {$IFDEF TapiDebug}
              WriteLn(Dbg, 'Soft Reinit: Line_LineDevState');
              {$ENDIF}
              DoLineDevState(Device, P3, 0, 0);
            end;

          { Soft reinit -- shutdown not required }
          else begin
            {$IFDEF TapiDebug}
            WriteLn(Dbg, 'Soft Reinit: Unknown, ignored: ', P2);
            {$ENDIF}
          end;
        end;
      end else begin
        {$IFDEF TapiDebug}
        WriteLn(Dbg, 'Unhandled LineDevState: ', P1, ' ', P2, ' ', P3);
        {$ENDIF}
      end;
    end;
  end;

  procedure TApdCustomTapiDevice.DoLineCreate(Device, P1, P2, P3 : LongInt);
  begin
    if (FDeviceCount <= DWORD(P1)) then
      FDeviceCount := P1 + 1;
    EnumLineDevices;
    {$IFDEF TapiDebug}
    WriteLn(Dbg, 'Line_Create');
    {$ENDIF}
  end;

  procedure TApdCustomTapiDevice.DoLineMonitorDigits(Device, P1, P2, P3 : LongInt);
  begin
    { A digit is detected and is available as an ASCII value in the low }
    { order byte of P1. Convert ASCII to character for OnTapiDTMF event }
    TapiDTMF(Char(Lo(P1)), 0);
    TapiLogging(ltapiReceivedDigit);
  end;

  procedure TApdCustomTapiDevice.DoLineGenerate(Device, P1, P2, P3 : LongInt);
  begin
    { Do nothing, this event indicates the end of digit generation }
  end;

  procedure TApdCustomTapiDevice.DoLineMonitorMedia(Device, P1, P2, P3 : LongInt);
  begin
    { Generate the OnTapiStatus event }
    TapiStatus(False, False, Device, Line_MonitorMedia, P1, P2, P3);   
  end;

  procedure TApdCustomTapiDevice.DoLineMonitorTone(Device, P1, P2, P3 : LongInt);
  begin
    { Generate the OnTapiStatus event }
    TapiStatus(False, False, Device, Line_MonitorTone, P1, P2, P3);    
  end;

  procedure TApdCustomTapiDevice.DoLineRequest(Device, P1, P2, P3 : LongInt);
  begin
    { Generate the OnTapiStatus event }
    TapiStatus(False, False, Device, Line_Request, P1, P2, P3);        
  end;

  function TApdCustomTapiDevice.HandleLineErr(LineErr : LongInt): Boolean;
  { This is a stub in case someone wants to handle line errors }
  begin
    Result := False;

    { Async reply, return False }
    if (LineErr > Success) then begin
      Exit;
    end;

    { No error, return True }
    if (LineErr = Success) then begin
      Result := True;
      Exit;
    end;

    { Unhandled error, return False }
    { This part might be expanded on in the future }
    if (LineErr < Success) then begin
      Exit;
    end;

  end;

  function TApdCustomTapiDevice.HangupCall(AbortRetries : Boolean) : Boolean;
  var
    lReturn : LongInt;
    CloseEventPending : Boolean;
    FinalRetry : Boolean;
    Failure : Boolean;
  begin
    Result := True;
    Failure := not(Connected);

    if StoppingCall then begin
      Exit;
    end;

    if TapiInUse then begin

      {$IFDEF TapiDebug}
      WriteLn(Dbg, 'Hangup Start: ', GetTickCount);
      {$ENDIF}

      StoppingCall := True;
      try
        CloseEventPending := CloseTapiPort;

        if CallHandle <> 0 then begin

          { Only drop the call when the line is not idle }
          if TapiState <> tsIdle then begin
            repeat
              lReturn := WaitForReply(tuLineDrop(CallHandle, nil, 0));

              if (lReturn = WaitErr_WaitTimedOut) then begin
                {$IFDEF TapiDebug}
                WriteLn(Dbg, 'Wait for lineDrop timed out');
                {$ENDIF}
                Break;
              end;

              if (lReturn = WaitErr_WaitAborted) then begin
                {$IFDEF TapiDebug}
                WriteLn(Dbg, 'Wait for lineDrop aborted');
                {$ENDIF}
                Break;
              end;

              if (lReturn = LineErr_InvalCallState) then
                Break;

              if HandleLineErr(lReturn) then
                Continue
              else begin
                {$IFDEF TapiDebug}
                WriteLn(Dbg, 'Unhandled error waiting for lineDrop');
                {$ENDIF}
                Break;
              end;
            until lReturn = Success;

            lReturn := WaitForCallState(LineCallState_Idle);

            if (lReturn = WaitErr_WaitTimedOut) then begin
              {$IFDEF TapiDebug}
              WriteLn(Dbg, 'Wait for LineCallState_Idle timed out');
              {$ENDIF}
            end;

            if lReturn = WaitErr_WaitAborted then begin
              {$IFDEF TapiDebug}
              WriteLn(Dbg, 'Wait for LineCallState_Idle aborted');
              {$ENDIF}
            end;
          end;

          { The call is now idle -- deallocate it }
          repeat
            lReturn := tuLineDeallocateCall(CallHandle);
            if not HandleLineErr(lReturn) then begin
              {$IFDEF TapiDebug}
              WriteLn(Dbg, 'Error from lineDeallocateCall');
              {$ENDIF}
              Break;
            end;
          until lReturn = Success;
        end;

        { If we have a line open, close it }
        if LineHandle <> 0 then begin
          repeat
            lReturn := tuLineClose(LineHandle);
            if not HandleLineErr(lReturn) then begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -