Beispiel #1
0
        /// <summary>
        /// This picks up a call alerting at the specified destination address and returns a call handle for the picked-up call.
        /// If invoked with null for the alertingAddress parameter, a group pickup is performed. If required by the device, groupId specifies the
        /// group identifier to which the alerting station belongs.
        /// </summary>
        /// <param name="alertingAddress">Address to retrieve call from</param>
        /// <param name="groupId">Optional group ID, can be null or empty</param>
        /// <returns>New <see cref="TapiCall"/> object.</returns>
        public ITapiCall Pickup(string alertingAddress, string groupId)
        {
            uint hCall;
            int  rc = NativeMethods.linePickup(_lineOwner.Handle, _addressId, out hCall, alertingAddress, groupId);

            if (rc < 0)
            {
                throw new TapiException("linePickup failed", rc);
            }

            // Wait for the LINE_REPLY .. same reason as lineMakeCall..
            var req = new PendingTapiRequest(rc, null, null);

            _lineOwner.TapiManager.AddAsyncRequest(req);
            req.AsyncWaitHandle.WaitOne();
            if (req.Result < 0)
            {
                throw new TapiException("linePickup failed", req.Result);
            }

            var call = new TapiCall(this, hCall);

            lock (_calls)
            {
                _calls.Add(call);
            }
            return(call);
        }
Beispiel #2
0
        /// <summary>
        /// This cancels any forwarding request that is currently in effect on this address
        /// </summary>
        public void CancelForward()
        {
            uint hCall;
            int  rc = NativeMethods.lineForward(_lineOwner.Handle, 0, _addressId, IntPtr.Zero, 0, out hCall, IntPtr.Zero);

            if (rc < 0)
            {
                throw new TapiException("lineForward failed", rc);
            }

            // Wait for the LINE_REPLY so we don't need to deal with the value type
            // issues of IntPtr being filled in async.
            var req = new PendingTapiRequest(rc, null, null);

            _lineOwner.TapiManager.AddAsyncRequest(req);
            if (req.AsyncWaitHandle.WaitOne(1000, true))
            {
                if (req.Result < 0)
                {
                    throw new TapiException("lineForward failed", req.Result);
                }
                if (hCall != 0)
                {
                    NativeMethods.lineDeallocateCall(hCall);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// This retrieves a call off a parked address
        /// </summary>
        /// <param name="parkedAddress">Address to retrieve call from</param>
        /// <returns>New <see cref="TapiCall"/> object.</returns>
        public TapiCall Unpark(string parkedAddress)
        {
            uint hCall;
            int  rc = NativeMethods.lineUnpark(Line.Handle, _addressId, out hCall, parkedAddress);

            if (rc < 0)
            {
                throw new TapiException("lineUnpark failed", rc);
            }

            // Wait for the LINE_REPLY .. same reason as lineMakeCall..
            var req = new PendingTapiRequest(rc, null, null);

            Line.TapiManager.AddAsyncRequest(req);
            req.AsyncWaitHandle.WaitOne();
            if (req.Result < 0)
            {
                throw new TapiException("lineUnpark failed", req.Result);
            }

            var call = new TapiCall(this, hCall);

            lock (_calls)
            {
                _calls.Add(call);
            }
            return(call);
        }
Beispiel #4
0
        /// <summary>
        /// This method is used to establish a conference call
        /// </summary>
        /// <param name="conferenceCount"># of parties anticipated the conference</param>
        /// <param name="mcp">Call parameters for created consultation call</param>
        /// <param name="consultCall">Returning consultation call</param>
        /// <returns>Conference call</returns>
        public ITapiCall SetupConference(int conferenceCount, MakeCallParams mcp, out TapiCall consultCall)
        {
            IntPtr lpCp      = IntPtr.Zero;
            int    callFlags = 0;

            try
            {
                if (mcp != null && !String.IsNullOrEmpty(mcp.TargetAddress))
                {
                    callFlags |= NativeMethods.LINECALLPARAMFLAGS_NOHOLDCONFERENCE;
                }
                lpCp = MakeCallParams.ProcessCallParams(Id, mcp, callFlags);
                uint hCall, hConfCall;
                int  rc = NativeMethods.lineSetupConference(new HTCALL(), _lineOwner.Handle, out hConfCall, out hCall, conferenceCount, lpCp);
                if (rc < 0)
                {
                    throw new TapiException("lineSetupConference failed", rc);
                }
                else
                {
                    // Wait for the LINE_REPLY so we don't need to deal with the value type
                    // issues of IntPtr being filled in async.
                    var req = new PendingTapiRequest(rc, null, null);
                    _lineOwner.TapiManager.AddAsyncRequest(req);
                    req.AsyncWaitHandle.WaitOne();
                    if (req.Result < 0)
                    {
                        throw new TapiException("lineSetupConference failed", req.Result);
                    }

                    if (hCall != 0)
                    {
                        consultCall = new TapiCall(this, hCall);
                        AddCall(consultCall);
                    }
                    else
                    {
                        consultCall = null;
                    }

                    var confCall = new TapiCall(this, hConfCall);
                    AddCall(confCall);

                    return(confCall);
                }
            }
            finally
            {
                if (lpCp != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(lpCp);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// This forwards calls destined for this address according to the specified forwarding instructions.
        /// Any specified incoming calls for that address are deflected to the other number by the switch.
        /// This function provides a combination of forward and do-not-disturb features.
        /// </summary>
        /// <param name="forwardInstructions">The forwarding instructions to apply</param>
        /// <param name="numRingsNoAnswer">Number of rings before a call is considered a "no answer." If dwNumRingsNoAnswer is out of range, the actual value is set to the nearest value in the allowable range.</param>
        /// <param name="param">Optional call parameters - only used if a consultation call is returned; otherwise ignored.  May be null for default parameters</param>
        public ITapiCall Forward(ForwardInfo[] forwardInstructions, int numRingsNoAnswer, MakeCallParams param)
        {
            if (!Line.IsOpen)
            {
                throw new TapiException("Line is not open", NativeMethods.LINEERR_OPERATIONUNAVAIL);
            }

            IntPtr lpCp    = IntPtr.Zero;
            IntPtr fwdList = ForwardInfo.ProcessForwardList(forwardInstructions);

            try
            {
                lpCp = MakeCallParams.ProcessCallParams(_addressId, param, 0);
                uint hCall;

                int rc = NativeMethods.lineForward(_lineOwner.Handle, 0, _addressId, fwdList, numRingsNoAnswer, out hCall, lpCp);
                if (rc < 0)
                {
                    throw new TapiException("lineForward failed", rc);
                }
                else
                {
                    // Wait for the LINE_REPLY so we don't need to deal with the value type
                    // issues of IntPtr being filled in async.
                    var req = new PendingTapiRequest(rc, null, null);
                    _lineOwner.TapiManager.AddAsyncRequest(req);
                    req.AsyncWaitHandle.WaitOne();
                    if (req.Result < 0)
                    {
                        throw new TapiException("lineForward failed", req.Result);
                    }

                    if (hCall != 0)
                    {
                        var call = new TapiCall(this, hCall);
                        AddCall(call);
                        return(call);
                    }
                }
            }
            finally
            {
                if (lpCp != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(lpCp);
                }
                if (fwdList != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(fwdList);
                }
            }

            return(null);
        }
Beispiel #6
0
 internal IAsyncResult AddAsyncRequest(PendingTapiRequest req)
 {
     if (req.AsyncRequestId != 0)
     {
         lock (_requests)
         {
             _requests.Add(req);
         }
     }
     return(req);
 }
Beispiel #7
0
        /// <summary>
        /// Places a new call on the address
        /// </summary>
        /// <param name="address">Number to dial</param>
        /// <param name="countryCode">Country code</param>
        /// <param name="param">Optional <see>MakeCallParams</see> to use while dialing</param>
        /// <returns>New <see cref="TapiCall"/> object.</returns>
        public ITapiCall MakeCall(string address, int countryCode, MakeCallParams param)
        {
            if (!Line.IsOpen)
            {
                throw new TapiException("Line is not open", NativeMethods.LINEERR_OPERATIONUNAVAIL);
            }

            IntPtr lpCp = IntPtr.Zero;

            try
            {
                lpCp = MakeCallParams.ProcessCallParams(_addressId, param, 0);
                uint hCall;
                int  rc = NativeMethods.lineMakeCall(_lineOwner.Handle, out hCall, address, countryCode, lpCp);
                if (rc < 0)
                {
                    throw new TapiException("lineMakeCall failed", rc);
                }
                else
                {
                    // Wait for the LINE_REPLY so we don't need to deal with the value type
                    // issues of IntPtr being filled in async.
                    var req = new PendingTapiRequest(rc, null, null);
                    _lineOwner.TapiManager.AddAsyncRequest(req);
                    req.AsyncWaitHandle.WaitOne();
                    if (req.Result < 0)
                    {
                        throw new TapiException("lineMakeCall failed", req.Result);
                    }

                    var call = new TapiCall(this, hCall);
                    AddCall(call);
                    return(call);
                }
            }
            finally
            {
                if (lpCp != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(lpCp);
                }
            }
        }