示例#1
0
        private void TapiThreadProc()
        {
            while (!stop)
            {
                LINEMESSAGE msg;
                if (NativeTapi.lineGetMessage(m_hLineApp, out msg, -1) == 0)
                {
                    OnMessage(msg);

                    switch (msg.dwMessageID)
                    {
                    case LINEMESSAGES.LINE_CLOSE:
                        OnLineClose(msg);
                        break;

                    case LINEMESSAGES.LINE_CALLINFO:
                        OnLineCallInfo(msg);
                        break;

                    case LINEMESSAGES.LINE_CALLSTATE:
                        OnLineCallState(msg);
                        break;

                    case LINEMESSAGES.LINE_REPLY:
                        OnLineReply(msg);
                        break;

                    case LINEMESSAGES.LINE_APPNEWCALL:
                        OnNewCall(msg);
                        break;
                    }
                }
            }
        }
示例#2
0
 /// <summary>
 /// Cleanup
 /// </summary>
 public void Dispose()
 {
     NativeTapi.lineClose(hLine);
     if (tapi.Lines.Contains(hLine))
     {
         tapi.Lines.Remove(hLine);
     }
 }
示例#3
0
        protected internal void LoadCallInfo()
        {
            m_info = new LINECALLINFO(1024);
            m_info.Store();
            int ret = NativeTapi.lineGetCallInfo(m_hCall, m_info.Data); m_info.Load();

            if (ret < 0)
            {
                throw new TapiException(ret);
            }
        }
示例#4
0
        /// <summary>
        /// Negotiates API version with TAPI for a given device
        /// </summary>
        /// <param name="deviceID">ID of the device. Must be less than <c>NumDevices</c></param>
        /// <returns>Negotiated API version</returns>
        public int NegotiateVersion(int deviceID)
        {
            int             dwApiVersion;
            LINEEXTENSIONID le;
            int             ret = NativeTapi.lineNegotiateAPIVersion(m_hLineApp, deviceID, dwAPIVersionLow, dwAPIVersionHigh, out dwApiVersion, out le);

            if (ret != 0)
            {
                throw new TapiException(ret);
            }
            return(dwApiVersion);
        }
示例#5
0
        protected internal void LoadCallState()
        {
            LINECALLSTATUS status = new LINECALLSTATUS(1024);

            status.Store();
            int ret = NativeTapi.lineGetCallStatus(m_hCall, status.Data);

            status.Load();
            if (ret < 0)
            {
                throw new TapiException(ret);
            }
            m_state = status.dwCallState;
        }
示例#6
0
        /// <summary>
        /// Opens TAPI line
        /// </summary>
        /// <param name="deviceID">ID of the device to open. Must be less than <c>NumDevices</c></param>
        /// <param name="mode">combination of <c>LINEMEDIAMODE</c> flags</param>
        /// <param name="priv">combination of <c>LINECALLPRIVILEGE</c> flags</param>
        /// <returns>Newly created Line object</returns>
        public Line CreateLine(int deviceID, LINEMEDIAMODE mode, LINECALLPRIVILEGE priv)
        {
            IntPtr hLine;
            int    ret = NativeTapi.lineOpen(m_hLineApp, deviceID, out hLine, NegotiateVersion(deviceID), 0, IntPtr.Zero, priv, mode, IntPtr.Zero);

            if (ret != 0)
            {
                throw new TapiException(ret);
            }
            Line line = new Line(this, hLine);

            Lines.Add(hLine, line);
            return(line);
        }
示例#7
0
        /// <summary>
        /// Retrieves device caps
        /// </summary>
        /// <param name="deviceID">ID of the device. Must be less than <c>NumDevices</c></param>
        /// <returns>Filled-in LINEDEVCAPS structure</returns>
        public LINEERR GetDevCaps(int deviceID, out LINEDEVCAPS dc)
        {
            dc = new LINEDEVCAPS(1024);
            dc.Store();
            int ret = NativeTapi.lineGetDevCaps(m_hLineApp, deviceID, NegotiateVersion(deviceID), 0, dc.Data);

            dc.Load();
            if ((LINEERR)ret == LINEERR.STRUCTURETOOSMALL)
            {
                dc  = new LINEDEVCAPS(dc.dwNeededSize);
                ret = NativeTapi.lineGetDevCaps(m_hLineApp, deviceID, NegotiateVersion(deviceID), 0, dc.Data);
                dc.Load();
            }
            return((LINEERR)ret);
        }
示例#8
0
        /// <summary>
        /// Asynchronous function to place a call
        /// </summary>
        /// <param name="Destination">String: phone number</param>
        /// <param name="CountryCode">int: country code, e.g. 1 for US</param>
        /// <param name="Params"><c>LINECALLPARAMS</c> structure data</param>
        /// <param name="Callback">Asynchronous callback. Will be invoked when the call is complete</param>
        /// <param name="State">User-defined state object. Can be null</param>
        /// <returns>IAsyncResult</returns>
        public IAsyncResult BeginMakeCall(string Destination, int CountryCode, /*LINECALLPARAMS*/ byte[] Params, AsyncCallback Callback, object State)
        {
            bSyncMakeCall = false;
            MakeCallAsyncResult result = new MakeCallAsyncResult(0, Callback, State);

            lock (tapi.PendingRequests.SyncRoot)
            {
                int ret = NativeTapi.lineMakeCall(m_hLine, out result.m_hCall, Destination, CountryCode, Params);
                result.ReplyID = ret;
                if (ret > 0)
                {
                    tapi.PendingRequests.Add(ret, result);
                }
            }
            return(result);
        }
示例#9
0
        /// <summary>
        /// Intialize TAPI data. Throws a TapiException if unsuccessful
        /// </summary>
        /// <returns>returns result of the call to lineInitializeEx</returns>
        public int Initialize()
        {
            // We support API version up to 2.0
            int dwApiVersion = 0x20000;
            LINEINITIALIZEEXPARAMS initParams = new LINEINITIALIZEEXPARAMS(hEvent);

            // Intialize TAPI app and throw an exception if failed
            int ret = NativeTapi.lineInitializeEx(out m_hLineApp, IntPtr.Zero, IntPtr.Zero, "MyApp", out dwNumDev, ref dwApiVersion, initParams);

            if (ret != 0)
            {
                throw new TapiException(ret);
            }

            // Start listen for events
            thTapi = new Thread(new ThreadStart(TapiThreadProc));
            thTapi.Start();

            //TODO: build device list

            return(ret);
        }
示例#10
0
        /// <summary>
        /// Stop all TAPI related activity. Perform cleanup
        /// </summary>
        public void Shutdown()
        {
            // Destroy active calls if any
            object[] arr = new object[Calls.Values.Count];
            Calls.Values.CopyTo(arr, 0);
            foreach (Call call in arr)
            {
                call.Dispose();
            }

            // Close lines
            arr = new object[Lines.Values.Count];
            Lines.Values.CopyTo(arr, 0);
            foreach (Line line in arr)
            {
                line.Dispose();
            }

            // Even though this flag is set to false, event thread will keep waiting indefinitely inside the call
            // to lineGetMessage. Calling lineShutdown will result in LINE_CLOSE being sent and thread successfully
            // terminated
            stop = true;
            NativeTapi.lineShutdown(m_hLineApp);
        }
示例#11
0
 public void Hangup()
 {
     NativeTapi.lineDrop(m_hCall, null, 0);
 }