예제 #1
0
파일: IPCast.cs 프로젝트: fflorat/IRAP
        //// 获取系统中所有终端的ID清单
        unsafe public static string GetAllTerms(string[] terms)
        {
            string termIds = "";
            // int OUT_put = 0;
            IntPtr pArray = Marshal.AllocHGlobal(0);
            int    count  = IPCast.GetTermList(pArray, 0);

            if (count > 0)
            {
                pArray = Marshal.ReAllocHGlobal(pArray, new IntPtr(count * 4));
                int ret = IPCast.GetTermList(pArray, count);        // 获取终端ID清单

                if (ret > 0)
                {
                    uint *pId = (uint *)pArray.ToPointer();
                    for (int i = 0; i < ret; i++)
                    {
                        uint tid = pId[i];
                        termIds += tid.ToString();
                        termIds += ",";
                        //获取终端状态
                        long   size          = Marshal.SizeOf(typeof(IPCast.TermAttrEx));
                        IntPtr pTermStatusEx = Marshal.AllocHGlobal((int)new IntPtr(size));

                        if (IPCast.GetTermStatusEx(tid, pTermStatusEx))
                        {
                            IPCast.TermAttrEx termAttrEx = (IPCast.TermAttrEx)Marshal.PtrToStructure(pTermStatusEx, typeof(IPCast.TermAttrEx));
                            Debug.WriteLine("termAttr.tid =" + termAttrEx.tid.ToString());
                            Debug.WriteLine("termAttr.status =" + termAttrEx.status.ToString());
                            Debug.WriteLine("termAttr.work_status =" + termAttrEx.work_status.ToString());
                            Debug.WriteLine("termAttr.call_status =" + termAttrEx.call_status.ToString());
                            Debug.WriteLine("termAttr.a_sid =" + termAttrEx.a_sid.ToString());
                            Debug.WriteLine("termAttr.vol =" + termAttrEx.vol.ToString());
                            Debug.WriteLine("termAttr.ipaddr =" + termAttrEx.ipaddr);
                            Debug.WriteLine("termAttr.fwdaddr =" + termAttrEx.fwdaddr);
                            Debug.WriteLine("termAttr.name =" + termAttrEx.name);
                            string tinfo = "tid:" + termAttrEx.tid.ToString() + " " + "name: " + termAttrEx.name + " " + "termIP: " + termAttrEx.ipaddr + " " + "vol:" + termAttrEx.vol.ToString() + "  " +
                                           "work_state:" + termAttrEx.work_status.ToString() + "Call_Status:" + termAttrEx.call_status.ToString() + " " + "a_sid:" + termAttrEx.a_sid.ToString() +
                                           "  " + "ServerIp: " + " " + termAttrEx.fwdaddr;
                            //MessageBox.Show(tinfo);

                            terms[i] = tinfo;
                        }

                        Marshal.FreeHGlobal(pTermStatusEx);
                    }
                }
                Marshal.FreeHGlobal(pArray);
            }
            termIds.Trim(',');
            return(termIds);
        }
예제 #2
0
        private bool TermsIdle(int[] terms)
        {
            bool rlt   = false;
            bool cycle = true;

            while (cycle)
            {
                cycle = false;

                for (int i = 0; i < terms.Length; i++)
                {
                    Thread.Sleep(10);

                    long   size          = Marshal.SizeOf(typeof(IPCast.TermAttrEx));
                    IntPtr pTermStatusEx = Marshal.AllocHGlobal((int)new IntPtr(size));

                    try
                    {
                        if (IPCast.GetTermStatusEx((uint)terms[i], pTermStatusEx))
                        {
                            IPCast.TermAttrEx termAttrEx =
                                (IPCast.TermAttrEx)Marshal.PtrToStructure(
                                    pTermStatusEx,
                                    typeof(IPCast.TermAttrEx));
                            if (termAttrEx.status != 0)
                            {
                                rlt   = false;
                                cycle = true;

                                break;
                            }
                            else
                            {
                                rlt = true;
                            }
                        }
                        else
                        {
                            rlt = false;
                            break;
                        }
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(pTermStatusEx);
                    }
                }
            }

            return(rlt);
        }